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

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


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