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

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


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