--- loncom/cgi/takeoffline.pl 2008/12/25 01:56:03 1.4
+++ loncom/cgi/takeoffline.pl 2009/04/23 17:29:58 1.6
@@ -2,7 +2,7 @@
$|=1;
# Take machine offline, reroute traffic
#
-# $Id: takeoffline.pl,v 1.4 2008/12/25 01:56:03 raeburn Exp $
+# $Id: takeoffline.pl,v 1.6 2009/04/23 17:29:58 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,6 +30,7 @@ $|=1;
use strict;
use lib '/home/httpd/lib/perl/';
use Apache::lonlocal;
+use Apache::loncommon;
use LONCAPA::loncgi;
use LONCAPA::lonauthcgi;
@@ -51,13 +52,129 @@ sub main {
return;
}
}
-
&Apache::lonlocal::get_language_handle();
- print '
+
+function setphase(form) {
+ var subaction = '/cgi-bin/takeoffline.pl?phase=two';
+ form.action = subaction+'&'+form.rerouteto.options[form.rerouteto.selectedIndex].value;
+ form.submit();
+}
+
+
+ENDJS
+ print &Apache::loncommon::start_page('Take Offline',$js,
+ {'no_inline_link' => 1,});
+ &phaseone();
+ }
+ print &Apache::loncommon::end_page();
+ return;
+}
+
+sub phaseone {
+# print '
+ print ''.&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("When a LON-CAPA server is 'taken offline' using this utility, the standard log-in page will be replaced with one of the following:").
+ '
- '.&mt('A page which automatically performs a redirect to another server in your domain - the server must be specified below.').'
'.
+ '- '.&mt('A page which announces that this LON-CAPA server is offline.').'
';
+ 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('The loopback device - 127.0.0.1 (localhost) - for times when you are web browsing from the server itself.').'
'.
+ '- '.&mt("Specified IP addresses set via the configuration for [_1]Access to Server Status Pages[_2] for domain(s) hosted on the server.",'','').'
'.
+ &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").'
';
+ if ($ip eq '127.0.0.1') {
+ print ''.&mt('You are accessing this page from the loopback device.').'
';
+ } elsif (!@okmachines) {
+ print ''.&mt("IP-based access to the 'take online' page is currently unavailable, as no IP addresses have been specified.").'
';
+ } elsif (!grep(/^\Q$ip\E$/,@okmachines)) {
+ print ''.&mt("Your current IP [_1] is not among those configured to have IP-based access to the 'take online' utility.",$ip).'
';
+ } else {
+ print ''.&mt("Your current IP [_1] is configured to have IP-based access to the 'take online' utility.",$ip).'
';
+ }
+ my (%allhosts,$otherserver,$domain);
if ($ENV{'QUERY_STRING'}) {
- my ($otherserver,$domain)=split(/\&/,$ENV{'QUERY_STRING'});
+ ($otherserver,$domain)=split(/\&/,$ENV{'QUERY_STRING'});
+ }
+ print '
'."\n";
+}
+
+sub phasetwo {
+ my ($reroute) = @_;
+ print ''.&Apache::lonlocal::mt('Take Offline').'
';
+ my $statusmsg;
+ if ($reroute) {
+ my ($otherserver,$domain)=split(/\&/,$reroute);
if (&reroute($otherserver,$domain)) {
print &Apache::lonlocal::mt('Rerouting to [_1]',$otherserver);
$statusmsg = "status=rerouting&server=$otherserver&domain=$domain&time=".time.
@@ -69,13 +186,12 @@ sub main {
$statusmsg = 'status=offline&time='.time."by=$Apache::lonnet::env{'user.name'}:$Apache::lonnet::env{'user.domain'}"
}
}
- print "";
if ($statusmsg) {
if (open (STATUS,'>/home/httpd/html/lon-status/reroute.txt')) {
print STATUS "$statusmsg\n";
close(STATUS);
} else {
- print &Apache::lonlocal::mt('Logging of status change to [_1] failed.','reroute.txt');
+ print &Apache::lonlocal::mt('Logging of status change to [_1] failed.','/home/httpd/html/lon-status/reroute.txt');
}
}
}
@@ -98,7 +214,7 @@ sub reroute {
Welcome to the LearningOnline Network with CAPA
-
+
Connecting to
http://$otherserver/