Annotation of loncom/cgi/takeoffline.pl, revision 1.3

1.1       www         1: #!/usr/bin/perl
1.3     ! raeburn     2: $|=1;
1.1       www         3: # Take machine offline, reroute traffic
                      4: #
1.3     ! raeburn     5: # $Id: takeoffline.pl,v 1.2 2003/09/11 20:54:11 www 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;
        !            34: 
        !            35: print "Content-type: text/html\n\n";
        !            36: 
        !            37: &main();
        !            38: 
        !            39: sub main {
        !            40:     if (!&LONCAPA::loncgi::check_ipbased_access('takeoffline')) {
        !            41:         if (!&LONCAPA::loncgi::check_cookie_and_load_env()) {
        !            42:             &Apache::lonlocal::get_language_handle();
        !            43:             print(&LONCAPA::loncgi::missing_cookie_msg());
        !            44:             return;
        !            45:         }
        !            46: 
        !            47:         if (!&LONCAPA::loncgi::can_view('takeoffline')) {
        !            48:             &Apache::lonlocal::get_language_handle();
        !            49:             print(&LONCAPA::loncgi::unauthorized_msg('takeoffline'));
        !            50:             return;
        !            51:         }
        !            52:     }
        !            53: 
        !            54:     &Apache::lonlocal::get_language_handle();
        !            55: 
        !            56:     print '<html><body bgcolor="#FFFFFF"><h1>'.&Apache::lonlocal::mt('Take Offline').'</h1>';
        !            57:     my $statusmsg;
        !            58:     if ($ENV{'QUERY_STRING'}) {
        !            59:         my ($otherserver,$domain)=split(/\&/,$ENV{'QUERY_STRING'});
        !            60:         if (&reroute($otherserver,$domain)) {
        !            61:             print &Apache::lonlocal::mt('Rerouting to [_1]',$otherserver);
        !            62:             $statusmsg = "status=rerouting&server=$otherserver&domain=$domain&time=".time.
        !            63:                          "by=$Apache::lonnet::env{'user.name'}:$Apache::lonnet::env{'user.domain'}";
        !            64:         }
        !            65:     } else {
        !            66:         if (&dead()) {
        !            67:             print &Apache::lonlocal::mt('No reroute server given, taking completely offline.');
        !            68:             $statusmsg = 'status=offline&time='.time."by=$Apache::lonnet::env{'user.name'}:$Apache::lonnet::env{'user.domain'}"
        !            69:         }
        !            70:     }
        !            71:     print "</body></html>";
        !            72:     if ($statusmsg) {
        !            73:         if (open (STATUS,'>/home/httpd/html/lon-status/reroute.txt')) {
        !            74:             print STATUS "$statusmsg\n";
        !            75:             close(STATUS);
        !            76:         } else {
        !            77:             print &Apache::lonlocal::mt('Logging of status change to [_1] failed.','reroute.txt'); 
        !            78:         }
        !            79:     }
1.1       www        80: }
                     81: 
                     82: sub dead {
1.3     ! raeburn    83:     if (open (OUT,'>/home/httpd/html/index.html')) {
        !            84:         print OUT &Apache::lonlocal::mt('This LON-CAPA server is currently offline.');
        !            85:         close(OUT);
        !            86:         return 'ok';
        !            87:     }
        !            88:     return;
1.1       www        89: }
                     90: 
                     91: sub reroute {
1.3     ! raeburn    92:     my ($otherserver,$domain) = @_;
        !            93:     if (open (OUT,'>/home/httpd/html/index.html')) {
        !            94:         print OUT (<<ENDNEWINDEX);
1.1       www        95: <html>
                     96:  <head>
                     97:   <title>Welcome to the LearningOnline Network with CAPA</title>
1.2       www        98:   <meta HTTP-EQUIV="Refresh" CONTENT="0.5; url=http://$otherserver/adm/login?domain=$domain">
1.1       www        99:  </head>
                    100:  <body bgcolor="#004400" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
                    101:   <img src="/adm/lonIcons/header.gif" />
                    102: <p><font color="#FFFFFF">Connecting to
1.2       www       103: <a href="http://$otherserver/adm/login?domain=$domain"><font color="#FFFFFF">http://$otherserver/</font></a></font></p>
1.1       www       104: </body>
                    105: </html>
                    106: ENDNEWINDEX
1.3     ! raeburn   107:        close(OUT);
        !           108:        return 'ok';
        !           109:     }
        !           110:     return;
1.1       www       111: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>