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

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


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