Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.9 and 1.172

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

Removed from v.1.158.2.9  
changed lines
  Added in v.1.172


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