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

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


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