Annotation of loncom/cgi/takeoffline.pl, revision 1.4
1.1 www 1: #!/usr/bin/perl
1.3 raeburn 2: $|=1;
1.1 www 3: # Take machine offline, reroute traffic
4: #
1.4 ! raeburn 5: # $Id: takeoffline.pl,v 1.3 2008/11/28 20:50:25 raeburn Exp $
1.1 www 6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
29:
1.3 raeburn 30: use strict;
31: use lib '/home/httpd/lib/perl/';
32: use Apache::lonlocal;
33: use LONCAPA::loncgi;
1.4 ! raeburn 34: use LONCAPA::lonauthcgi;
1.3 raeburn 35:
36: print "Content-type: text/html\n\n";
37:
38: &main();
39:
40: sub main {
1.4 ! raeburn 41: if (!&LONCAPA::lonauthcgi::check_ipbased_access('takeoffline')) {
1.3 raeburn 42: if (!&LONCAPA::loncgi::check_cookie_and_load_env()) {
43: &Apache::lonlocal::get_language_handle();
44: print(&LONCAPA::loncgi::missing_cookie_msg());
45: return;
46: }
47:
1.4 ! raeburn 48: if (!&LONCAPA::lonauthcgi::can_view('takeoffline')) {
1.3 raeburn 49: &Apache::lonlocal::get_language_handle();
1.4 ! raeburn 50: print(&LONCAPA::lonauthcgi::unauthorized_msg('takeoffline'));
1.3 raeburn 51: return;
52: }
53: }
54:
55: &Apache::lonlocal::get_language_handle();
56:
57: print '<html><body bgcolor="#FFFFFF"><h1>'.&Apache::lonlocal::mt('Take Offline').'</h1>';
58: my $statusmsg;
59: if ($ENV{'QUERY_STRING'}) {
60: my ($otherserver,$domain)=split(/\&/,$ENV{'QUERY_STRING'});
61: if (&reroute($otherserver,$domain)) {
62: print &Apache::lonlocal::mt('Rerouting to [_1]',$otherserver);
63: $statusmsg = "status=rerouting&server=$otherserver&domain=$domain&time=".time.
64: "by=$Apache::lonnet::env{'user.name'}:$Apache::lonnet::env{'user.domain'}";
65: }
66: } else {
67: if (&dead()) {
68: print &Apache::lonlocal::mt('No reroute server given, taking completely offline.');
69: $statusmsg = 'status=offline&time='.time."by=$Apache::lonnet::env{'user.name'}:$Apache::lonnet::env{'user.domain'}"
70: }
71: }
72: print "</body></html>";
73: if ($statusmsg) {
74: if (open (STATUS,'>/home/httpd/html/lon-status/reroute.txt')) {
75: print STATUS "$statusmsg\n";
76: close(STATUS);
77: } else {
78: print &Apache::lonlocal::mt('Logging of status change to [_1] failed.','reroute.txt');
79: }
80: }
1.1 www 81: }
82:
83: sub dead {
1.3 raeburn 84: if (open (OUT,'>/home/httpd/html/index.html')) {
85: print OUT &Apache::lonlocal::mt('This LON-CAPA server is currently offline.');
86: close(OUT);
87: return 'ok';
88: }
89: return;
1.1 www 90: }
91:
92: sub reroute {
1.3 raeburn 93: my ($otherserver,$domain) = @_;
94: if (open (OUT,'>/home/httpd/html/index.html')) {
95: print OUT (<<ENDNEWINDEX);
1.1 www 96: <html>
97: <head>
98: <title>Welcome to the LearningOnline Network with CAPA</title>
1.2 www 99: <meta HTTP-EQUIV="Refresh" CONTENT="0.5; url=http://$otherserver/adm/login?domain=$domain">
1.1 www 100: </head>
101: <body bgcolor="#004400" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
102: <img src="/adm/lonIcons/header.gif" />
103: <p><font color="#FFFFFF">Connecting to
1.2 www 104: <a href="http://$otherserver/adm/login?domain=$domain"><font color="#FFFFFF">http://$otherserver/</font></a></font></p>
1.1 www 105: </body>
106: </html>
107: ENDNEWINDEX
1.3 raeburn 108: close(OUT);
109: return 'ok';
110: }
111: return;
1.1 www 112: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>