Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.6.2.1 and 1.161

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


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