Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.7 and 1.174

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

Removed from v.1.158.2.7  
changed lines
  Added in v.1.174


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