Diff for /loncom/auth/lonlogin.pm between versions 1.159 and 1.176

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

Removed from v.1.159  
changed lines
  Added in v.1.176


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