Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.12 and 1.176

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

Removed from v.1.158.2.12  
changed lines
  Added in v.1.176


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