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

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


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