Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.9 and 1.160

version 1.158.2.9, 2019/08/04 12:18:44 version 1.160, 2014/12/05 12:03:20
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 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'},
  (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},        $ENV{'REDIRECT_QUERY_STRING'}),
       $ENV{'REDIRECT_QUERY_STRING'}),   ['interface','username','domain','firsturl','localpath','localres',
  ['interface','username','domain','firsturl','localpath','localres',    'token','role','symb','iptoken']);
   'token','role','symb','iptoken','btoken']);      if (!defined($env{'form.firsturl'})) {
     if (!defined($env{'form.firsturl'})) {          &Apache::lonacc::get_posted_cgi($r,['firsturl']);
         &Apache::lonacc::get_posted_cgi($r,['firsturl']);      }
     }  
   # -- check if they are a migrating user
 # -- check if they are a migrating user      if (defined($env{'form.token'})) {
     if (defined($env{'form.token'})) {   return &Apache::migrateuser::handler($r);
  return &Apache::migrateuser::handler($r);      }
     }  
       &Apache::loncommon::no_cache($r);
 # For "public user" - remove any exising "public" cookie, as user really wants to log-in      &Apache::lonlocal::get_language_handle($r);
     my ($handle,$lonidsdir,$expirepub,$userdom);      &Apache::loncommon::content_type($r,'text/html');
     $lonidsdir=$r->dir_config('lonIDsDir');      $r->send_http_header;
     unless ($r->header_only) {      return OK if $r->header_only;
         $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);  
         if ($handle ne '') {  
             if ($handle=~/^publicuser\_/) {  # Are we re-routing?
                 unlink($r->dir_config('lonIDsDir')."/$handle.id");      my $londocroot = $r->dir_config('lonDocRoot');
                 undef($handle);      if (-e "$londocroot/lon-status/reroute.txt") {
                 undef($userdom);   &Apache::lonauth::reroute($r);
                 $expirepub = 1;   return OK;
             }      }
         }  
     }      $env{'form.firsturl'} =~ s/(`)/'/g;
   
     &Apache::loncommon::no_cache($r);  # -------------------------------- Prevent users from attempting to login twice
     &Apache::lonlocal::get_language_handle($r);      my $handle = &Apache::lonnet::check_for_valid_session($r);
     &Apache::loncommon::content_type($r,'text/html');      if ($handle ne '') {
     if ($expirepub) {          my $lonidsdir=$r->dir_config('lonIDsDir');
         my $c = new CGI::Cookie(-name    => 'lonPubID',          if ($handle=~/^publicuser\_/) {
                                 -value   => '',  # For "public user" - remove it, we apparently really want to login
                                 -expires => '-10y',);      unlink($r->dir_config('lonIDsDir')."/$handle.id");
         $r->header_out('Set-cookie' => $c);          } else {
     } elsif (($handle eq '') && ($userdom ne '')) {  # Indeed, a valid token is found
         my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));              &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
         foreach my $name (keys(%cookies)) {      my $start_page =
             next unless ($name =~ /^lon(|S|Link|Pub)ID$/);          &Apache::loncommon::start_page('Already logged in');
             my $c = new CGI::Cookie(-name    => $name,      my $end_page =
                                     -value   => '',          &Apache::loncommon::end_page();
                                     -expires => '-10y',);              my $dest = '/adm/roles';
             $r->headers_out->add('Set-cookie' => $c);              if ($env{'form.firsturl'} ne '') {
         }                  $dest = $env{'form.firsturl'};
     }              }
     $r->send_http_header;      $r->print(
     return OK if $r->header_only;                    $start_page
                    .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
                    .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
 # Are we re-routing?                    '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
     my $londocroot = $r->dir_config('lonDocRoot');                    .$end_page
     if (-e "$londocroot/lon-status/reroute.txt") {                   );
  &Apache::lonauth::reroute($r);              return OK;
  return OK;          }
     }      }
   
     my $lonhost = $r->dir_config('lonHostID');  # ---------------------------------------------------- No valid token, continue
     $env{'form.firsturl'} =~ s/(`)/'/g;  
   # ---------------------------- Not possible to really login to domain "public"
 # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)      if ($env{'form.domain'} eq 'public') {
    $env{'form.domain'}='';
     my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);   $env{'form.username'}='';
     if ($found_server) {      }
         my $hostname = &Apache::lonnet::hostname($found_server);  
         if ($hostname ne '') {  # ------ Is this page requested because /adm/migrateuser detected an IP change?
             my $protocol = $Apache::lonnet::protocol{$found_server};      my %sessiondata;
             $protocol = 'http' if ($protocol ne 'https');      if ($env{'form.iptoken'}) {
             my $dest = '/adm/roles';          %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
             if ($env{'form.firsturl'} ne '') {          my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
                 $dest = $env{'form.firsturl'};      }
             }  # ----------------------------------------------------------- Process Interface
             my %info = (      $env{'form.interface'}=~s/\W//g;
                          balcookie => $lonhost.':'.$balancer_cookie,  
                        );      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
             my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);          &Apache::loncommon::decode_user_agent();
             if ($balancer_token) {  
                 $dest .=  (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;      my $iconpath=
             }   &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
             my $url = $protocol.'://'.$hostname.$dest;  
             my $start_page =      my $lonhost = $r->dir_config('lonHostID');
                 &Apache::loncommon::start_page('Switching Server ...',undef,      my $domain = &Apache::lonnet::default_login_domain();
                                                {'redirect'       => [0,$url],});      if ($lonhost ne '') {
             my $end_page   = &Apache::loncommon::end_page();          unless ($sessiondata{'sessionserver'}) {
             $r->print($start_page.$end_page);              my $redirect = &check_loginvia($domain,$lonhost);
             return OK;              if ($redirect) {
         }                  $r->print($redirect);
     }                  return OK;
               }
 #          }
 # Check if a LON-CAPA load balancer sent user here because user's browser sent      }
 # it a balancer cookie for an active session on this server.  
 #      if (($sessiondata{'domain'}) &&
           (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
     my $balcookie;          $domain=$sessiondata{'domain'};
     if ($env{'form.btoken'}) {      } elsif (($env{'form.domain'}) &&
         my %info = &Apache::lonnet::tmpget($env{'form.btoken'});   (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
         $balcookie = $info{'balcookie'};   $domain=$env{'form.domain'};
         &Apache::lonnet::tmpdel($env{'form.btoken'});      }
         delete($env{'form.btoken'});  
     }      my $role    = $r->dir_config('lonRole');
       my $loadlim = $r->dir_config('lonLoadLim');
 #      my $uloadlim= $r->dir_config('lonUserLoadLim');
 # If browser sent an old cookie for which the session file had been removed      my $servadm = $r->dir_config('lonAdmEMail');
 # check if configuration for user's domain has a portal URL set.  If so      my $tabdir  = $r->dir_config('lonTabDir');
 # switch user's log-in to the portal.      my $include = $r->dir_config('lonIncludes');
 #      my $expire  = $r->dir_config('lonExpire');
       my $version = $r->dir_config('lonVersion');
     if (($handle eq '') && ($userdom ne '')) {      my $host_name = &Apache::lonnet::hostname($lonhost);
         my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);  
         if ($domdefaults{'portal_def'} =~ /^https?\:/) {  # --------------------------------------------- Default values for login fields
             my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,     
                                           {'redirect' => [0,$domdefaults{'portal_def'}],});      my ($authusername,$authdomain);
             my $end_page   = &Apache::loncommon::end_page();      if ($sessiondata{'username'}) {
             $r->print($start_page.$end_page);          $authusername=$sessiondata{'username'};
             return OK;      } else {
         }          $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
     }          $authusername=($env{'form.username'}?$env{'form.username'}:'');
       }
     $env{'form.firsturl'} =~ s/(`)/'/g;      if ($sessiondata{'domain'}) {
           $authdomain=$sessiondata{'domain'};
 # -------------------------------- Prevent users from attempting to login twice      } else {
     if ($handle ne '') {          $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
  my $start_page =       }
     &Apache::loncommon::start_page('Already logged in');  
  my $end_page =   # ---------------------------------------------------------- Determine own load
     &Apache::loncommon::end_page();      my $loadavg;
         my $dest = '/adm/roles';      {
         if ($env{'form.firsturl'} ne '') {   my $loadfile=Apache::File->new('/proc/loadavg');
             $dest = $env{'form.firsturl'};    $loadavg=<$loadfile>;
         }      }
  $r->print(      $loadavg =~ s/\s.*//g;
               $start_page  
              .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'      my ($loadpercent,$userloadpercent);
              .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',      if ($loadlim) {
               '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
              .$end_page      }
              );      if ($uloadlim) {
         return OK;          $userloadpercent=&Apache::lonnet::userload();
     }      }
   
 # ---------------------------------------------------- No valid token, continue      my $firsturl=
       ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
 # ---------------------------- Not possible to really login to domain "public"  
     if ($env{'form.domain'} eq 'public') {  # ----------------------------------------------------------- Get announcements
  $env{'form.domain'}='';      my $announcements=&Apache::lonnet::getannounce();
  $env{'form.username'}='';  # -------------------------------------------------------- Set login parameters
     }  
       my @hexstr=('0','1','2','3','4','5','6','7',
 # ------ Is this page requested because /adm/migrateuser detected an IP change?                  '8','9','a','b','c','d','e','f');
     my %sessiondata;      my $lkey='';
     if ($env{'form.iptoken'}) {      for (0..7) {
         %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});          $lkey.=$hexstr[rand(15)];
         unless ($sessiondata{'sessionserver'}) {      }
             my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});  
             delete($env{'form.iptoken'});      my $ukey='';
         }      for (0..7) {
     }          $ukey.=$hexstr[rand(15)];
 # ----------------------------------------------------------- Process Interface      }
     $env{'form.interface'}=~s/\W//g;  
       my $lextkey=hex($lkey);
     (undef,undef,undef,undef,undef,undef,my $clientmobile) =      if ($lextkey>2147483647) { $lextkey-=4294967296; }
         &Apache::loncommon::decode_user_agent();  
       my $uextkey=hex($ukey);
     my $iconpath=       if ($uextkey>2147483647) { $uextkey-=4294967296; }
  &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));  
   # -------------------------------------------------------- Store away log token
     my $domain = &Apache::lonnet::default_login_domain();      my $tokenextras;
     my $defdom = $domain;      if ($env{'form.role'}) {
     if ($lonhost ne '') {          $tokenextras = '&role='.&escape($env{'form.role'});
         unless ($sessiondata{'sessionserver'}) {      }
             my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);      if ($env{'form.symb'}) {
             if ($redirect) {          if (!$tokenextras) {
                 $r->print($redirect);              $tokenextras = '&';
                 return OK;          }
             }          $tokenextras .= '&symb='.&escape($env{'form.symb'});
         }      }
     }      my $logtoken=Apache::lonnet::reply(
          'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
     if (($sessiondata{'domain'}) &&         $lonhost);
         (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {  
         $domain=$sessiondata{'domain'};  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
     } elsif (($env{'form.domain'}) &&   #    we are in serious trouble
  (&Apache::lonnet::domain($env{'form.domain'},'description'))) {  
  $domain=$env{'form.domain'};      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
     }          if ($logtoken eq 'no_such_host') {
               &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
     my $role    = $r->dir_config('lonRole');          }
     my $loadlim = $r->dir_config('lonLoadLim');          my $spares='';
     my $uloadlim= $r->dir_config('lonUserLoadLim');   my $last;
     my $servadm = $r->dir_config('lonAdmEMail');          foreach my $hostid (sort
     my $tabdir  = $r->dir_config('lonTabDir');      {
     my $include = $r->dir_config('lonIncludes');   &Apache::lonnet::hostname($a) cmp
     my $expire  = $r->dir_config('lonExpire');      &Apache::lonnet::hostname($b);
     my $version = $r->dir_config('lonVersion');      }
     my $host_name = &Apache::lonnet::hostname($lonhost);      keys(%Apache::lonnet::spareid)) {
               next if ($hostid eq $lonhost);
 # --------------------------------------------- Default values for login fields      my $hostname = &Apache::lonnet::hostname($hostid);
           next if (($last eq $hostname) || ($hostname eq ''));
     my ($authusername,$authdomain);              $spares.='<br /><font size="+1"><a href="http://'.
     if ($sessiondata{'username'}) {                  $hostname.
         $authusername=$sessiondata{'username'};                  '/adm/login?domain='.$authdomain.'">'.
     } else {                  $hostname.'</a>'.
         $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});                  ' '.&mt('(preferred)').'</font>'.$/;
         $authusername=($env{'form.username'}?$env{'form.username'}:'');      $last=$hostname;
     }          }
     if ($sessiondata{'domain'}) {          if ($spares) {
         $authdomain=$sessiondata{'domain'};              $spares.= '<br />';
     } else {          }
         $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});          my %all_hostnames = &Apache::lonnet::all_hostnames();
         $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);          foreach my $hostid (sort
     }      {
    &Apache::lonnet::hostname($a) cmp
 # ---------------------------------------------------------- Determine own load      &Apache::lonnet::hostname($b);
     my $loadavg;      }
     {      keys(%all_hostnames)) {
  my $loadfile=Apache::File->new('/proc/loadavg');              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
  $loadavg=<$loadfile>;              my $hostname = &Apache::lonnet::hostname($hostid);
     }              next if (($last eq $hostname) || ($hostname eq ''));
     $loadavg =~ s/\s.*//g;              $spares.='<br /><a href="http://'.
                $hostname.
     my ($loadpercent,$userloadpercent);               '/adm/login?domain='.$authdomain.'">'.
     if ($loadlim) {               $hostname.'</a>';
         $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);              $last=$hostname;
     }           }
     if ($uloadlim) {           $r->print(
         $userloadpercent=&Apache::lonnet::userload();     '<html>'
     }    .'<head><title>'
     .&mt('The LearningOnline Network with CAPA')
     my $firsturl=    .'</title></head>'
     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});    .'<body bgcolor="#FFFFFF">'
     .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
 # ----------------------------------------------------------- Get announcements    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
     my $announcements=&Apache::lonnet::getannounce();    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
 # -------------------------------------------------------- Set login parameters          if ($spares) {
               $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
     my @hexstr=('0','1','2','3','4','5','6','7',                       .'</p>'
                 '8','9','a','b','c','d','e','f');                       .$spares);
     my $lkey='';          }
     for (0..7) {          $r->print('</body>'
         $lkey.=$hexstr[rand(15)];                   .'</html>'
     }          );
           return OK;
     my $ukey='';      }
     for (0..7) {  
         $ukey.=$hexstr[rand(15)];  # ----------------------------------------------- Apparently we are in business
     }      $servadm=~s/\,/\<br \/\>/g;
   
     my $lextkey=hex($lkey);  # ----------------------------------------------------------- Front page design
     if ($lextkey>2147483647) { $lextkey-=4294967296; }      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
       my $font=&Apache::loncommon::designparm('login.font',$domain);
     my $uextkey=hex($ukey);      my $link=&Apache::loncommon::designparm('login.link',$domain);
     if ($uextkey>2147483647) { $uextkey-=4294967296; }      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
       my $alink=&Apache::loncommon::designparm('login.alink',$domain);
 # -------------------------------------------------------- Store away log token      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
     my $tokenextras;      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
     if ($env{'form.role'}) {      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
         $tokenextras = '&role='.&escape($env{'form.role'});      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
     }      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
     if ($env{'form.symb'}) {      my $img=&Apache::loncommon::designparm('login.img',$domain);
         if (!$tokenextras) {      my $domainlogo=&Apache::loncommon::domainlogo($domain);
             $tokenextras = '&';      my $showbanner = 1;
         }      my $showmainlogo = 1;
         $tokenextras .= '&symb='.&escape($env{'form.symb'});      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
     }          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
     if ($env{'form.iptoken'}) {      }
         if (!$tokenextras) {      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
             $tokenextras = '&&';          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
         }      }
         $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});      my $showadminmail;
     }      my @possdoms = &Apache::lonnet::current_machine_domains();
     my $logtoken=Apache::lonnet::reply(      if (grep(/^\Q$domain\E$/,@possdoms)) {
        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
        $lonhost);      }
       my $showcoursecat =
 # -- If we cannot talk to ourselves, or hostID does not map to a hostname          &Apache::loncommon::designparm('login.coursecatalog',$domain);
 #    we are in serious trouble      my $shownewuserlink =
           &Apache::loncommon::designparm('login.newuser',$domain);
     if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {      my $showhelpdesk =
         if ($logtoken eq 'no_such_host') {          &Apache::loncommon::designparm('login.helpdesk',$domain);
             &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');      my $now=time;
         }      my $js = (<<ENDSCRIPT);
         my $spares='';  
  my $last;  <script type="text/javascript" language="JavaScript">
         foreach my $hostid (sort  // <![CDATA[
     {  function send()
  &Apache::lonnet::hostname($a) cmp  {
     &Apache::lonnet::hostname($b);  this.document.server.elements.uname.value
     }  =this.document.client.elements.uname.value;
     keys(%Apache::lonnet::spareid)) {  
             next if ($hostid eq $lonhost);  this.document.server.elements.udom.value
     my $hostname = &Apache::lonnet::hostname($hostid);  =this.document.client.elements.udom.value;
     next if (($last eq $hostname) || ($hostname eq ''));  
             $spares.='<br /><font size="+1"><a href="http://'.  uextkey=this.document.client.elements.uextkey.value;
                 $hostname.  lextkey=this.document.client.elements.lextkey.value;
                 '/adm/login?domain='.$authdomain.'">'.  initkeys();
                 $hostname.'</a>'.  
                 ' '.&mt('(preferred)').'</font>'.$/;  this.document.server.elements.upass0.value
     $last=$hostname;      =this.document.client.elements.upass$now.value.substr(0,15);
         }  this.document.server.elements.upass1.value
         if ($spares) {      =this.document.client.elements.upass$now.value.substr(15,15);
             $spares.= '<br />';  this.document.server.elements.upass2.value
         }      =this.document.client.elements.upass$now.value.substr(30,15);
         my %all_hostnames = &Apache::lonnet::all_hostnames();  
         foreach my $hostid (sort  if(this.document.server.action.substr(0,5) === 'http:'){
     {      for (var idx in [1,2,3]){
  &Apache::lonnet::hostname($a) cmp          this.document.server.elements['upass' + idx].value =
     &Apache::lonnet::hostname($b);              crypted(this.document.server.elements['upass' + idx].value);
     }      }
     keys(%all_hostnames)) {  }
             next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});  
             my $hostname = &Apache::lonnet::hostname($hostid);  this.document.client.elements.uname.value='';
             next if (($last eq $hostname) || ($hostname eq ''));  this.document.client.elements.upass$now.value='';
             $spares.='<br /><a href="http://'.  
              $hostname.  this.document.server.submit();
              '/adm/login?domain='.$authdomain.'">'.  return false;
              $hostname.'</a>';  }
             $last=$hostname;  
          }  function enableInput() {
          $r->print(      this.document.client.elements.upass$now.removeAttribute("readOnly");
    '<html>'      this.document.client.elements.uname.removeAttribute("readOnly");
   .'<head><title>'      this.document.client.elements.udom.removeAttribute("readOnly");
   .&mt('The LearningOnline Network with CAPA')      return;
   .'</title></head>'  }
   .'<body bgcolor="#FFFFFF">'  
   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'  // ]]>
   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'  </script>
   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');  
         if ($spares) {  ENDSCRIPT
             $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')  
                      .'</p>'  # --------------------------------------------------- Print login screen header
                      .$spares);  
         }      my %add_entries = (
         $r->print('</body>'         bgcolor      => "$mainbg",
                  .'</html>'         text         => "$font",
         );         link         => "$link",
         return OK;         vlink        => "$vlink",
     }         alink        => "$alink",
                  onload       => 'javascript:enableInput();',);
 # ----------------------------------------------- Apparently we are in business  
     $servadm=~s/\,/\<br \/\>/g;      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
          { 'redirect'       => [$expire,'/adm/roles'],
 # ----------------------------------------------------------- Front page design   'add_entries' => \%add_entries,
     my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);   'only_body'   => 1,}));
     my $font=&Apache::loncommon::designparm('login.font',$domain);  
     my $link=&Apache::loncommon::designparm('login.link',$domain);  # ----------------------------------------------------------------------- Texts
     my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);  
     my $alink=&Apache::loncommon::designparm('login.alink',$domain);      my %lt=&Apache::lonlocal::texthash(
     my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);            'un'       => 'Username',
     my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);            'pw'       => 'Password',
     my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);            'dom'      => 'Domain',
     my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);            'perc'     => 'percent',
     my $logo=&Apache::loncommon::designparm('login.logo',$domain);            'load'     => 'Server Load',
     my $img=&Apache::loncommon::designparm('login.img',$domain);            'userload' => 'User Load',
     my $domainlogo=&Apache::loncommon::domainlogo($domain);            'catalog'  => 'Course/Community Catalog',
     my $showbanner = 1;            'log'      => 'Log in',
     my $showmainlogo = 1;            'help'     => 'Log-in Help',
     if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {            'serv'     => 'Server',
         $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);            'servadm'  => 'Server Administration',
     }            'helpdesk' => 'Contact Helpdesk',
     if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {            'forgotpw' => 'Forgot password?',
         $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);            'newuser'  => 'New User?',
     }         );
     my $showadminmail;  # -------------------------------------------------- Change password field name
     my @possdoms = &Apache::lonnet::current_machine_domains();  
     if (grep(/^\Q$domain\E$/,@possdoms)) {      my $forgotpw = &forgotpwdisplay(%lt);
         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);      $forgotpw .= '<br />' if $forgotpw;
     }      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
     my $showcoursecat =      if ($loginhelp) {
         &Apache::loncommon::designparm('login.coursecatalog',$domain);          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
     my $shownewuserlink =       }
         &Apache::loncommon::designparm('login.newuser',$domain);  
     my $showhelpdesk =  # ---------------------------------------------------- Serve out DES JavaScript
         &Apache::loncommon::designparm('login.helpdesk',$domain);      {
     my $now=time;      my $jsh=Apache::File->new($include."/londes.js");
     my $js = (<<ENDSCRIPT);      $r->print(<$jsh>);
       }
 <script type="text/javascript" language="JavaScript">  # ---------------------------------------------------------- Serve rest of page
 // <![CDATA[  
 function send()      $r->print(
 {      '<div class="LC_Box"'
 this.document.server.elements.uname.value     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
 =this.document.client.elements.uname.value;  );
   
 this.document.server.elements.udom.value      $r->print(<<ENDSERVERFORM);
 =this.document.client.elements.udom.value;  <form name="server" action="/adm/authenticate" method="post" target="_top">
      <input type="hidden" name="logtoken" value="$logtoken" />
 uextkey=this.document.client.elements.uextkey.value;     <input type="hidden" name="serverid" value="$lonhost" />
 lextkey=this.document.client.elements.lextkey.value;     <input type="hidden" name="uname" value="" />
 initkeys();     <input type="hidden" name="upass0" value="" />
      <input type="hidden" name="upass1" value="" />
 this.document.server.elements.upass0.value     <input type="hidden" name="upass2" value="" />
     =getCrypted(this.document.client.elements.upass$now.value);     <input type="hidden" name="udom" value="" />
      <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
 this.document.client.elements.uname.value='';     <input type="hidden" name="localres" value="$env{'form.localres'}" />
 this.document.client.elements.upass$now.value='';    </form>
   ENDSERVERFORM
 this.document.server.submit();      my $coursecatalog;
 return false;      if (($showcoursecat eq '') || ($showcoursecat)) {
 }          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
       }
 function enableInput() {      my $newuserlink;
     this.document.client.elements.upass$now.removeAttribute("readOnly");      if ($shownewuserlink) {
     this.document.client.elements.uname.removeAttribute("readOnly");          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
     this.document.client.elements.udom.removeAttribute("readOnly");      }
     return;      my $logintitle =
 }          '<h2 class="LC_hcell"'
          .' style="background:'.$loginbox_header_bgcol.';'
 // ]]>         .' color:'.$loginbox_header_textcol.'">'
 </script>         .$lt{'log'}
          .'</h2>';
 ENDSCRIPT  
       my $noscript_warning='<noscript><span class="LC_warning"><b>'
 # --------------------------------------------------- Print login screen header                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
                           .'</b></span></noscript>';
     my %add_entries = (      my $helpdeskscript;
        bgcolor      => "$mainbg",      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
        text         => "$font",                                         $authdomain,\$helpdeskscript,
        link         => "$link",                                         $showhelpdesk,\@possdoms);
        vlink        => "$vlink",  
        alink        => "$alink",      my $mobileargs;
                onload       => 'javascript:enableInput();',);      if ($clientmobile) {
           $mobileargs = 'autocapitalize="off" autocorrect="off"';
     my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);      }
     @hosts = &Apache::lonnet::current_machine_ids();      my $loginform=(<<LFORM);
     $lonhost_in_use = $lonhost;  <form name="client" action="" onsubmit="return(send())">
     if (@hosts > 1) {    <input type="hidden" name="lextkey" value="$lextkey" />
         foreach my $hostid (@hosts) {    <input type="hidden" name="uextkey" value="$uextkey" />
             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {    <b><label for="uname">$lt{'un'}</label>:</b><br />
                 $lonhost_in_use = $hostid;    <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
                 last;    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
             }    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
         }    <b><label for="udom">$lt{'dom'}</label>:</b><br />
     }    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);    <input type="submit" value="$lt{'log'}" />
     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};  </form>
     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};  LFORM
     if ($headextra) {  
         my $omitextra;      if ($showbanner) {
         if ($headextra_exempt ne '') {          $r->print(<<HEADER);
             my @exempt = split(',',$headextra_exempt);  <!-- The LON-CAPA Header -->
             my $ip = $ENV{'REMOTE_ADDR'};  <div style="background:$pgbg;margin:0;width:100%;">
             if (grep(/^\Q$ip\E$/,@exempt)) {    <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
                 $omitextra = 1;  </div>
             }  HEADER
         }      }
         unless ($omitextra) {      $r->print(<<ENDTOP);
             my $confname = $defdom.'-domainconfig';  <div style="float:left;margin-top:0;">
             if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {  <div class="LC_Box" style="background:$loginbox_bg;">
                 my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));    $logintitle
                 unless ($extra eq '-1') {    $loginform
                     $js .= "\n".$extra."\n";    $noscript_warning
                 }  </div>
             }   
         }  <div class="LC_Box" style="padding-top: 10px;">
     }    $loginhelp
     $forgotpw
     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,    $contactblock
        { 'redirect'       => [$expire,'/adm/roles'],     $newuserlink
  'add_entries' => \%add_entries,    $coursecatalog
  'only_body'   => 1,}));  </div>
   </div>
 # ----------------------------------------------------------------------- Texts  
   <div>
     my %lt=&Apache::lonlocal::texthash(  ENDTOP
           'un'       => 'Username',      if ($showmainlogo) {
           'pw'       => 'Password',          $r->print(' <img src="'.$logo.'" alt="" />'."\n");
           'dom'      => 'Domain',      }
           'perc'     => 'percent',  $r->print(<<ENDTOP);
           'load'     => 'Server Load',  $announcements
           'userload' => 'User Load',  </div>
           'catalog'  => 'Course/Community Catalog',  <hr style="clear:both;" />
           'log'      => 'Log in',  ENDTOP
           'help'     => 'Log-in Help',      my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
           'serv'     => 'Server',      $domainrow = <<"END";
           'servadm'  => 'Server Administration',        <tr>
           'helpdesk' => 'Contact Helpdesk',         <td  align="left" valign="top">
           'forgotpw' => 'Forgot password?',          <small><b>$lt{'dom'}:&nbsp;</b></small>
           'newuser'  => 'New User?',         </td>
        );         <td  align="left" valign="top">
 # -------------------------------------------------- Change password field name          <small><tt>&nbsp;$domain</tt></small>
          </td>
     my $forgotpw = &forgotpwdisplay(%lt);        </tr>
     $forgotpw .= '<br />' if $forgotpw;  END
     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);      $serverrow = <<"END";
     if ($loginhelp) {        <tr>
         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';         <td  align="left" valign="top">
     }          <small><b>$lt{'serv'}:&nbsp;</b></small>
          </td>
 # ---------------------------------------------------- Serve out DES JavaScript         <td align="left" valign="top">
     {          <small><tt>&nbsp;$lonhost ($role)</tt></small>
     my $jsh=Apache::File->new($include."/londes.js");         </td>
     $r->print(<$jsh>);        </tr>
     }  END
 # ---------------------------------------------------------- Serve rest of page      if ($loadlim) {
           $loadrow = <<"END";
     $r->print(        <tr>
     '<div class="LC_Box"'         <td align="left" valign="top">
    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'          <small><b>$lt{'load'}:&nbsp;</b></small>
 );         </td>
          <td align="left" valign="top">
     $r->print(<<ENDSERVERFORM);          <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
 <form name="server" action="/adm/authenticate" method="post" target="_top">         </td>
    <input type="hidden" name="logtoken" value="$logtoken" />        </tr>
    <input type="hidden" name="serverid" value="$lonhost" />  END
    <input type="hidden" name="uname" value="" />      }
    <input type="hidden" name="upass0" value="" />      if ($uloadlim) {
    <input type="hidden" name="udom" value="" />          $userloadrow = <<"END";
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />        <tr>
    <input type="hidden" name="localres" value="$env{'form.localres'}" />         <td align="left" valign="top">
   </form>          <small><b>$lt{'userload'}:&nbsp;</b></small>
 ENDSERVERFORM         </td>
     my $coursecatalog;         <td align="left" valign="top">
     if (($showcoursecat eq '') || ($showcoursecat)) {          <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';         </td>
     }        </tr>
     my $newuserlink;  END
     if ($shownewuserlink) {      }
         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';      if (($version ne '') && ($version ne '<!-- VERSION -->')) {
     }          $versionrow = <<"END";
     my $logintitle =        <tr>
         '<h2 class="LC_hcell"'         <td colspan="2" align="left">
        .' style="background:'.$loginbox_header_bgcol.';'          <small>$version</small>
        .' color:'.$loginbox_header_textcol.'">'         </td>
        .$lt{'log'}        </tr>
        .'</h2>';  END
       }
     my $noscript_warning='<noscript><span class="LC_warning"><b>'  
                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')      $r->print(<<ENDDOCUMENT);
                         .'</b></span></noscript>';      <div style="float: left;">
     my $helpdeskscript;       <table border="0" cellspacing="0" cellpadding="0">
     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,  $domainrow
                                        $authdomain,\$helpdeskscript,  $serverrow
                                        $showhelpdesk,\@possdoms);  $loadrow    
   $userloadrow
     my $mobileargs;  $versionrow
     if ($clientmobile) {       </table>
         $mobileargs = 'autocapitalize="off" autocorrect="off"';       </div>
     }      <div style="float: right;">
     my $loginform=(<<LFORM);      $domainlogo
 <form name="client" action="" onsubmit="return(send())">      </div>
   <input type="hidden" name="lextkey" value="$lextkey" />      <br style="clear:both;" />
   <input type="hidden" name="uextkey" value="$uextkey" />   </div>
   <b><label for="uname">$lt{'un'}</label>:</b><br />  
   <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />  <script type="text/javascript">
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />  // <![CDATA[
   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />  // the if prevents the script error if the browser can not handle this
   <b><label for="udom">$lt{'dom'}</label>:</b><br />  if ( document.client.uname ) { document.client.uname.focus(); }
   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />  // ]]>
   <input type="submit" value="$lt{'log'}" />  </script>
 </form>  $helpdeskscript
 LFORM  
   ENDDOCUMENT
     if ($showbanner) {      my %endargs = ( 'noredirectlink' => 1, );
         $r->print(<<HEADER);      $r->print(&Apache::loncommon::end_page(\%endargs));
 <!-- The LON-CAPA Header -->      return OK;
 <div style="background:$pgbg;margin:0;width:100%;">  }
   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />  
 </div>  sub check_loginvia {
 HEADER      my ($domain,$lonhost) = @_;
     }      if ($domain eq '' || $lonhost eq '') {
     $r->print(<<ENDTOP);          return;
 <div style="float:left;margin-top:0;">      }
 <div class="LC_Box" style="background:$loginbox_bg;">      my %domconfhash = &Apache::loncommon::get_domainconf($domain);
   $logintitle      my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
   $loginform      my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
   $noscript_warning      my $output;
 </div>      if ($loginvia ne '') {
             my $noredirect;
 <div class="LC_Box" style="padding-top: 10px;">          my $ip = $ENV{'REMOTE_ADDR'};
   $loginhelp          if ($ip eq '127.0.0.1') {
   $forgotpw              $noredirect = 1;
   $contactblock          } else {
   $newuserlink              if ($loginvia_exempt ne '') {
   $coursecatalog                  my @exempt = split(',',$loginvia_exempt);
 </div>                  if (grep(/^\Q$ip\E$/,@exempt)) {
 </div>                      $noredirect = 1;
                   }
 <div>              }
 ENDTOP          }
     if ($showmainlogo) {          unless ($noredirect) {
         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");              my ($newhost,$path);
     }              if ($loginvia =~ /:/) {
 $r->print(<<ENDTOP);                  ($newhost,$path) = split(':',$loginvia);
 $announcements              } else {
 </div>                  $newhost = $loginvia;
 <hr style="clear:both;" />              }
 ENDTOP              if ($newhost ne $lonhost) {
     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);                  if (&Apache::lonnet::hostname($newhost) ne '') {
     $domainrow = <<"END";                      $output = &redirect_page($newhost,$path);
       <tr>                  }
        <td  align="left" valign="top">              }
         <small><b>$lt{'dom'}:&nbsp;</b></small>          }
        </td>      }
        <td  align="left" valign="top">      return $output;
         <small><tt>&nbsp;$domain</tt></small>  }
        </td>  
       </tr>  sub redirect_page {
 END      my ($desthost,$path) = @_;
     $serverrow = <<"END";      my $protocol = $Apache::lonnet::protocol{$desthost};
       <tr>      $protocol = 'http' if ($protocol ne 'https');
        <td  align="left" valign="top">      unless ($path =~ m{^/}) {
         <small><b>$lt{'serv'}:&nbsp;</b></small>          $path = '/'.$path;
        </td>      }
        <td align="left" valign="top">      my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
         <small><tt>&nbsp;$lonhost ($role)</tt></small>      if ($env{'form.firsturl'} ne '') {
        </td>          $url .='?firsturl='.$env{'form.firsturl'};
       </tr>      }
 END      my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
     if ($loadlim) {                                                      {'redirect' => [0,$url],});
         $loadrow = <<"END";      my $end_page   = &Apache::loncommon::end_page();
       <tr>      return $start_page.$end_page;
        <td align="left" valign="top">  }
         <small><b>$lt{'load'}:&nbsp;</b></small>  
        </td>  sub contactdisplay {
        <td align="left" valign="top">      my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>          $possdoms) = @_;
        </td>      my $contactblock;
       </tr>      my $origmail;
 END      if (ref($possdoms) eq 'ARRAY') {
     }          if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
     if ($uloadlim) {              $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
         $userloadrow = <<"END";          }
       <tr>      }
        <td align="left" valign="top">      my $requestmail =
         <small><b>$lt{'userload'}:&nbsp;</b></small>          &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
        </td>                                                   $authdomain,$origmail);
        <td align="left" valign="top">      unless ($showhelpdesk eq '0') {
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>          if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
        </td>              $showhelpdesk = 1;
       </tr>          } else {
 END              $showhelpdesk = 0;
     }          }
     if (($version ne '') && ($version ne '<!-- VERSION -->')) {      }
         $versionrow = <<"END";      if ($servadm && $showadminmail) {
       <tr>          $contactblock .= $$lt{'servadm'}.':<br />'.
        <td colspan="2" align="left">                           '<tt>'.$servadm.'</tt><br />';
         <small>$version</small>      }
        </td>      if ($showhelpdesk) {
       </tr>          $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
 END          my $thisurl = &escape('/adm/login');
     }          $$helpdeskscript = <<"ENDSCRIPT";
   <script type="text/javascript">
     $r->print(<<ENDDOCUMENT);  // <![CDATA[
     <div style="float: left;">  function helpdesk() {
      <table border="0" cellspacing="0" cellpadding="0">      var possdom = document.client.udom.value;
 $domainrow      var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
 $serverrow      if (codedom == '') {
 $loadrow              codedom = "$authdomain";
 $userloadrow      }
 $versionrow      var querystr = "origurl=$thisurl&codedom="+codedom;
      </table>      document.location.href = "/adm/helpdesk?"+querystr;
     </div>      return;
     <div style="float: right;">  }
     $domainlogo  // ]]>
     </div>  </script>
     <br style="clear:both;" />  ENDSCRIPT
  </div>      }
       return $contactblock;
 <script type="text/javascript">  }
 // <![CDATA[  
 // the if prevents the script error if the browser can not handle this  sub forgotpwdisplay {
 if ( document.client.uname ) { document.client.uname.focus(); }      my (%lt) = @_;
 // ]]>      my $prompt_for_resetpw = 1;
 </script>      if ($prompt_for_resetpw) {
 $helpdeskscript          return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
       }
 ENDDOCUMENT      return;
     my %endargs = ( 'noredirectlink' => 1, );  }
     $r->print(&Apache::loncommon::end_page(\%endargs));  
     return OK;  sub coursecatalog_link {
 }      my ($linkname) = @_;
       return <<"END";
 sub check_loginvia {        <a href="/adm/coursecatalog">$linkname</a>
     my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;  END
     if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {  }
         return;  
     }  sub newuser_link {
     my %domconfhash = &Apache::loncommon::get_domainconf($domain);      my ($linkname) = @_;
     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};      return '<a href="/adm/createaccount">'.$linkname.'</a>';
     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};  }
     my $output;  
     if ($loginvia ne '') {  1;
         my $noredirect;  __END__
         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 $hostname = &Apache::lonnet::hostname($desthost);  
     my $protocol = $Apache::lonnet::protocol{$desthost};  
     $protocol = 'http' if ($protocol ne 'https');  
     unless ($path =~ m{^/}) {  
         $path = '/'.$path;  
     }  
     my $url = $protocol.'://'.$hostname.$path;  
     if ($env{'form.firsturl'} ne '') {  
         $url .='?firsturl='.$env{'form.firsturl'};  
     }  
     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.158.2.9  
changed lines
  Added in v.1.160


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