Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.12 and 1.167

version 1.158.2.12, 2021/01/04 03:49:10 version 1.167, 2016/05/03 22:27:14
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');  if(this.document.server.action.substr(0,5) === 'http:'){
             $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.      this.document.server.elements.upass0.value
                 $hostname.          =getCrypted(this.document.client.elements.upass$now.value);
                 '/adm/login?domain='.$authdomain.'">'.  } else {
                 $hostname.'</a>'.      this.document.server.elements.upass0.value
                 ' '.&mt('(preferred)').'</span>'.$/;          =this.document.client.elements.upass$now.value;
         }  }
         if ($spares) {  
             $spares.= '<br />';  this.document.client.elements.uname.value='';
         }  this.document.client.elements.upass$now.value='';
         my %all_hostnames = &Apache::lonnet::all_hostnames();  
         foreach my $hostid (sort  this.document.server.submit();
     {  return false;
  &Apache::lonnet::hostname($a) cmp  }
     &Apache::lonnet::hostname($b);  
     }  function enableInput() {
     keys(%all_hostnames)) {      this.document.client.elements.upass$now.removeAttribute("readOnly");
             next if ($hostid eq $lonhost);      this.document.client.elements.uname.removeAttribute("readOnly");
             my $hostname = &Apache::lonnet::hostname($hostid);      this.document.client.elements.udom.removeAttribute("readOnly");
             next if (($hostname eq '') || ($spareservers{$hostname}));      return;
             $spareservers{$hostname} = 1;  }
             my $protocol = $Apache::lonnet::protocol{$hostid};  
             $protocol = 'http' if ($protocol ne 'https');  // ]]>
             $spares.='<br /><a href="'.$protocol.'://'.  </script>
              $hostname.  
              '/adm/login?domain='.$authdomain.'">'.  ENDSCRIPT
              $hostname.'</a>';  
          }  # --------------------------------------------------- Print login screen header
          $r->print(  
    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'      my %add_entries = (
   .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'         bgcolor      => "$mainbg",
   .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'         text         => "$font",
   .&mt('The LearningOnline Network with CAPA')         link         => "$link",
   .'</title></head>'         vlink        => "$vlink",
   .'<body bgcolor="#FFFFFF">'         alink        => "$alink",
   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'                 onload       => 'javascript:enableInput();',);
   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'  
   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
         if ($spares) {      @hosts = &Apache::lonnet::current_machine_ids();
             $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')      $lonhost_in_use = $lonhost;
                      .'</p>'      if (@hosts > 1) {
                      .$spares);          foreach my $hostid (@hosts) {
         }              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
         $r->print('</body>'                  $lonhost_in_use = $hostid;
                  .'</html>'                  last;
         );              }
         return OK;          }
     }      }
       %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
 # ----------------------------------------------- Apparently we are in business      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
     $servadm=~s/\,/\<br \/\>/g;      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
       if ($headextra) {
 # ----------------------------------------------------------- Front page design          my $omitextra;
     my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);          if ($headextra_exempt ne '') {
     my $font=&Apache::loncommon::designparm('login.font',$domain);              my @exempt = split(',',$headextra_exempt);
     my $link=&Apache::loncommon::designparm('login.link',$domain);              my $ip = $ENV{'REMOTE_ADDR'};
     my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);              if (grep(/^\Q$ip\E$/,@exempt)) {
     my $alink=&Apache::loncommon::designparm('login.alink',$domain);                  $omitextra = 1;
     my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);              }
     my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);          }
     my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);          unless ($omitextra) {
     my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);              my $confname = $defdom.'-domainconfig';
     my $logo=&Apache::loncommon::designparm('login.logo',$domain);              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
     my $img=&Apache::loncommon::designparm('login.img',$domain);                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
     my $domainlogo=&Apache::loncommon::domainlogo($domain);                  unless ($extra eq '-1') {
     my $showbanner = 1;                      $js .= "\n".$extra."\n";
     my $showmainlogo = 1;                  }
     if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {              }
         $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);          }
     }      }
     if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {  
         $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
     }         { 'redirect'       => [$expire,'/adm/roles'],
     my $showadminmail;   'add_entries' => \%add_entries,
     my @possdoms = &Apache::lonnet::current_machine_domains();   'only_body'   => 1,}));
     if (grep(/^\Q$domain\E$/,@possdoms)) {  
         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);  # ----------------------------------------------------------------------- Texts
     }  
     my $showcoursecat =      my %lt=&Apache::lonlocal::texthash(
         &Apache::loncommon::designparm('login.coursecatalog',$domain);            'un'       => 'Username',
     my $shownewuserlink =             'pw'       => 'Password',
         &Apache::loncommon::designparm('login.newuser',$domain);            'dom'      => 'Domain',
     my $showhelpdesk =            'perc'     => 'percent',
         &Apache::loncommon::designparm('login.helpdesk',$domain);            'load'     => 'Server Load',
     my $now=time;            'userload' => 'User Load',
     my $js = (<<ENDSCRIPT);            'catalog'  => 'Course/Community Catalog',
             'log'      => 'Log in',
 <script type="text/javascript" language="JavaScript">            'help'     => 'Log-in Help',
 // <![CDATA[            'serv'     => 'Server',
 function send()            'servadm'  => 'Server Administration',
 {            'helpdesk' => 'Contact Helpdesk',
 this.document.server.elements.uname.value            'forgotpw' => 'Forgot password?',
 =this.document.client.elements.uname.value;            'newuser'  => 'New User?',
          );
 this.document.server.elements.udom.value  # -------------------------------------------------- Change password field name
 =this.document.client.elements.udom.value;  
       my $forgotpw = &forgotpwdisplay(%lt);
 uextkey=this.document.client.elements.uextkey.value;      $forgotpw .= '<br />' if $forgotpw;
 lextkey=this.document.client.elements.lextkey.value;      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
 initkeys();      if ($loginhelp) {
           $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
 this.document.server.elements.upass0.value      }
     =getCrypted(this.document.client.elements.upass$now.value);  
   # ---------------------------------------------------- Serve out DES JavaScript
 this.document.client.elements.uname.value='';      {
 this.document.client.elements.upass$now.value='';      my $jsh=Apache::File->new($include."/londes.js");
       $r->print(<$jsh>);
 this.document.server.submit();      }
 return false;  # ---------------------------------------------------------- Serve rest of page
 }  
       $r->print(
 function enableInput() {      '<div class="LC_Box"'
     this.document.client.elements.upass$now.removeAttribute("readOnly");     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
     this.document.client.elements.uname.removeAttribute("readOnly");  );
     this.document.client.elements.udom.removeAttribute("readOnly");  
     return;      $r->print(<<ENDSERVERFORM);
 }  <form name="server" action="/adm/authenticate" method="post" target="_top">
      <input type="hidden" name="logtoken" value="$logtoken" />
 // ]]>     <input type="hidden" name="serverid" value="$lonhost" />
 </script>     <input type="hidden" name="uname" value="" />
      <input type="hidden" name="upass0" value="" />
 ENDSCRIPT     <input type="hidden" name="udom" value="" />
      <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
 # --------------------------------------------------- Print login screen header     <input type="hidden" name="localres" value="$env{'form.localres'}" />
     </form>
     my %add_entries = (  ENDSERVERFORM
        bgcolor      => "$mainbg",      my $coursecatalog;
        text         => "$font",      if (($showcoursecat eq '') || ($showcoursecat)) {
        link         => "$link",          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
        vlink        => "$vlink",      }
        alink        => "$alink",      my $newuserlink;
                onload       => 'javascript:enableInput();',);      if ($shownewuserlink) {
           $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
     my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);      }
     @hosts = &Apache::lonnet::current_machine_ids();      my $logintitle =
     $lonhost_in_use = $lonhost;          '<h2 class="LC_hcell"'
     if (@hosts > 1) {         .' style="background:'.$loginbox_header_bgcol.';'
         foreach my $hostid (@hosts) {         .' color:'.$loginbox_header_textcol.'">'
             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {         .$lt{'log'}
                 $lonhost_in_use = $hostid;         .'</h2>';
                 last;  
             }      my $noscript_warning='<noscript><span class="LC_warning"><b>'
         }                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
     }                          .'</b></span></noscript>';
     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);      my $helpdeskscript;
     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};                                         $authdomain,\$helpdeskscript,
     if ($headextra) {                                         $showhelpdesk,\@possdoms);
         my $omitextra;  
         if ($headextra_exempt ne '') {      my $mobileargs;
             my @exempt = split(',',$headextra_exempt);      if ($clientmobile) {
             my $ip = &Apache::lonnet::get_requestor_ip();          $mobileargs = 'autocapitalize="off" autocorrect="off"';
             if (grep(/^\Q$ip\E$/,@exempt)) {      }
                 $omitextra = 1;      my $loginform=(<<LFORM);
             }  <form name="client" action="" onsubmit="return(send())">
         }    <input type="hidden" name="lextkey" value="$lextkey" />
         unless ($omitextra) {    <input type="hidden" name="uextkey" value="$uextkey" />
             my $confname = $defdom.'-domainconfig';    <b><label for="uname">$lt{'un'}</label>:</b><br />
             if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {    <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
                 my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
                 unless ($extra eq '-1') {    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
                     $js .= "\n".$extra."\n";    <b><label for="udom">$lt{'dom'}</label>:</b><br />
                 }    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
             }    <input type="submit" value="$lt{'log'}" />
         }  </form>
     }  LFORM
   
     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,      if ($showbanner) {
        { 'redirect'       => [$expire,'/adm/roles'],           $r->print(<<HEADER);
  'add_entries' => \%add_entries,  <!-- The LON-CAPA Header -->
  'only_body'   => 1,}));  <div style="background:$pgbg;margin:0;width:100%;">
     <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
 # ----------------------------------------------------------------------- Texts  </div>
   HEADER
     my %lt=&Apache::lonlocal::texthash(      }
           'un'       => 'Username',      $r->print(<<ENDTOP);
           'pw'       => 'Password',  <div style="float:left;margin-top:0;">
           'dom'      => 'Domain',  <div class="LC_Box" style="background:$loginbox_bg;">
           'perc'     => 'percent',    $logintitle
           'load'     => 'Server Load',    $loginform
           'userload' => 'User Load',    $noscript_warning
           'catalog'  => 'Course/Community Catalog',  </div>
           'log'      => 'Log in',   
           'help'     => 'Log-in Help',  <div class="LC_Box" style="padding-top: 10px;">
           'serv'     => 'Server',    $loginhelp
           'servadm'  => 'Server Administration',    $forgotpw
           'helpdesk' => 'Contact Helpdesk',    $contactblock
           'forgotpw' => 'Forgot password?',    $newuserlink
           'newuser'  => 'New User?',    $coursecatalog
        );  </div>
 # -------------------------------------------------- Change password field name  </div>
   
     my $forgotpw = &forgotpwdisplay(%lt);  <div>
     $forgotpw .= '<br />' if $forgotpw;  ENDTOP
     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);      if ($showmainlogo) {
     if ($loginhelp) {          $r->print(' <img src="'.$logo.'" alt="" />'."\n");
         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';      }
     }  $r->print(<<ENDTOP);
   $announcements
 # ---------------------------------------------------- Serve out DES JavaScript  </div>
     {  <hr style="clear:both;" />
     my $jsh=Apache::File->new($include."/londes.js");  ENDTOP
     $r->print(<$jsh>);      my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
     }      $domainrow = <<"END";
 # ---------------------------------------------------------- Serve rest of page        <tr>
          <td  align="left" valign="top">
     $r->print(          <small><b>$lt{'dom'}:&nbsp;</b></small>
     '<div class="LC_Box"'         </td>
    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'         <td  align="left" valign="top">
 );          <small><tt>&nbsp;$domain</tt></small>
          </td>
     $r->print(<<ENDSERVERFORM);        </tr>
 <form name="server" action="/adm/authenticate" method="post" target="_top">  END
    <input type="hidden" name="logtoken" value="$logtoken" />      $serverrow = <<"END";
    <input type="hidden" name="serverid" value="$lonhost" />        <tr>
    <input type="hidden" name="uname" value="" />         <td  align="left" valign="top">
    <input type="hidden" name="upass0" value="" />          <small><b>$lt{'serv'}:&nbsp;</b></small>
    <input type="hidden" name="udom" value="" />         </td>
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />         <td align="left" valign="top">
    <input type="hidden" name="localres" value="$env{'form.localres'}" />          <small><tt>&nbsp;$lonhost ($role)</tt></small>
   </form>         </td>
 ENDSERVERFORM        </tr>
     my $coursecatalog;  END
     if (($showcoursecat eq '') || ($showcoursecat)) {      if ($loadlim) {
         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';          $loadrow = <<"END";
     }        <tr>
     my $newuserlink;         <td align="left" valign="top">
     if ($shownewuserlink) {          <small><b>$lt{'load'}:&nbsp;</b></small>
         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';         </td>
     }         <td align="left" valign="top">
     my $logintitle =          <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
         '<h2 class="LC_hcell"'         </td>
        .' style="background:'.$loginbox_header_bgcol.';'        </tr>
        .' color:'.$loginbox_header_textcol.'">'  END
        .$lt{'log'}      }
        .'</h2>';      if ($uloadlim) {
           $userloadrow = <<"END";
     my $noscript_warning='<noscript><span class="LC_warning"><b>'        <tr>
                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')         <td align="left" valign="top">
                         .'</b></span></noscript>';          <small><b>$lt{'userload'}:&nbsp;</b></small>
     my $helpdeskscript;         </td>
     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,         <td align="left" valign="top">
                                        $authdomain,\$helpdeskscript,          <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
                                        $showhelpdesk,\@possdoms);         </td>
         </tr>
     my $mobileargs;  END
     if ($clientmobile) {      }
         $mobileargs = 'autocapitalize="off" autocorrect="off"';       if (($version ne '') && ($version ne '<!-- VERSION -->')) {
     }          $versionrow = <<"END";
     my $loginform=(<<LFORM);        <tr>
 <form name="client" action="" onsubmit="return(send())">         <td colspan="2" align="left">
   <input type="hidden" name="lextkey" value="$lextkey" />          <small>$version</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 />  
   <b><label for="udom">$lt{'dom'}</label>:</b><br />      $r->print(<<ENDDOCUMENT);
   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />      <div style="float: left;">
   <input type="submit" value="$lt{'log'}" />       <table border="0" cellspacing="0" cellpadding="0">
 </form>  $domainrow
 LFORM  $serverrow
   $loadrow    
     if ($showbanner) {  $userloadrow
         $r->print(<<HEADER);  $versionrow
 <!-- The LON-CAPA Header -->       </table>
 <div style="background:$pgbg;margin:0;width:100%;">      </div>
   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />      <div style="float: right;">
 </div>      $domainlogo
 HEADER      </div>
     }      <br style="clear:both;" />
     $r->print(<<ENDTOP);   </div>
 <div style="float:left;margin-top:0;">  
 <div class="LC_Box" style="background:$loginbox_bg;">  <script type="text/javascript">
   $logintitle  // <![CDATA[
   $loginform  // the if prevents the script error if the browser can not handle this
   $noscript_warning  if ( document.client.uname ) { document.client.uname.focus(); }
 </div>  // ]]>
     </script>
 <div class="LC_Box" style="padding-top: 10px;">  $helpdeskscript
   $loginhelp  
   $forgotpw  ENDDOCUMENT
   $contactblock      my %endargs = ( 'noredirectlink' => 1, );
   $newuserlink      $r->print(&Apache::loncommon::end_page(\%endargs));
   $coursecatalog      return OK;
 </div>  }
 </div>  
   sub check_loginvia {
 <div>      my ($domain,$lonhost) = @_;
 ENDTOP      if ($domain eq '' || $lonhost eq '') {
     if ($showmainlogo) {          return;
         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");      }
     }      my %domconfhash = &Apache::loncommon::get_domainconf($domain);
 $r->print(<<ENDTOP);      my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
 $announcements      my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
 </div>      my $output;
 <hr style="clear:both;" />      if ($loginvia ne '') {
 ENDTOP          my $noredirect;
     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);          my $ip = $ENV{'REMOTE_ADDR'};
     $domainrow = <<"END";          if ($ip eq '127.0.0.1') {
       <tr>              $noredirect = 1;
        <td  align="left" valign="top">          } else {
         <small><b>$lt{'dom'}:&nbsp;</b></small>              if ($loginvia_exempt ne '') {
        </td>                  my @exempt = split(',',$loginvia_exempt);
        <td  align="left" valign="top">                  if (grep(/^\Q$ip\E$/,@exempt)) {
         <small><tt>&nbsp;$domain</tt></small>                      $noredirect = 1;
        </td>                  }
       </tr>              }
 END          }
     $serverrow = <<"END";          unless ($noredirect) {
       <tr>              my ($newhost,$path);
        <td  align="left" valign="top">              if ($loginvia =~ /:/) {
         <small><b>$lt{'serv'}:&nbsp;</b></small>                  ($newhost,$path) = split(':',$loginvia);
        </td>              } else {
        <td align="left" valign="top">                  $newhost = $loginvia;
         <small><tt>&nbsp;$lonhost ($role)</tt></small>              }
        </td>              if ($newhost ne $lonhost) {
       </tr>                  if (&Apache::lonnet::hostname($newhost) ne '') {
 END                      $output = &redirect_page($newhost,$path);
     if ($loadlim) {                  }
         $loadrow = <<"END";              }
       <tr>          }
        <td align="left" valign="top">      }
         <small><b>$lt{'load'}:&nbsp;</b></small>      return $output;
        </td>  }
        <td align="left" valign="top">  
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>  sub redirect_page {
        </td>      my ($desthost,$path) = @_;
       </tr>      my $protocol = $Apache::lonnet::protocol{$desthost};
 END      $protocol = 'http' if ($protocol ne 'https');
     }      unless ($path =~ m{^/}) {
     if ($uloadlim) {          $path = '/'.$path;
         $userloadrow = <<"END";      }
       <tr>      my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
        <td align="left" valign="top">      if ($env{'form.firsturl'} ne '') {
         <small><b>$lt{'userload'}:&nbsp;</b></small>          $url .='?firsturl='.$env{'form.firsturl'};
        </td>      }
        <td align="left" valign="top">      my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>                                                      {'redirect' => [0,$url],});
        </td>      my $end_page   = &Apache::loncommon::end_page();
       </tr>      return $start_page.$end_page;
 END  }
     }  
     if (($version ne '') && ($version ne '<!-- VERSION -->')) {  sub contactdisplay {
         $versionrow = <<"END";      my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
       <tr>          $possdoms) = @_;
        <td colspan="2" align="left">      my $contactblock;
         <small>$version</small>      my $origmail;
        </td>      if (ref($possdoms) eq 'ARRAY') {
       </tr>          if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
 END              $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
     }          }
       }
     $r->print(<<ENDDOCUMENT);      my $requestmail =
     <div style="float: left;">          &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
      <table border="0" cellspacing="0" cellpadding="0">                                                   $authdomain,$origmail);
 $domainrow      unless ($showhelpdesk eq '0') {
 $serverrow          if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
 $loadrow                  $showhelpdesk = 1;
 $userloadrow          } else {
 $versionrow              $showhelpdesk = 0;
      </table>          }
     </div>      }
     <div style="float: right;">      if ($servadm && $showadminmail) {
     $domainlogo          $contactblock .= $$lt{'servadm'}.':<br />'.
     </div>                           '<tt>'.$servadm.'</tt><br />';
     <br style="clear:both;" />      }
  </div>      if ($showhelpdesk) {
           $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
 <script type="text/javascript">          my $thisurl = &escape('/adm/login');
 // <![CDATA[          $$helpdeskscript = <<"ENDSCRIPT";
 // the if prevents the script error if the browser can not handle this  <script type="text/javascript">
 if ( document.client.uname ) { document.client.uname.focus(); }  // <![CDATA[
 // ]]>  function helpdesk() {
 </script>      var possdom = document.client.udom.value;
 $helpdeskscript      var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
       if (codedom == '') {
 ENDDOCUMENT          codedom = "$authdomain";
     my %endargs = ( 'noredirectlink' => 1, );      }
     $r->print(&Apache::loncommon::end_page(\%endargs));      var querystr = "origurl=$thisurl&codedom="+codedom;
     return OK;      document.location.href = "/adm/helpdesk?"+querystr;
 }      return;
   }
 sub check_loginvia {  // ]]>
     my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;  </script>
     if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {  ENDSCRIPT
         return;      }
     }      return $contactblock;
     my %domconfhash = &Apache::loncommon::get_domainconf($domain);  }
     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};  
     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};  sub forgotpwdisplay {
     my $output;      my (%lt) = @_;
     if ($loginvia ne '') {      my $prompt_for_resetpw = 1;
         my $noredirect;      if ($prompt_for_resetpw) {
         my $ip = &Apache::lonnet::get_requestor_ip();          return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
         if ($ip eq '127.0.0.1') {      }
             $noredirect = 1;      return;
         } else {  }
             if ($loginvia_exempt ne '') {  
                 my @exempt = split(',',$loginvia_exempt);  sub coursecatalog_link {
                 if (grep(/^\Q$ip\E$/,@exempt)) {      my ($linkname) = @_;
                     $noredirect = 1;      return <<"END";
                 }        <a href="/adm/coursecatalog">$linkname</a>
             }  END
         }  }
         unless ($noredirect) {  
             my ($newhost,$path);  sub newuser_link {
             if ($loginvia =~ /:/) {      my ($linkname) = @_;
                 ($newhost,$path) = split(':',$loginvia);      return '<a href="/adm/createaccount">'.$linkname.'</a>';
             } else {  }
                 $newhost = $loginvia;  
             }  1;
             if ($newhost ne $lonhost) {  __END__
                 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.12  
changed lines
  Added in v.1.167


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