Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.10 and 1.169

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


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