Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.10 and 1.173

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

Removed from v.1.158.2.10  
changed lines
  Added in v.1.173


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