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

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

Removed from v.1.158.2.6.2.3  
changed lines
  Added in v.1.176


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