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

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


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