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

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


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