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

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

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


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