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

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


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