Diff for /loncom/auth/lonlogin.pm between versions 1.63 and 1.182

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


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