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

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


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