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

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

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


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