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

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

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


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