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

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


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