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

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


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