Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.9 and 1.163

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


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