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

version 1.117, 2009/04/01 14:43:19 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]log out[_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 $httpbrowser=$ENV{"HTTP_USER_AGENT"};   &Apache::lonauth::reroute($r);
        return OK;
     my $fullgraph=($env{'form.interface'} ne 'textual');      }
   
     my $iconpath=       my $lonhost = $r->dir_config('lonHostID');
  &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));      $env{'form.firsturl'} =~ s/(`)/'/g;
   
     my $domain = &Apache::lonnet::default_login_domain();  # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
     if (($env{'form.domain'}) &&   
  (&Apache::lonnet::domain($env{'form.domain'},'description'))) {      my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
  $domain=$env{'form.domain'};      if ($found_server) {
     }          my $hostname = &Apache::lonnet::hostname($found_server);
     my $role    = $r->dir_config('lonRole');          if ($hostname ne '') {
     my $loadlim = $r->dir_config('lonLoadLim');              my $protocol = $Apache::lonnet::protocol{$found_server};
     my $servadm = $r->dir_config('lonAdmEMail');              $protocol = 'http' if ($protocol ne 'https');
     my $lonhost = $r->dir_config('lonHostID');              my $dest = '/adm/roles';
     my $tabdir  = $r->dir_config('lonTabDir');              if ($env{'form.firsturl'} ne '') {
     my $include = $r->dir_config('lonIncludes');                  $dest = $env{'form.firsturl'};
     my $expire  = $r->dir_config('lonExpire');              }
     my $version = $r->dir_config('lonVersion');              my %info = (
     my $host_name = &Apache::lonnet::hostname($lonhost);                           balcookie => $lonhost.':'.$balancer_cookie,
                          );
 # --------------------------------------------- Default values for login fields              my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
               if ($balancer_token) {
     my $authusername=($env{'form.username'}?$env{'form.username'}:'');                  $dest .=  (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;
     my $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);              }
               my $url = $protocol.'://'.$hostname.$dest;
 # ---------------------------------------------------------- Determine own load              my $start_page =
     my $loadavg;                  &Apache::loncommon::start_page('Switching Server ...',undef,
     {                                                 {'redirect'       => [0,$url],});
  my $loadfile=Apache::File->new('/proc/loadavg');              my $end_page   = &Apache::loncommon::end_page();
  $loadavg=<$loadfile>;              $r->print($start_page.$end_page);
     }              return OK;
     $loadavg =~ s/\s.*//g;          }
     my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);      }
     my $userloadpercent=&Apache::lonnet::userload();  
   #
 # ------------------------------------------------------- Do the load balancing  # Check if a LON-CAPA load balancer sent user here because user's browser sent
     my $otherserver= &Apache::lonnet::absolute_url($host_name);  # it a balancer cookie for an active session on this server.
     my $firsturl=  #
     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});  
 # ---------------------------------------------------------- Are we overloaded?      my $balcookie;
     if ((($userloadpercent>100.0)||($loadpercent>100.0))) {      if ($env{'form.btoken'}) {
         my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent);          my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
  if ($unloaded) { $otherserver=$unloaded; }          $balcookie = $info{'balcookie'};
     }          &Apache::lonnet::tmpdel($env{'form.btoken'});
           delete($env{'form.btoken'});
 # ----------------------------------------------------------- Get announcements      }
     my $announcements=&Apache::lonnet::getannounce();  
 # -------------------------------------------------------- Set login parameters  #
   # If browser sent an old cookie for which the session file had been removed
     my @hexstr=('0','1','2','3','4','5','6','7',  # check if configuration for user's domain has a portal URL set.  If so
                 '8','9','a','b','c','d','e','f');  # switch user's log-in to the portal.
     my $lkey='';  #
     for (0..7) {  
         $lkey.=$hexstr[rand(15)];      if (($handle eq '') && ($userdom ne '')) {
     }          my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
           if ($domdefaults{'portal_def'} =~ /^https?\:/) {
     my $ukey='';              my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
     for (0..7) {                                            {'redirect' => [0,$domdefaults{'portal_def'}],});
         $ukey.=$hexstr[rand(15)];              my $end_page   = &Apache::loncommon::end_page();
     }              $r->print($start_page.$end_page);
               return OK;
     my $lextkey=hex($lkey);          }
     if ($lextkey>2147483647) { $lextkey-=4294967296; }      }
   
     my $uextkey=hex($ukey);  # -------------------------------- Prevent users from attempting to login twice
     if ($uextkey>2147483647) { $uextkey-=4294967296; }      if ($handle ne '') {
           &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
 # -------------------------------------------------------- Store away log token   my $start_page =
     my $logtoken=Apache::lonnet::reply(      &Apache::loncommon::start_page('Already logged in');
        'tmpput:'.$ukey.$lkey.'&'.$firsturl,   my $end_page =
        $lonhost);      &Apache::loncommon::end_page();
           my $dest = '/adm/roles';
 # ------------------- If we cannot talk to ourselves, we are in serious trouble          if ($env{'form.firsturl'} ne '') {
               $dest = $env{'form.firsturl'};
     if ($logtoken eq 'con_lost') {          }
         my $spares='';   $r->print(
  my $last;                    $start_page
         foreach my $hostid (sort                   .'<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].',
  &Apache::lonnet::hostname($a) cmp                    '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
     &Apache::lonnet::hostname($b);                   .$end_page
     }                   );
     keys(%Apache::lonnet::spareid)) {          return OK;
             next if ($hostid eq $lonhost);      }
     my $hostname = &Apache::lonnet::hostname($hostid);  
     next if ($last eq $hostname);  # ---------------------------------------------------- No valid token, continue
             $spares.='<br /><font size="+1"><a href="http://'.  
                 $hostname.  # ---------------------------- Not possible to really login to domain "public"
                 '/adm/login?domain='.$authdomain.'">'.      if ($env{'form.domain'} eq 'public') {
                 $hostname.'</a>'.   $env{'form.domain'}='';
                 ' '.&mt('(preferred)').'</font>'.$/;   $env{'form.username'}='';
     $last=$hostname;      }
         }  
 $spares.= '<br />';  # ------ Is this page requested because /adm/migrateuser detected an IP change?
 my %all_hostnames = &Apache::lonnet::all_hostnames();      my %sessiondata;
 foreach my $hostid (sort      if ($env{'form.iptoken'}) {
     {          %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
  &Apache::lonnet::hostname($a) cmp          unless ($sessiondata{'sessionserver'}) {
     &Apache::lonnet::hostname($b);              my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
     }              delete($env{'form.iptoken'});
     keys(%all_hostnames)) {          }
     next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});      }
     my $hostname = &Apache::lonnet::hostname($hostid);  # ----------------------------------------------------------- Process Interface
     next if ($last eq $hostname);      $env{'form.interface'}=~s/\W//g;
     $spares.='<br /><a href="http://'.  
  $hostname.      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
  '/adm/login?domain='.$authdomain.'">'.          &Apache::loncommon::decode_user_agent();
  $hostname.'</a>';  
     $last=$hostname;      my $iconpath=
 }   &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
 $r->print(  
    '<html>'      my $domain = &Apache::lonnet::default_login_domain();
   .'<head><title>'      my $defdom = $domain;
   .&mt('The LearningOnline Network with CAPA')      if ($lonhost ne '') {
   .'</title></head>'          unless ($sessiondata{'sessionserver'}) {
   .'<body bgcolor="#FFFFFF">'              my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);
   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'              if ($redirect) {
   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'                  $r->print($redirect);
   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>'                  return OK;
   .'<p>'.&mt('Please attempt to login to one of the following servers:').'</p>'              }
   .$spares          }
   .'</body>'      }
   .'</html>'  
 );      if (($sessiondata{'domain'}) &&
 return OK;          (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
 }          $domain=$sessiondata{'domain'};
       } elsif (($env{'form.domain'}) &&
 # ----------------------------------------------- Apparently we are in business   (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
 $servadm=~s/\,/\<br \/\>/g;   $domain=$env{'form.domain'};
       }
 # ----------------------------------------------------------- Front page design  
 my $pgbg=      my $role    = $r->dir_config('lonRole');
 ($fullgraph?&Apache::loncommon::designparm('login.pgbg',$domain):'#FFFFFF');      my $loadlim = $r->dir_config('lonLoadLim');
 my $font=      my $uloadlim= $r->dir_config('lonUserLoadLim');
 ($fullgraph?&Apache::loncommon::designparm('login.font',$domain):'#000000');      my $servadm = $r->dir_config('lonAdmEMail');
 my $link=      my $tabdir  = $r->dir_config('lonTabDir');
 ($fullgraph?&Apache::loncommon::designparm('login.link',$domain):'#0000FF');      my $include = $r->dir_config('lonIncludes');
 my $vlink=      my $expire  = $r->dir_config('lonExpire');
 ($fullgraph?&Apache::loncommon::designparm('login.vlink',$domain):'#0000FF');      my $version = $r->dir_config('lonVersion');
 my $alink=&Apache::loncommon::designparm('login.alink',$domain);      my $host_name = &Apache::lonnet::hostname($lonhost);
 my $mainbg=  
 ($fullgraph?&Apache::loncommon::designparm('login.mainbg',$domain):'#FFFFFF');  # --------------------------------------------- Default values for login fields
 my $logo=&Apache::loncommon::designparm('login.logo',$domain);     
 my $img=&Apache::loncommon::designparm('login.img',$domain);      my ($authusername,$authdomain);
 my $domainlogo=&Apache::loncommon::domainlogo($domain);      if ($sessiondata{'username'}) {
 my $login=&Apache::loncommon::designparm('login.login',$domain);          $authusername=$sessiondata{'username'};
 if ($login eq '') {      } else {
 $login = $iconpath.'/'.&mt('userauthentication.gif');          $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
 }          $authusername=($env{'form.username'}?$env{'form.username'}:'');
 my $showbanner = 1;      }
 my $showmainlogo = 1;      if ($sessiondata{'domain'}) {
 if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {          $authdomain=$sessiondata{'domain'};
     $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);      } else {
 }          $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
 if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
     $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);      }
 }  
 my $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);  # ---------------------------------------------------------- Determine own load
 my $showcoursecat =      my $loadavg;
 &Apache::loncommon::designparm('login.coursecatalog',$domain);      {
 my $loginheader =&Apache::loncommon::designparm('login.loginheader',$domain);   my $loadfile=Apache::File->new('/proc/loadavg');
 my $shownewuserlink =    $loadavg=<$loadfile>;
 &Apache::loncommon::designparm('login.newuser',$domain);      }
 my $now=time;      $loadavg =~ s/\s.*//g;
 my $js = (<<ENDSCRIPT);  
       my ($loadpercent,$userloadpercent);
 <script type="text/javascript" language="JavaScript">      if ($loadlim) {
 function send()          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
 {      }
 this.document.server.elements.uname.value      if ($uloadlim) {
 =this.document.client.elements.uname.value;          $userloadpercent=&Apache::lonnet::userload();
       }
 this.document.server.elements.udom.value  
 =this.document.client.elements.udom.value;      my $firsturl=
       ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
 uextkey=this.document.client.elements.uextkey.value;  
 lextkey=this.document.client.elements.lextkey.value;  # ----------------------------------------------------------- Get announcements
 initkeys();      my $announcements=&Apache::lonnet::getannounce();
   # -------------------------------------------------------- Set login parameters
 this.document.server.elements.upass0.value  
     =crypted(this.document.client.elements.upass$now.value.substr(0,15));      my @hexstr=('0','1','2','3','4','5','6','7',
 this.document.server.elements.upass1.value                  '8','9','a','b','c','d','e','f');
     =crypted(this.document.client.elements.upass$now.value.substr(15,15));      my $lkey='';
 this.document.server.elements.upass2.value      for (0..7) {
     =crypted(this.document.client.elements.upass$now.value.substr(30,15));          $lkey.=$hexstr[rand(15)];
       }
 this.document.client.elements.uname.value='';  
 this.document.client.elements.upass$now.value='';      my $ukey='';
       for (0..7) {
 this.document.server.submit();          $ukey.=$hexstr[rand(15)];
 return false;      }
 }  
 </script>      my $lextkey=hex($lkey);
       if ($lextkey>2147483647) { $lextkey-=4294967296; }
 ENDSCRIPT  
       my $uextkey=hex($ukey);
 # --------------------------------------------------- Print login screen header      if ($uextkey>2147483647) { $uextkey-=4294967296; }
   
 my %add_entries = (topmargin    => "0",  # -------------------------------------------------------- Store away log token
        leftmargin   => "0",      my $tokenextras;
        marginheight => "0",      if ($env{'form.role'}) {
        marginwidth  => "0",          $tokenextras = '&role='.&escape($env{'form.role'});
        bgcolor      => "$mainbg",      }
        text         => "$font",      if ($env{'form.symb'}) {
        link         => "$link",          if (!$tokenextras) {
        vlink        => "$vlink",              $tokenextras = '&';
        alink        => "$alink",);          }
           $tokenextras .= '&symb='.&escape($env{'form.symb'});
 $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,      }
        { 'redirect'       => [$expire,'/adm/roles'],       if ($env{'form.iptoken'}) {
  'add_entries' => \%add_entries,          if (!$tokenextras) {
  'only_body'   => 1,}));              $tokenextras = '&&';
           }
 # ----------------------------------------------------------------------- Texts          $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
       }
 my %lt=&Apache::lonlocal::texthash(      my $logtoken=Apache::lonnet::reply(
   'un'  => 'Username',         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
   'pw'  => 'Password',         $lonhost);
   'dom' => 'Domain',  
   'perc' => 'percent',  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
   'load' => 'Server Load',  #    we are in serious trouble
   'userload' => 'User Load',  
   'about'  => 'About LON-CAPA',      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
   'catalog' => 'Course Catalog',          if ($logtoken eq 'no_such_host') {
   'log' => 'Log in',              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
   'help' => 'Log-in Help',          }
   'serv' => 'Server',          my $spares='';
   'servadm' => 'Server Administration',   my $last;
   'helpdesk' => 'Contact Helpdesk',          foreach my $hostid (sort
   'forgotpw' => 'Forgot password?',      {
   'newuser'  => 'New User?',   &Apache::lonnet::hostname($a) cmp
   );      &Apache::lonnet::hostname($b);
 # -------------------------------------------------- Change password field name      }
 my $forgotpw = &forgotpwdisplay(%lt);      keys(%Apache::lonnet::spareid)) {
 my $loginhelp = &loginhelpdisplay(%lt);              next if ($hostid eq $lonhost);
       my $hostname = &Apache::lonnet::hostname($hostid);
 # ---------------------------------------------------- Serve out DES JavaScript      next if (($last eq $hostname) || ($hostname eq ''));
 {              $spares.='<br /><font size="+1"><a href="http://'.
 my $jsh=Apache::File->new($include."/londes.js");                  $hostname.
 $r->print(<$jsh>);                  '/adm/login?domain='.$authdomain.'">'.
 }                  $hostname.'</a>'.
 # ---------------------------------------------------------- Serve rest of page                  ' '.&mt('(preferred)').'</font>'.$/;
       $last=$hostname;
 if ($fullgraph) {          }
 $r->print(          if ($spares) {
   '<div class="LC_loginpage_container">');              $spares.= '<br />';
 }          }
           my %all_hostnames = &Apache::lonnet::all_hostnames();
 $r->print(<<ENDSERVERFORM);          foreach my $hostid (sort
 <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">      {
    <input type="hidden" name="logtoken" value="$logtoken" />   &Apache::lonnet::hostname($a) cmp
    <input type="hidden" name="serverid" value="$lonhost" />      &Apache::lonnet::hostname($b);
    <input type="hidden" name="uname" value="" />      }
    <input type="hidden" name="upass0" value="" />      keys(%all_hostnames)) {
    <input type="hidden" name="upass1" value="" />              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
    <input type="hidden" name="upass2" value="" />              my $hostname = &Apache::lonnet::hostname($hostid);
    <input type="hidden" name="udom" value="" />              next if (($last eq $hostname) || ($hostname eq ''));
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />              $spares.='<br /><a href="http://'.
    <input type="hidden" name="localres" value="$env{'form.localres'}" />               $hostname.
   </form>               '/adm/login?domain='.$authdomain.'">'.
 ENDSERVERFORM               $hostname.'</a>';
 my $coursecatalog;              $last=$hostname;
 if (($showcoursecat eq '') || ($showcoursecat)) {           }
     $coursecatalog = &coursecatalog_link($lt{'catalog'});           $r->print(
 }     '<html>'
 my $newuserlink;    .'<head><title>'
 if ($shownewuserlink) {    .&mt('The LearningOnline Network with CAPA')
     $newuserlink = &newuser_link($lt{'newuser'}).'<br />';    .'</title></head>'
 }    .'<body bgcolor="#FFFFFF">'
 my $logintitle;    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
 if ($loginheader eq 'text') {    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
     $logintitle ='<h2>'.$lt{'log'}.'</h2>';    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
 } else {          if ($spares) {
     $logintitle = '<img src="'.$login.'" alt="'.              $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
                   &mt('User Authentication').'" />';                       .'</p>'
 }                       .$spares);
           }
 my $noscript_warning='<noscript><span class="LC_warning"><b>'          $r->print('</body>'
                      .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')                   .'</html>'
                     .'</b></span></noscript>';          );
 my $helpdeskscript;          return OK;
 my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,      }
                             $version,$authdomain,\$helpdeskscript);  
   # ----------------------------------------------- Apparently we are in business
 my $loginform=(<<LFORM);      $servadm=~s/\,/\<br \/\>/g;
 <form name="client" onsubmit="return(send())">  
   <input type="hidden" name="lextkey" value="$lextkey" />  # ----------------------------------------------------------- Front page design
   <input type="hidden" name="uextkey" value="$uextkey" />      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
   <b><label for="uname">$lt{'un'}</label>:</b><br />      my $font=&Apache::loncommon::designparm('login.font',$domain);
   <input type="text" name="uname" size="15" value="$authusername" /><br />      my $link=&Apache::loncommon::designparm('login.link',$domain);
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
   <input type="password" name="upass$now" size="15" /><br />      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
   <b><label for="udom">$lt{'dom'}</label>:</b><br />      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
   <input type="text" name="udom" size="15" value="$authdomain" /><br />      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
   <input type="submit" value="$lt{'log'}" />      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
 </form>      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
 LFORM      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
       my $img=&Apache::loncommon::designparm('login.img',$domain);
 if ($fullgraph) {      my $domainlogo=&Apache::loncommon::domainlogo($domain);
     if ($showbanner) {      my $showbanner = 1;
         $r->print(<<HEADER);      my $showmainlogo = 1;
 <!-- The LON-CAPA Header -->      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
 <table border="0" align="left" width="100%" cellspacing="0" cellpadding="1">          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
  <tr>      }
   <td align="left" valign="top" bgcolor="$pgbg">      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
       <img src="$img" border="0" alt="The Learning Online Network with CAPA" />          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
   </td>      }
  </tr>      my $showadminmail;
 </table>      my @possdoms = &Apache::lonnet::current_machine_domains();
 HEADER      if (grep(/^\Q$domain\E$/,@possdoms)) {
     }          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
     if ($showmainlogo) {      }
         $r->print('<div class="LC_loginpage_space">&nbsp;</div>'."\n".      my $showcoursecat =
                   '    <img src="'.$logo.'" alt="" />'."\n");          &Apache::loncommon::designparm('login.coursecatalog',$domain);
     }      my $shownewuserlink =
     $r->print(<<ENDTOP);          &Apache::loncommon::designparm('login.newuser',$domain);
 <div class="LC_loginpage_loginDomain">$domainlogo</div>      my $showhelpdesk =
 <div class="LC_loginpage_loginContainer">          &Apache::loncommon::designparm('login.helpdesk',$domain);
   $logintitle      my $now=time;
    <table border="0" align="left" cellspacing="1" cellpadding="2" width="100%">      my $js = (<<ENDSCRIPT);
       <tr>  
    <td>  <script type="text/javascript" language="JavaScript">
  $loginform  // <![CDATA[
            </td>  function send()
       </tr>  {
    </table>    this.document.server.elements.uname.value
    $noscript_warning  =this.document.client.elements.uname.value;
 </div>  
     this.document.server.elements.udom.value
 <div class="LC_loginpage_loginInfo">  =this.document.client.elements.udom.value;
         $loginhelp<br />  
         $forgotpw<br />  uextkey=this.document.client.elements.uextkey.value;
  $contactblock<br />  lextkey=this.document.client.elements.lextkey.value;
         $newuserlink  initkeys();
         $coursecatalog<br /><br />  
         <a href="/adm/about.html"><b>$lt{'about'}</b></a>  if(this.document.server.action.substr(0,5) === 'http:'){
 </div>      this.document.server.elements.upass0.value
           =getCrypted(this.document.client.elements.upass$now.value);
 <div class="LC_loginpage_space">&nbsp;</div>  } else {
 $announcements      this.document.server.elements.upass0.value
 ENDTOP          =this.document.client.elements.upass$now.value;
 }  }
   
 if($announcements){$r->print('<div class="LC_loginpage_space">&nbsp;</div>');}  this.document.client.elements.uname.value='';
   this.document.client.elements.upass$now.value='';
 if ($fullgraph) {  
 $r->print(<<ENDDOCUMENT);  this.document.server.submit();
      <table border="0" cellspacing="0" cellpadding="0">  return false;
       <tr>  }
        <td  align="left" valign="top">  
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'dom'}:&nbsp;</b></small>  function enableInput() {
        </td>      this.document.client.elements.upass$now.removeAttribute("readOnly");
        <td  align="left" valign="top">      this.document.client.elements.uname.removeAttribute("readOnly");
         <small><tt>&nbsp;$domain</tt></small>      this.document.client.elements.udom.removeAttribute("readOnly");
        </td>      return;
       </tr>  }
       <tr>  
        <td  align="left" valign="top">  // ]]>
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'serv'}:&nbsp;</b></small>  </script>
        </td>  
        <td align="left" valign="top">  ENDSCRIPT
         <small><tt>&nbsp;$lonhost ($role)</tt></small>  
        </td>  # --------------------------------------------------- Print login screen header
       </tr>  
       <tr>      my %add_entries = (
        <td align="left" valign="top">         bgcolor      => "$mainbg",
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'load'}:&nbsp;</b></small>         text         => "$font",
        </td>         link         => "$link",
        <td align="left" valign="top">         vlink        => "$vlink",
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>         alink        => "$alink",
        </td>                 onload       => 'javascript:enableInput();',);
       </tr>  
       <tr>      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
        <td align="left" valign="top">      @hosts = &Apache::lonnet::current_machine_ids();
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'userload'}:&nbsp;</b></small>      $lonhost_in_use = $lonhost;
        </td>      if (@hosts > 1) {
        <td align="left" valign="top">          foreach my $hostid (@hosts) {
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
        </td>                  $lonhost_in_use = $hostid;
       </tr>                  last;
      </table>              }
  </div>          }
       }
 <script type="text/javascript">      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
 // the if prevents the script error if the browser can not handle this      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
 if ( document.client.uname ) { document.client.uname.focus(); }      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
 </script>      if ($headextra) {
 $helpdeskscript          my $omitextra;
           if ($headextra_exempt ne '') {
 ENDDOCUMENT              my @exempt = split(',',$headextra_exempt);
 }              my $ip = $ENV{'REMOTE_ADDR'};
     my %endargs = ( 'noredirectlink' => 1, );              if (grep(/^\Q$ip\E$/,@exempt)) {
     $r->print(&Apache::loncommon::end_page(\%endargs));                  $omitextra = 1;
     return OK;              }
 }          }
           unless ($omitextra) {
 sub contactdisplay {              my $confname = $defdom.'-domainconfig';
     my ($lt,$servadm,$showadminmail,$version,$authdomain,$helpdeskscript) = @_;              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
     my $contactblock;                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
     my $showhelpdesk = 0;                  unless ($extra eq '-1') {
     my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};                      $js .= "\n".$extra."\n";
     if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {                  }
         $showhelpdesk = 1;              }
     }          }
     if ($servadm && $showadminmail) {      }
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;'.$$lt{'servadm'}.':</b><br />'.  
                          '<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$servadm.'</tt><br />&nbsp;<br />';      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
     }         { 'redirect'       => [$expire,'/adm/roles'],
     if ($showhelpdesk) {   'add_entries' => \%add_entries,
         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';   'only_body'   => 1,}));
         my $thisurl = &escape('/adm/login');  
         $$helpdeskscript = <<"ENDSCRIPT";  # ----------------------------------------------------------------------- Texts
 <script type="text/javascript">  
 function helpdesk() {      my %lt=&Apache::lonlocal::texthash(
     var codedom = document.client.udom.value;            'un'       => 'Username',
     if (codedom == '') {            'pw'       => 'Password',
         codedom = "$authdomain";            'dom'      => 'Domain',
     }            'perc'     => 'percent',
     var querystr = "origurl=$thisurl&codedom="+codedom;            'load'     => 'Server Load',
     document.location.href = "/adm/helpdesk?"+querystr;            'userload' => 'User Load',
     return;            'catalog'  => 'Course/Community Catalog',
 }            'log'      => 'Log in',
 </script>            'help'     => 'Log-in Help',
 ENDSCRIPT            'serv'     => 'Server',
     }            'servadm'  => 'Server Administration',
     $contactblock .= <<"ENDBLOCK";            'helpdesk' => 'Contact Helpdesk',
      &nbsp;&nbsp;&nbsp;$version            'forgotpw' => 'Forgot password?',
 ENDBLOCK            'newuser'  => 'New User?',
     return $contactblock;         );
 }  # -------------------------------------------------- Change password field name
   
 sub forgotpwdisplay {      my $forgotpw = &forgotpwdisplay(%lt);
     my (%lt) = @_;      $forgotpw .= '<br />' if $forgotpw;
     my $prompt_for_resetpw = 1;       my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
     if ($prompt_for_resetpw) {      if ($loginhelp) {
         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
     }      }
     return;  
 }  # ---------------------------------------------------- Serve out DES JavaScript
       {
 sub loginhelpdisplay {      my $jsh=Apache::File->new($include."/londes.js");
     my (%lt) = @_;      $r->print(<$jsh>);
     my $login_help = 1;      }
     if ($login_help) {  # ---------------------------------------------------------- Serve rest of page
         return '<a href="/adm/loginproblems.html">'.$lt{'help'}.'</a>';  
     }      $r->print(
     return;      '<div class="LC_Box"'
 }     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
   );
 sub coursecatalog_link {  
     my ($linkname) = @_;      $r->print(<<ENDSERVERFORM);
     return <<"END";  <form name="server" action="/adm/authenticate" method="post" target="_top">
       <a href="/adm/coursecatalog">$linkname</a>     <input type="hidden" name="logtoken" value="$logtoken" />
 END     <input type="hidden" name="serverid" value="$lonhost" />
 }     <input type="hidden" name="uname" value="" />
      <input type="hidden" name="upass0" value="" />
 sub newuser_link {     <input type="hidden" name="udom" value="" />
     my ($linkname) = @_;     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
     return '&nbsp;&nbsp;&nbsp;<a href="/adm/createaccount"><b>'.$linkname.'</b></a><br />';     <input type="hidden" name="localres" value="$env{'form.localres'}" />
 }    </form>
   ENDSERVERFORM
 1;      my $coursecatalog;
 __END__      if (($showcoursecat eq '') || ($showcoursecat)) {
           $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
       }
       my $newuserlink;
       if ($shownewuserlink) {
           $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
       }
       my $logintitle =
           '<h2 class="LC_hcell"'
          .' 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.117  
changed lines
  Added in v.1.176


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