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

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


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