Diff for /loncom/auth/lonlogin.pm between versions 1.158 and 1.173

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


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