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

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


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