Diff for /loncom/auth/lonlogin.pm between versions 1.133 and 1.175

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


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