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

version 1.55.2.3, 2005/06/14 20:10:50 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 CGI::Cookie();  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 lib '/home/httpd/lib/perl/';
 sub handler {  use LONCAPA qw(:DEFAULT :match);
     my $r = shift;  use CGI::Cookie();
     &Apache::loncommon::no_cache($r);   
     &Apache::lonlocal::get_language_handle($r);  sub handler {
     &Apache::loncommon::content_type($r,'text/html');      my $r = shift;
     $r->send_http_header;  
     return OK if $r->header_only;      &Apache::loncommon::get_unprocessed_cgi
    (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
         $ENV{'REDIRECT_QUERY_STRING'}),
 # Are we re-routing?   ['interface','username','domain','firsturl','localpath','localres',
     if (-e '/home/httpd/html/lon-status/reroute.txt') {    'token','role','symb','iptoken','btoken']);
  &Apache::lonauth::reroute($r);      if (!defined($env{'form.firsturl'})) {
  return OK;          &Apache::lonacc::get_posted_cgi($r,['firsturl']);
     }      }
       if (!defined($env{'form.firsturl'})) {
 # -------------------------------- Prevent users from attempting to login twice          if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {
     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));              $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};
     my $lonid=$cookies{'lonID'};          }
     my $cookie;      }
     if ($lonid) {  
  my $handle=$lonid->value;  # -- check if they are a migrating user
         $handle=~s/\W//g;      if (defined($env{'form.token'})) {
         my $lonidsdir=$r->dir_config('lonIDsDir');   return &Apache::migrateuser::handler($r);
         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {      }
 # Indeed, a valid token is found  
     my $bodytag=&Apache::loncommon::bodytag('Already logged in');  # For "public user" - remove any exising "public" cookie, as user really wants to log-in
     $r->print(<<ENDFAILED);      my ($handle,$lonidsdir,$expirepub,$userdom);
 <html>      $lonidsdir=$r->dir_config('lonIDsDir');
 <head>      unless ($r->header_only) {
 <title>Already logged in</title>          $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
 </head>          if ($handle ne '') {
 <html>              if ($handle=~/^publicuser\_/) {
 $bodytag                  unlink($r->dir_config('lonIDsDir')."/$handle.id");
 <h1>You are already logged in</h1>                  undef($handle);
 <p>Please either <a href="/adm/roles">continue the current session</a> or                  undef($userdom);
 <a href="/adm/logout">logout</a>.</p>                  $expirepub = 1;
 <p>              }
 <a href="/adm/loginproblems.html">Problems?</a></p>          }
 </body>      }
 </html>  
 ENDFAILED      &Apache::loncommon::no_cache($r);
            return OK;      &Apache::lonlocal::get_language_handle($r);
  }      &Apache::loncommon::content_type($r,'text/html');
     }      if ($expirepub) {
           my $c = new CGI::Cookie(-name    => 'lonPubID',
 # ---------------------------------------------------- No valid token, continue                                  -value   => '',
                                   -expires => '-10y',);
     &Apache::loncommon::get_unprocessed_cgi          $r->header_out('Set-cookie' => $c);
      ($ENV{'QUERY_STRING'}.'&'.$ENV{'request.querystring'},      } elsif (($handle eq '') && ($userdom ne '')) {
       ['interface','username','domain','firsturl','localpath','localres']);          my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
            foreach my $name (keys(%cookies)) {
               next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
 # ----------------------------------------------------------- Process Interface              my $c = new CGI::Cookie(-name    => $name,
     $ENV{'form.interface'}=~s/\W//g;                                      -value   => '',
                                       -expires => '-10y',);
     my $textbrowsers=$r->dir_config('lonTextBrowsers');              $r->headers_out->add('Set-cookie' => $c);
     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};          }
           }
     foreach (split(/\:/,$textbrowsers)) {      $r->send_http_header;
  if ($httpbrowser=~/$_/i) {      return OK if $r->header_only;
     $ENV{'form.interface'}='textual';  
         }  
     }  # Are we re-routing?
       my $londocroot = $r->dir_config('lonDocRoot');
     my $fullgraph=($ENV{'form.interface'} ne 'textual');      if (-e "$londocroot/lon-status/reroute.txt") {
     my $port_to_use=$r->dir_config('lonhttpdPort');   &Apache::lonauth::reroute($r);
     if (!defined($port_to_use)) {   return OK;
  $port_to_use='8080';      }
     }  
     my $iconpath= 'http://'.$ENV{'HTTP_HOST'}.':'.$port_to_use.      my $lonhost = $r->dir_config('lonHostID');
                   $r->dir_config('lonIconsURL');      $env{'form.firsturl'} =~ s/(`)/'/g;
     my $domain  = $r->dir_config('lonDefDomain');  
     my $testdomain=(split(/\./,$ENV{'HTTP_HOST'}))[0];  # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
     foreach my $posdom (values(%Apache::lonnet::hostdom)) {  
  if (lc($posdom) eq lc($testdomain)) { $domain=$posdom; }      my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
     }      if ($found_server) {
     if (($ENV{'form.domain'}) &&           my $hostname = &Apache::lonnet::hostname($found_server);
  ($Apache::lonnet::domaindescription{$ENV{'form.domain'}})) {          if ($hostname ne '') {
  $domain=$ENV{'form.domain'};              my $protocol = $Apache::lonnet::protocol{$found_server};
     }              $protocol = 'http' if ($protocol ne 'https');
     my $role    = $r->dir_config('lonRole');              my $dest = '/adm/roles';
     my $loadlim = $r->dir_config('lonLoadLim');              if ($env{'form.firsturl'} ne '') {
     my $servadm = $r->dir_config('lonAdmEMail');                  $dest = $env{'form.firsturl'};
     my $sysadm  = $r->dir_config('lonSysEMail');              }
     my $lonhost = $r->dir_config('lonHostID');              my %info = (
     my $tabdir  = $r->dir_config('lonTabDir');                           balcookie => $lonhost.':'.$balancer_cookie,
     my $include = $r->dir_config('lonIncludes');                         );
     my $expire  = $r->dir_config('lonExpire');              my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
     my $version = $r->dir_config('lonVersion');              if ($balancer_token) {
                   $dest .=  (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;
 # --------------------------------------------- Default values for login fields              }
               my $url = $protocol.'://'.$hostname.$dest;
     my $authusername=($ENV{'form.username'}?$ENV{'form.username'}:'');              my $start_page =
     my $authdomain=($ENV{'form.domain'}?$ENV{'form.domain'}:$domain);                  &Apache::loncommon::start_page('Switching Server ...',undef,
                                                  {'redirect'       => [0,$url],});
 # ---------------------------------------------------------- Determine own load              my $end_page   = &Apache::loncommon::end_page();
     my $loadavg;              $r->print($start_page.$end_page);
     {              return OK;
  my $loadfile=Apache::File->new('/proc/loadavg');          }
  $loadavg=<$loadfile>;      }
     }  
     $loadavg =~ s/\s.*//g;  #
     my $loadpercent=100*$loadavg/$loadlim;  # Check if a LON-CAPA load balancer sent user here because user's browser sent
     my $userloadpercent=&Apache::lonnet::userload();  # it a balancer cookie for an active session on this server.
   #
 # ------------------------------------------------------- Do the load balancing  
     my $otherserver='http://'.$ENV{'SERVER_NAME'};      my $balcookie;
     my $firsturl=      if ($env{'form.btoken'}) {
     ($ENV{'request.firsturl'}?$ENV{'request.firsturl'}:$ENV{'form.firsturl'});          my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
 # ---------------------------------------- Are we access server and overloaded?          $balcookie = $info{'balcookie'};
     if (($role eq 'access') &&          &Apache::lonnet::tmpdel($env{'form.btoken'});
  (($userloadpercent>100.0)||($loadpercent>100.0))) {          delete($env{'form.btoken'});
         my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent);      }
  if ($unloaded) { $otherserver=$unloaded; }  
     }  #
   # If browser sent an old cookie for which the session file had been removed
 # ----------------------------------------------------------- Get announcements  # check if configuration for user's domain has a portal URL set.  If so
     my $announcements=&Apache::lonnet::getannounce();  # switch user's log-in to the portal.
 # -------------------------------------------------------- Set login parameters  #
   
     my @hexstr=('0','1','2','3','4','5','6','7',      if (($handle eq '') && ($userdom ne '')) {
                 '8','9','a','b','c','d','e','f');          my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
     my $lkey='';          if ($domdefaults{'portal_def'} =~ /^https?\:/) {
     for (0..7) {              my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
         $lkey.=$hexstr[rand(15)];                                            {'redirect' => [0,$domdefaults{'portal_def'}],});
     }              my $end_page   = &Apache::loncommon::end_page();
               $r->print($start_page.$end_page);
     my $ukey='';              return OK;
     for (0..7) {          }
         $ukey.=$hexstr[rand(15)];      }
     }  
   # -------------------------------- Prevent users from attempting to login twice
     my $lextkey=hex($lkey);      if ($handle ne '') {
     if ($lextkey>2147483647) { $lextkey-=4294967296; }          &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
    my $start_page =
     my $uextkey=hex($ukey);      &Apache::loncommon::start_page('Already logged in');
     if ($uextkey>2147483647) { $uextkey-=4294967296; }   my $end_page =
       &Apache::loncommon::end_page();
 # -------------------------------------------------------- Store away log token          my $dest = '/adm/roles';
     my $logtoken=Apache::lonnet::reply(          if ($env{'form.firsturl'} ne '') {
        'tmpput:'.$ukey.$lkey.'&'.$firsturl,              $dest = $env{'form.firsturl'};
        $lonhost);          }
    $r->print(
 # ------------------- If we cannot talk to ourselves, we are in serious trouble                    $start_page
                    .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
     if ($logtoken eq 'con_lost') {                   .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
         my $spares='';                    '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
         foreach (keys %Apache::lonnet::hostname) {                   .$end_page
             if ($_ ne $lonhost) {                   );
                $spares.='<br /><a href="http://'.$Apache::lonnet::hostname{$_}.          return OK;
  '/adm/login?domain='.$authdomain.'">'.      }
                  $Apache::lonnet::hostname{$_}.'</a>';  
                if ($Apache::lonnet::spareid{$_}) {  # ---------------------------------------------------- No valid token, continue
    $spares.=' (preferred)';  
                }  # ---------------------------- Not possible to really login to domain "public"
    }      if ($env{'form.domain'} eq 'public') {
         }   $env{'form.domain'}='';
  $r->print(<<ENDTROUBLE);   $env{'form.username'}='';
 <html>      }
 <head><title>The LearningOnline Network with CAPA</title></head>  
 <body bgcolor="#FFFFFF">  # ------ Is this page requested because /adm/migrateuser detected an IP change?
 <img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />      my %sessiondata;
 <h3>This LON-CAPA server is temporarily not available for login</h3>      if ($env{'form.iptoken'}) {
 <p>Please attempt to login to one of the following servers:</p>$spares          %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
 <p>If the problem persists, please contact <tt>$servadm</tt>.</p>          unless ($sessiondata{'sessionserver'}) {
 </body>              my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
 </html>              delete($env{'form.iptoken'});
 ENDTROUBLE          }
         return OK;      }
     }  # ----------------------------------------------------------- Process Interface
       $env{'form.interface'}=~s/\W//g;
 # ----------------------------------------------- Apparently we are in business  
       (undef,undef,undef,undef,undef,undef,my $clientmobile) =
     my $domainlogo=&Apache::loncommon::domainlogo($domain);          &Apache::loncommon::decode_user_agent();
     $servadm=~s/\,/\<br \/\>/g;  
     $sysadm=~s/\,/\<br \/\>/g;      my $iconpath=
    &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
 # --------------------------------------------------- Print login screen header  
     $r->print(<<ENDHEADER);      my $domain = &Apache::lonnet::default_login_domain();
 <html>      my $defdom = $domain;
 <head>      if ($lonhost ne '') {
 <meta HTTP-EQUIV="Refresh" CONTENT="$expire; url=/adm/roles" />          unless ($sessiondata{'sessionserver'}) {
 <title>The LearningOnline Network with CAPA Login</title>              my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);
 </head>              if ($redirect) {
 ENDHEADER                  $r->print($redirect);
 # ---------------------------------------------------- Serve out DES JavaScript                  return OK;
     {              }
  my $jsh=Apache::File->new($include."/londes.js");          }
         $r->print(<$jsh>);      }
     }  
       if (($sessiondata{'domain'}) &&
 # ----------------------------------------------------------- Front page design          (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
     my $pgbg=          $domain=$sessiondata{'domain'};
       ($fullgraph?&Apache::loncommon::designparm('login.pgbg',$domain):'#FFFFFF');      } elsif (($env{'form.domain'}) &&
     my $font=   (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
       ($fullgraph?&Apache::loncommon::designparm('login.font',$domain):'#000000');   $domain=$env{'form.domain'};
     my $link=      }
       ($fullgraph?&Apache::loncommon::designparm('login.link',$domain):'#0000FF');  
     my $vlink=      my $role    = $r->dir_config('lonRole');
       ($fullgraph?&Apache::loncommon::designparm('login.vlink',$domain):'#0000FF');      my $loadlim = $r->dir_config('lonLoadLim');
     my $alink=&Apache::loncommon::designparm('login.alink',$domain);      my $uloadlim= $r->dir_config('lonUserLoadLim');
     my $mainbg=      my $servadm = $r->dir_config('lonAdmEMail');
       ($fullgraph?&Apache::loncommon::designparm('login.mainbg',$domain):'#FFFFFF');      my $tabdir  = $r->dir_config('lonTabDir');
     my $sidebg=      my $include = $r->dir_config('lonIncludes');
       ($fullgraph?&Apache::loncommon::designparm('login.sidebg',$domain):'#FFFFFF');      my $expire  = $r->dir_config('lonExpire');
     my $logo=&Apache::loncommon::designparm('login.logo',$domain);      my $version = $r->dir_config('lonVersion');
     my $img=&Apache::loncommon::designparm('login.img',$domain);      my $host_name = &Apache::lonnet::hostname($lonhost);
   
 # ----------------------------------------------------------------------- Texts  # --------------------------------------------- Default values for login fields
      
 my %lt=&Apache::lonlocal::texthash(      my ($authusername,$authdomain);
   'un'  => 'Username',      if ($sessiondata{'username'}) {
   'pw'  => 'Password',          $authusername=$sessiondata{'username'};
   'dom' => 'Domain',      } else {
   'perc' => 'percent',          $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
   'load' => 'Load',          $authusername=($env{'form.username'}?$env{'form.username'}:'');
                   'userload' => 'User Load',      }
                   'about'  => 'aboutlon.gif',      if ($sessiondata{'domain'}) {
                   'access' => 'accessbutton.gif',          $authdomain=$sessiondata{'domain'};
   'auth' => 'userauthentication.gif',      } else {
   'log' => 'Log in',          $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
   'help' => 'Help',          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
   'serv' => 'Server',      }
                   'servadm' => 'Server Administration',  
                   'sysadm' => 'System Administration');  # ---------------------------------------------------------- Determine own load
       my $loadavg;
       {
 # ---------------------------------------------------------- Serve rest of page   my $loadfile=Apache::File->new('/proc/loadavg');
     $r->print(<<ENDSCRIPT);   $loadavg=<$loadfile>;
       }
 <body bgcolor="$pgbg" text="$font" link="$link" vlink="$vlink" alink="$alink"      $loadavg =~ s/\s.*//g;
   topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>  
       my ($loadpercent,$userloadpercent);
  <script language="JavaScript">      if ($loadlim) {
     function send()          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
     {      }
  this.document.server.elements.uname.value      if ($uloadlim) {
        =this.document.client.elements.uname.value;          $userloadpercent=&Apache::lonnet::userload();
       }
         this.document.server.elements.udom.value  
        =this.document.client.elements.udom.value;      my $firsturl=
       ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
         this.document.server.elements.imagesuppress.value  
        =this.document.client.elements.imagesuppress.checked;  # ----------------------------------------------------------- Get announcements
       my $announcements=&Apache::lonnet::getannounce();
         this.document.server.elements.embedsuppress.value  # -------------------------------------------------------- Set login parameters
        =this.document.client.elements.embedsuppress.checked;  
       my @hexstr=('0','1','2','3','4','5','6','7',
         this.document.server.elements.appletsuppress.value                  '8','9','a','b','c','d','e','f');
        =this.document.client.elements.appletsuppress.checked;      my $lkey='';
       for (0..7) {
         this.document.server.elements.fontenhance.value          $lkey.=$hexstr[rand(15)];
        =this.document.client.elements.fontenhance.checked;      }
   
         this.document.server.elements.blackwhite.value      my $ukey='';
        =this.document.client.elements.blackwhite.checked;      for (0..7) {
           $ukey.=$hexstr[rand(15)];
         this.document.server.elements.remember.value      }
        =this.document.client.elements.remember.checked;  
       my $lextkey=hex($lkey);
         uextkey=this.document.client.elements.uextkey.value;      if ($lextkey>2147483647) { $lextkey-=4294967296; }
         lextkey=this.document.client.elements.lextkey.value;  
         initkeys();      my $uextkey=hex($ukey);
       if ($uextkey>2147483647) { $uextkey-=4294967296; }
         this.document.server.elements.upass.value  
     =crypted(this.document.client.elements.upass.value);  # -------------------------------------------------------- Store away log token
       my $tokenextras;
         this.document.server.submit();      if ($env{'form.role'}) {
  return false;          $tokenextras = '&role='.&escape($env{'form.role'});
     }      }
  </script>      if ($env{'form.symb'}) {
 ENDSCRIPT          if (!$tokenextras) {
               $tokenextras = '&';
     if ($fullgraph) {          }
  $r->print(          $tokenextras .= '&symb='.&escape($env{'form.symb'});
   '<table width="100%" cellpadding=0 cellspacing=0 border=0>');      }
     }      if ($env{'form.iptoken'}) {
           if (!$tokenextras) {
     $r->print(<<ENDSERVERFORM);              $tokenextras = '&&';
   <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">          }
    <input type="hidden" name="logtoken" value="$logtoken" />          $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
    <input type="hidden" name="serverid" value="$lonhost" />      }
    <input type="hidden" name="interface" value="$ENV{'form.interface'}" />      my $logtoken=Apache::lonnet::reply(
    <input type="hidden" name="uname" value="" />         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
    <input type="hidden" name="upass" value="" />         $lonhost);
    <input type="hidden" name="udom" value="" />  
    <input type="hidden" name="imagesuppress"  value="" />  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
    <input type="hidden" name="appletsuppress"  value="" />  #    we are in serious trouble
    <input type="hidden" name="embedsuppress"  value="" />  
    <input type="hidden" name="fontenhance"  value="" />      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
    <input type="hidden" name="blackwhite"  value="" />          if ($logtoken eq 'no_such_host') {
    <input type="hidden" name="remember"  value="" />              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
    <input type="hidden" name="localpath" value="$ENV{'form.localpath'}" />          }
    <input type="hidden" name="localres" value="$ENV{'form.localres'}" />          my $spares='';
   </form>   my $last;
 ENDSERVERFORM          foreach my $hostid (sort
     if ($fullgraph) { $r->print(<<ENDTOP);      {
   <!-- The LON-CAPA Header -->   &Apache::lonnet::hostname($a) cmp
   <tr>      &Apache::lonnet::hostname($b);
       }
    <!-- Row 1 Columns 2-4 -->      keys(%Apache::lonnet::spareid)) {
    <td width="100%" height=75 colspan=4 align="left" valign="top" bgcolor="$pgbg"><img src="$img" border=0 alt="The Learning Online Network with CAPA" /></td>              next if ($hostid eq $lonhost);
   </tr>      my $hostname = &Apache::lonnet::hostname($hostid);
       next if (($last eq $hostname) || ($hostname eq ''));
   <!-- The gray bar that starts the two table frames -->              $spares.='<br /><font size="+1"><a href="http://'.
   <tr>                  $hostname.
                   '/adm/login?domain='.$authdomain.'">'.
    <!-- Row 2 Column 1 -->                  $hostname.'</a>'.
    <td width=182 height=27 bgcolor="$sidebg">&nbsp;</td>                  ' '.&mt('(preferred)').'</font>'.$/;
       $last=$hostname;
    <!-- Row 2 Column 2 -->          }
    <td width=27 height=27 align="left" background="$iconpath/filltop.gif"><img src="$iconpath/upperleft.gif" border=0 alt="" /></td>          if ($spares) {
               $spares.= '<br />';
    <!-- Row 2 Column 3 -->          }
    <td height=27 background="$iconpath/filltop.gif"><img src="$iconpath/filltop.gif" alt="" /></td>          my %all_hostnames = &Apache::lonnet::all_hostnames();
           foreach my $hostid (sort
    <!-- Row 2 Column 4 -->      {
    <td width=27 height=27 align="right" background="$iconpath/filltop.gif"><img src="$iconpath/upperright.gif" border=0 alt="" /></td>   &Apache::lonnet::hostname($a) cmp
   </tr>      &Apache::lonnet::hostname($b);
   <tr>      }
          keys(%all_hostnames)) {
    <!-- A cell that will hold the 'access' and 'about' buttons -->              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
    <!-- Row 3 Column 1 -->              my $hostname = &Apache::lonnet::hostname($hostid);
    <td valign="top" height=60 align="center" bgcolor="$sidebg">              next if (($last eq $hostname) || ($hostname eq ''));
     <a href="/adm/login?interface=textual"><img src="$iconpath/$lt{'access'}" border=0 alt="Accessibility Options" /></a>              $spares.='<br /><a href="http://'.
     <br />               $hostname.
     <a href="/adm/about.html"><img src="$iconpath/$lt{'about'}" border=0 alt="About LON-CAPA" /></a>               '/adm/login?domain='.$authdomain.'">'.
    </td>               $hostname.'</a>';
               $last=$hostname;
    <!-- The shaded space between the two main columns -->           }
    <!-- Row 3 Column 2 -->           $r->print(
    <td width=27 height=60 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>     '<html>'
     .'<head><title>'
    <!-- The right main column holding the large LON-CAPA logo-->    .&mt('The LearningOnline Network with CAPA')
    <!-- Rows 3-4 Column 3 -->    .'</title></head>'
    <td align="center" valign="top" width="100%" height="100%" bgcolor="$mainbg">    .'<body bgcolor="#FFFFFF">'
     <center>    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
      <img src="$logo" alt="" />    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
     </center>    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
    </td>          if ($spares) {
               $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
    <!-- Row 3 Column 4 -->                       .'</p>'
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>                       .$spares);
   </tr>          }
   <tr>          $r->print('</body>'
                    .'</html>'
    <!-- The entry form -->          );
    <!-- Row 4 Column 1 -->          return OK;
    <td align="center" valign="middle" bgcolor="$sidebg">      }
 ENDTOP  
 } else {  # ----------------------------------------------- Apparently we are in business
     $r->print('<h1>The Learning<i>Online</i> Network with CAPA</h1><h2>Text-based Interface Login</h2>'.$announcements);      $servadm=~s/\,/\<br \/\>/g;
 }  
     $r->print('<form name="client" onsubmit="return(send())">');  # ----------------------------------------------------------- Front page design
     unless ($fullgraph) {      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
         $r->print(<<ENDACCESSOPTIONS);      my $font=&Apache::loncommon::designparm('login.font',$domain);
 <h3>Select Accessibility Options</h3>      my $link=&Apache::loncommon::designparm('login.link',$domain);
 <input type="checkbox" name="imagesuppress" /> Suppress rendering of images<br />      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
 <input type="checkbox" name="appletsuppress" /> Suppress Java applets<br />      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
 <input type="checkbox" name="embedsuppress" /> Suppress rendering of embedded multimedia<br />      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
 <input type="checkbox" name="fontenhance" /> Increase font size<br />      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
 <input type="checkbox" name="blackwhite" /> Switch to black and white mode<br />      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
 <p>If you have accessibility needs that are not addressed by this interface,       my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
 please      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
 contact the system administrator at <tt>$sysadm</tt>.</p><br />      my $img=&Apache::loncommon::designparm('login.img',$domain);
 <input type="checkbox" name="remember" /> Remember these settings for next login<hr />      my $domainlogo=&Apache::loncommon::domainlogo($domain);
 ENDACCESSOPTIONS      my $showbanner = 1;
 } else {      my $showmainlogo = 1;
     $r->print(<<ENDNOOPT);      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
 <input type="hidden" name="imagesuppress"  value="" />          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
 <input type="hidden" name="embedsuppress"  value="" />      }
 <input type="hidden" name="appletsuppress"  value="" />      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
 <input type="hidden" name="fontenhance"  value="" />          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
 <input type="hidden" name="blackwhite"  value="" />      }
 <input type="hidden" name="remember"  value="" />      my $showadminmail;
 ENDNOOPT      my @possdoms = &Apache::lonnet::current_machine_domains();
 }      if (grep(/^\Q$domain\E$/,@possdoms)) {
     $r->print(<<ENDLOGIN);          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
      <input type="hidden" name="lextkey" value="$lextkey">      }
      <input type="hidden" name="uextkey" value="$uextkey">      my $showcoursecat =
           &Apache::loncommon::designparm('login.coursecatalog',$domain);
      <!-- Start the sub-table for text and input alignment -->      my $shownewuserlink =
      <table border=0 cellspacing=0 cellpadding=0>          &Apache::loncommon::designparm('login.newuser',$domain);
       <tr><td bgcolor="$sidebg" colspan=2><img src="$iconpath/$lt{'auth'}" alt="User Authentication" /></td></tr>      my $showhelpdesk =
       <tr>          &Apache::loncommon::designparm('login.helpdesk',$domain);
        <td bgcolor="$mainbg"><br /><font size=-1><b>&nbsp;&nbsp;&nbsp;$lt{'un'}:</b></font></td>      my $now=time;
        <td bgcolor="$mainbg"><br /><input type="text" name="uname" size="10" value="$authusername" /></td>      my $js = (<<ENDSCRIPT);
       </tr>  
       <tr>  <script type="text/javascript" language="JavaScript">
        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;$lt{'pw'}:</b></font></td>  // <![CDATA[
        <td bgcolor="$mainbg"><input type="password" name="upass" size="10" /></td>  function send()
       </tr>  {
       <tr>  this.document.server.elements.uname.value
        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;$lt{'dom'}:</b></font></td>  =this.document.client.elements.uname.value;
        <td bgcolor="$mainbg"><input type="text" name="udom" size="10" value="$authdomain" /></td>  
       </tr>  this.document.server.elements.udom.value
       <tr>  =this.document.client.elements.udom.value;
        <td bgcolor="$mainbg">&nbsp;&nbsp;&nbsp;<a href="/adm/loginproblems.html">$lt{'help'}</a></td>  
        <td bgcolor="$mainbg" valign="bottom" align="center">  uextkey=this.document.client.elements.uextkey.value;
         <br />  lextkey=this.document.client.elements.lextkey.value;
         <input type="submit" value="$lt{'log'}" />  initkeys();
        </td>  
       </tr>  if(this.document.server.action.substr(0,5) === 'http:'){
      </table>      this.document.server.elements.upass0.value
      <!-- End sub-table -->          =getCrypted(this.document.client.elements.upass$now.value);
     </form>  } else {
 ENDLOGIN      this.document.server.elements.upass0.value
     if ($fullgraph) {          =this.document.client.elements.upass$now.value;
  $r->print(<<ENDDOCUMENT);  }
    </td>  
   this.document.client.elements.uname.value='';
    <!-- Row 4 Column 2 -->  this.document.client.elements.upass$now.value='';
    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>  
   this.document.server.submit();
    <!-- Row 4 Column 3 -->  return false;
 <td bgcolor="$mainbg">$announcements</td>  }
   
    <!-- Row 4 Column 4 -->  function enableInput() {
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>      this.document.client.elements.upass$now.removeAttribute("readOnly");
   </tr>      this.document.client.elements.uname.removeAttribute("readOnly");
   <tr>      this.document.client.elements.udom.removeAttribute("readOnly");
       return;
    <!-- Row 5 Column 1 -->  }
    <td bgcolor="$sidebg" valign="middle" align="left">  
      <br />  // ]]>
      <table border=0 cellspacing=0 cellpadding=0>  </script>
       <tr>  
        <td bgcolor="$sidebg" align="left" valign="top">  ENDSCRIPT
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'dom'}:&nbsp;</b></small>  
        </td>  # --------------------------------------------------- Print login screen header
        <td bgcolor="$sidebg" align="left" valign="top">  
         <small><tt>&nbsp;$domain</tt></small>      my %add_entries = (
        </td>         bgcolor      => "$mainbg",
       </tr>         text         => "$font",
       <tr>         link         => "$link",
        <td bgcolor="$sidebg" align="left" valign="top">         vlink        => "$vlink",
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'serv'}:&nbsp;</b></small>         alink        => "$alink",
        </td>                 onload       => 'javascript:enableInput();',);
        <td bgcolor="$sidebg" align="left" valign="top">  
         <small><tt>&nbsp;$lonhost ($role)</tt></small>      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
        </td>      @hosts = &Apache::lonnet::current_machine_ids();
       </tr>      $lonhost_in_use = $lonhost;
       <tr>      if (@hosts > 1) {
        <td bgcolor="$sidebg" align="left" valign="top">          foreach my $hostid (@hosts) {
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'load'}:&nbsp;</b></small>              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
        </td>                  $lonhost_in_use = $hostid;
        <td bgcolor="$sidebg" align="left" valign="top">                  last;
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>              }
        </td>          }
       </tr>      }
       <tr>      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
        <td bgcolor="$sidebg" align="left" valign="top">      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'userload'}:&nbsp;</b></small>      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
        </td>      if ($headextra) {
        <td bgcolor="$sidebg" align="left" valign="top">          my $omitextra;
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>          if ($headextra_exempt ne '') {
        </td>              my @exempt = split(',',$headextra_exempt);
       </tr>              my $ip = $ENV{'REMOTE_ADDR'};
      </table>              if (grep(/^\Q$ip\E$/,@exempt)) {
      <br />                  $omitextra = 1;
     <small>              }
      <b>&nbsp;&nbsp;&nbsp;$lt{'sysadm'}:</b><br />          }
      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sysadm</tt><br />          unless ($omitextra) {
      <b>&nbsp;&nbsp;&nbsp;$lt{'servadm'}:</b><br />              my $confname = $defdom.'-domainconfig';
      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$servadm</tt><br />&nbsp;<br />              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
      &nbsp;&nbsp;&nbsp;$version                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
     </small>                  unless ($extra eq '-1') {
    </td>                      $js .= "\n".$extra."\n";
                   }
    <!-- Row 5 Column 2 -->              }
    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>          }
       }
    <!-- Row 5 Column 3 -->  
    <td width="100%" valign="bottom" bgcolor="$mainbg">      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
 $domainlogo         { 'redirect'       => [$expire,'/adm/roles'],
 </td>   'add_entries' => \%add_entries,
    'only_body'   => 1,}));
    <!-- Row 5 Column 4 -->  
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>  # ----------------------------------------------------------------------- Texts
   </tr>  
   <tr>      my %lt=&Apache::lonlocal::texthash(
             'un'       => 'Username',
    <!-- Row 6 Column 1 -->            'pw'       => 'Password',
    <td bgcolor="$sidebg">&nbsp;</td>            'dom'      => 'Domain',
             'perc'     => 'percent',
    <!-- Row 6 Column 2 -->            'load'     => 'Server Load',
    <td align="left" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerleft.gif" alt="" /></td>            'userload' => 'User Load',
             'catalog'  => 'Course/Community Catalog',
    <!-- Row 6 Column 3 -->            'log'      => 'Log in',
    <td background="$iconpath/fillbottom.gif"><img src="$iconpath/fillbottom.gif" alt="" /></td>            'help'     => 'Log-in Help',
             'serv'     => 'Server',
    <!-- Row 6 Column 4 -->            'servadm'  => 'Server Administration',
    <td align="right" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerright.gif" alt="" /></td>            'helpdesk' => 'Contact Helpdesk',
   </tr>            'forgotpw' => 'Forgot password?',
  </table>            'newuser'  => 'New User?',
          );
 <script>  # -------------------------------------------------- Change password field name
 // the if prevents the script error if the browser can't handle this  
 if ( document.client.uname ) { document.client.uname.focus(); }      my $forgotpw = &forgotpwdisplay(%lt);
 </script>      $forgotpw .= '<br />' if $forgotpw;
       my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
 ENDDOCUMENT      if ($loginhelp) {
 }          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
     $r->print('</body></html>');      }
     return OK;  
 }   # ---------------------------------------------------- Serve out DES JavaScript
       {
 1;      my $jsh=Apache::File->new($include."/londes.js");
 __END__      $r->print(<$jsh>);
       }
   # ---------------------------------------------------------- Serve rest of page
   
       $r->print(
       '<div class="LC_Box"'
      .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
   );
   
       $r->print(<<ENDSERVERFORM);
   <form name="server" action="/adm/authenticate" method="post" target="_top">
      <input type="hidden" name="logtoken" value="$logtoken" />
      <input type="hidden" name="serverid" value="$lonhost" />
      <input type="hidden" name="uname" value="" />
      <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'}" />
     </form>
   ENDSERVERFORM
       my $coursecatalog;
       if (($showcoursecat eq '') || ($showcoursecat)) {
           $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
       }
       my $newuserlink;
       if ($shownewuserlink) {
           $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
       }
       my $logintitle =
           '<h2 class="LC_hcell"'
          .' style="background:'.$loginbox_header_bgcol.';'
          .' color:'.$loginbox_header_textcol.'">'
          .$lt{'log'}
          .'</h2>';
   
       my $noscript_warning='<noscript><span class="LC_warning"><b>'
                           .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
                           .'</b></span></noscript>';
       my $helpdeskscript;
       my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
                                          $authdomain,\$helpdeskscript,
                                          $showhelpdesk,\@possdoms);
   
       my $mobileargs;
       if ($clientmobile) {
           $mobileargs = 'autocapitalize="off" autocorrect="off"';
       }
       my $loginform=(<<LFORM);
   <form name="client" action="" onsubmit="return(send())">
     <input type="hidden" name="lextkey" value="$lextkey" />
     <input type="hidden" name="uextkey" value="$uextkey" />
     <b><label for="uname">$lt{'un'}</label>:</b><br />
     <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 />
     <b><label for="udom">$lt{'dom'}</label>:</b><br />
     <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
     <input type="submit" value="$lt{'log'}" />
   </form>
   LFORM
   
       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" class="LC_maxwidth" />
   </div>
   HEADER
       }
       $r->print(<<ENDTOP);
   <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.55.2.3  
changed lines
  Added in v.1.176


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