File:  [LON-CAPA] / loncom / cgi / takeoffline.pl
Revision 1.4: download - view: text, annotated - select for diffs
Thu Dec 25 01:56:03 2008 UTC (15 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_7_99_0, HEAD
- Changes resulting from movement of subroutines from loncgi.pm
  to lonauthcgi.pm.

    1: #!/usr/bin/perl
    2: $|=1;
    3: # Take machine offline, reroute traffic
    4: #
    5: # $Id: takeoffline.pl,v 1.4 2008/12/25 01:56:03 raeburn Exp $
    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: 
   30: use strict;
   31: use lib '/home/httpd/lib/perl/';
   32: use Apache::lonlocal;
   33: use LONCAPA::loncgi;
   34: use LONCAPA::lonauthcgi;
   35: 
   36: print "Content-type: text/html\n\n";
   37: 
   38: &main();
   39: 
   40: sub main {
   41:     if (!&LONCAPA::lonauthcgi::check_ipbased_access('takeoffline')) {
   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: 
   48:         if (!&LONCAPA::lonauthcgi::can_view('takeoffline')) {
   49:             &Apache::lonlocal::get_language_handle();
   50:             print(&LONCAPA::lonauthcgi::unauthorized_msg('takeoffline'));
   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:     }
   81: }
   82: 
   83: sub dead {
   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;
   90: }
   91: 
   92: sub reroute {
   93:     my ($otherserver,$domain) = @_;
   94:     if (open (OUT,'>/home/httpd/html/index.html')) {
   95:         print OUT (<<ENDNEWINDEX);
   96: <html>
   97:  <head>
   98:   <title>Welcome to the LearningOnline Network with CAPA</title>
   99:   <meta HTTP-EQUIV="Refresh" CONTENT="0.5; url=http://$otherserver/adm/login?domain=$domain">
  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
  104: <a href="http://$otherserver/adm/login?domain=$domain"><font color="#FFFFFF">http://$otherserver/</font></a></font></p>
  105: </body>
  106: </html>
  107: ENDNEWINDEX
  108:        close(OUT);
  109:        return 'ok';
  110:     }
  111:     return;
  112: }

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