Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.9.2.3 and 1.161

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


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