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

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


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