Diff for /loncom/auth/lonlogin.pm between versions 1.81 and 1.180

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


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