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

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

Removed from v.1.158.2.9.2.2  
changed lines
  Added in v.1.167


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