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

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


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