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

version 1.67, 2005/06/14 20:09:13 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 CGI::Cookie();  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 lib '/home/httpd/lib/perl/';
 sub handler {  use LONCAPA;
     my $r = shift;  use CGI::Cookie();
     &Apache::loncommon::no_cache($r);   
     &Apache::lonlocal::get_language_handle($r);  sub handler {
     &Apache::loncommon::content_type($r,'text/html');      my $r = shift;
     $r->send_http_header;  
     return OK if $r->header_only;      &Apache::loncommon::get_unprocessed_cgi
    (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
         $ENV{'REDIRECT_QUERY_STRING'}),
 # Are we re-routing?   ['interface','username','domain','firsturl','localpath','localres',
     if (-e '/home/httpd/html/lon-status/reroute.txt') {    'token','role','symb','iptoken']);
  &Apache::lonauth::reroute($r);      if (!defined($env{'form.firsturl'})) {
  return OK;          &Apache::lonacc::get_posted_cgi($r,['firsturl']);
     }      }
       if (!defined($env{'form.firsturl'})) {
 # -------------------------------- Prevent users from attempting to login twice          if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {
     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));              $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};
     my $lonid=$cookies{'lonID'};          }
     my $cookie;      }
     if ($lonid) {  
  my $handle=$lonid->value;  # -- check if they are a migrating user
         $handle=~s/\W//g;      if (defined($env{'form.token'})) {
         my $lonidsdir=$r->dir_config('lonIDsDir');   return &Apache::migrateuser::handler($r);
         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {      }
 # Indeed, a valid token is found  
     my $bodytag=&Apache::loncommon::bodytag('Already logged in');  # For "public user" - remove any exising "public" cookie, as user really wants to log-in
     $r->print(<<ENDFAILED);      my ($handle,$lonidsdir,$expirepub,$userdom);
 <html>      unless ($r->header_only) {
 <head>          $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
 <title>Already logged in</title>          if ($handle ne '') {
 </head>              $lonidsdir=$r->dir_config('lonIDsDir');
 $bodytag              if ($handle=~/^publicuser\_/) {
 <h1>You are already logged in</h1>                  unlink($r->dir_config('lonIDsDir')."/$handle.id");
 <p>Please either <a href="/adm/roles">continue the current session</a> or                  undef($handle);
 <a href="/adm/logout">logout</a>.</p>                  undef($userdom);
 <p>                  $expirepub = 1;
 <a href="/adm/loginproblems.html">Problems?</a></p>              }
 </body>          }
 </html>      }
 ENDFAILED  
            return OK;      &Apache::loncommon::no_cache($r);
  }      &Apache::lonlocal::get_language_handle($r);
     }      &Apache::loncommon::content_type($r,'text/html');
       if ($expirepub) {
 # ---------------------------------------------------- No valid token, continue          my $c = new CGI::Cookie(-name    => 'lonPubID',
                                   -value   => '',
     &Apache::loncommon::get_unprocessed_cgi                                  -expires => '-10y',);
      ($ENV{'QUERY_STRING'}.'&'.$env{'request.querystring'},          $r->header_out('Set-cookie' => $c);
       ['interface','username','domain','firsturl','localpath','localres']);      } elsif (($handle eq '') && ($userdom ne '')) {
            my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
           foreach my $name (keys(%cookies)) {
 # ----------------------------------------------------------- Process Interface              next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
     $env{'form.interface'}=~s/\W//g;              my $c = new CGI::Cookie(-name    => $name,
                                       -value   => '',
     my $textbrowsers=$r->dir_config('lonTextBrowsers');                                      -expires => '-10y',);
     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};              $r->headers_out->add('Set-cookie' => $c);
               }
     foreach (split(/\:/,$textbrowsers)) {      }
  if ($httpbrowser=~/$_/i) {      $r->send_http_header;
     $env{'form.interface'}='textual';      return OK if $r->header_only;
         }  
     }  
   # Are we re-routing?
     my $fullgraph=($env{'form.interface'} ne 'textual');      my $londocroot = $r->dir_config('lonDocRoot');
     my $port_to_use=$r->dir_config('lonhttpdPort');      if (-e "$londocroot/lon-status/reroute.txt") {
     if (!defined($port_to_use)) {   &Apache::lonauth::reroute($r);
  $port_to_use='8080';   return OK;
     }      }
     my $iconpath= 'http://'.$ENV{'HTTP_HOST'}.':'.$port_to_use.  
                   $r->dir_config('lonIconsURL');      $env{'form.firsturl'} =~ s/(`)/'/g;
     my $domain  = $r->dir_config('lonDefDomain');  
     if (($env{'form.domain'}) &&   # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
  ($Apache::lonnet::domaindescription{$env{'form.domain'}})) {  
  $domain=$env{'form.domain'};      my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
     }      if ($found_server) {
     my $role    = $r->dir_config('lonRole');          my $hostname = &Apache::lonnet::hostname($found_server);
     my $loadlim = $r->dir_config('lonLoadLim');          if ($hostname ne '') {
     my $servadm = $r->dir_config('lonAdmEMail');              my $protocol = $Apache::lonnet::protocol{$found_server};
     my $sysadm  = $r->dir_config('lonSysEMail');              $protocol = 'http' if ($protocol ne 'https');
     my $lonhost = $r->dir_config('lonHostID');              my $dest = '/adm/roles';
     my $tabdir  = $r->dir_config('lonTabDir');              if ($env{'form.firsturl'} ne '') {
     my $include = $r->dir_config('lonIncludes');                  $dest = $env{'form.firsturl'};
     my $expire  = $r->dir_config('lonExpire');              }
     my $version = $r->dir_config('lonVersion');              my $url = $protocol.'://'.$hostname.$dest;
               my $start_page =
 # --------------------------------------------- Default values for login fields                  &Apache::loncommon::start_page('Switching Server ...',undef,
                                                  {'redirect'       => [0,$url],});
     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');  #
  $loadavg=<$loadfile>;  # If browser sent an old cookie for which the session file had been removed
     }  # check if configuration for user's domain has a portal URL set.  If so
     $loadavg =~ s/\s.*//g;  # switch user's log-in to the portal.
     my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);  #
     my $userloadpercent=&Apache::lonnet::userload();  
       if (($handle eq '') && ($userdom ne '')) {
 # ------------------------------------------------------- Do the load balancing          my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
     my $otherserver='http://'.$ENV{'SERVER_NAME'};          if ($domdefaults{'portal_def'} =~ /^https?\:/) {
     my $firsturl=              my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});                                            {'redirect' => [0,$domdefaults{'portal_def'}],});
 # ---------------------------------------- Are we access server and overloaded?              my $end_page   = &Apache::loncommon::end_page();
     if (($role eq 'access') &&              $r->print($start_page.$end_page);
  (($userloadpercent>100.0)||($loadpercent>100.0))) {              return OK;
         my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent);          }
  if ($unloaded) { $otherserver=$unloaded; }      }
     }  
   # -------------------------------- Prevent users from attempting to login twice
 # ----------------------------------------------------------- Get announcements      if ($handle ne '') {
     my $announcements=&Apache::lonnet::getannounce();          &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
 # -------------------------------------------------------- Set login parameters   my $start_page =
       &Apache::loncommon::start_page('Already logged in');
     my @hexstr=('0','1','2','3','4','5','6','7',   my $end_page =
                 '8','9','a','b','c','d','e','f');      &Apache::loncommon::end_page();
     my $lkey='';          my $dest = '/adm/roles';
     for (0..7) {          if ($env{'form.firsturl'} ne '') {
         $lkey.=$hexstr[rand(15)];              $dest = $env{'form.firsturl'};
     }          }
    $r->print(
     my $ukey='';                    $start_page
     for (0..7) {                   .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
         $ukey.=$hexstr[rand(15)];                   .'<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>'
                    .$end_page
     my $lextkey=hex($lkey);                   );
     if ($lextkey>2147483647) { $lextkey-=4294967296; }          return OK;
       }
     my $uextkey=hex($ukey);  
     if ($uextkey>2147483647) { $uextkey-=4294967296; }  # ---------------------------------------------------- No valid token, continue
   
 # -------------------------------------------------------- Store away log token  # ---------------------------- Not possible to really login to domain "public"
     my $logtoken=Apache::lonnet::reply(      if ($env{'form.domain'} eq 'public') {
        'tmpput:'.$ukey.$lkey.'&'.$firsturl,   $env{'form.domain'}='';
        $lonhost);   $env{'form.username'}='';
       }
 # ------------------- If we cannot talk to ourselves, we are in serious trouble  
   # ------ Is this page requested because /adm/migrateuser detected an IP change?
     if ($logtoken eq 'con_lost') {      my %sessiondata;
         my $spares='';      if ($env{'form.iptoken'}) {
  my $last;          %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
         foreach my $hostid (sort          unless ($sessiondata{'sessionserver'}) {
     {              my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
  $Apache::lonnet::hostname{$a} cmp              delete($env{'form.iptoken'});
     $Apache::lonnet::hostname{$b};          }
     }      }
     keys(%Apache::lonnet::spareid)) {  # ----------------------------------------------------------- Process Interface
             next if ($hostid eq $lonhost);      $env{'form.interface'}=~s/\W//g;
             next if ($last eq $Apache::lonnet::hostname{$hostid});  
             $spares.='<br /><font size="+1"><a href="http://'.      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
                 $Apache::lonnet::hostname{$hostid}.          &Apache::loncommon::decode_user_agent();
                 '/adm/login?domain='.$authdomain.'">'.  
                 $Apache::lonnet::hostname{$hostid}.'</a>'.      my $iconpath=
                 ' (preferred)</font>'.$/;   &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
     $last=$Apache::lonnet::hostname{$hostid};  
         }      my $lonhost = $r->dir_config('lonHostID');
         $spares.= '<br />';      my $domain = &Apache::lonnet::default_login_domain();
         foreach my $hostid (sort      my $defdom = $domain;
     {      if ($lonhost ne '') {
  $Apache::lonnet::hostname{$a} cmp          unless ($sessiondata{'sessionserver'}) {
     $Apache::lonnet::hostname{$b};              my $redirect = &check_loginvia($domain,$lonhost);
     }              if ($redirect) {
     keys(%Apache::lonnet::hostname)) {                  $r->print($redirect);
             next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});                  return OK;
             next if ($last eq $Apache::lonnet::hostname{$hostid});              }
             $spares.='<br /><a href="http://'.          }
                 $Apache::lonnet::hostname{$hostid}.      }
                 '/adm/login?domain='.$authdomain.'">'.  
                 $Apache::lonnet::hostname{$hostid}.'</a>';      if (($sessiondata{'domain'}) &&
     $last=$Apache::lonnet::hostname{$hostid};          (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
         }          $domain=$sessiondata{'domain'};
  $r->print(<<ENDTROUBLE);      } elsif (($env{'form.domain'}) &&
 <html>   (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
 <head><title>The LearningOnline Network with CAPA</title></head>   $domain=$env{'form.domain'};
 <body bgcolor="#FFFFFF">      }
 <img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />  
 <h3>This LON-CAPA server is temporarily not available for login</h3>      my $role    = $r->dir_config('lonRole');
 <p>Please attempt to login to one of the following servers:</p>$spares      my $loadlim = $r->dir_config('lonLoadLim');
 <p>If the problem persists, please contact <tt>$servadm</tt>.</p>      my $uloadlim= $r->dir_config('lonUserLoadLim');
 </body>      my $servadm = $r->dir_config('lonAdmEMail');
 </html>      my $tabdir  = $r->dir_config('lonTabDir');
 ENDTROUBLE      my $include = $r->dir_config('lonIncludes');
         return OK;      my $expire  = $r->dir_config('lonExpire');
     }      my $version = $r->dir_config('lonVersion');
       my $host_name = &Apache::lonnet::hostname($lonhost);
 # ----------------------------------------------- Apparently we are in business  
   # --------------------------------------------- Default values for login fields
     my $domainlogo=&Apache::loncommon::domainlogo($domain);     
     $servadm=~s/\,/\<br \/\>/g;      my ($authusername,$authdomain);
     $sysadm=~s/\,/\<br \/\>/g;      if ($sessiondata{'username'}) {
           $authusername=$sessiondata{'username'};
 # --------------------------------------------------- Print login screen header      } else {
     $r->print(<<ENDHEADER);          $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
 <html>          $authusername=($env{'form.username'}?$env{'form.username'}:'');
 <head>      }
 <meta HTTP-EQUIV="Refresh" CONTENT="$expire; url=/adm/roles" />      if ($sessiondata{'domain'}) {
 <title>The LearningOnline Network with CAPA Login</title>          $authdomain=$sessiondata{'domain'};
 </head>      } else {
 ENDHEADER          $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
 # ---------------------------------------------------- Serve out DES JavaScript          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
     {      }
  my $jsh=Apache::File->new($include."/londes.js");  
         $r->print(<$jsh>);  # ---------------------------------------------------------- Determine own load
     }      my $loadavg;
       {
 # ----------------------------------------------------------- Front page design   my $loadfile=Apache::File->new('/proc/loadavg');
     my $pgbg=   $loadavg=<$loadfile>;
       ($fullgraph?&Apache::loncommon::designparm('login.pgbg',$domain):'#FFFFFF');      }
     my $font=      $loadavg =~ s/\s.*//g;
       ($fullgraph?&Apache::loncommon::designparm('login.font',$domain):'#000000');  
     my $link=      my ($loadpercent,$userloadpercent);
       ($fullgraph?&Apache::loncommon::designparm('login.link',$domain):'#0000FF');      if ($loadlim) {
     my $vlink=          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
       ($fullgraph?&Apache::loncommon::designparm('login.vlink',$domain):'#0000FF');      }
     my $alink=&Apache::loncommon::designparm('login.alink',$domain);      if ($uloadlim) {
     my $mainbg=          $userloadpercent=&Apache::lonnet::userload();
       ($fullgraph?&Apache::loncommon::designparm('login.mainbg',$domain):'#FFFFFF');      }
     my $sidebg=  
       ($fullgraph?&Apache::loncommon::designparm('login.sidebg',$domain):'#FFFFFF');      my $firsturl=
     my $logo=&Apache::loncommon::designparm('login.logo',$domain);      ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
     my $img=&Apache::loncommon::designparm('login.img',$domain);  
   # ----------------------------------------------------------- Get announcements
 # ----------------------------------------------------------------------- Texts      my $announcements=&Apache::lonnet::getannounce();
   # -------------------------------------------------------- Set login parameters
 my %lt=&Apache::lonlocal::texthash(  
   'un'  => 'Username',      my @hexstr=('0','1','2','3','4','5','6','7',
   'pw'  => 'Password',                  '8','9','a','b','c','d','e','f');
   'dom' => 'Domain',      my $lkey='';
   'perc' => 'percent',      for (0..7) {
   'load' => 'Load',          $lkey.=$hexstr[rand(15)];
                   'userload' => 'User Load',      }
                   'about'  => 'aboutlon.gif',  
                   'access' => 'accessbutton.gif',      my $ukey='';
   'auth' => 'userauthentication.gif',      for (0..7) {
   'log' => 'Log in',          $ukey.=$hexstr[rand(15)];
   'help' => 'Help',      }
   'serv' => 'Server',  
                   'servadm' => 'Server Administration',      my $lextkey=hex($lkey);
                   'sysadm' => 'System Administration',      if ($lextkey>2147483647) { $lextkey-=4294967296; }
                   'helpdesk' => 'Contact Helpdesk');  
 # -------------------------------------------------- Change password field name      my $uextkey=hex($ukey);
     my $now=time;      if ($uextkey>2147483647) { $uextkey-=4294967296; }
 # ---------------------------------------------------------- Serve rest of page  
     $r->print(<<ENDSCRIPT);  # -------------------------------------------------------- Store away log token
       my $tokenextras;
 <body bgcolor="$pgbg" text="$font" link="$link" vlink="$vlink" alink="$alink"      if ($env{'form.role'}) {
   topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>          $tokenextras = '&role='.&escape($env{'form.role'});
       }
  <script language="JavaScript">      if ($env{'form.symb'}) {
     function send()          if (!$tokenextras) {
     {              $tokenextras = '&';
  this.document.server.elements.uname.value          }
        =this.document.client.elements.uname.value;          $tokenextras .= '&symb='.&escape($env{'form.symb'});
       }
         this.document.server.elements.udom.value      if ($env{'form.iptoken'}) {
        =this.document.client.elements.udom.value;          if (!$tokenextras) {
               $tokenextras = '&&';
         this.document.server.elements.imagesuppress.value          }
        =this.document.client.elements.imagesuppress.checked;          $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
       }
         this.document.server.elements.embedsuppress.value      my $logtoken=Apache::lonnet::reply(
        =this.document.client.elements.embedsuppress.checked;         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
          $lonhost);
         this.document.server.elements.appletsuppress.value  
        =this.document.client.elements.appletsuppress.checked;  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
   #    we are in serious trouble
         this.document.server.elements.fontenhance.value  
        =this.document.client.elements.fontenhance.checked;      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
           if ($logtoken eq 'no_such_host') {
         this.document.server.elements.blackwhite.value              &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.blackwhite.checked;          }
           my $spares='';
         this.document.server.elements.remember.value   my $last;
        =this.document.client.elements.remember.checked;          foreach my $hostid (sort
       {
         uextkey=this.document.client.elements.uextkey.value;   &Apache::lonnet::hostname($a) cmp
         lextkey=this.document.client.elements.lextkey.value;      &Apache::lonnet::hostname($b);
         initkeys();      }
       keys(%Apache::lonnet::spareid)) {
         this.document.server.elements.upass0.value              next if ($hostid eq $lonhost);
     =crypted(this.document.client.elements.upass$now.value.substr(0,15));      my $hostname = &Apache::lonnet::hostname($hostid);
  this.document.server.elements.upass1.value      next if (($last eq $hostname) || ($hostname eq ''));
     =crypted(this.document.client.elements.upass$now.value.substr(15,15));              $spares.='<br /><font size="+1"><a href="http://'.
  this.document.server.elements.upass2.value                  $hostname.
     =crypted(this.document.client.elements.upass$now.value.substr(30,15));                  '/adm/login?domain='.$authdomain.'">'.
                   $hostname.'</a>'.
         this.document.client.elements.uname.value='';                  ' '.&mt('(preferred)').'</font>'.$/;
         this.document.client.elements.upass$now.value='';      $last=$hostname;
           }
         this.document.server.submit();          if ($spares) {
  return false;              $spares.= '<br />';
     }          }
  </script>          my %all_hostnames = &Apache::lonnet::all_hostnames();
 ENDSCRIPT          foreach my $hostid (sort
       {
     if ($fullgraph) {   &Apache::lonnet::hostname($a) cmp
  $r->print(      &Apache::lonnet::hostname($b);
   '<table width="100%" cellpadding=0 cellspacing=0 border=0>');      }
     }      keys(%all_hostnames)) {
               next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
     $r->print(<<ENDSERVERFORM);              my $hostname = &Apache::lonnet::hostname($hostid);
   <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">              next if (($last eq $hostname) || ($hostname eq ''));
    <input type="hidden" name="logtoken" value="$logtoken" />              $spares.='<br /><a href="http://'.
    <input type="hidden" name="serverid" value="$lonhost" />               $hostname.
    <input type="hidden" name="interface" value="$env{'form.interface'}" />               '/adm/login?domain='.$authdomain.'">'.
    <input type="hidden" name="uname" value="" />               $hostname.'</a>';
    <input type="hidden" name="upass0" value="" />              $last=$hostname;
    <input type="hidden" name="upass1" value="" />           }
    <input type="hidden" name="upass2" value="" />           $r->print(
    <input type="hidden" name="udom" value="" />     '<html>'
    <input type="hidden" name="imagesuppress"  value="" />    .'<head><title>'
    <input type="hidden" name="appletsuppress"  value="" />    .&mt('The LearningOnline Network with CAPA')
    <input type="hidden" name="embedsuppress"  value="" />    .'</title></head>'
    <input type="hidden" name="fontenhance"  value="" />    .'<body bgcolor="#FFFFFF">'
    <input type="hidden" name="blackwhite"  value="" />    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
    <input type="hidden" name="remember"  value="" />    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
    <input type="hidden" name="localres" value="$env{'form.localres'}" />          if ($spares) {
   </form>              $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
 ENDSERVERFORM                       .'</p>'
     if ($fullgraph) { $r->print(<<ENDTOP);                       .$spares);
   <!-- The LON-CAPA Header -->          }
   <tr>          $r->print('</body>'
                    .'</html>'
    <!-- Row 1 Columns 2-4 -->          );
    <td width="100%" height=75 colspan=4 align="left" valign="top" bgcolor="$pgbg"><img src="$img" border=0 alt="The Learning Online Network with CAPA" /></td>          return OK;
   </tr>      }
   
   <!-- The gray bar that starts the two table frames -->  # ----------------------------------------------- Apparently we are in business
   <tr>      $servadm=~s/\,/\<br \/\>/g;
   
    <!-- Row 2 Column 1 -->  # ----------------------------------------------------------- Front page design
    <td width=182 height=27 bgcolor="$sidebg">&nbsp;</td>      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
       my $font=&Apache::loncommon::designparm('login.font',$domain);
    <!-- Row 2 Column 2 -->      my $link=&Apache::loncommon::designparm('login.link',$domain);
    <td width=27 height=27 align="left" background="$iconpath/filltop.gif"><img src="$iconpath/upperleft.gif" border=0 alt="" /></td>      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
       my $alink=&Apache::loncommon::designparm('login.alink',$domain);
    <!-- Row 2 Column 3 -->      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
    <td height=27 background="$iconpath/filltop.gif"><img src="$iconpath/filltop.gif" alt="" /></td>      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
       my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
    <!-- Row 2 Column 4 -->      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
    <td width=27 height=27 align="right" background="$iconpath/filltop.gif"><img src="$iconpath/upperright.gif" border=0 alt="" /></td>      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
   </tr>      my $img=&Apache::loncommon::designparm('login.img',$domain);
   <tr>      my $domainlogo=&Apache::loncommon::domainlogo($domain);
          my $showbanner = 1;
    <!-- A cell that will hold the 'access' and 'about' buttons -->      my $showmainlogo = 1;
    <!-- Row 3 Column 1 -->      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
    <td valign="top" height=60 align="center" bgcolor="$sidebg">          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
     <a href="/adm/login?interface=textual"><img src="$iconpath/$lt{'access'}" border=0 alt="Accessibility Options" /></a>      }
     <br />      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
     <a href="/adm/about.html"><img src="$iconpath/$lt{'about'}" border=0 alt="About LON-CAPA" /></a>          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
    </td>      }
       my $showadminmail;
    <!-- The shaded space between the two main columns -->      my @possdoms = &Apache::lonnet::current_machine_domains();
    <!-- Row 3 Column 2 -->      if (grep(/^\Q$domain\E$/,@possdoms)) {
    <td width=27 height=60 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
       }
    <!-- The right main column holding the large LON-CAPA logo-->      my $showcoursecat =
    <!-- Rows 3-4 Column 3 -->          &Apache::loncommon::designparm('login.coursecatalog',$domain);
    <td align="center" valign="top" width="100%" height="100%" bgcolor="$mainbg">      my $shownewuserlink =
     <center>          &Apache::loncommon::designparm('login.newuser',$domain);
      <img src="$logo" alt="" />      my $showhelpdesk =
     </center>          &Apache::loncommon::designparm('login.helpdesk',$domain);
    </td>      my $now=time;
       my $js = (<<ENDSCRIPT);
    <!-- Row 3 Column 4 -->  
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>  <script type="text/javascript" language="JavaScript">
   </tr>  // <![CDATA[
   <tr>  function send()
   {
    <!-- The entry form -->  this.document.server.elements.uname.value
    <!-- Row 4 Column 1 -->  =this.document.client.elements.uname.value;
    <td align="center" valign="middle" bgcolor="$sidebg">  
 ENDTOP  this.document.server.elements.udom.value
 } else {  =this.document.client.elements.udom.value;
     $r->print('<h1>The Learning<i>Online</i> Network with CAPA</h1><h2>Text-based Interface Login</h2>'.$announcements);  
 }  uextkey=this.document.client.elements.uextkey.value;
     $r->print('<form name="client" onsubmit="return(send())">');  lextkey=this.document.client.elements.lextkey.value;
     unless ($fullgraph) {  initkeys();
         $r->print(<<ENDACCESSOPTIONS);  
 <h3>Select Accessibility Options</h3>  if(this.document.server.action.substr(0,5) === 'http:'){
 <label><input type="checkbox" name="imagesuppress" /> Suppress rendering of images</label><br />      this.document.server.elements.upass0.value
 <label><input type="checkbox" name="appletsuppress" /> Suppress Java applets</label><br />          =getCrypted(this.document.client.elements.upass$now.value);
 <label><input type="checkbox" name="embedsuppress" /> Suppress rendering of embedded multimedia</label><br />  } else {
 <label><input type="checkbox" name="fontenhance" /> Increase font size</label><br />      this.document.server.elements.upass0.value
 <label><input type="checkbox" name="blackwhite" /> Switch to black and white mode</label><br />          =this.document.client.elements.upass$now.value;
 <p>If you have accessibility needs that are not addressed by this interface,   }
 please  
 contact the system administrator at <tt>$sysadm</tt>.</p><br />  this.document.client.elements.uname.value='';
 <input type="checkbox" name="remember" /> Remember these settings for next login<hr />  this.document.client.elements.upass$now.value='';
 ENDACCESSOPTIONS  
 } else {  this.document.server.submit();
     $r->print(<<ENDNOOPT);  return false;
 <input type="hidden" name="imagesuppress"  value="" />  }
 <input type="hidden" name="embedsuppress"  value="" />  
 <input type="hidden" name="appletsuppress"  value="" />  function enableInput() {
 <input type="hidden" name="fontenhance"  value="" />      this.document.client.elements.upass$now.removeAttribute("readOnly");
 <input type="hidden" name="blackwhite"  value="" />      this.document.client.elements.uname.removeAttribute("readOnly");
 <input type="hidden" name="remember"  value="" />      this.document.client.elements.udom.removeAttribute("readOnly");
 ENDNOOPT      return;
 }  }
     $r->print(<<ENDLOGIN);  
      <input type="hidden" name="lextkey" value="$lextkey">  // ]]>
      <input type="hidden" name="uextkey" value="$uextkey">  </script>
   
      <!-- Start the sub-table for text and input alignment -->  ENDSCRIPT
      <table border=0 cellspacing=0 cellpadding=0>  
       <tr><td bgcolor="$sidebg" colspan=2><img src="$iconpath/$lt{'auth'}" alt="User Authentication" /></td></tr>  # --------------------------------------------------- Print login screen header
       <tr>  
        <td bgcolor="$mainbg"><br /><font size=-1><b>&nbsp;&nbsp;&nbsp;$lt{'un'}:</b></font></td>      my %add_entries = (
        <td bgcolor="$mainbg"><br /><input type="text" name="uname" size="10" value="$authusername" /></td>         bgcolor      => "$mainbg",
       </tr>         text         => "$font",
       <tr>         link         => "$link",
        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;$lt{'pw'}:</b></font></td>         vlink        => "$vlink",
        <td bgcolor="$mainbg"><input type="password" name="upass$now" size="10" /></td>         alink        => "$alink",
       </tr>                 onload       => 'javascript:enableInput();',);
       <tr>  
        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;$lt{'dom'}:</b></font></td>      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
        <td bgcolor="$mainbg"><input type="text" name="udom" size="10" value="$authdomain" /></td>      @hosts = &Apache::lonnet::current_machine_ids();
       </tr>      $lonhost_in_use = $lonhost;
       <tr>      if (@hosts > 1) {
        <td bgcolor="$mainbg">&nbsp;&nbsp;&nbsp;<a href="/adm/loginproblems.html">$lt{'help'}</a></td>          foreach my $hostid (@hosts) {
        <td bgcolor="$mainbg" valign="bottom" align="center">              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
         <br />                  $lonhost_in_use = $hostid;
         <input type="submit" value="$lt{'log'}" />                  last;
        </td>              }
       </tr>          }
      </table>      }
      <!-- End sub-table -->      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
     </form>      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
 ENDLOGIN      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
     if ($fullgraph) {      if ($headextra) {
         my $helpdeskscript;          my $omitextra;
         my $contactblock = &contactdisplay(\%lt,$sysadm,$servadm,$version,$authdomain,\$helpdeskscript);          if ($headextra_exempt ne '') {
  $r->print(<<ENDDOCUMENT);              my @exempt = split(',',$headextra_exempt);
    </td>              my $ip = $ENV{'REMOTE_ADDR'};
               if (grep(/^\Q$ip\E$/,@exempt)) {
    <!-- Row 4 Column 2 -->                  $omitextra = 1;
    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>              }
           }
    <!-- Row 4 Column 3 -->          unless ($omitextra) {
 <td bgcolor="$mainbg">$announcements</td>              my $confname = $defdom.'-domainconfig';
               if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
    <!-- Row 4 Column 4 -->                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>                  unless ($extra eq '-1') {
   </tr>                      $js .= "\n".$extra."\n";
   <tr>                  }
               }
    <!-- Row 5 Column 1 -->          }
    <td bgcolor="$sidebg" valign="middle" align="left">      }
      <br />  
      <table border=0 cellspacing=0 cellpadding=0>      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
       <tr>         { 'redirect'       => [$expire,'/adm/roles'],
        <td bgcolor="$sidebg" align="left" valign="top">   'add_entries' => \%add_entries,
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'dom'}:&nbsp;</b></small>   'only_body'   => 1,}));
        </td>  
        <td bgcolor="$sidebg" align="left" valign="top">  # ----------------------------------------------------------------------- Texts
         <small><tt>&nbsp;$domain</tt></small>  
        </td>      my %lt=&Apache::lonlocal::texthash(
       </tr>            'un'       => 'Username',
       <tr>            'pw'       => 'Password',
        <td bgcolor="$sidebg" align="left" valign="top">            'dom'      => 'Domain',
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'serv'}:&nbsp;</b></small>            'perc'     => 'percent',
        </td>            'load'     => 'Server Load',
        <td bgcolor="$sidebg" align="left" valign="top">            'userload' => 'User Load',
         <small><tt>&nbsp;$lonhost ($role)</tt></small>            'catalog'  => 'Course/Community Catalog',
        </td>            'log'      => 'Log in',
       </tr>            'help'     => 'Log-in Help',
       <tr>            'serv'     => 'Server',
        <td bgcolor="$sidebg" align="left" valign="top">            'servadm'  => 'Server Administration',
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'load'}:&nbsp;</b></small>            'helpdesk' => 'Contact Helpdesk',
        </td>            'forgotpw' => 'Forgot password?',
        <td bgcolor="$sidebg" align="left" valign="top">            'newuser'  => 'New User?',
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>         );
        </td>  # -------------------------------------------------- Change password field name
       </tr>  
       <tr>      my $forgotpw = &forgotpwdisplay(%lt);
        <td bgcolor="$sidebg" align="left" valign="top">      $forgotpw .= '<br />' if $forgotpw;
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'userload'}:&nbsp;</b></small>      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
        </td>      if ($loginhelp) {
        <td bgcolor="$sidebg" align="left" valign="top">          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>      }
        </td>  
       </tr>  # ---------------------------------------------------- Serve out DES JavaScript
      </table>      {
      <br />      my $jsh=Apache::File->new($include."/londes.js");
     $contactblock      $r->print(<$jsh>);
    </td>      }
   # ---------------------------------------------------------- Serve rest of page
    <!-- Row 5 Column 2 -->  
    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>      $r->print(
       '<div class="LC_Box"'
    <!-- Row 5 Column 3 -->     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
    <td width="100%" valign="bottom" bgcolor="$mainbg">  );
 $domainlogo  
 </td>      $r->print(<<ENDSERVERFORM);
   <form name="server" action="/adm/authenticate" method="post" target="_top">
    <!-- Row 5 Column 4 -->     <input type="hidden" name="logtoken" value="$logtoken" />
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>     <input type="hidden" name="serverid" value="$lonhost" />
   </tr>     <input type="hidden" name="uname" value="" />
   <tr>     <input type="hidden" name="upass0" value="" />
      <input type="hidden" name="udom" value="" />
    <!-- Row 6 Column 1 -->     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
    <td bgcolor="$sidebg">&nbsp;</td>     <input type="hidden" name="localres" value="$env{'form.localres'}" />
     </form>
    <!-- Row 6 Column 2 -->  ENDSERVERFORM
    <td align="left" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerleft.gif" alt="" /></td>      my $coursecatalog;
       if (($showcoursecat eq '') || ($showcoursecat)) {
    <!-- Row 6 Column 3 -->          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
    <td background="$iconpath/fillbottom.gif"><img src="$iconpath/fillbottom.gif" alt="" /></td>      }
       my $newuserlink;
    <!-- Row 6 Column 4 -->      if ($shownewuserlink) {
    <td align="right" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerright.gif" alt="" /></td>          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
   </tr>      }
  </table>      my $logintitle =
           '<h2 class="LC_hcell"'
 <script type="text/javascript">         .' style="background:'.$loginbox_header_bgcol.';'
 // the if prevents the script error if the browser can not handle this         .' color:'.$loginbox_header_textcol.'">'
 if ( document.client.uname ) { document.client.uname.focus(); }         .$lt{'log'}
 </script>         .'</h2>';
 $helpdeskscript  
       my $noscript_warning='<noscript><span class="LC_warning"><b>'
 ENDDOCUMENT                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
 }                          .'</b></span></noscript>';
     $r->print('</body></html>');      my $helpdeskscript;
     return OK;      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
 }                                         $authdomain,\$helpdeskscript,
                                          $showhelpdesk,\@possdoms);
 sub contactdisplay {  
     my ($lt,$sysadm,$servadm,$version,$authdomain,$helpdeskscript) = @_;      my $mobileargs;
     my $contactblock;      if ($clientmobile) {
     my $showsysadm = 1;          $mobileargs = 'autocapitalize="off" autocorrect="off"';
     my $showservadm = 1;      }
     my $showhelpdesk = 0;      my $loginform=(<<LFORM);
     my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};  <form name="client" action="" onsubmit="return(send())">
     if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {    <input type="hidden" name="lextkey" value="$lextkey" />
         $showhelpdesk = 1;    <input type="hidden" name="uextkey" value="$uextkey" />
     }    <b><label for="uname">$lt{'un'}</label>:</b><br />
     if ($showsysadm) {    <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;'.$$lt{'sysadm'}.':</b><br />'.    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
                          '<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$sysadm.'</tt><br />';    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
     }    <b><label for="udom">$lt{'dom'}</label>:</b><br />
     if ($showservadm) {    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;'.$$lt{'servadm'}.':</b><br />'.    <input type="submit" value="$lt{'log'}" />
                          '<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$servadm.'</tt><br />&nbsp;<br />';  </form>
     }  LFORM
     if ($showhelpdesk) {  
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;<a href="javascript:helpdesk()">'.$$lt{'helpdesk'}.'</a></b><br />';      if ($showbanner) {
         my $thisurl = &Apache::lonnet::escape('/adm/login');          $r->print(<<HEADER);
         $$helpdeskscript = <<"ENDSCRIPT";  <!-- The LON-CAPA Header -->
 <script type="text/javascript">  <div style="background:$pgbg;margin:0;width:100%;">
 function helpdesk() {    <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
     var codedom = document.client.udom.value;  </div>
     if (codedom == '') {  HEADER
         codedom = "$authdomain";      }
     }      $r->print(<<ENDTOP);
     var querystr = "origurl=$thisurl&codedom="+codedom;  <div style="float:left;margin-top:0;">
     document.location.href = "/adm/helpdesk?"+querystr;  <div class="LC_Box" style="background:$loginbox_bg;">
     return;    $logintitle
 }    $loginform
 </script>    $noscript_warning
 ENDSCRIPT  </div>
     }   
     $contactblock .= <<"ENDBLOCK";  <div class="LC_Box" style="padding-top: 10px;">
      &nbsp;&nbsp;&nbsp;$version    $loginhelp
 ENDBLOCK    $forgotpw
     return $contactblock;    $contactblock
 }    $newuserlink
      $coursecatalog
   </div>
 1;  </div>
 __END__  
   <div>
   ENDTOP
       if ($showmainlogo) {
           $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
       }
   $r->print(<<ENDTOP);
   $announcements
   </div>
   <hr style="clear:both;" />
   ENDTOP
       my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
       $domainrow = <<"END";
         <tr>
          <td  align="left" valign="top">
           <small><b>$lt{'dom'}:&nbsp;</b></small>
          </td>
          <td  align="left" valign="top">
           <small><tt>&nbsp;$domain</tt></small>
          </td>
         </tr>
   END
       $serverrow = <<"END";
         <tr>
          <td  align="left" valign="top">
           <small><b>$lt{'serv'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$lonhost ($role)</tt></small>
          </td>
         </tr>
   END
       if ($loadlim) {
           $loadrow = <<"END";
         <tr>
          <td align="left" valign="top">
           <small><b>$lt{'load'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
          </td>
         </tr>
   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.67  
changed lines
  Added in v.1.175


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