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

version 1.158.2.6.2.1, 2017/10/14 20:59:35 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'})) {
 # -- check if they are a migrating user          if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {
     if (defined($env{'form.token'})) {              $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};
  return &Apache::migrateuser::handler($r);          }
     }      }
   
 # For "public user" - remove any exising "public" cookie, as user really wants to log-in  # -- check if they are a migrating user
     my ($handle,$lonidsdir,$expirepub,$userdom);      if (defined($env{'form.token'})) {
     unless ($r->header_only) {   return &Apache::migrateuser::handler($r);
         $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);      }
         if ($handle ne '') {  
             $lonidsdir=$r->dir_config('lonIDsDir');  # For "public user" - remove any exising "public" cookie, as user really wants to log-in
             if ($handle=~/^publicuser\_/) {      my ($handle,$lonidsdir,$expirepub,$userdom);
                 unlink($r->dir_config('lonIDsDir')."/$handle.id");      $lonidsdir=$r->dir_config('lonIDsDir');
                 undef($handle);      unless ($r->header_only) {
                 undef($userdom);          $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
                 $expirepub = 1;          if ($handle ne '') {
             }              if ($handle=~/^publicuser\_/) {
         }                  unlink($r->dir_config('lonIDsDir')."/$handle.id");
     }                  undef($handle);
                   undef($userdom);
     &Apache::loncommon::no_cache($r);                  $expirepub = 1;
     &Apache::lonlocal::get_language_handle($r);              }
     &Apache::loncommon::content_type($r,'text/html');          }
     if ($expirepub) {      }
         my $c = new CGI::Cookie(-name    => 'lonID',  
                                 -value   => '',      &Apache::loncommon::no_cache($r);
                                 -expires => '-10y',);      &Apache::lonlocal::get_language_handle($r);
         $r->header_out('Set-cookie' => $c);      &Apache::loncommon::content_type($r,'text/html');
     } elsif (($handle eq '') && ($userdom ne '')) {      if ($expirepub) {
         my $c = new CGI::Cookie(-name    => 'lonID',          my $c = new CGI::Cookie(-name    => 'lonPubID',
                                 -value   => '',                                  -value   => '',
                                 -expires => '-10y',);                                  -expires => '-10y',);
         $r->headers_out->add('Set-cookie' => $c);          $r->header_out('Set-cookie' => $c);
     }      } elsif (($handle eq '') && ($userdom ne '')) {
     $r->send_http_header;          my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
     return OK if $r->header_only;          foreach my $name (keys(%cookies)) {
               next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
               my $c = new CGI::Cookie(-name    => $name,
 # Are we re-routing?                                      -value   => '',
     my $londocroot = $r->dir_config('lonDocRoot');                                       -expires => '-10y',);
     if (-e "$londocroot/lon-status/reroute.txt") {              $r->headers_out->add('Set-cookie' => $c);
  &Apache::lonauth::reroute($r);          }
  return OK;      }
     }      $r->send_http_header;
       return OK if $r->header_only;
 #  
 # 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  # Are we re-routing?
 # switch user's log-in to the portal.      my $londocroot = $r->dir_config('lonDocRoot');
 #      if (-e "$londocroot/lon-status/reroute.txt") {
    &Apache::lonauth::reroute($r);
     if (($handle eq '') && ($userdom ne '')) {   return OK;
         my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);      }
         if ($domdefaults{'portal_def'} =~ /^https?\:/) {  
             my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,      my $lonhost = $r->dir_config('lonHostID');
                                           {'redirect' => [0,$domdefaults{'portal_def'}],});      $env{'form.firsturl'} =~ s/(`)/'/g;
             my $end_page   = &Apache::loncommon::end_page();  
             $r->print($start_page.$end_page);  # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
             return OK;  
         }      my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
     }      if ($found_server) {
           my $hostname = &Apache::lonnet::hostname($found_server);
     $env{'form.firsturl'} =~ s/(`)/'/g;          if ($hostname ne '') {
               my $protocol = $Apache::lonnet::protocol{$found_server};
 # -------------------------------- Prevent users from attempting to login twice              $protocol = 'http' if ($protocol ne 'https');
     my $handle = &Apache::lonnet::check_for_valid_session($r);              my $dest = '/adm/roles';
     if ($handle ne '') {              if ($env{'form.firsturl'} ne '') {
         my $lonidsdir=$r->dir_config('lonIDsDir');                  $dest = $env{'form.firsturl'};
         if ($handle=~/^publicuser\_/) {              }
 # For "public user" - remove it, we apparently really want to login              my %info = (
     unlink($r->dir_config('lonIDsDir')."/$handle.id");                           balcookie => $lonhost.':'.$balancer_cookie,
         } else {                         );
 # Indeed, a valid token is found              my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
             &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);              if ($balancer_token) {
     my $start_page =                   $dest .=  (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;
         &Apache::loncommon::start_page('Already logged in');              }
     my $end_page =               my $url = $protocol.'://'.$hostname.$dest;
         &Apache::loncommon::end_page();              my $start_page =
             my $dest = '/adm/roles';                  &Apache::loncommon::start_page('Switching Server ...',undef,
             if ($env{'form.firsturl'} ne '') {                                                 {'redirect'       => [0,$url],});
                 $dest = $env{'form.firsturl'};               my $end_page   = &Apache::loncommon::end_page();
             }              $r->print($start_page.$end_page);
     $r->print(              return OK;
                   $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>'  #
                  .$end_page  # 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.
             return OK;  #
         }  
     }      my $balcookie;
       if ($env{'form.btoken'}) {
 # ---------------------------------------------------- No valid token, continue          my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
           $balcookie = $info{'balcookie'};
 # ---------------------------- Not possible to really login to domain "public"          &Apache::lonnet::tmpdel($env{'form.btoken'});
     if ($env{'form.domain'} eq 'public') {          delete($env{'form.btoken'});
  $env{'form.domain'}='';      }
  $env{'form.username'}='';  
     }  #
   # If browser sent an old cookie for which the session file had been removed
 # ------ Is this page requested because /adm/migrateuser detected an IP change?  # check if configuration for user's domain has a portal URL set.  If so
     my %sessiondata;  # switch user's log-in to the portal.
     if ($env{'form.iptoken'}) {  #
         %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});  
         unless ($sessiondata{'sessionserver'}) {      if (($handle eq '') && ($userdom ne '')) {
             my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});          my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
             delete($env{'form.iptoken'});          if ($domdefaults{'portal_def'} =~ /^https?\:/) {
         }              my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
     }                                            {'redirect' => [0,$domdefaults{'portal_def'}],});
 # ----------------------------------------------------------- Process Interface              my $end_page   = &Apache::loncommon::end_page();
     $env{'form.interface'}=~s/\W//g;              $r->print($start_page.$end_page);
               return OK;
     (undef,undef,undef,undef,undef,undef,my $clientmobile) =          }
         &Apache::loncommon::decode_user_agent();      }
   
     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);
 this.document.server.elements.upass0.value      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
     =getCrypted(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.client.elements.uname.value='';      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
 this.document.client.elements.upass$now.value='';      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
       my $img=&Apache::loncommon::designparm('login.img',$domain);
 this.document.server.submit();      my $domainlogo=&Apache::loncommon::domainlogo($domain);
 return false;      my $showbanner = 1;
 }      my $showmainlogo = 1;
       if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
 function enableInput() {          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
     this.document.client.elements.upass$now.removeAttribute("readOnly");      }
     this.document.client.elements.uname.removeAttribute("readOnly");      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
     this.document.client.elements.udom.removeAttribute("readOnly");          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
     return;      }
 }      my $showadminmail;
       my @possdoms = &Apache::lonnet::current_machine_domains();
 // ]]>      if (grep(/^\Q$domain\E$/,@possdoms)) {
 </script>          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
       }
 ENDSCRIPT      my $showcoursecat =
           &Apache::loncommon::designparm('login.coursecatalog',$domain);
 # --------------------------------------------------- Print login screen header      my $shownewuserlink =
           &Apache::loncommon::designparm('login.newuser',$domain);
     my %add_entries = (      my $showhelpdesk =
        bgcolor      => "$mainbg",          &Apache::loncommon::designparm('login.helpdesk',$domain);
        text         => "$font",      my $now=time;
        link         => "$link",      my $js = (<<ENDSCRIPT);
        vlink        => "$vlink",  
        alink        => "$alink",  <script type="text/javascript" language="JavaScript">
                onload       => 'javascript:enableInput();',);  // <![CDATA[
   function send()
     my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);  {
     @hosts = &Apache::lonnet::current_machine_ids();  this.document.server.elements.uname.value
     $lonhost_in_use = $lonhost;  =this.document.client.elements.uname.value;
     if (@hosts > 1) {  
         foreach my $hostid (@hosts) {  this.document.server.elements.udom.value
             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {  =this.document.client.elements.udom.value;
                 $lonhost_in_use = $hostid;  
                 last;  uextkey=this.document.client.elements.uextkey.value;
             }  lextkey=this.document.client.elements.lextkey.value;
         }  initkeys();
     }  
     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);  if(this.document.server.action.substr(0,5) === 'http:'){
     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};      this.document.server.elements.upass0.value
     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};          =getCrypted(this.document.client.elements.upass$now.value);
     if ($headextra) {  } else {
         my $omitextra;      this.document.server.elements.upass0.value
         if ($headextra_exempt ne '') {          =this.document.client.elements.upass$now.value;
             my @exempt = split(',',$headextra_exempt);  }
             my $ip = $ENV{'REMOTE_ADDR'};  
             if (grep(/^\Q$ip\E$/,@exempt)) {  this.document.client.elements.uname.value='';
                 $omitextra = 1;  this.document.client.elements.upass$now.value='';
             }  
         }  this.document.server.submit();
         unless ($omitextra) {  return false;
             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));  function enableInput() {
                 unless ($extra eq '-1') {      this.document.client.elements.upass$now.removeAttribute("readOnly");
                     $js .= "\n".$extra."\n";      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,  </script>
        { 'redirect'       => [$expire,'/adm/roles'],   
  'add_entries' => \%add_entries,  ENDSCRIPT
  'only_body'   => 1,}));  
   # --------------------------------------------------- Print login screen header
 # ----------------------------------------------------------------------- Texts  
       my %add_entries = (
     my %lt=&Apache::lonlocal::texthash(         bgcolor      => "$mainbg",
           'un'       => 'Username',         text         => "$font",
           'pw'       => 'Password',         link         => "$link",
           'dom'      => 'Domain',         vlink        => "$vlink",
           'perc'     => 'percent',         alink        => "$alink",
           'load'     => 'Server Load',                 onload       => 'javascript:enableInput();',);
           'userload' => 'User Load',  
           'catalog'  => 'Course/Community Catalog',      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
           'log'      => 'Log in',      @hosts = &Apache::lonnet::current_machine_ids();
           'help'     => 'Log-in Help',      $lonhost_in_use = $lonhost;
           'serv'     => 'Server',      if (@hosts > 1) {
           'servadm'  => 'Server Administration',          foreach my $hostid (@hosts) {
           'helpdesk' => 'Contact Helpdesk',              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
           'forgotpw' => 'Forgot password?',                  $lonhost_in_use = $hostid;
           'newuser'  => 'New User?',                  last;
        );              }
 # -------------------------------------------------- Change password field name          }
       }
     my $forgotpw = &forgotpwdisplay(%lt);      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
     $forgotpw .= '<br />' if $forgotpw;      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
     if ($loginhelp) {      if ($headextra) {
         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';          my $omitextra;
     }          if ($headextra_exempt ne '') {
               my @exempt = split(',',$headextra_exempt);
 # ---------------------------------------------------- Serve out DES JavaScript              my $ip = $ENV{'REMOTE_ADDR'};
     {              if (grep(/^\Q$ip\E$/,@exempt)) {
     my $jsh=Apache::File->new($include."/londes.js");                  $omitextra = 1;
     $r->print(<$jsh>);              }
     }          }
 # ---------------------------------------------------------- Serve rest of page          unless ($omitextra) {
               my $confname = $defdom.'-domainconfig';
     $r->print(              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
     '<div class="LC_Box"'                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'                  unless ($extra eq '-1') {
 );                      $js .= "\n".$extra."\n";
                   }
     $r->print(<<ENDSERVERFORM);              }
 <form name="server" action="/adm/authenticate" method="post" target="_top">          }
    <input type="hidden" name="logtoken" value="$logtoken" />      }
    <input type="hidden" name="serverid" value="$lonhost" />  
    <input type="hidden" name="uname" value="" />      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
    <input type="hidden" name="upass0" value="" />         { 'redirect'       => [$expire,'/adm/roles'],
    <input type="hidden" name="udom" value="" />   'add_entries' => \%add_entries,
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />   'only_body'   => 1,}));
    <input type="hidden" name="localres" value="$env{'form.localres'}" />  
   </form>  # ----------------------------------------------------------------------- Texts
 ENDSERVERFORM  
     my $coursecatalog;      my %lt=&Apache::lonlocal::texthash(
     if (($showcoursecat eq '') || ($showcoursecat)) {            'un'       => 'Username',
         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';            'pw'       => 'Password',
     }            'dom'      => 'Domain',
     my $newuserlink;            'perc'     => 'percent',
     if ($shownewuserlink) {            'load'     => 'Server Load',
         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';            'userload' => 'User Load',
     }            'catalog'  => 'Course/Community Catalog',
     my $logintitle =            'log'      => 'Log in',
         '<h2 class="LC_hcell"'            'help'     => 'Log-in Help',
        .' style="background:'.$loginbox_header_bgcol.';'            'serv'     => 'Server',
        .' color:'.$loginbox_header_textcol.'">'            'servadm'  => 'Server Administration',
        .$lt{'log'}            'helpdesk' => 'Contact Helpdesk',
        .'</h2>';            'forgotpw' => 'Forgot password?',
             'newuser'  => 'New User?',
     my $noscript_warning='<noscript><span class="LC_warning"><b>'         );
                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')  # -------------------------------------------------- Change password field name
                         .'</b></span></noscript>';  
     my $helpdeskscript;      my $forgotpw = &forgotpwdisplay(%lt);
     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,      $forgotpw .= '<br />' if $forgotpw;
                                        $authdomain,\$helpdeskscript,      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
                                        $showhelpdesk,\@possdoms);      if ($loginhelp) {
           $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
     my $mobileargs;      }
     if ($clientmobile) {  
         $mobileargs = 'autocapitalize="off" autocorrect="off"';   # ---------------------------------------------------- Serve out DES JavaScript
     }      {
     my $loginform=(<<LFORM);      my $jsh=Apache::File->new($include."/londes.js");
 <form name="client" action="" onsubmit="return(send())">      $r->print(<$jsh>);
   <input type="hidden" name="lextkey" value="$lextkey" />      }
   <input type="hidden" name="uextkey" value="$uextkey" />  # ---------------------------------------------------------- Serve rest of page
   <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(
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />      '<div class="LC_Box"'
   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
   <b><label for="udom">$lt{'dom'}</label>:</b><br />  );
   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />  
   <input type="submit" value="$lt{'log'}" />      $r->print(<<ENDSERVERFORM);
 </form>  <form name="server" action="/adm/authenticate" method="post" target="_top">
 LFORM     <input type="hidden" name="logtoken" value="$logtoken" />
      <input type="hidden" name="serverid" value="$lonhost" />
     if ($showbanner) {     <input type="hidden" name="uname" value="" />
         $r->print(<<HEADER);     <input type="hidden" name="upass0" value="" />
 <!-- The LON-CAPA Header -->     <input type="hidden" name="udom" value="" />
 <div style="background:$pgbg;margin:0;width:100%;">     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />     <input type="hidden" name="localres" value="$env{'form.localres'}" />
 </div>    </form>
 HEADER  ENDSERVERFORM
     }      my $coursecatalog;
     $r->print(<<ENDTOP);      if (($showcoursecat eq '') || ($showcoursecat)) {
 <div style="float:left;margin-top:0;">          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
 <div class="LC_Box" style="background:$loginbox_bg;">      }
   $logintitle      my $newuserlink;
   $loginform      if ($shownewuserlink) {
   $noscript_warning          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
 </div>      }
         my $logintitle =
 <div class="LC_Box" style="padding-top: 10px;">          '<h2 class="LC_hcell"'
   $loginhelp         .' style="background:'.$loginbox_header_bgcol.';'
   $forgotpw         .' color:'.$loginbox_header_textcol.'">'
   $contactblock         .$lt{'log'}
   $newuserlink         .'</h2>';
   $coursecatalog  
 </div>      my $noscript_warning='<noscript><span class="LC_warning"><b>'
 </div>                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
                           .'</b></span></noscript>';
 <div>      my $helpdeskscript;
 ENDTOP      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
     if ($showmainlogo) {                                         $authdomain,\$helpdeskscript,
         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");                                         $showhelpdesk,\@possdoms);
     }  
 $r->print(<<ENDTOP);      my $mobileargs;
 $announcements      if ($clientmobile) {
 </div>          $mobileargs = 'autocapitalize="off" autocorrect="off"';
 <hr style="clear:both;" />      }
 ENDTOP      my $loginform=(<<LFORM);
     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);  <form name="client" action="" onsubmit="return(send())">
     $domainrow = <<"END";    <input type="hidden" name="lextkey" value="$lextkey" />
       <tr>    <input type="hidden" name="uextkey" value="$uextkey" />
        <td  align="left" valign="top">    <b><label for="uname">$lt{'un'}</label>:</b><br />
         <small><b>$lt{'dom'}:&nbsp;</b></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 />
        <td  align="left" valign="top">    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
         <small><tt>&nbsp;$domain</tt></small>    <b><label for="udom">$lt{'dom'}</label>:</b><br />
        </td>    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
       </tr>    <input type="submit" value="$lt{'log'}" />
 END  </form>
     $serverrow = <<"END";  LFORM
       <tr>  
        <td  align="left" valign="top">      if ($showbanner) {
         <small><b>$lt{'serv'}:&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;$lonhost ($role)</tt></small>    <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
        </td>  </div>
       </tr>  HEADER
 END      }
     if ($loadlim) {      $r->print(<<ENDTOP);
         $loadrow = <<"END";  <div style="float:left;margin-top:0;">
       <tr>  <div class="LC_Box" style="background:$loginbox_bg;">
        <td align="left" valign="top">    $logintitle
         <small><b>$lt{'load'}:&nbsp;</b></small>    $loginform
        </td>    $noscript_warning
        <td align="left" valign="top">  </div>
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>   
        </td>  <div class="LC_Box" style="padding-top: 10px;">
       </tr>    $loginhelp
 END    $forgotpw
     }    $contactblock
     if ($uloadlim) {    $newuserlink
         $userloadrow = <<"END";    $coursecatalog
       <tr>  </div>
        <td align="left" valign="top">  </div>
         <small><b>$lt{'userload'}:&nbsp;</b></small>  
        </td>  <div>
        <td align="left" valign="top">  ENDTOP
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>      if ($showmainlogo) {
        </td>          $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
       </tr>      }
 END  $r->print(<<ENDTOP);
     }  $announcements
     if (($version ne '') && ($version ne '<!-- VERSION -->')) {  </div>
         $versionrow = <<"END";  <hr style="clear:both;" />
       <tr>  ENDTOP
        <td colspan="2" align="left">      my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
         <small>$version</small>      $domainrow = <<"END";
        </td>        <tr>
       </tr>         <td  align="left" valign="top">
 END          <small><b>$lt{'dom'}:&nbsp;</b></small>
     }         </td>
          <td  align="left" valign="top">
     $r->print(<<ENDDOCUMENT);          <small><tt>&nbsp;$domain</tt></small>
     <div style="float: left;">         </td>
      <table border="0" cellspacing="0" cellpadding="0">        </tr>
 $domainrow  END
 $serverrow      $serverrow = <<"END";
 $loadrow            <tr>
 $userloadrow         <td  align="left" valign="top">
 $versionrow          <small><b>$lt{'serv'}:&nbsp;</b></small>
      </table>         </td>
     </div>         <td align="left" valign="top">
     <div style="float: right;">          <small><tt>&nbsp;$lonhost ($role)</tt></small>
     $domainlogo         </td>
     </div>        </tr>
     <br style="clear:both;" />  END
  </div>      if ($loadlim) {
           $loadrow = <<"END";
 <script type="text/javascript">        <tr>
 // <![CDATA[         <td align="left" valign="top">
 // the if prevents the script error if the browser can not handle this          <small><b>$lt{'load'}:&nbsp;</b></small>
 if ( document.client.uname ) { document.client.uname.focus(); }         </td>
 // ]]>         <td align="left" valign="top">
 </script>          <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
 $helpdeskscript         </td>
         </tr>
 ENDDOCUMENT  END
     my %endargs = ( 'noredirectlink' => 1, );      }
     $r->print(&Apache::loncommon::end_page(\%endargs));      if ($uloadlim) {
     return OK;          $userloadrow = <<"END";
 }        <tr>
          <td align="left" valign="top">
 sub check_loginvia {          <small><b>$lt{'userload'}:&nbsp;</b></small>
     my ($domain,$lonhost) = @_;         </td>
     if ($domain eq '' || $lonhost eq '') {         <td align="left" valign="top">
         return;          <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
     }         </td>
     my %domconfhash = &Apache::loncommon::get_domainconf($domain);        </tr>
     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};  END
     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};      }
     my $output;      if (($version ne '') && ($version ne '<!-- VERSION -->')) {
     if ($loginvia ne '') {          $versionrow = <<"END";
         my $noredirect;        <tr>
         my $ip = $ENV{'REMOTE_ADDR'};         <td colspan="2" align="left">
         if ($ip eq '127.0.0.1') {          <small>$version</small>
             $noredirect = 1;         </td>
         } else {        </tr>
             if ($loginvia_exempt ne '') {  END
                 my @exempt = split(',',$loginvia_exempt);      }
                 if (grep(/^\Q$ip\E$/,@exempt)) {  
                     $noredirect = 1;      $r->print(<<ENDDOCUMENT);
                 }      <div style="float: left;">
             }       <table border="0" cellspacing="0" cellpadding="0">
         }  $domainrow
         unless ($noredirect) {  $serverrow
             my ($newhost,$path);  $loadrow    
             if ($loginvia =~ /:/) {  $userloadrow
                 ($newhost,$path) = split(':',$loginvia);  $versionrow
             } else {       </table>
                 $newhost = $loginvia;      </div>
             }      <div style="float: right;">
             if ($newhost ne $lonhost) {      $domainlogo
                 if (&Apache::lonnet::hostname($newhost) ne '') {      </div>
                     $output = &redirect_page($newhost,$path);      <br style="clear:both;" />
                 }   </div>
             }  
         }  <script type="text/javascript">
     }  // <![CDATA[
     return $output;  // the if prevents the script error if the browser can not handle this
 }  if ( document.client.uname ) { document.client.uname.focus(); }
   // ]]>
 sub redirect_page {  </script>
     my ($desthost,$path) = @_;  $helpdeskscript
     my $protocol = $Apache::lonnet::protocol{$desthost};  
     $protocol = 'http' if ($protocol ne 'https');  ENDDOCUMENT
     unless ($path =~ m{^/}) {      my %endargs = ( 'noredirectlink' => 1, );
         $path = '/'.$path;      $r->print(&Apache::loncommon::end_page(\%endargs));
     }      return OK;
     my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;  }
     if ($env{'form.firsturl'} ne '') {  
         $url .='?firsturl='.$env{'form.firsturl'};  sub check_loginvia {
     }      my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,      if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
                                                     {'redirect' => [0,$url],});          return;
     my $end_page   = &Apache::loncommon::end_page();      }
     return $start_page.$end_page;      my %domconfhash = &Apache::loncommon::get_domainconf($domain);
 }      my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
       my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
 sub contactdisplay {      my $output;
     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,      if ($loginvia ne '') {
         $possdoms) = @_;          my $noredirect;
     my $contactblock;          my $ip = $ENV{'REMOTE_ADDR'};
     my $origmail;          if ($ip eq '127.0.0.1') {
     if (ref($possdoms) eq 'ARRAY') {              $noredirect = 1;
         if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {           } else {
             $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};              if ($loginvia_exempt ne '') {
         }                  my @exempt = split(',',$loginvia_exempt);
     }                  if (grep(/^\Q$ip\E$/,@exempt)) {
     my $requestmail =                       $noredirect = 1;
         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',                  }
                                                  $authdomain,$origmail);              }
     unless ($showhelpdesk eq '0') {          }
         if ($requestmail =~ m/[^\@]+\@[^\@]+/) {          unless ($noredirect) {
             $showhelpdesk = 1;              my ($newhost,$path);
         } else {              if ($loginvia =~ /:/) {
             $showhelpdesk = 0;                  ($newhost,$path) = split(':',$loginvia);
         }              } else {
     }                  $newhost = $loginvia;
     if ($servadm && $showadminmail) {              }
         $contactblock .= $$lt{'servadm'}.':<br />'.              if ($newhost ne $lonhost) {
                          '<tt>'.$servadm.'</tt><br />';                  if (&Apache::lonnet::hostname($newhost) ne '') {
     }                      if ($balcookie) {
     if ($showhelpdesk) {                          my ($balancer,$cookie) = split(/:/,$balcookie);
         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';                          if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
         my $thisurl = &escape('/adm/login');                              my ($udom,$uname,$cookieid) = ($1,$2,$3);
         $$helpdeskscript = <<"ENDSCRIPT";                              unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
 <script type="text/javascript">                                  if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
 // <![CDATA[                                      while (my $filename=readdir($dh)) {
 function helpdesk() {                                          if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
     var possdom = document.client.udom.value;                                              my $handle = $1;
     var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');                                              my %hash =
     if (codedom == '') {                                                  &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
         codedom = "$authdomain";                                                                                       ['request.balancercookie',
     }                                                                                        'user.linkedenv']);
     var querystr = "origurl=$thisurl&codedom="+codedom;                                              if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
     document.location.href = "/adm/helpdesk?"+querystr;                                                  if (unlink("$lonidsdir/$filename")) {
     return;                                                      if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
 }                                                          (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
 // ]]>                                                          (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
 </script>                                                          unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
 ENDSCRIPT                                                      }
     }                                                  }
     return $contactblock;                                              }
 }                                              last;
                                           }
 sub forgotpwdisplay {                                      }
     my (%lt) = @_;                                      closedir($dh);
     my $prompt_for_resetpw = 1;                                   }
     if ($prompt_for_resetpw) {                              }
         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';                          }
     }                      }
     return;                      $output = &redirect_page($newhost,$path);
 }                  }
               }
 sub coursecatalog_link {          }
     my ($linkname) = @_;      }
     return <<"END";      return $output;
       <a href="/adm/coursecatalog">$linkname</a>  }
 END  
 }  sub redirect_page {
       my ($desthost,$path) = @_;
 sub newuser_link {      my $protocol = $Apache::lonnet::protocol{$desthost};
     my ($linkname) = @_;      $protocol = 'http' if ($protocol ne 'https');
     return '<a href="/adm/createaccount">'.$linkname.'</a>';      unless ($path =~ m{^/}) {
 }          $path = '/'.$path;
       }
 1;      my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
 __END__      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.1  
changed lines
  Added in v.1.176


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