Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.9.2.1 and 1.174

version 1.158.2.9.2.1, 2020/01/22 16:43:52 version 1.174, 2018/11/24 16:19:04
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($env{'form.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 $last;      {
         foreach my $hostid (sort   &Apache::lonnet::hostname($a) cmp
     {      &Apache::lonnet::hostname($b);
  &Apache::lonnet::hostname($a) cmp      }
     &Apache::lonnet::hostname($b);      keys(%all_hostnames)) {
     }              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
     keys(%Apache::lonnet::spareid)) {              my $hostname = &Apache::lonnet::hostname($hostid);
             next if ($hostid eq $lonhost);              next if (($last eq $hostname) || ($hostname eq ''));
     my $hostname = &Apache::lonnet::hostname($hostid);              $spares.='<br /><a href="http://'.
     next if (($last eq $hostname) || ($hostname eq ''));               $hostname.
             $spares.='<br /><font size="+1"><a href="http://'.               '/adm/login?domain='.$authdomain.'">'.
                 $hostname.               $hostname.'</a>';
                 '/adm/login?domain='.$authdomain.'">'.              $last=$hostname;
                 $hostname.'</a>'.           }
                 ' '.&mt('(preferred)').'</font>'.$/;           $r->print(
     $last=$hostname;     '<html>'
         }    .'<head><title>'
         if ($spares) {    .&mt('The LearningOnline Network with CAPA')
             $spares.= '<br />';    .'</title></head>'
         }    .'<body bgcolor="#FFFFFF">'
         my %all_hostnames = &Apache::lonnet::all_hostnames();    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
         foreach my $hostid (sort    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
     {    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
  &Apache::lonnet::hostname($a) cmp          if ($spares) {
     &Apache::lonnet::hostname($b);              $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
     }                       .'</p>'
     keys(%all_hostnames)) {                       .$spares);
             next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});          }
             my $hostname = &Apache::lonnet::hostname($hostid);          $r->print('</body>'
             next if (($last eq $hostname) || ($hostname eq ''));                   .'</html>'
             $spares.='<br /><a href="http://'.          );
              $hostname.          return OK;
              '/adm/login?domain='.$authdomain.'">'.      }
              $hostname.'</a>';  
             $last=$hostname;  # ----------------------------------------------- Apparently we are in business
          }      $servadm=~s/\,/\<br \/\>/g;
          $r->print(  
    '<html>'  # ----------------------------------------------------------- Front page design
   .'<head><title>'      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
   .&mt('The LearningOnline Network with CAPA')      my $font=&Apache::loncommon::designparm('login.font',$domain);
   .'</title></head>'      my $link=&Apache::loncommon::designparm('login.link',$domain);
   .'<body bgcolor="#FFFFFF">'      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
         if ($spares) {      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
             $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
                      .'</p>'      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
                      .$spares);      my $img=&Apache::loncommon::designparm('login.img',$domain);
         }      my $domainlogo=&Apache::loncommon::domainlogo($domain);
         $r->print('</body>'      my $showbanner = 1;
                  .'</html>'      my $showmainlogo = 1;
         );      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
         return OK;          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
     }      }
       if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
 # ----------------------------------------------- Apparently we are in business          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
     $servadm=~s/\,/\<br \/\>/g;      }
       my $showadminmail;
 # ----------------------------------------------------------- Front page design      my @possdoms = &Apache::lonnet::current_machine_domains();
     my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);      if (grep(/^\Q$domain\E$/,@possdoms)) {
     my $font=&Apache::loncommon::designparm('login.font',$domain);          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
     my $link=&Apache::loncommon::designparm('login.link',$domain);      }
     my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);      my $showcoursecat =
     my $alink=&Apache::loncommon::designparm('login.alink',$domain);          &Apache::loncommon::designparm('login.coursecatalog',$domain);
     my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);      my $shownewuserlink =
     my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);          &Apache::loncommon::designparm('login.newuser',$domain);
     my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);      my $showhelpdesk =
     my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);          &Apache::loncommon::designparm('login.helpdesk',$domain);
     my $logo=&Apache::loncommon::designparm('login.logo',$domain);      my $now=time;
     my $img=&Apache::loncommon::designparm('login.img',$domain);      my $js = (<<ENDSCRIPT);
     my $domainlogo=&Apache::loncommon::domainlogo($domain);  
     my $showbanner = 1;  <script type="text/javascript" language="JavaScript">
     my $showmainlogo = 1;  // <![CDATA[
     if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {  function send()
         $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);  {
     }  this.document.server.elements.uname.value
     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.server.elements.udom.value
     my $showadminmail;  =this.document.client.elements.udom.value;
     my @possdoms = &Apache::lonnet::current_machine_domains();  
     if (grep(/^\Q$domain\E$/,@possdoms)) {  uextkey=this.document.client.elements.uextkey.value;
         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);  lextkey=this.document.client.elements.lextkey.value;
     }  initkeys();
     my $showcoursecat =  
         &Apache::loncommon::designparm('login.coursecatalog',$domain);  if(this.document.server.action.substr(0,5) === 'http:'){
     my $shownewuserlink =       this.document.server.elements.upass0.value
         &Apache::loncommon::designparm('login.newuser',$domain);          =getCrypted(this.document.client.elements.upass$now.value);
     my $showhelpdesk =  } else {
         &Apache::loncommon::designparm('login.helpdesk',$domain);      this.document.server.elements.upass0.value
     my $now=time;          =this.document.client.elements.upass$now.value;
     my $js = (<<ENDSCRIPT);  }
   
 <script type="text/javascript" language="JavaScript">  this.document.client.elements.uname.value='';
 // <![CDATA[  this.document.client.elements.upass$now.value='';
 function send()  
 {  this.document.server.submit();
 this.document.server.elements.uname.value  return false;
 =this.document.client.elements.uname.value;  }
   
 this.document.server.elements.udom.value  function enableInput() {
 =this.document.client.elements.udom.value;      this.document.client.elements.upass$now.removeAttribute("readOnly");
       this.document.client.elements.uname.removeAttribute("readOnly");
 uextkey=this.document.client.elements.uextkey.value;      this.document.client.elements.udom.removeAttribute("readOnly");
 lextkey=this.document.client.elements.lextkey.value;      return;
 initkeys();  }
   
 this.document.server.elements.upass0.value  // ]]>
     =getCrypted(this.document.client.elements.upass$now.value);  </script>
   
 this.document.client.elements.uname.value='';  ENDSCRIPT
 this.document.client.elements.upass$now.value='';  
   # --------------------------------------------------- Print login screen header
 this.document.server.submit();  
 return false;      my %add_entries = (
 }         bgcolor      => "$mainbg",
          text         => "$font",
 function enableInput() {         link         => "$link",
     this.document.client.elements.upass$now.removeAttribute("readOnly");         vlink        => "$vlink",
     this.document.client.elements.uname.removeAttribute("readOnly");         alink        => "$alink",
     this.document.client.elements.udom.removeAttribute("readOnly");                 onload       => 'javascript:enableInput();',);
     return;  
 }      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
       @hosts = &Apache::lonnet::current_machine_ids();
 // ]]>      $lonhost_in_use = $lonhost;
 </script>      if (@hosts > 1) {
           foreach my $hostid (@hosts) {
 ENDSCRIPT              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
                   $lonhost_in_use = $hostid;
 # --------------------------------------------------- Print login screen header                  last;
               }
     my %add_entries = (          }
        bgcolor      => "$mainbg",      }
        text         => "$font",      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
        link         => "$link",      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
        vlink        => "$vlink",      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
        alink        => "$alink",      if ($headextra) {
                onload       => 'javascript:enableInput();',);          my $omitextra;
           if ($headextra_exempt ne '') {
     my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);              my @exempt = split(',',$headextra_exempt);
     @hosts = &Apache::lonnet::current_machine_ids();              my $ip = $ENV{'REMOTE_ADDR'};
     $lonhost_in_use = $lonhost;              if (grep(/^\Q$ip\E$/,@exempt)) {
     if (@hosts > 1) {                  $omitextra = 1;
         foreach my $hostid (@hosts) {              }
             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {          }
                 $lonhost_in_use = $hostid;          unless ($omitextra) {
                 last;              my $confname = $defdom.'-domainconfig';
             }              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
         }                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
     }                  unless ($extra eq '-1') {
     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);                      $js .= "\n".$extra."\n";
     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};                  }
     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};              }
     if ($headextra) {          }
         my $omitextra;      }
         if ($headextra_exempt ne '') {  
             my @exempt = split(',',$headextra_exempt);      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
             my $ip = $ENV{'REMOTE_ADDR'};         { 'redirect'       => [$expire,'/adm/roles'],
             if (grep(/^\Q$ip\E$/,@exempt)) {   'add_entries' => \%add_entries,
                 $omitextra = 1;   'only_body'   => 1,}));
             }  
         }  # ----------------------------------------------------------------------- Texts
         unless ($omitextra) {  
             my $confname = $defdom.'-domainconfig';      my %lt=&Apache::lonlocal::texthash(
             if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {            'un'       => 'Username',
                 my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));            'pw'       => 'Password',
                 unless ($extra eq '-1') {            'dom'      => 'Domain',
                     $js .= "\n".$extra."\n";            'perc'     => 'percent',
                 }            'load'     => 'Server Load',
             }            'userload' => 'User Load',
         }            'catalog'  => 'Course/Community Catalog',
     }            'log'      => 'Log in',
             'help'     => 'Log-in Help',
     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,            'serv'     => 'Server',
        { 'redirect'       => [$expire,'/adm/roles'],             'servadm'  => 'Server Administration',
  'add_entries' => \%add_entries,            'helpdesk' => 'Contact Helpdesk',
  'only_body'   => 1,}));            'forgotpw' => 'Forgot password?',
             'newuser'  => 'New User?',
 # ----------------------------------------------------------------------- Texts         );
   # -------------------------------------------------- Change password field name
     my %lt=&Apache::lonlocal::texthash(  
           'un'       => 'Username',      my $forgotpw = &forgotpwdisplay(%lt);
           'pw'       => 'Password',      $forgotpw .= '<br />' if $forgotpw;
           'dom'      => 'Domain',      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
           'perc'     => 'percent',      if ($loginhelp) {
           'load'     => 'Server Load',          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
           'userload' => 'User Load',      }
           'catalog'  => 'Course/Community Catalog',  
           'log'      => 'Log in',  # ---------------------------------------------------- Serve out DES JavaScript
           'help'     => 'Log-in Help',      {
           'serv'     => 'Server',      my $jsh=Apache::File->new($include."/londes.js");
           'servadm'  => 'Server Administration',      $r->print(<$jsh>);
           'helpdesk' => 'Contact Helpdesk',      }
           'forgotpw' => 'Forgot password?',  # ---------------------------------------------------------- Serve rest of page
           'newuser'  => 'New User?',  
        );      $r->print(
 # -------------------------------------------------- Change password field name      '<div class="LC_Box"'
      .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
     my $forgotpw = &forgotpwdisplay(%lt);  );
     $forgotpw .= '<br />' if $forgotpw;  
     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);      $r->print(<<ENDSERVERFORM);
     if ($loginhelp) {  <form name="server" action="/adm/authenticate" method="post" target="_top">
         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';     <input type="hidden" name="logtoken" value="$logtoken" />
     }     <input type="hidden" name="serverid" value="$lonhost" />
      <input type="hidden" name="uname" value="" />
 # ---------------------------------------------------- Serve out DES JavaScript     <input type="hidden" name="upass0" value="" />
     {     <input type="hidden" name="udom" value="" />
     my $jsh=Apache::File->new($include."/londes.js");     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
     $r->print(<$jsh>);     <input type="hidden" name="localres" value="$env{'form.localres'}" />
     }    </form>
 # ---------------------------------------------------------- Serve rest of page  ENDSERVERFORM
       my $coursecatalog;
     $r->print(      if (($showcoursecat eq '') || ($showcoursecat)) {
     '<div class="LC_Box"'          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'      }
 );      my $newuserlink;
       if ($shownewuserlink) {
     $r->print(<<ENDSERVERFORM);          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
 <form name="server" action="/adm/authenticate" method="post" target="_top">      }
    <input type="hidden" name="logtoken" value="$logtoken" />      my $logintitle =
    <input type="hidden" name="serverid" value="$lonhost" />          '<h2 class="LC_hcell"'
    <input type="hidden" name="uname" value="" />         .' style="background:'.$loginbox_header_bgcol.';'
    <input type="hidden" name="upass0" value="" />         .' color:'.$loginbox_header_textcol.'">'
    <input type="hidden" name="udom" value="" />         .$lt{'log'}
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />         .'</h2>';
    <input type="hidden" name="localres" value="$env{'form.localres'}" />  
   </form>      my $noscript_warning='<noscript><span class="LC_warning"><b>'
 ENDSERVERFORM                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
     my $coursecatalog;                          .'</b></span></noscript>';
     if (($showcoursecat eq '') || ($showcoursecat)) {      my $helpdeskscript;
         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
     }                                         $authdomain,\$helpdeskscript,
     my $newuserlink;                                         $showhelpdesk,\@possdoms);
     if ($shownewuserlink) {  
         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';      my $mobileargs;
     }      if ($clientmobile) {
     my $logintitle =          $mobileargs = 'autocapitalize="off" autocorrect="off"';
         '<h2 class="LC_hcell"'      }
        .' style="background:'.$loginbox_header_bgcol.';'      my $loginform=(<<LFORM);
        .' color:'.$loginbox_header_textcol.'">'  <form name="client" action="" onsubmit="return(send())">
        .$lt{'log'}    <input type="hidden" name="lextkey" value="$lextkey" />
        .'</h2>';    <input type="hidden" name="uextkey" value="$uextkey" />
     <b><label for="uname">$lt{'un'}</label>:</b><br />
     my $noscript_warning='<noscript><span class="LC_warning"><b>'    <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
                         .'</b></span></noscript>';    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
     my $helpdeskscript;    <b><label for="udom">$lt{'dom'}</label>:</b><br />
     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
                                        $authdomain,\$helpdeskscript,    <input type="submit" value="$lt{'log'}" />
                                        $showhelpdesk,\@possdoms);  </form>
   LFORM
     my $mobileargs;  
     if ($clientmobile) {      if ($showbanner) {
         $mobileargs = 'autocapitalize="off" autocorrect="off"';           $r->print(<<HEADER);
     }  <!-- The LON-CAPA Header -->
     my $loginform=(<<LFORM);  <div style="background:$pgbg;margin:0;width:100%;">
 <form name="client" action="" onsubmit="return(send())">    <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
   <input type="hidden" name="lextkey" value="$lextkey" />  </div>
   <input type="hidden" name="uextkey" value="$uextkey" />  HEADER
   <b><label for="uname">$lt{'un'}</label>:</b><br />      }
   <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />      $r->print(<<ENDTOP);
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />  <div style="float:left;margin-top:0;">
   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />  <div class="LC_Box" style="background:$loginbox_bg;">
   <b><label for="udom">$lt{'dom'}</label>:</b><br />    $logintitle
   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />    $loginform
   <input type="submit" value="$lt{'log'}" />    $noscript_warning
 </form>  </div>
 LFORM   
   <div class="LC_Box" style="padding-top: 10px;">
     if ($showbanner) {    $loginhelp
         $r->print(<<HEADER);    $forgotpw
 <!-- The LON-CAPA Header -->    $contactblock
 <div style="background:$pgbg;margin:0;width:100%;">    $newuserlink
   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />    $coursecatalog
 </div>  </div>
 HEADER  </div>
     }  
     $r->print(<<ENDTOP);  <div>
 <div style="float:left;margin-top:0;">  ENDTOP
 <div class="LC_Box" style="background:$loginbox_bg;">      if ($showmainlogo) {
   $logintitle          $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
   $loginform      }
   $noscript_warning  $r->print(<<ENDTOP);
 </div>  $announcements
     </div>
 <div class="LC_Box" style="padding-top: 10px;">  <hr style="clear:both;" />
   $loginhelp  ENDTOP
   $forgotpw      my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
   $contactblock      $domainrow = <<"END";
   $newuserlink        <tr>
   $coursecatalog         <td  align="left" valign="top">
 </div>          <small><b>$lt{'dom'}:&nbsp;</b></small>
 </div>         </td>
          <td  align="left" valign="top">
 <div>          <small><tt>&nbsp;$domain</tt></small>
 ENDTOP         </td>
     if ($showmainlogo) {        </tr>
         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");  END
     }      $serverrow = <<"END";
 $r->print(<<ENDTOP);        <tr>
 $announcements         <td  align="left" valign="top">
 </div>          <small><b>$lt{'serv'}:&nbsp;</b></small>
 <hr style="clear:both;" />         </td>
 ENDTOP         <td align="left" valign="top">
     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);          <small><tt>&nbsp;$lonhost ($role)</tt></small>
     $domainrow = <<"END";         </td>
       <tr>        </tr>
        <td  align="left" valign="top">  END
         <small><b>$lt{'dom'}:&nbsp;</b></small>      if ($loadlim) {
        </td>          $loadrow = <<"END";
        <td  align="left" valign="top">        <tr>
         <small><tt>&nbsp;$domain</tt></small>         <td align="left" valign="top">
        </td>          <small><b>$lt{'load'}:&nbsp;</b></small>
       </tr>         </td>
 END         <td align="left" valign="top">
     $serverrow = <<"END";          <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
       <tr>         </td>
        <td  align="left" valign="top">        </tr>
         <small><b>$lt{'serv'}:&nbsp;</b></small>  END
        </td>      }
        <td align="left" valign="top">      if ($uloadlim) {
         <small><tt>&nbsp;$lonhost ($role)</tt></small>          $userloadrow = <<"END";
        </td>        <tr>
       </tr>         <td align="left" valign="top">
 END          <small><b>$lt{'userload'}:&nbsp;</b></small>
     if ($loadlim) {         </td>
         $loadrow = <<"END";         <td align="left" valign="top">
       <tr>          <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
        <td align="left" valign="top">         </td>
         <small><b>$lt{'load'}:&nbsp;</b></small>        </tr>
        </td>  END
        <td align="left" valign="top">      }
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>      if (($version ne '') && ($version ne '<!-- VERSION -->')) {
        </td>          $versionrow = <<"END";
       </tr>        <tr>
 END         <td colspan="2" align="left">
     }          <small>$version</small>
     if ($uloadlim) {         </td>
         $userloadrow = <<"END";        </tr>
       <tr>  END
        <td align="left" valign="top">      }
         <small><b>$lt{'userload'}:&nbsp;</b></small>  
        </td>      $r->print(<<ENDDOCUMENT);
        <td align="left" valign="top">      <div style="float: left;">
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>       <table border="0" cellspacing="0" cellpadding="0">
        </td>  $domainrow
       </tr>  $serverrow
 END  $loadrow    
     }  $userloadrow
     if (($version ne '') && ($version ne '<!-- VERSION -->')) {  $versionrow
         $versionrow = <<"END";       </table>
       <tr>      </div>
        <td colspan="2" align="left">      <div style="float: right;">
         <small>$version</small>      $domainlogo
        </td>      </div>
       </tr>      <br style="clear:both;" />
 END   </div>
     }  
   <script type="text/javascript">
     $r->print(<<ENDDOCUMENT);  // <![CDATA[
     <div style="float: left;">  // the if prevents the script error if the browser can not handle this
      <table border="0" cellspacing="0" cellpadding="0">  if ( document.client.uname ) { document.client.uname.focus(); }
 $domainrow  // ]]>
 $serverrow  </script>
 $loadrow      $helpdeskscript
 $userloadrow  
 $versionrow  ENDDOCUMENT
      </table>      my %endargs = ( 'noredirectlink' => 1, );
     </div>      $r->print(&Apache::loncommon::end_page(\%endargs));
     <div style="float: right;">      return OK;
     $domainlogo  }
     </div>  
     <br style="clear:both;" />  sub check_loginvia {
  </div>      my ($domain,$lonhost) = @_;
       if ($domain eq '' || $lonhost eq '') {
 <script type="text/javascript">          return;
 // <![CDATA[      }
 // the if prevents the script error if the browser can not handle this      my %domconfhash = &Apache::loncommon::get_domainconf($domain);
 if ( document.client.uname ) { document.client.uname.focus(); }      my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
 // ]]>      my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
 </script>      my $output;
 $helpdeskscript      if ($loginvia ne '') {
           my $noredirect;
 ENDDOCUMENT          my $ip = $ENV{'REMOTE_ADDR'};
     my %endargs = ( 'noredirectlink' => 1, );          if ($ip eq '127.0.0.1') {
     $r->print(&Apache::loncommon::end_page(\%endargs));              $noredirect = 1;
     return OK;          } else {
 }              if ($loginvia_exempt ne '') {
                   my @exempt = split(',',$loginvia_exempt);
 sub check_loginvia {                  if (grep(/^\Q$ip\E$/,@exempt)) {
     my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;                      $noredirect = 1;
     if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {                  }
         return;              }
     }          }
     my %domconfhash = &Apache::loncommon::get_domainconf($domain);          unless ($noredirect) {
     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};              my ($newhost,$path);
     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};              if ($loginvia =~ /:/) {
     my $output;                  ($newhost,$path) = split(':',$loginvia);
     if ($loginvia ne '') {              } else {
         my $noredirect;                  $newhost = $loginvia;
         my $ip = $ENV{'REMOTE_ADDR'};              }
         if ($ip eq '127.0.0.1') {              if ($newhost ne $lonhost) {
             $noredirect = 1;                  if (&Apache::lonnet::hostname($newhost) ne '') {
         } else {                      $output = &redirect_page($newhost,$path);
             if ($loginvia_exempt ne '') {                  }
                 my @exempt = split(',',$loginvia_exempt);              }
                 if (grep(/^\Q$ip\E$/,@exempt)) {          }
                     $noredirect = 1;      }
                 }      return $output;
             }  }
         }  
         unless ($noredirect) {  sub redirect_page {
             my ($newhost,$path);      my ($desthost,$path) = @_;
             if ($loginvia =~ /:/) {      my $protocol = $Apache::lonnet::protocol{$desthost};
                 ($newhost,$path) = split(':',$loginvia);      $protocol = 'http' if ($protocol ne 'https');
             } else {      unless ($path =~ m{^/}) {
                 $newhost = $loginvia;          $path = '/'.$path;
             }      }
             if ($newhost ne $lonhost) {      my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
                 if (&Apache::lonnet::hostname($newhost) ne '') {      if ($env{'form.firsturl'} ne '') {
                     if ($balcookie) {          $url .='?firsturl='.$env{'form.firsturl'};
                         my ($balancer,$cookie) = split(/:/,$balcookie);      }
                         if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {      my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
                             my ($udom,$uname,$cookieid) = ($1,$2,$3);                                                      {'redirect' => [0,$url],});
                             unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {      my $end_page   = &Apache::loncommon::end_page();
                                 if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {      return $start_page.$end_page;
                                     while (my $filename=readdir($dh)) {  }
                                         if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {  
                                             my $handle = $1;  sub contactdisplay {
                                             my %hash =      my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
                                                 &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,          $possdoms) = @_;
                                                                                      ['request.balancercookie',      my $contactblock;
                                                                                       'user.linkedenv']);      my $origmail;
                                             if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {      if (ref($possdoms) eq 'ARRAY') {
                                                 if (unlink("$lonidsdir/$filename")) {          if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
                                                     if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&              $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                                                         (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&          }
                                                         (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {      }
                                                         unlink("$lonidsdir/$hash{'user.linkedenv'}.id");      my $requestmail =
                                                     }          &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
                                                 }                                                   $authdomain,$origmail);
                                             }      unless ($showhelpdesk eq '0') {
                                             last;          if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
                                         }              $showhelpdesk = 1;
                                     }          } else {
                                     closedir($dh);              $showhelpdesk = 0;
                                 }          }
                             }      }
                         }      if ($servadm && $showadminmail) {
                     }          $contactblock .= $$lt{'servadm'}.':<br />'.
                     $output = &redirect_page($newhost,$path);                           '<tt>'.$servadm.'</tt><br />';
                 }      }
             }      if ($showhelpdesk) {
         }          $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
     }          my $thisurl = &escape('/adm/login');
     return $output;          $$helpdeskscript = <<"ENDSCRIPT";
 }  <script type="text/javascript">
   // <![CDATA[
 sub redirect_page {  function helpdesk() {
     my ($desthost,$path) = @_;      var possdom = document.client.udom.value;
     my $hostname = &Apache::lonnet::hostname($desthost);      var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
     my $protocol = $Apache::lonnet::protocol{$desthost};      if (codedom == '') {
     $protocol = 'http' if ($protocol ne 'https');          codedom = "$authdomain";
     unless ($path =~ m{^/}) {      }
         $path = '/'.$path;      var querystr = "origurl=$thisurl&codedom="+codedom;
     }      document.location.href = "/adm/helpdesk?"+querystr;
     my $url = $protocol.'://'.$hostname.$path;      return;
     if ($env{'form.firsturl'} ne '') {  }
         $url .='?firsturl='.$env{'form.firsturl'};  // ]]>
     }  </script>
     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,  ENDSCRIPT
                                                     {'redirect' => [0,$url],});      }
     my $end_page   = &Apache::loncommon::end_page();      return $contactblock;
     return $start_page.$end_page;  }
 }  
   sub forgotpwdisplay {
 sub contactdisplay {      my (%lt) = @_;
     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,      my $prompt_for_resetpw = 1;
         $possdoms) = @_;      if ($prompt_for_resetpw) {
     my $contactblock;          return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
     my $origmail;      }
     if (ref($possdoms) eq 'ARRAY') {      return;
         if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {   }
             $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};  
         }  sub coursecatalog_link {
     }      my ($linkname) = @_;
     my $requestmail =       return <<"END";
         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',        <a href="/adm/coursecatalog">$linkname</a>
                                                  $authdomain,$origmail);  END
     unless ($showhelpdesk eq '0') {  }
         if ($requestmail =~ m/[^\@]+\@[^\@]+/) {  
             $showhelpdesk = 1;  sub newuser_link {
         } else {      my ($linkname) = @_;
             $showhelpdesk = 0;      return '<a href="/adm/createaccount">'.$linkname.'</a>';
         }  }
     }  
     if ($servadm && $showadminmail) {  1;
         $contactblock .= $$lt{'servadm'}.':<br />'.  __END__
                          '<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.1  
changed lines
  Added in v.1.174


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