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

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


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