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

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

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


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