Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.9.2.2 and 1.176

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


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