Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.9 and 1.174

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

Removed from v.1.158.2.9  
changed lines
  Added in v.1.174


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