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

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

Removed from v.1.158.2.6.2.1  
changed lines
  Added in v.1.175


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