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

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

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


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