Diff for /loncom/auth/lonlogin.pm between versions 1.146 and 1.174

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


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