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

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

Removed from v.1.158.2.9.2.1  
changed lines
  Added in v.1.178


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