Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.8 and 1.170

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


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