Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.3 and 1.176

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


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