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

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


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