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

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

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


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