--- loncom/cgi/takeoffline.pl 2010/03/22 20:11:15 1.7 +++ loncom/cgi/takeoffline.pl 2015/01/21 15:12:03 1.8 @@ -2,7 +2,7 @@ $|=1; # Take machine offline, reroute traffic # -# $Id: takeoffline.pl,v 1.7 2010/03/22 20:11:15 droeschl Exp $ +# $Id: takeoffline.pl,v 1.8 2015/01/21 15:12:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,6 +31,7 @@ use strict; use lib '/home/httpd/lib/perl/'; use Apache::lonlocal; use Apache::loncommon; +use Apache::lonnet; use LONCAPA::loncgi; use LONCAPA::lonauthcgi; @@ -61,6 +62,7 @@ sub main { } else { my $js = < +// ENDJS print &Apache::loncommon::start_page('Take Offline',$js); @@ -78,7 +81,6 @@ ENDJS } sub phaseone { -# print ' print '

'.&Apache::lonlocal::mt('Take Offline').'

'; my ($is_dc,@okmachines,%servers); my @poss_domains = &Apache::lonnet::current_machine_domains(); @@ -98,14 +100,14 @@ sub phaseone { } 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:"). + 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 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("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) { @@ -119,7 +121,7 @@ sub phaseone { if ($ENV{'QUERY_STRING'}) { ($otherserver,$domain)=split(/\&/,$ENV{'QUERY_STRING'}); } - print '


    '; + print '
    '; my $options; if ($domain) { @@ -129,11 +131,10 @@ sub phaseone { next if ($hostid eq $lonhost); my $selchk = ''; if ($otherserver eq $hostid) { - $selchk = 'selected="selected"'; + $selchk = ' selected="selected"'; } $options .= - "'."\n"; + "\n"; } } } @@ -147,11 +148,10 @@ sub phaseone { $allhosts{$hostid} = 1; my $selchk = ''; if ($otherserver eq $hostid) { - $selchk = 'selected="selected"'; + $selchk = ' selected="selected"'; } - $options .= - "'; + $options .= + "\n"; } } } @@ -171,10 +171,11 @@ sub phasetwo { my ($reroute) = @_; print '

    '.&Apache::lonlocal::mt('Take Offline').'

    '; my $statusmsg; - if ($reroute) { + if ($reroute ne '') { my ($otherserver,$domain)=split(/\&/,$reroute); - if (&reroute($otherserver,$domain)) { - print &Apache::lonlocal::mt('Rerouting to [_1]',$otherserver); + my $otherhostname = &reroute($otherserver,$domain); + if ($otherhostname ne '') { + print &Apache::lonlocal::mt('Rerouting to [_1]',$otherhostname); $statusmsg = "status=rerouting&server=$otherserver&domain=$domain&time=".time. "by=$Apache::lonnet::env{'user.name'}:$Apache::lonnet::env{'user.domain'}"; } @@ -205,22 +206,30 @@ sub dead { sub reroute { my ($otherserver,$domain) = @_; - if (open (OUT,'>/home/httpd/html/index.html')) { - print OUT (< + my $otherhostname = &Apache::lonnet::hostname($otherserver); + my $protocol = $Apache::lonnet::protocol{$otherserver}; + $protocol = 'http' if ($protocol ne 'https'); + if ($otherhostname ne '') { + if (open (OUT,'>/home/httpd/html/index.html')) { + print OUT (< + Welcome to the LearningOnline Network with CAPA - + + + - - -

    Connecting to -http://$otherserver/

    + + loncapa banner +

    Connecting to +$protocol://$otherhostname/

    ENDNEWINDEX - close(OUT); - return 'ok'; + close(OUT); + return $otherhostname; + } } return; }