Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.8 and 1.178

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


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