Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.10 and 1.164

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


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