Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.11 and 1.175

version 1.158.2.11, 2020/10/26 02:00:13 version 1.175, 2018/12/02 14:55:59
Line 1 Line 1
 # The LearningOnline Network  # The LearningOnline Network
 # Login Screen  # Login Screen
 #  #
 # $Id$  # $Id$
 #  #
 # Copyright Michigan State University Board of Trustees  # Copyright Michigan State University Board of Trustees
 #  #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).  # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
 #  #
 # LON-CAPA is free software; you can redistribute it and/or modify  # 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  # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or  # the Free Software Foundation; either version 2 of the License, or
 # (at your option) any later version.  # (at your option) any later version.
 #  #
 # LON-CAPA is distributed in the hope that it will be useful,  # LON-CAPA is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of  # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.  # GNU General Public License for more details.
 #  #
 # You should have received a copy of the GNU General Public License  # You should have received a copy of the GNU General Public License
 # along with LON-CAPA; if not, write to the Free Software  # along with LON-CAPA; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #  #
 # /home/httpd/html/adm/gpl.txt  # /home/httpd/html/adm/gpl.txt
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
   
 package Apache::lonlogin;  package Apache::lonlogin;
   
 use strict;  use strict;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::File ();  use Apache::File ();
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonauth();  use Apache::lonauth();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::migrateuser();  use Apache::migrateuser();
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA;
 use CGI::Cookie();  use CGI::Cookie();
     
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
   
     &Apache::loncommon::get_unprocessed_cgi      &Apache::loncommon::get_unprocessed_cgi
  (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},   (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
       $ENV{'REDIRECT_QUERY_STRING'}),        $ENV{'REDIRECT_QUERY_STRING'}),
  ['interface','username','domain','firsturl','localpath','localres',   ['interface','username','domain','firsturl','localpath','localres',
   'token','role','symb','iptoken','btoken']);    'token','role','symb','iptoken']);
     if (!defined($env{'form.firsturl'})) {      if (!defined($env{'form.firsturl'})) {
         &Apache::lonacc::get_posted_cgi($r,['firsturl']);          &Apache::lonacc::get_posted_cgi($r,['firsturl']);
     }      }
       if (!defined($env{'form.firsturl'})) {
 # -- check if they are a migrating user          if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {
     if (defined($env{'form.token'})) {              $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};
  return &Apache::migrateuser::handler($r);          }
     }      }
   
 # For "public user" - remove any exising "public" cookie, as user really wants to log-in  # -- check if they are a migrating user
     my ($handle,$lonidsdir,$expirepub,$userdom);      if (defined($env{'form.token'})) {
     $lonidsdir=$r->dir_config('lonIDsDir');   return &Apache::migrateuser::handler($r);
     unless ($r->header_only) {      }
         $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);  
         if ($handle ne '') {  # For "public user" - remove any exising "public" cookie, as user really wants to log-in
             if ($handle=~/^publicuser\_/) {      my ($handle,$lonidsdir,$expirepub,$userdom);
                 unlink($r->dir_config('lonIDsDir')."/$handle.id");      unless ($r->header_only) {
                 undef($handle);          $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
                 undef($userdom);          if ($handle ne '') {
                 $expirepub = 1;              $lonidsdir=$r->dir_config('lonIDsDir');
             }              if ($handle=~/^publicuser\_/) {
         }                  unlink($r->dir_config('lonIDsDir')."/$handle.id");
     }                  undef($handle);
                   undef($userdom);
     &Apache::loncommon::no_cache($r);                  $expirepub = 1;
     &Apache::lonlocal::get_language_handle($r);              }
     &Apache::loncommon::content_type($r,'text/html');          }
     if ($expirepub) {      }
         my $c = new CGI::Cookie(-name    => 'lonPubID',  
                                 -value   => '',      &Apache::loncommon::no_cache($r);
                                 -expires => '-10y',);      &Apache::lonlocal::get_language_handle($r);
         $r->header_out('Set-cookie' => $c);      &Apache::loncommon::content_type($r,'text/html');
     } elsif (($handle eq '') && ($userdom ne '')) {      if ($expirepub) {
         my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));          my $c = new CGI::Cookie(-name    => 'lonPubID',
         foreach my $name (keys(%cookies)) {                                  -value   => '',
             next unless ($name =~ /^lon(|S|Link|Pub)ID$/);                                  -expires => '-10y',);
             my $c = new CGI::Cookie(-name    => $name,          $r->header_out('Set-cookie' => $c);
                                     -value   => '',      } elsif (($handle eq '') && ($userdom ne '')) {
                                     -expires => '-10y',);          my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
             $r->headers_out->add('Set-cookie' => $c);          foreach my $name (keys(%cookies)) {
         }              next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
     }              my $c = new CGI::Cookie(-name    => $name,
     $r->send_http_header;                                      -value   => '',
     return OK if $r->header_only;                                      -expires => '-10y',);
               $r->headers_out->add('Set-cookie' => $c);
           }
 # Are we re-routing?      }
     my $londocroot = $r->dir_config('lonDocRoot');       $r->send_http_header;
     if (-e "$londocroot/lon-status/reroute.txt") {      return OK if $r->header_only;
  &Apache::lonauth::reroute($r);  
  return OK;  
     }  # Are we re-routing?
       my $londocroot = $r->dir_config('lonDocRoot');
     my $lonhost = $r->dir_config('lonHostID');      if (-e "$londocroot/lon-status/reroute.txt") {
     $env{'form.firsturl'} =~ s/(`)/'/g;   &Apache::lonauth::reroute($r);
    return OK;
 # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)      }
   
     my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);      $env{'form.firsturl'} =~ s/(`)/'/g;
     if ($found_server) {  
         my $hostname = &Apache::lonnet::hostname($found_server);  # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
         if ($hostname ne '') {  
             my $protocol = $Apache::lonnet::protocol{$found_server};      my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
             $protocol = 'http' if ($protocol ne 'https');      if ($found_server) {
             my $dest = '/adm/roles';          my $hostname = &Apache::lonnet::hostname($found_server);
             if ($env{'form.firsturl'} ne '') {          if ($hostname ne '') {
                 $dest = $env{'form.firsturl'};              my $protocol = $Apache::lonnet::protocol{$found_server};
             }              $protocol = 'http' if ($protocol ne 'https');
             my %info = (              my $dest = '/adm/roles';
                          balcookie => $lonhost.':'.$balancer_cookie,              if ($env{'form.firsturl'} ne '') {
                        );                  $dest = $env{'form.firsturl'};
             my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);              }
             if ($balancer_token) {              my $url = $protocol.'://'.$hostname.$dest;
                 $dest .=  (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;              my $start_page =
             }                  &Apache::loncommon::start_page('Switching Server ...',undef,
             my $url = $protocol.'://'.$hostname.$dest;                                                 {'redirect'       => [0,$url],});
             my $start_page =              my $end_page   = &Apache::loncommon::end_page();
                 &Apache::loncommon::start_page('Switching Server ...',undef,              $r->print($start_page.$end_page);
                                                {'redirect'       => [0,$url],});              return OK;
             my $end_page   = &Apache::loncommon::end_page();          }
             $r->print($start_page.$end_page);      }
             return OK;  
         }  #
     }  # If browser sent an old cookie for which the session file had been removed
   # check if configuration for user's domain has a portal URL set.  If so
 #  # switch user's log-in to the portal.
 # Check if a LON-CAPA load balancer sent user here because user's browser sent  #
 # it a balancer cookie for an active session on this server.  
 #      if (($handle eq '') && ($userdom ne '')) {
           my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
     my $balcookie;          if ($domdefaults{'portal_def'} =~ /^https?\:/) {
     if ($env{'form.btoken'}) {              my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
         my %info = &Apache::lonnet::tmpget($env{'form.btoken'});                                            {'redirect' => [0,$domdefaults{'portal_def'}],});
         $balcookie = $info{'balcookie'};              my $end_page   = &Apache::loncommon::end_page();
         &Apache::lonnet::tmpdel($env{'form.btoken'});              $r->print($start_page.$end_page);
         delete($env{'form.btoken'});              return OK;
     }          }
       }
 #  
 # If browser sent an old cookie for which the session file had been removed  # -------------------------------- Prevent users from attempting to login twice
 # check if configuration for user's domain has a portal URL set.  If so      if ($handle ne '') {
 # switch user's log-in to the portal.          &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
 #   my $start_page =
       &Apache::loncommon::start_page('Already logged in');
     if (($handle eq '') && ($userdom ne '')) {   my $end_page =
         my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);      &Apache::loncommon::end_page();
         if ($domdefaults{'portal_def'} =~ /^https?\:/) {          my $dest = '/adm/roles';
             my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,          if ($env{'form.firsturl'} ne '') {
                                           {'redirect' => [0,$domdefaults{'portal_def'}],});              $dest = $env{'form.firsturl'};
             my $end_page   = &Apache::loncommon::end_page();          }
             $r->print($start_page.$end_page);   $r->print(
             return OK;                    $start_page
         }                   .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
     }                   .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
                     '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
     $env{'form.firsturl'} =~ s/(`)/'/g;                   .$end_page
                    );
 # -------------------------------- Prevent users from attempting to login twice          return OK;
     if ($handle ne '') {      }
         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);  
  my $start_page =   # ---------------------------------------------------- No valid token, continue
     &Apache::loncommon::start_page('Already logged in');  
  my $end_page =   # ---------------------------- Not possible to really login to domain "public"
     &Apache::loncommon::end_page();      if ($env{'form.domain'} eq 'public') {
         my $dest = '/adm/roles';   $env{'form.domain'}='';
         if ($env{'form.firsturl'} ne '') {   $env{'form.username'}='';
             $dest = $env{'form.firsturl'};       }
         }  
  $r->print(  # ------ Is this page requested because /adm/migrateuser detected an IP change?
               $start_page      my %sessiondata;
              .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'      if ($env{'form.iptoken'}) {
              .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',          %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
               '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'          unless ($sessiondata{'sessionserver'}) {
              .$end_page              my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
              );              delete($env{'form.iptoken'});
         return OK;          }
     }      }
   # ----------------------------------------------------------- Process Interface
 # ---------------------------------------------------- No valid token, continue      $env{'form.interface'}=~s/\W//g;
   
 # ---------------------------- Not possible to really login to domain "public"      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
     if ($env{'form.domain'} eq 'public') {          &Apache::loncommon::decode_user_agent();
  $env{'form.domain'}='';  
  $env{'form.username'}='';      my $iconpath=
     }   &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
   
 # ------ Is this page requested because /adm/migrateuser detected an IP change?      my $lonhost = $r->dir_config('lonHostID');
     my %sessiondata;      my $domain = &Apache::lonnet::default_login_domain();
     if ($env{'form.iptoken'}) {      my $defdom = $domain;
         %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});      if ($lonhost ne '') {
         unless ($sessiondata{'sessionserver'}) {          unless ($sessiondata{'sessionserver'}) {
             my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});              my $redirect = &check_loginvia($domain,$lonhost);
             delete($env{'form.iptoken'});              if ($redirect) {
         }                  $r->print($redirect);
     }                  return OK;
 # ----------------------------------------------------------- Process Interface              }
     $env{'form.interface'}=~s/\W//g;          }
       }
     (undef,undef,undef,undef,undef,undef,my $clientmobile) =  
         &Apache::loncommon::decode_user_agent();      if (($sessiondata{'domain'}) &&
           (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
     my $iconpath=           $domain=$sessiondata{'domain'};
  &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));      } elsif (($env{'form.domain'}) &&
    (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
     my $domain = &Apache::lonnet::default_login_domain();   $domain=$env{'form.domain'};
     my $defdom = $domain;      }
     if ($lonhost ne '') {  
         unless ($sessiondata{'sessionserver'}) {      my $role    = $r->dir_config('lonRole');
             my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);      my $loadlim = $r->dir_config('lonLoadLim');
             if ($redirect) {      my $uloadlim= $r->dir_config('lonUserLoadLim');
                 $r->print($redirect);      my $servadm = $r->dir_config('lonAdmEMail');
                 return OK;      my $tabdir  = $r->dir_config('lonTabDir');
             }      my $include = $r->dir_config('lonIncludes');
         }      my $expire  = $r->dir_config('lonExpire');
     }      my $version = $r->dir_config('lonVersion');
       my $host_name = &Apache::lonnet::hostname($lonhost);
     if (($sessiondata{'domain'}) &&  
         (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {  # --------------------------------------------- Default values for login fields
         $domain=$sessiondata{'domain'};     
     } elsif (($env{'form.domain'}) &&       my ($authusername,$authdomain);
  (&Apache::lonnet::domain($env{'form.domain'},'description'))) {      if ($sessiondata{'username'}) {
  $domain=$env{'form.domain'};          $authusername=$sessiondata{'username'};
     }      } else {
           $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
     my $role    = $r->dir_config('lonRole');          $authusername=($env{'form.username'}?$env{'form.username'}:'');
     my $loadlim = $r->dir_config('lonLoadLim');      }
     my $uloadlim= $r->dir_config('lonUserLoadLim');      if ($sessiondata{'domain'}) {
     my $servadm = $r->dir_config('lonAdmEMail');          $authdomain=$sessiondata{'domain'};
     my $tabdir  = $r->dir_config('lonTabDir');      } else {
     my $include = $r->dir_config('lonIncludes');          $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
     my $expire  = $r->dir_config('lonExpire');          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
     my $version = $r->dir_config('lonVersion');      }
     my $host_name = &Apache::lonnet::hostname($lonhost);  
   # ---------------------------------------------------------- Determine own load
 # --------------------------------------------- Default values for login fields      my $loadavg;
           {
     my ($authusername,$authdomain);   my $loadfile=Apache::File->new('/proc/loadavg');
     if ($sessiondata{'username'}) {   $loadavg=<$loadfile>;
         $authusername=$sessiondata{'username'};      }
     } else {      $loadavg =~ s/\s.*//g;
         $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});  
         $authusername=($env{'form.username'}?$env{'form.username'}:'');      my ($loadpercent,$userloadpercent);
     }      if ($loadlim) {
     if ($sessiondata{'domain'}) {          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
         $authdomain=$sessiondata{'domain'};      }
     } else {      if ($uloadlim) {
         $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});          $userloadpercent=&Apache::lonnet::userload();
         $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);      }
     }  
       my $firsturl=
 # ---------------------------------------------------------- Determine own load      ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
     my $loadavg;  
     {  # ----------------------------------------------------------- Get announcements
  my $loadfile=Apache::File->new('/proc/loadavg');      my $announcements=&Apache::lonnet::getannounce();
  $loadavg=<$loadfile>;  # -------------------------------------------------------- Set login parameters
     }  
     $loadavg =~ s/\s.*//g;      my @hexstr=('0','1','2','3','4','5','6','7',
                   '8','9','a','b','c','d','e','f');
     my ($loadpercent,$userloadpercent);      my $lkey='';
     if ($loadlim) {      for (0..7) {
         $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);          $lkey.=$hexstr[rand(15)];
     }      }
     if ($uloadlim) {  
         $userloadpercent=&Apache::lonnet::userload();      my $ukey='';
     }      for (0..7) {
           $ukey.=$hexstr[rand(15)];
     my $firsturl=      }
     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});  
       my $lextkey=hex($lkey);
 # ----------------------------------------------------------- Get announcements      if ($lextkey>2147483647) { $lextkey-=4294967296; }
     my $announcements=&Apache::lonnet::getannounce();  
 # -------------------------------------------------------- Set login parameters      my $uextkey=hex($ukey);
       if ($uextkey>2147483647) { $uextkey-=4294967296; }
     my @hexstr=('0','1','2','3','4','5','6','7',  
                 '8','9','a','b','c','d','e','f');  # -------------------------------------------------------- Store away log token
     my $lkey='';      my $tokenextras;
     for (0..7) {      if ($env{'form.role'}) {
         $lkey.=$hexstr[rand(15)];          $tokenextras = '&role='.&escape($env{'form.role'});
     }      }
       if ($env{'form.symb'}) {
     my $ukey='';          if (!$tokenextras) {
     for (0..7) {              $tokenextras = '&';
         $ukey.=$hexstr[rand(15)];          }
     }          $tokenextras .= '&symb='.&escape($env{'form.symb'});
       }
     my $lextkey=hex($lkey);      if ($env{'form.iptoken'}) {
     if ($lextkey>2147483647) { $lextkey-=4294967296; }          if (!$tokenextras) {
               $tokenextras = '&&';
     my $uextkey=hex($ukey);          }
     if ($uextkey>2147483647) { $uextkey-=4294967296; }          $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
       }
 # -------------------------------------------------------- Store away log token      my $logtoken=Apache::lonnet::reply(
     my $tokenextras;         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
     if ($env{'form.role'}) {         $lonhost);
         $tokenextras = '&role='.&escape($env{'form.role'});  
     }  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
     if ($env{'form.symb'}) {  #    we are in serious trouble
         if (!$tokenextras) {  
             $tokenextras = '&';      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
         }          if ($logtoken eq 'no_such_host') {
         $tokenextras .= '&symb='.&escape($env{'form.symb'});              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
     }          }
     if ($env{'form.iptoken'}) {          my $spares='';
         if (!$tokenextras) {   my $last;
             $tokenextras = '&&';          foreach my $hostid (sort
         }      {
         $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});   &Apache::lonnet::hostname($a) cmp
     }      &Apache::lonnet::hostname($b);
     my $logtoken=Apache::lonnet::reply(      }
        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,      keys(%Apache::lonnet::spareid)) {
        $lonhost);              next if ($hostid eq $lonhost);
       my $hostname = &Apache::lonnet::hostname($hostid);
 # -- If we cannot talk to ourselves, or hostID does not map to a hostname      next if (($last eq $hostname) || ($hostname eq ''));
 #    we are in serious trouble              $spares.='<br /><font size="+1"><a href="http://'.
                   $hostname.
     if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {                  '/adm/login?domain='.$authdomain.'">'.
         if ($logtoken eq 'no_such_host') {                  $hostname.'</a>'.
             &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');                  ' '.&mt('(preferred)').'</font>'.$/;
         }      $last=$hostname;
         my $spares='';          }
         my (@sparehosts,%spareservers);          if ($spares) {
         my $sparesref = &Apache::lonnet::this_host_spares($defdom);              $spares.= '<br />';
         if (ref($sparesref) eq 'HASH') {          }
             foreach my $key (keys(%{$sparesref})) {          my %all_hostnames = &Apache::lonnet::all_hostnames();
                 if (ref($sparesref->{$key}) eq 'ARRAY') {          foreach my $hostid (sort
                     my @sorted = sort { &Apache::lonnet::hostname($a) cmp      {
                                         &Apache::lonnet::hostname($b);   &Apache::lonnet::hostname($a) cmp
                                       } @{$sparesref->{$key}};      &Apache::lonnet::hostname($b);
                     if (@sorted) {      }
                         if ($key eq 'primary') {      keys(%all_hostnames)) {
                             unshift(@sparehosts,@sorted);              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
                         } elsif ($key eq 'default') {              my $hostname = &Apache::lonnet::hostname($hostid);
                             push(@sparehosts,@sorted);              next if (($last eq $hostname) || ($hostname eq ''));
                         }              $spares.='<br /><a href="http://'.
                     }               $hostname.
                 }               '/adm/login?domain='.$authdomain.'">'.
             }               $hostname.'</a>';
         }              $last=$hostname;
         foreach my $hostid (@sparehosts) {           }
             next if ($hostid eq $lonhost);           $r->print(
     my $hostname = &Apache::lonnet::hostname($hostid);     '<html>'
     next if (($hostname eq '') || ($spareservers{$hostname}));    .'<head><title>'
             $spareservers{$hostname} = 1;    .&mt('The LearningOnline Network with CAPA')
             my $protocol = $Apache::lonnet::protocol{$hostid};    .'</title></head>'
             $protocol = 'http' if ($protocol ne 'https');    .'<body bgcolor="#FFFFFF">'
             $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
                 $hostname.    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
                 '/adm/login?domain='.$authdomain.'">'.    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
                 $hostname.'</a>'.          if ($spares) {
                 ' '.&mt('(preferred)').'</span>'.$/;              $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
         }                       .'</p>'
         if ($spares) {                       .$spares);
             $spares.= '<br />';          }
         }          $r->print('</body>'
         my %all_hostnames = &Apache::lonnet::all_hostnames();                   .'</html>'
         foreach my $hostid (sort          );
     {          return OK;
  &Apache::lonnet::hostname($a) cmp      }
     &Apache::lonnet::hostname($b);  
     }  # ----------------------------------------------- Apparently we are in business
     keys(%all_hostnames)) {      $servadm=~s/\,/\<br \/\>/g;
             next if ($hostid eq $lonhost);  
             my $hostname = &Apache::lonnet::hostname($hostid);  # ----------------------------------------------------------- Front page design
             next if (($hostname eq '') || ($spareservers{$hostname}));      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
             $spareservers{$hostname} = 1;      my $font=&Apache::loncommon::designparm('login.font',$domain);
             my $protocol = $Apache::lonnet::protocol{$hostid};      my $link=&Apache::loncommon::designparm('login.link',$domain);
             $protocol = 'http' if ($protocol ne 'https');      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
             $spares.='<br /><a href="'.$protocol.'://'.      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
              $hostname.      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
              '/adm/login?domain='.$authdomain.'">'.      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
              $hostname.'</a>';      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
          }      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
          $r->print(      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'      my $img=&Apache::loncommon::designparm('login.img',$domain);
   .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'      my $domainlogo=&Apache::loncommon::domainlogo($domain);
   .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'      my $showbanner = 1;
   .&mt('The LearningOnline Network with CAPA')      my $showmainlogo = 1;
   .'</title></head>'      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
   .'<body bgcolor="#FFFFFF">'          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'      }
   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
         if ($spares) {      }
             $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')      my $showadminmail;
                      .'</p>'      my @possdoms = &Apache::lonnet::current_machine_domains();
                      .$spares);      if (grep(/^\Q$domain\E$/,@possdoms)) {
         }          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
         $r->print('</body>'      }
                  .'</html>'      my $showcoursecat =
         );          &Apache::loncommon::designparm('login.coursecatalog',$domain);
         return OK;      my $shownewuserlink =
     }          &Apache::loncommon::designparm('login.newuser',$domain);
       my $showhelpdesk =
 # ----------------------------------------------- Apparently we are in business          &Apache::loncommon::designparm('login.helpdesk',$domain);
     $servadm=~s/\,/\<br \/\>/g;      my $now=time;
       my $js = (<<ENDSCRIPT);
 # ----------------------------------------------------------- Front page design  
     my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);  <script type="text/javascript" language="JavaScript">
     my $font=&Apache::loncommon::designparm('login.font',$domain);  // <![CDATA[
     my $link=&Apache::loncommon::designparm('login.link',$domain);  function send()
     my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);  {
     my $alink=&Apache::loncommon::designparm('login.alink',$domain);  this.document.server.elements.uname.value
     my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);  =this.document.client.elements.uname.value;
     my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);  
     my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);  this.document.server.elements.udom.value
     my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);  =this.document.client.elements.udom.value;
     my $logo=&Apache::loncommon::designparm('login.logo',$domain);  
     my $img=&Apache::loncommon::designparm('login.img',$domain);  uextkey=this.document.client.elements.uextkey.value;
     my $domainlogo=&Apache::loncommon::domainlogo($domain);  lextkey=this.document.client.elements.lextkey.value;
     my $showbanner = 1;  initkeys();
     my $showmainlogo = 1;  
     if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {  if(this.document.server.action.substr(0,5) === 'http:'){
         $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);      this.document.server.elements.upass0.value
     }          =getCrypted(this.document.client.elements.upass$now.value);
     if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {  } else {
         $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);      this.document.server.elements.upass0.value
     }          =this.document.client.elements.upass$now.value;
     my $showadminmail;  }
     my @possdoms = &Apache::lonnet::current_machine_domains();  
     if (grep(/^\Q$domain\E$/,@possdoms)) {  this.document.client.elements.uname.value='';
         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);  this.document.client.elements.upass$now.value='';
     }  
     my $showcoursecat =  this.document.server.submit();
         &Apache::loncommon::designparm('login.coursecatalog',$domain);  return false;
     my $shownewuserlink =   }
         &Apache::loncommon::designparm('login.newuser',$domain);  
     my $showhelpdesk =  function enableInput() {
         &Apache::loncommon::designparm('login.helpdesk',$domain);      this.document.client.elements.upass$now.removeAttribute("readOnly");
     my $now=time;      this.document.client.elements.uname.removeAttribute("readOnly");
     my $js = (<<ENDSCRIPT);      this.document.client.elements.udom.removeAttribute("readOnly");
       return;
 <script type="text/javascript" language="JavaScript">  }
 // <![CDATA[  
 function send()  // ]]>
 {  </script>
 this.document.server.elements.uname.value  
 =this.document.client.elements.uname.value;  ENDSCRIPT
   
 this.document.server.elements.udom.value  # --------------------------------------------------- Print login screen header
 =this.document.client.elements.udom.value;  
       my %add_entries = (
 uextkey=this.document.client.elements.uextkey.value;         bgcolor      => "$mainbg",
 lextkey=this.document.client.elements.lextkey.value;         text         => "$font",
 initkeys();         link         => "$link",
          vlink        => "$vlink",
 this.document.server.elements.upass0.value         alink        => "$alink",
     =getCrypted(this.document.client.elements.upass$now.value);                 onload       => 'javascript:enableInput();',);
   
 this.document.client.elements.uname.value='';      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
 this.document.client.elements.upass$now.value='';      @hosts = &Apache::lonnet::current_machine_ids();
       $lonhost_in_use = $lonhost;
 this.document.server.submit();      if (@hosts > 1) {
 return false;          foreach my $hostid (@hosts) {
 }              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
                   $lonhost_in_use = $hostid;
 function enableInput() {                  last;
     this.document.client.elements.upass$now.removeAttribute("readOnly");              }
     this.document.client.elements.uname.removeAttribute("readOnly");          }
     this.document.client.elements.udom.removeAttribute("readOnly");      }
     return;      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
 }      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
       $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
 // ]]>      if ($headextra) {
 </script>          my $omitextra;
           if ($headextra_exempt ne '') {
 ENDSCRIPT              my @exempt = split(',',$headextra_exempt);
               my $ip = $ENV{'REMOTE_ADDR'};
 # --------------------------------------------------- Print login screen header              if (grep(/^\Q$ip\E$/,@exempt)) {
                   $omitextra = 1;
     my %add_entries = (              }
        bgcolor      => "$mainbg",          }
        text         => "$font",          unless ($omitextra) {
        link         => "$link",              my $confname = $defdom.'-domainconfig';
        vlink        => "$vlink",              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
        alink        => "$alink",                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
                onload       => 'javascript:enableInput();',);                  unless ($extra eq '-1') {
                       $js .= "\n".$extra."\n";
     my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);                  }
     @hosts = &Apache::lonnet::current_machine_ids();              }
     $lonhost_in_use = $lonhost;          }
     if (@hosts > 1) {      }
         foreach my $hostid (@hosts) {  
             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
                 $lonhost_in_use = $hostid;         { 'redirect'       => [$expire,'/adm/roles'],
                 last;   'add_entries' => \%add_entries,
             }   'only_body'   => 1,}));
         }  
     }  # ----------------------------------------------------------------------- Texts
     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);  
     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};      my %lt=&Apache::lonlocal::texthash(
     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};            'un'       => 'Username',
     if ($headextra) {            'pw'       => 'Password',
         my $omitextra;            'dom'      => 'Domain',
         if ($headextra_exempt ne '') {            'perc'     => 'percent',
             my @exempt = split(',',$headextra_exempt);            'load'     => 'Server Load',
             my $ip = $ENV{'REMOTE_ADDR'};            'userload' => 'User Load',
             if (grep(/^\Q$ip\E$/,@exempt)) {            'catalog'  => 'Course/Community Catalog',
                 $omitextra = 1;            'log'      => 'Log in',
             }            'help'     => 'Log-in Help',
         }            'serv'     => 'Server',
         unless ($omitextra) {            'servadm'  => 'Server Administration',
             my $confname = $defdom.'-domainconfig';            'helpdesk' => 'Contact Helpdesk',
             if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {            'forgotpw' => 'Forgot password?',
                 my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));            'newuser'  => 'New User?',
                 unless ($extra eq '-1') {         );
                     $js .= "\n".$extra."\n";  # -------------------------------------------------- Change password field name
                 }  
             }      my $forgotpw = &forgotpwdisplay(%lt);
         }      $forgotpw .= '<br />' if $forgotpw;
     }      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
       if ($loginhelp) {
     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
        { 'redirect'       => [$expire,'/adm/roles'],       }
  'add_entries' => \%add_entries,  
  'only_body'   => 1,}));  # ---------------------------------------------------- Serve out DES JavaScript
       {
 # ----------------------------------------------------------------------- Texts      my $jsh=Apache::File->new($include."/londes.js");
       $r->print(<$jsh>);
     my %lt=&Apache::lonlocal::texthash(      }
           'un'       => 'Username',  # ---------------------------------------------------------- Serve rest of page
           'pw'       => 'Password',  
           'dom'      => 'Domain',      $r->print(
           'perc'     => 'percent',      '<div class="LC_Box"'
           'load'     => 'Server Load',     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
           'userload' => 'User Load',  );
           'catalog'  => 'Course/Community Catalog',  
           'log'      => 'Log in',      $r->print(<<ENDSERVERFORM);
           'help'     => 'Log-in Help',  <form name="server" action="/adm/authenticate" method="post" target="_top">
           'serv'     => 'Server',     <input type="hidden" name="logtoken" value="$logtoken" />
           'servadm'  => 'Server Administration',     <input type="hidden" name="serverid" value="$lonhost" />
           'helpdesk' => 'Contact Helpdesk',     <input type="hidden" name="uname" value="" />
           'forgotpw' => 'Forgot password?',     <input type="hidden" name="upass0" value="" />
           'newuser'  => 'New User?',     <input type="hidden" name="udom" value="" />
        );     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
 # -------------------------------------------------- Change password field name     <input type="hidden" name="localres" value="$env{'form.localres'}" />
     </form>
     my $forgotpw = &forgotpwdisplay(%lt);  ENDSERVERFORM
     $forgotpw .= '<br />' if $forgotpw;      my $coursecatalog;
     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);      if (($showcoursecat eq '') || ($showcoursecat)) {
     if ($loginhelp) {          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';      }
     }      my $newuserlink;
       if ($shownewuserlink) {
 # ---------------------------------------------------- Serve out DES JavaScript          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
     {      }
     my $jsh=Apache::File->new($include."/londes.js");      my $logintitle =
     $r->print(<$jsh>);          '<h2 class="LC_hcell"'
     }         .' style="background:'.$loginbox_header_bgcol.';'
 # ---------------------------------------------------------- Serve rest of page         .' color:'.$loginbox_header_textcol.'">'
          .$lt{'log'}
     $r->print(         .'</h2>';
     '<div class="LC_Box"'  
    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'      my $noscript_warning='<noscript><span class="LC_warning"><b>'
 );                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
                           .'</b></span></noscript>';
     $r->print(<<ENDSERVERFORM);      my $helpdeskscript;
 <form name="server" action="/adm/authenticate" method="post" target="_top">      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
    <input type="hidden" name="logtoken" value="$logtoken" />                                         $authdomain,\$helpdeskscript,
    <input type="hidden" name="serverid" value="$lonhost" />                                         $showhelpdesk,\@possdoms);
    <input type="hidden" name="uname" value="" />  
    <input type="hidden" name="upass0" value="" />      my $mobileargs;
    <input type="hidden" name="udom" value="" />      if ($clientmobile) {
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />          $mobileargs = 'autocapitalize="off" autocorrect="off"';
    <input type="hidden" name="localres" value="$env{'form.localres'}" />      }
   </form>      my $loginform=(<<LFORM);
 ENDSERVERFORM  <form name="client" action="" onsubmit="return(send())">
     my $coursecatalog;    <input type="hidden" name="lextkey" value="$lextkey" />
     if (($showcoursecat eq '') || ($showcoursecat)) {    <input type="hidden" name="uextkey" value="$uextkey" />
         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';    <b><label for="uname">$lt{'un'}</label>:</b><br />
     }    <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
     my $newuserlink;    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
     if ($shownewuserlink) {    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';    <b><label for="udom">$lt{'dom'}</label>:</b><br />
     }    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
     my $logintitle =    <input type="submit" value="$lt{'log'}" />
         '<h2 class="LC_hcell"'  </form>
        .' style="background:'.$loginbox_header_bgcol.';'  LFORM
        .' color:'.$loginbox_header_textcol.'">'  
        .$lt{'log'}      if ($showbanner) {
        .'</h2>';          $r->print(<<HEADER);
   <!-- The LON-CAPA Header -->
     my $noscript_warning='<noscript><span class="LC_warning"><b>'  <div style="background:$pgbg;margin:0;width:100%;">
                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')    <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
                         .'</b></span></noscript>';  </div>
     my $helpdeskscript;  HEADER
     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,      }
                                        $authdomain,\$helpdeskscript,      $r->print(<<ENDTOP);
                                        $showhelpdesk,\@possdoms);  <div style="float:left;margin-top:0;">
   <div class="LC_Box" style="background:$loginbox_bg;">
     my $mobileargs;    $logintitle
     if ($clientmobile) {    $loginform
         $mobileargs = 'autocapitalize="off" autocorrect="off"';     $noscript_warning
     }  </div>
     my $loginform=(<<LFORM);   
 <form name="client" action="" onsubmit="return(send())">  <div class="LC_Box" style="padding-top: 10px;">
   <input type="hidden" name="lextkey" value="$lextkey" />    $loginhelp
   <input type="hidden" name="uextkey" value="$uextkey" />    $forgotpw
   <b><label for="uname">$lt{'un'}</label>:</b><br />    $contactblock
   <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />    $newuserlink
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />    $coursecatalog
   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />  </div>
   <b><label for="udom">$lt{'dom'}</label>:</b><br />  </div>
   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />  
   <input type="submit" value="$lt{'log'}" />  <div>
 </form>  ENDTOP
 LFORM      if ($showmainlogo) {
           $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
     if ($showbanner) {      }
         $r->print(<<HEADER);  $r->print(<<ENDTOP);
 <!-- The LON-CAPA Header -->  $announcements
 <div style="background:$pgbg;margin:0;width:100%;">  </div>
   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />  <hr style="clear:both;" />
 </div>  ENDTOP
 HEADER      my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
     }      $domainrow = <<"END";
     $r->print(<<ENDTOP);        <tr>
 <div style="float:left;margin-top:0;">         <td  align="left" valign="top">
 <div class="LC_Box" style="background:$loginbox_bg;">          <small><b>$lt{'dom'}:&nbsp;</b></small>
   $logintitle         </td>
   $loginform         <td  align="left" valign="top">
   $noscript_warning          <small><tt>&nbsp;$domain</tt></small>
 </div>         </td>
           </tr>
 <div class="LC_Box" style="padding-top: 10px;">  END
   $loginhelp      $serverrow = <<"END";
   $forgotpw        <tr>
   $contactblock         <td  align="left" valign="top">
   $newuserlink          <small><b>$lt{'serv'}:&nbsp;</b></small>
   $coursecatalog         </td>
 </div>         <td align="left" valign="top">
 </div>          <small><tt>&nbsp;$lonhost ($role)</tt></small>
          </td>
 <div>        </tr>
 ENDTOP  END
     if ($showmainlogo) {      if ($loadlim) {
         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");          $loadrow = <<"END";
     }        <tr>
 $r->print(<<ENDTOP);         <td align="left" valign="top">
 $announcements          <small><b>$lt{'load'}:&nbsp;</b></small>
 </div>         </td>
 <hr style="clear:both;" />         <td align="left" valign="top">
 ENDTOP          <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);         </td>
     $domainrow = <<"END";        </tr>
       <tr>  END
        <td  align="left" valign="top">      }
         <small><b>$lt{'dom'}:&nbsp;</b></small>      if ($uloadlim) {
        </td>          $userloadrow = <<"END";
        <td  align="left" valign="top">        <tr>
         <small><tt>&nbsp;$domain</tt></small>         <td align="left" valign="top">
        </td>          <small><b>$lt{'userload'}:&nbsp;</b></small>
       </tr>         </td>
 END         <td align="left" valign="top">
     $serverrow = <<"END";          <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
       <tr>         </td>
        <td  align="left" valign="top">        </tr>
         <small><b>$lt{'serv'}:&nbsp;</b></small>  END
        </td>      }
        <td align="left" valign="top">      if (($version ne '') && ($version ne '<!-- VERSION -->')) {
         <small><tt>&nbsp;$lonhost ($role)</tt></small>          $versionrow = <<"END";
        </td>        <tr>
       </tr>         <td colspan="2" align="left">
 END          <small>$version</small>
     if ($loadlim) {         </td>
         $loadrow = <<"END";        </tr>
       <tr>  END
        <td align="left" valign="top">      }
         <small><b>$lt{'load'}:&nbsp;</b></small>  
        </td>      $r->print(<<ENDDOCUMENT);
        <td align="left" valign="top">      <div style="float: left;">
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>       <table border="0" cellspacing="0" cellpadding="0">
        </td>  $domainrow
       </tr>  $serverrow
 END  $loadrow    
     }  $userloadrow
     if ($uloadlim) {  $versionrow
         $userloadrow = <<"END";       </table>
       <tr>      </div>
        <td align="left" valign="top">      <div style="float: right;">
         <small><b>$lt{'userload'}:&nbsp;</b></small>      $domainlogo
        </td>      </div>
        <td align="left" valign="top">      <br style="clear:both;" />
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>   </div>
        </td>  
       </tr>  <script type="text/javascript">
 END  // <![CDATA[
     }  // the if prevents the script error if the browser can not handle this
     if (($version ne '') && ($version ne '<!-- VERSION -->')) {  if ( document.client.uname ) { document.client.uname.focus(); }
         $versionrow = <<"END";  // ]]>
       <tr>  </script>
        <td colspan="2" align="left">  $helpdeskscript
         <small>$version</small>  
        </td>  ENDDOCUMENT
       </tr>      my %endargs = ( 'noredirectlink' => 1, );
 END      $r->print(&Apache::loncommon::end_page(\%endargs));
     }      return OK;
   }
     $r->print(<<ENDDOCUMENT);  
     <div style="float: left;">  sub check_loginvia {
      <table border="0" cellspacing="0" cellpadding="0">      my ($domain,$lonhost) = @_;
 $domainrow      if ($domain eq '' || $lonhost eq '') {
 $serverrow          return;
 $loadrow          }
 $userloadrow      my %domconfhash = &Apache::loncommon::get_domainconf($domain);
 $versionrow      my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
      </table>      my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
     </div>      my $output;
     <div style="float: right;">      if ($loginvia ne '') {
     $domainlogo          my $noredirect;
     </div>          my $ip = $ENV{'REMOTE_ADDR'};
     <br style="clear:both;" />          if ($ip eq '127.0.0.1') {
  </div>              $noredirect = 1;
           } else {
 <script type="text/javascript">              if ($loginvia_exempt ne '') {
 // <![CDATA[                  my @exempt = split(',',$loginvia_exempt);
 // the if prevents the script error if the browser can not handle this                  if (grep(/^\Q$ip\E$/,@exempt)) {
 if ( document.client.uname ) { document.client.uname.focus(); }                      $noredirect = 1;
 // ]]>                  }
 </script>              }
 $helpdeskscript          }
           unless ($noredirect) {
 ENDDOCUMENT              my ($newhost,$path);
     my %endargs = ( 'noredirectlink' => 1, );              if ($loginvia =~ /:/) {
     $r->print(&Apache::loncommon::end_page(\%endargs));                  ($newhost,$path) = split(':',$loginvia);
     return OK;              } else {
 }                  $newhost = $loginvia;
               }
 sub check_loginvia {              if ($newhost ne $lonhost) {
     my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;                  if (&Apache::lonnet::hostname($newhost) ne '') {
     if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {                      $output = &redirect_page($newhost,$path);
         return;                  }
     }              }
     my %domconfhash = &Apache::loncommon::get_domainconf($domain);          }
     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};      }
     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};      return $output;
     my $output;  }
     if ($loginvia ne '') {  
         my $noredirect;  sub redirect_page {
         my $ip = $ENV{'REMOTE_ADDR'};      my ($desthost,$path) = @_;
         if ($ip eq '127.0.0.1') {      my $protocol = $Apache::lonnet::protocol{$desthost};
             $noredirect = 1;      $protocol = 'http' if ($protocol ne 'https');
         } else {      unless ($path =~ m{^/}) {
             if ($loginvia_exempt ne '') {          $path = '/'.$path;
                 my @exempt = split(',',$loginvia_exempt);      }
                 if (grep(/^\Q$ip\E$/,@exempt)) {      my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
                     $noredirect = 1;      if ($env{'form.firsturl'} ne '') {
                 }          $url .='?firsturl='.$env{'form.firsturl'};
             }      }
         }      my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
         unless ($noredirect) {                                                      {'redirect' => [0,$url],});
             my ($newhost,$path);      my $end_page   = &Apache::loncommon::end_page();
             if ($loginvia =~ /:/) {      return $start_page.$end_page;
                 ($newhost,$path) = split(':',$loginvia);  }
             } else {  
                 $newhost = $loginvia;  sub contactdisplay {
             }      my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
             if ($newhost ne $lonhost) {          $possdoms) = @_;
                 if (&Apache::lonnet::hostname($newhost) ne '') {      my $contactblock;
                     if ($balcookie) {      my $origmail;
                         my ($balancer,$cookie) = split(/:/,$balcookie);      if (ref($possdoms) eq 'ARRAY') {
                         if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {          if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
                             my ($udom,$uname,$cookieid) = ($1,$2,$3);              $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                             unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {          }
                                 if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {      }
                                     while (my $filename=readdir($dh)) {      my $requestmail =
                                         if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {          &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
                                             my $handle = $1;                                                   $authdomain,$origmail);
                                             my %hash =      unless ($showhelpdesk eq '0') {
                                                 &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,          if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
                                                                                      ['request.balancercookie',              $showhelpdesk = 1;
                                                                                       'user.linkedenv']);          } else {
                                             if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {              $showhelpdesk = 0;
                                                 if (unlink("$lonidsdir/$filename")) {          }
                                                     if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&      }
                                                         (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&      if ($servadm && $showadminmail) {
                                                         (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {          $contactblock .= $$lt{'servadm'}.':<br />'.
                                                         unlink("$lonidsdir/$hash{'user.linkedenv'}.id");                           '<tt>'.$servadm.'</tt><br />';
                                                     }      }
                                                 }      if ($showhelpdesk) {
                                             }          $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
                                             last;          my $thisurl = &escape('/adm/login');
                                         }          $$helpdeskscript = <<"ENDSCRIPT";
                                     }  <script type="text/javascript">
                                     closedir($dh);  // <![CDATA[
                                 }  function helpdesk() {
                             }      var possdom = document.client.udom.value;
                         }      var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
                     }      if (codedom == '') {
                     $output = &redirect_page($newhost,$path);          codedom = "$authdomain";
                 }      }
             }      var querystr = "origurl=$thisurl&codedom="+codedom;
         }      document.location.href = "/adm/helpdesk?"+querystr;
     }      return;
     return $output;  }
 }  // ]]>
   </script>
 sub redirect_page {  ENDSCRIPT
     my ($desthost,$path) = @_;      }
     my $hostname = &Apache::lonnet::hostname($desthost);      return $contactblock;
     my $protocol = $Apache::lonnet::protocol{$desthost};  }
     $protocol = 'http' if ($protocol ne 'https');  
     unless ($path =~ m{^/}) {  sub forgotpwdisplay {
         $path = '/'.$path;      my (%lt) = @_;
     }      my $prompt_for_resetpw = 1;
     my $url = $protocol.'://'.$hostname.$path;      if ($prompt_for_resetpw) {
     if ($env{'form.firsturl'} ne '') {          return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
         $url .='?firsturl='.$env{'form.firsturl'};      }
     }      return;
     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,  }
                                                     {'redirect' => [0,$url],});  
     my $end_page   = &Apache::loncommon::end_page();  sub coursecatalog_link {
     return $start_page.$end_page;      my ($linkname) = @_;
 }      return <<"END";
         <a href="/adm/coursecatalog">$linkname</a>
 sub contactdisplay {  END
     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,  }
         $possdoms) = @_;  
     my $contactblock;  sub newuser_link {
     my $origmail;      my ($linkname) = @_;
     if (ref($possdoms) eq 'ARRAY') {      return '<a href="/adm/createaccount">'.$linkname.'</a>';
         if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {   }
             $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};  
         }  1;
     }  __END__
     my $requestmail =   
         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',  
                                                  $authdomain,$origmail);  
     unless ($showhelpdesk eq '0') {  
         if ($requestmail =~ m/[^\@]+\@[^\@]+/) {  
             $showhelpdesk = 1;  
         } else {  
             $showhelpdesk = 0;  
         }  
     }  
     if ($servadm && $showadminmail) {  
         $contactblock .= $$lt{'servadm'}.':<br />'.  
                          '<tt>'.$servadm.'</tt><br />';  
     }  
     if ($showhelpdesk) {  
         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';  
         my $thisurl = &escape('/adm/login');  
         $$helpdeskscript = <<"ENDSCRIPT";  
 <script type="text/javascript">  
 // <![CDATA[  
 function helpdesk() {  
     var possdom = document.client.udom.value;  
     var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');  
     if (codedom == '') {  
         codedom = "$authdomain";  
     }  
     var querystr = "origurl=$thisurl&codedom="+codedom;  
     document.location.href = "/adm/helpdesk?"+querystr;  
     return;  
 }  
 // ]]>  
 </script>  
 ENDSCRIPT  
     }  
     return $contactblock;  
 }  
   
 sub forgotpwdisplay {  
     my (%lt) = @_;  
     my $prompt_for_resetpw = 1;   
     if ($prompt_for_resetpw) {  
         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';  
     }  
     return;  
 }  
   
 sub coursecatalog_link {  
     my ($linkname) = @_;  
     return <<"END";  
       <a href="/adm/coursecatalog">$linkname</a>  
 END  
 }  
   
 sub newuser_link {  
     my ($linkname) = @_;  
     return '<a href="/adm/createaccount">'.$linkname.'</a>';  
 }  
   
 1;  
 __END__  

Removed from v.1.158.2.11  
changed lines
  Added in v.1.175


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