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

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


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