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

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


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