Diff for /loncom/auth/lonlogin.pm between versions 1.132 and 1.176

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


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