#!/usr/bin/perl
$|=1;
# Take machine offline, reroute traffic
#
# $Id: takeoffline.pl,v 1.6 2009/04/23 17:29:58 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
use strict;
use lib '/home/httpd/lib/perl/';
use Apache::lonlocal;
use Apache::loncommon;
use LONCAPA::loncgi;
use LONCAPA::lonauthcgi;
print "Content-type: text/html\n\n";
&main();
sub main {
if (!&LONCAPA::lonauthcgi::check_ipbased_access('takeoffline')) {
if (!&LONCAPA::loncgi::check_cookie_and_load_env()) {
&Apache::lonlocal::get_language_handle();
print(&LONCAPA::loncgi::missing_cookie_msg());
return;
}
if (!&LONCAPA::lonauthcgi::can_view('takeoffline')) {
&Apache::lonlocal::get_language_handle();
print(&LONCAPA::lonauthcgi::unauthorized_msg('takeoffline'));
return;
}
}
&Apache::lonlocal::get_language_handle();
if ($ENV{'QUERY_STRING'} =~ /^phase\=two\&?(.*)$/) {
my $reroute = $1;
print &Apache::loncommon::start_page('Take Offline','',
{'no_inline_link' => 1,});
&phasetwo($reroute);
} else {
my $js = < '.&mt("When a LON-CAPA server is 'taken offline' using this utility, the standard log-in page will be replaced with one of the following:").
''.&Apache::lonlocal::mt('Take Offline').'
';
my ($is_dc,@okmachines,%servers);
my @poss_domains = &Apache::lonnet::current_machine_domains();
foreach my $dom (@poss_domains) {
if ($Apache::lonnet::env{'request.role'} eq "dc./$dom/") {
$is_dc = 1;
}
my %domconfig = &Apache::lonnet::get_dom('configuration',['serverstatuses'],$dom);
if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
if (ref($domconfig{'serverstatuses'}{'takeonline'}) eq 'HASH') {
if ($domconfig{'serverstatuses'}{'takeonline'}{'machines'} ne '') {
@okmachines = split(/,/,$domconfig{'serverstatuses'}{'takeonline'}{'machines'});
}
}
}
%{$servers{$dom}} = &Apache::lonnet::get_servers($dom);
}
my $ip = $ENV{'REMOTE_ADDR'};
my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
print '
'.&mt("Once a server is offline, the [_1]'take online'[_2] utility can be used to reverse this, but you should verify that you will still be able to access that script once the server is in an offline state.",'','').'
'; print ''.&mt("In common with other Domain Status pages the 'take online' script is accessible from certain IP addresses:").'
'.
&mt("Once the server is offline you will not be able to log-in directly to select a Domain Coordinator role to use the 'Take online' script, unless IP-based controls provide your access.").'
'.&mt("However, you will be able to log-in to a different server in the LON-CAPA network, select a Domain Coordinator role in this server's domain, and then use: [_1] to migrate you session to this machine.","
/adm/switchserver?otherserver=$lonhost").'
Connecting to http://$otherserver/
ENDNEWINDEX close(OUT); return 'ok'; } return; }