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

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


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.