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

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


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