Diff for /loncom/auth/lonlogin.pm between versions 1.70 and 1.182

version 1.70, 2005/11/23 20:58:31 version 1.182, 2020/12/18 15:23:03
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 CGI::Cookie();  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 lib '/home/httpd/lib/perl/';
 sub handler {  use LONCAPA qw(:DEFAULT :match);
     my $r = shift;  use CGI::Cookie();
     &Apache::loncommon::no_cache($r);   
     &Apache::lonlocal::get_language_handle($r);  sub handler {
     &Apache::loncommon::content_type($r,'text/html');      my $r = shift;
     $r->send_http_header;  
     return OK if $r->header_only;      &Apache::loncommon::get_unprocessed_cgi
    (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
         $ENV{'REDIRECT_QUERY_STRING'}),
 # Are we re-routing?   ['interface','username','domain','firsturl','localpath','localres',
     if (-e '/home/httpd/html/lon-status/reroute.txt') {    'token','role','symb','iptoken','btoken','ltoken','linkkey']);
  &Apache::lonauth::reroute($r);      if (!defined($env{'form.firsturl'})) {
  return OK;          &Apache::lonacc::get_posted_cgi($r,['firsturl']);
     }      }
       if (!defined($env{'form.firsturl'})) {
 # -------------------------------- Prevent users from attempting to login twice          if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {
     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));              $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};
     my $lonid=$cookies{'lonID'};          }
     my $cookie;      }
     if ($lonid) {      if (($env{'form.firsturl'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) &&
  my $handle=$lonid->value;          (!$env{'form.ltoken'}) && (!$env{'form.linkkey'})) {
         $handle=~s/\W//g;          &Apache::lonacc::get_posted_cgi($r,['linkkey']);
         my $lonidsdir=$r->dir_config('lonIDsDir');      }
  if (-e "$lonidsdir/$handle.id") {  
 # Is there an existing token file?  # -- check if they are a migrating user
     if ($handle=~/^publicuser\_/) {      if (defined($env{'form.token'})) {
 # For "public user" - remove it, we apparently really want to login   return &Apache::migrateuser::handler($r);
  unlink("$lonidsdir/$handle.id");      }
     } elsif ($handle ne '') {  
 # Indeed, a valid token is found  # For "public user" - remove any exising "public" cookie, as user really wants to log-in
  my $bodytag=&Apache::loncommon::bodytag('Already logged in');      my ($handle,$lonidsdir,$expirepub,$userdom);
  $r->print(<<ENDFAILED);      $lonidsdir=$r->dir_config('lonIDsDir');
 <html>      unless ($r->header_only) {
 <head>          $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
 <title>Already logged in</title>          if ($handle ne '') {
 </head>              if ($handle=~/^publicuser\_/) {
 $bodytag                  unlink($r->dir_config('lonIDsDir')."/$handle.id");
 <h1>You are already logged in</h1>                  undef($handle);
 <p>Please either <a href="/adm/roles">continue the current session</a> or                  undef($userdom);
 <a href="/adm/logout">logout</a>.</p>                  $expirepub = 1;
 <p>              }
 <a href="/adm/loginproblems.html">Problems?</a></p>          }
 </body>      }
 </html>  
 ENDFAILED      &Apache::loncommon::no_cache($r);
                 return OK;      &Apache::lonlocal::get_language_handle($r);
      }        &Apache::loncommon::content_type($r,'text/html');
  }      if ($expirepub) {
     }          my $c = new CGI::Cookie(-name    => 'lonPubID',
                                   -value   => '',
 # ---------------------------------------------------- No valid token, continue                                  -expires => '-10y',);
           $r->header_out('Set-cookie' => $c);
     &Apache::loncommon::get_unprocessed_cgi      } elsif (($handle eq '') && ($userdom ne '')) {
      ($ENV{'QUERY_STRING'}.'&'.$env{'request.querystring'},          my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
       ['interface','username','domain','firsturl','localpath','localres']);          foreach my $name (keys(%cookies)) {
               next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
  # ---------------------------- Not possible to really login to domain "public"              my $c = new CGI::Cookie(-name    => $name,
     if ($env{'form.domain'} eq 'public') {                                      -value   => '',
  $env{'form.domain'}='';                                      -expires => '-10y',);
  $env{'form.username'}='';              $r->headers_out->add('Set-cookie' => $c);
     }          }
 # ----------------------------------------------------------- Process Interface      }
     $env{'form.interface'}=~s/\W//g;      $r->send_http_header;
       return OK if $r->header_only;
     my $textbrowsers=$r->dir_config('lonTextBrowsers');  
     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};  
       # Are we re-routing?
     foreach (split(/\:/,$textbrowsers)) {      my $londocroot = $r->dir_config('lonDocRoot');
  if ($httpbrowser=~/$_/i) {      if (-e "$londocroot/lon-status/reroute.txt") {
     $env{'form.interface'}='textual';   &Apache::lonauth::reroute($r);
         }   return OK;
     }      }
   
     my $fullgraph=($env{'form.interface'} ne 'textual');      my $lonhost = $r->dir_config('lonHostID');
     my $port_to_use=$r->dir_config('lonhttpdPort');      $env{'form.firsturl'} =~ s/(`)/'/g;
     if (!defined($port_to_use)) {  
  $port_to_use='8080';  # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
     }  
     my $iconpath= 'http://'.$ENV{'HTTP_HOST'}.':'.$port_to_use.      my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
                   $r->dir_config('lonIconsURL');      if ($found_server) {
     my $domain  = $r->dir_config('lonDefDomain');          my $hostname = &Apache::lonnet::hostname($found_server);
     my $testdomain=(split(/\./,$ENV{'HTTP_HOST'}))[0];          if ($hostname ne '') {
     foreach my $posdom (&Apache::lonnet::current_machine_domains()) {              my $protocol = $Apache::lonnet::protocol{$found_server};
  if ($posdom eq $testdomain) { $domain=$testdomain; }              $protocol = 'http' if ($protocol ne 'https');
     }              my $dest = '/adm/roles';
     if (($env{'form.domain'}) &&               if ($env{'form.firsturl'} ne '') {
  ($Apache::lonnet::domaindescription{$env{'form.domain'}})) {                  $dest = $env{'form.firsturl'};
  $domain=$env{'form.domain'};              }
     }              my %info = (
     my $role    = $r->dir_config('lonRole');                           balcookie => $lonhost.':'.$balancer_cookie,
     my $loadlim = $r->dir_config('lonLoadLim');                         );
     my $servadm = $r->dir_config('lonAdmEMail');              if ($env{'form.ltoken'}) {
     my $sysadm  = $r->dir_config('lonSysEMail');                  my %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
     my $lonhost = $r->dir_config('lonHostID');                  if ($link_info{'linkprot'}) {
     my $tabdir  = $r->dir_config('lonTabDir');                      $info{'linkprot'} = $link_info{'linkprot'};
     my $include = $r->dir_config('lonIncludes');                  }
     my $expire  = $r->dir_config('lonExpire');                  &Apache::lonnet::tmpdel($env{'form.ltoken'});
     my $version = $r->dir_config('lonVersion');                  delete($env{'form.ltoken'});
               } elsif ($env{'form.linkkey'}) {
 # --------------------------------------------- Default values for login fields                  $info{'linkkey'} = $env{'form.linkkey'};
                   delete($env{'form.linkkey'});
     my $authusername=($env{'form.username'}?$env{'form.username'}:'');              }
     my $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);              my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
               if ($balancer_token) {
 # ---------------------------------------------------------- Determine own load                  $dest .=  (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;
     my $loadavg;              }
     {              my $url = $protocol.'://'.$hostname.$dest;
  my $loadfile=Apache::File->new('/proc/loadavg');              my $start_page =
  $loadavg=<$loadfile>;                  &Apache::loncommon::start_page('Switching Server ...',undef,
     }                                                 {'redirect'       => [0,$url],});
     $loadavg =~ s/\s.*//g;              my $end_page   = &Apache::loncommon::end_page();
     my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);              $r->print($start_page.$end_page);
     my $userloadpercent=&Apache::lonnet::userload();              return OK;
           }
 # ------------------------------------------------------- Do the load balancing      }
     my $otherserver='http://'.$ENV{'SERVER_NAME'};  
     my $firsturl=  #
     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});  # Check if a LON-CAPA load balancer sent user here because user's browser sent
 # ---------------------------------------- Are we access server and overloaded?  # it a balancer cookie for an active session on this server.
     if (($role eq 'access') &&  #
  (($userloadpercent>100.0)||($loadpercent>100.0))) {  
         my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent);      my ($balcookie,$linkprot,$linkkey);
  if ($unloaded) { $otherserver=$unloaded; }      if ($env{'form.btoken'}) {
     }          my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
           $balcookie = $info{'balcookie'};
 # ----------------------------------------------------------- Get announcements          if ($balcookie) {
     my $announcements=&Apache::lonnet::getannounce();              if ($info{'linkprot'}) {
 # -------------------------------------------------------- Set login parameters                  $linkprot = $info{'linkprot'};
               } elsif ($info{'linkkey'}) {
     my @hexstr=('0','1','2','3','4','5','6','7',                  $linkkey = $info{'linkkey'};
                 '8','9','a','b','c','d','e','f');              }
     my $lkey='';          }    
     for (0..7) {          &Apache::lonnet::tmpdel($env{'form.btoken'});
         $lkey.=$hexstr[rand(15)];          delete($env{'form.btoken'});
     }      }
   
     my $ukey='';  #
     for (0..7) {  # If browser sent an old cookie for which the session file had been removed
         $ukey.=$hexstr[rand(15)];  # check if configuration for user's domain has a portal URL set.  If so
     }  # switch user's log-in to the portal.
   #
     my $lextkey=hex($lkey);  
     if ($lextkey>2147483647) { $lextkey-=4294967296; }      if (($handle eq '') && ($userdom ne '')) {
           my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
     my $uextkey=hex($ukey);          if ($domdefaults{'portal_def'} =~ /^https?\:/) {
     if ($uextkey>2147483647) { $uextkey-=4294967296; }              my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
                                             {'redirect' => [0,$domdefaults{'portal_def'}],});
 # -------------------------------------------------------- Store away log token              my $end_page   = &Apache::loncommon::end_page();
     my $logtoken=Apache::lonnet::reply(              $r->print($start_page.$end_page);
        'tmpput:'.$ukey.$lkey.'&'.$firsturl,              return OK;
        $lonhost);          }
       }
 # ------------------- If we cannot talk to ourselves, we are in serious trouble  
   # -------------------------------- Prevent users from attempting to login twice
     if ($logtoken eq 'con_lost') {      if ($handle ne '') {
         my $spares='';          &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
  my $last;   my $start_page =
         foreach my $hostid (sort      &Apache::loncommon::start_page('Already logged in');
     {   my $end_page =
  $Apache::lonnet::hostname{$a} cmp      &Apache::loncommon::end_page();
     $Apache::lonnet::hostname{$b};          my $dest = '/adm/roles';
     }          if ($env{'form.firsturl'} ne '') {
     keys(%Apache::lonnet::spareid)) {              $dest = $env{'form.firsturl'};
             next if ($hostid eq $lonhost);          }
             next if ($last eq $Apache::lonnet::hostname{$hostid});          if (($env{'form.ltoken'}) || ($linkprot)) {
             $spares.='<br /><font size="+1"><a href="http://'.              unless ($linkprot) {
                 $Apache::lonnet::hostname{$hostid}.                  my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
                 '/adm/login?domain='.$authdomain.'">'.                  $linkprot = $info{'linkprot'};
                 $Apache::lonnet::hostname{$hostid}.'</a>'.                  my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'});
                 ' (preferred)</font>'.$/;                  delete($env{'form.ltoken'});
     $last=$Apache::lonnet::hostname{$hostid};              }
         }              if ($linkprot) {
         $spares.= '<br />';                  my ($linkprotector,$deeplink) = split(/:/,$linkprot,2);
         foreach my $hostid (sort                  if ($env{'user.linkprotector'}) {
     {                      my @protectors = split(/,/,$env{'user.linkprotector'});
  $Apache::lonnet::hostname{$a} cmp                      unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
     $Apache::lonnet::hostname{$b};                          push(@protectors,$linkprotector);
     }                          @protectors = sort { $a <=> $b } @protectors;
     keys(%Apache::lonnet::hostname)) {                          &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
             next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});                      }
             next if ($last eq $Apache::lonnet::hostname{$hostid});                  } else {
             $spares.='<br /><a href="http://'.                      &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
                 $Apache::lonnet::hostname{$hostid}.                  }
                 '/adm/login?domain='.$authdomain.'">'.                  if ($env{'user.linkproturi'}) {
                 $Apache::lonnet::hostname{$hostid}.'</a>';                      my @proturis = split(/,/,$env{'user.linkproturi'});
     $last=$Apache::lonnet::hostname{$hostid};                      unless (grep(/^\Q$deeplink\E$/,@proturis)) {
         }                          push(@proturis,$deeplink);
  $r->print(<<ENDTROUBLE);                          @proturis = sort @proturis;
 <html>                          &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
 <head><title>The LearningOnline Network with CAPA</title></head>                      }
 <body bgcolor="#FFFFFF">                  } else {
 <img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />                      &Apache::lonnet::appenv({'user.linkproturi' => $deeplink});
 <h3>This LON-CAPA server is temporarily not available for login</h3>                  }
 <p>Please attempt to login to one of the following servers:</p>$spares              }
 <p>If the problem persists, please contact <tt>$servadm</tt>.</p>          } elsif (($env{'form.linkkey'}) || ($linkkey)) {
 </body>              if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
 </html>                  if ($linkkey eq '') {
 ENDTROUBLE                      $linkkey = $env{'form.linkkey'};
         return OK;                  }
     }                  if ($env{'user.deeplinkkey'}) {
                       my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
 # ----------------------------------------------- Apparently we are in business                      unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
                           push(@linkkeys,$linkkey);
     my $domainlogo=&Apache::loncommon::domainlogo($domain);                          &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});  
     $servadm=~s/\,/\<br \/\>/g;                      }
     $sysadm=~s/\,/\<br \/\>/g;                  } else {
                       &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
 # --------------------------------------------------- Print login screen header                  }
     $r->print(<<ENDHEADER);                  my $deeplink = $env{'form.firsturl'};
 <html>                  if ($env{'user.keyedlinkuri'}) {
 <head>                      my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
 <meta HTTP-EQUIV="Refresh" CONTENT="$expire; url=/adm/roles" />                      unless (grep(/^\Q$deeplink\E$/,@keyeduris)) {
 <title>The LearningOnline Network with CAPA Login</title>                          push(@keyeduris,$deeplink);
 </head>                          &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
 ENDHEADER                      }
 # ---------------------------------------------------- Serve out DES JavaScript                  } else {
     {                      &Apache::lonnet::appenv({'user.keyedlinkuri' => $deeplink});
  my $jsh=Apache::File->new($include."/londes.js");                  }
         $r->print(<$jsh>);              }
     }          }
    $r->print(
 # ----------------------------------------------------------- Front page design                    $start_page
     my $pgbg=                   .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
       ($fullgraph?&Apache::loncommon::designparm('login.pgbg',$domain):'#FFFFFF');                   .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
     my $font=                    '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
       ($fullgraph?&Apache::loncommon::designparm('login.font',$domain):'#000000');                   .$end_page
     my $link=                   );
       ($fullgraph?&Apache::loncommon::designparm('login.link',$domain):'#0000FF');          return OK;
     my $vlink=      }
       ($fullgraph?&Apache::loncommon::designparm('login.vlink',$domain):'#0000FF');  
     my $alink=&Apache::loncommon::designparm('login.alink',$domain);  # ---------------------------------------------------- No valid token, continue
     my $mainbg=  
       ($fullgraph?&Apache::loncommon::designparm('login.mainbg',$domain):'#FFFFFF');  # ---------------------------- Not possible to really login to domain "public"
     my $sidebg=      if ($env{'form.domain'} eq 'public') {
       ($fullgraph?&Apache::loncommon::designparm('login.sidebg',$domain):'#FFFFFF');   $env{'form.domain'}='';
     my $logo=&Apache::loncommon::designparm('login.logo',$domain);   $env{'form.username'}='';
     my $img=&Apache::loncommon::designparm('login.img',$domain);      }
   
 # ----------------------------------------------------------------------- Texts  # ------ Is this page requested because /adm/migrateuser detected an IP change?
       my %sessiondata;
 my %lt=&Apache::lonlocal::texthash(      if ($env{'form.iptoken'}) {
   'un'  => 'Username',          %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
   'pw'  => 'Password',          unless ($sessiondata{'sessionserver'}) {
   'dom' => 'Domain',              my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
   'perc' => 'percent',              delete($env{'form.iptoken'});
   'load' => 'Load',          }
                   'userload' => 'User Load',      }
                   'about'  => 'aboutlon.gif',  # ----------------------------------------------------------- Process Interface
                   'access' => 'accessbutton.gif',      $env{'form.interface'}=~s/\W//g;
   'auth' => 'userauthentication.gif',  
   'log' => 'Log in',      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
   'help' => 'Help',          &Apache::loncommon::decode_user_agent();
   'serv' => 'Server',  
                   'servadm' => 'Server Administration',      my $iconpath=
                   'sysadm' => 'System Administration',   &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                   'helpdesk' => 'Contact Helpdesk');  
 # -------------------------------------------------- Change password field name      my $domain = &Apache::lonnet::default_login_domain();
     my $now=time;      my $defdom = $domain;
 # ---------------------------------------------------------- Serve rest of page      if ($lonhost ne '') {
     $r->print(<<ENDSCRIPT);          unless ($sessiondata{'sessionserver'}) {
               my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie,$linkprot);
 <body bgcolor="$pgbg" text="$font" link="$link" vlink="$vlink" alink="$alink"              if ($redirect) {
   topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>                  $r->print($redirect);
                   return OK;
  <script language="JavaScript">              }
     function send()          }
     {      }
  this.document.server.elements.uname.value  
        =this.document.client.elements.uname.value;      if (($sessiondata{'domain'}) &&
           (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
         this.document.server.elements.udom.value          $domain=$sessiondata{'domain'};
        =this.document.client.elements.udom.value;      } elsif (($env{'form.domain'}) &&
    (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
         this.document.server.elements.imagesuppress.value   $domain=$env{'form.domain'};
        =this.document.client.elements.imagesuppress.checked;      }
   
         this.document.server.elements.embedsuppress.value      my $role    = $r->dir_config('lonRole');
        =this.document.client.elements.embedsuppress.checked;      my $loadlim = $r->dir_config('lonLoadLim');
       my $uloadlim= $r->dir_config('lonUserLoadLim');
         this.document.server.elements.appletsuppress.value      my $servadm = $r->dir_config('lonAdmEMail');
        =this.document.client.elements.appletsuppress.checked;      my $tabdir  = $r->dir_config('lonTabDir');
       my $include = $r->dir_config('lonIncludes');
         this.document.server.elements.fontenhance.value      my $expire  = $r->dir_config('lonExpire');
        =this.document.client.elements.fontenhance.checked;      my $version = $r->dir_config('lonVersion');
       my $host_name = &Apache::lonnet::hostname($lonhost);
         this.document.server.elements.blackwhite.value  
        =this.document.client.elements.blackwhite.checked;  # --------------------------------------------- Default values for login fields
      
         this.document.server.elements.remember.value      my ($authusername,$authdomain);
        =this.document.client.elements.remember.checked;      if ($sessiondata{'username'}) {
           $authusername=$sessiondata{'username'};
         uextkey=this.document.client.elements.uextkey.value;      } else {
         lextkey=this.document.client.elements.lextkey.value;          $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
         initkeys();          $authusername=($env{'form.username'}?$env{'form.username'}:'');
       }
         this.document.server.elements.upass0.value      if ($sessiondata{'domain'}) {
     =crypted(this.document.client.elements.upass$now.value.substr(0,15));          $authdomain=$sessiondata{'domain'};
  this.document.server.elements.upass1.value      } else {
     =crypted(this.document.client.elements.upass$now.value.substr(15,15));          $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
  this.document.server.elements.upass2.value          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
     =crypted(this.document.client.elements.upass$now.value.substr(30,15));      }
   
         this.document.client.elements.uname.value='';  # ---------------------------------------------------------- Determine own load
         this.document.client.elements.upass$now.value='';      my $loadavg;
       {
         this.document.server.submit();   my $loadfile=Apache::File->new('/proc/loadavg');
  return false;   $loadavg=<$loadfile>;
     }      }
  </script>      $loadavg =~ s/\s.*//g;
 ENDSCRIPT  
       my ($loadpercent,$userloadpercent);
     if ($fullgraph) {      if ($loadlim) {
  $r->print(          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
   '<table width="100%" cellpadding=0 cellspacing=0 border=0>');      }
     }      if ($uloadlim) {
           $userloadpercent=&Apache::lonnet::userload();
     $r->print(<<ENDSERVERFORM);      }
   <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">  
    <input type="hidden" name="logtoken" value="$logtoken" />      my $firsturl=
    <input type="hidden" name="serverid" value="$lonhost" />      ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
    <input type="hidden" name="interface" value="$env{'form.interface'}" />  
    <input type="hidden" name="uname" value="" />  # ----------------------------------------------------------- Get announcements
    <input type="hidden" name="upass0" value="" />      my $announcements=&Apache::lonnet::getannounce();
    <input type="hidden" name="upass1" value="" />  # -------------------------------------------------------- Set login parameters
    <input type="hidden" name="upass2" value="" />  
    <input type="hidden" name="udom" value="" />      my @hexstr=('0','1','2','3','4','5','6','7',
    <input type="hidden" name="imagesuppress"  value="" />                  '8','9','a','b','c','d','e','f');
    <input type="hidden" name="appletsuppress"  value="" />      my $lkey='';
    <input type="hidden" name="embedsuppress"  value="" />      for (0..7) {
    <input type="hidden" name="fontenhance"  value="" />          $lkey.=$hexstr[rand(15)];
    <input type="hidden" name="blackwhite"  value="" />      }
    <input type="hidden" name="remember"  value="" />  
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />      my $ukey='';
    <input type="hidden" name="localres" value="$env{'form.localres'}" />      for (0..7) {
   </form>          $ukey.=$hexstr[rand(15)];
 ENDSERVERFORM      }
     if ($fullgraph) { $r->print(<<ENDTOP);  
   <!-- The LON-CAPA Header -->      my $lextkey=hex($lkey);
   <tr>      if ($lextkey>2147483647) { $lextkey-=4294967296; }
   
    <!-- Row 1 Columns 2-4 -->      my $uextkey=hex($ukey);
    <td width="100%" height=75 colspan=4 align="left" valign="top" bgcolor="$pgbg"><img src="$img" border=0 alt="The Learning Online Network with CAPA" /></td>      if ($uextkey>2147483647) { $uextkey-=4294967296; }
   </tr>  
   # -------------------------------------------------------- Store away log token
   <!-- The gray bar that starts the two table frames -->      my $tokenextras;
   <tr>      if ($env{'form.role'}) {
           $tokenextras = '&role='.&escape($env{'form.role'});
    <!-- Row 2 Column 1 -->      }
    <td width=182 height=27 bgcolor="$sidebg">&nbsp;</td>      if ($env{'form.symb'}) {
           if (!$tokenextras) {
    <!-- Row 2 Column 2 -->              $tokenextras = '&';
    <td width=27 height=27 align="left" background="$iconpath/filltop.gif"><img src="$iconpath/upperleft.gif" border=0 alt="" /></td>          }
           $tokenextras .= '&symb='.&escape($env{'form.symb'});
    <!-- Row 2 Column 3 -->      }
    <td height=27 background="$iconpath/filltop.gif"><img src="$iconpath/filltop.gif" alt="" /></td>      if ($env{'form.iptoken'}) {
           if (!$tokenextras) {
    <!-- Row 2 Column 4 -->              $tokenextras = '&&';
    <td width=27 height=27 align="right" background="$iconpath/filltop.gif"><img src="$iconpath/upperright.gif" border=0 alt="" /></td>          }
   </tr>          $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
   <tr>      }
          if ($env{'form.ltoken'}) {
    <!-- A cell that will hold the 'access' and 'about' buttons -->          my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
    <!-- Row 3 Column 1 -->          &Apache::lonnet::tmpdel($env{'form.ltoken'});
    <td valign="top" height=60 align="center" bgcolor="$sidebg">          delete($env{'form.ltoken'});
     <a href="/adm/login?interface=textual"><img src="$iconpath/$lt{'access'}" border=0 alt="Accessibility Options" /></a>          if ($info{'linkprot'}) {
     <br />              if (!$tokenextras) {
     <a href="/adm/about.html"><img src="$iconpath/$lt{'about'}" border=0 alt="About LON-CAPA" /></a>                  $tokenextras = '&&&';
    </td>              }
               $tokenextras .= '&linkprot='.&escape($info{'linkprot'});
    <!-- The shaded space between the two main columns -->          }
    <!-- Row 3 Column 2 -->      } elsif ($env{'form.linkkey'}) {
    <td width=27 height=60 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>          if (!$tokenextras) {
               $tokenextras = '&&&';
    <!-- The right main column holding the large LON-CAPA logo-->          }
    <!-- Rows 3-4 Column 3 -->          $tokenextras .= '&linkkey='.&escape($env{'form.linkkey'});
    <td align="center" valign="top" width="100%" height="100%" bgcolor="$mainbg">      }
     <center>      my $logtoken=Apache::lonnet::reply(
      <img src="$logo" alt="" />         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
     </center>         $lonhost);
    </td>  
   # -- If we cannot talk to ourselves, or hostID does not map to a hostname
    <!-- Row 3 Column 4 -->  #    we are in serious trouble
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>  
   </tr>      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
   <tr>          if ($logtoken eq 'no_such_host') {
               &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
    <!-- The entry form -->          }
    <!-- Row 4 Column 1 -->          my $spares='';
    <td align="center" valign="middle" bgcolor="$sidebg">          my (@sparehosts,%spareservers);
 ENDTOP          my $sparesref = &Apache::lonnet::this_host_spares($defdom);
 } else {          if (ref($sparesref) eq 'HASH') {
     $r->print('<h1>The Learning<i>Online</i> Network with CAPA</h1><h2>Text-based Interface Login</h2>'.$announcements);              foreach my $key (keys(%{$sparesref})) {
 }                  if (ref($sparesref->{$key}) eq 'ARRAY') {
     $r->print('<form name="client" onsubmit="return(send())">');                      my @sorted = sort { &Apache::lonnet::hostname($a) cmp
     unless ($fullgraph) {                                          &Apache::lonnet::hostname($b);
         $r->print(<<ENDACCESSOPTIONS);                                        } @{$sparesref->{$key}};
 <h3>Select Accessibility Options</h3>                      if (@sorted) {
 <label><input type="checkbox" name="imagesuppress" /> Suppress rendering of images</label><br />                          if ($key eq 'primary') {
 <label><input type="checkbox" name="appletsuppress" /> Suppress Java applets</label><br />                              unshift(@sparehosts,@sorted);
 <label><input type="checkbox" name="embedsuppress" /> Suppress rendering of embedded multimedia</label><br />                          } elsif ($key eq 'default') {
 <label><input type="checkbox" name="fontenhance" /> Increase font size</label><br />                              push(@sparehosts,@sorted);
 <label><input type="checkbox" name="blackwhite" /> Switch to black and white mode</label><br />                          }
 <p>If you have accessibility needs that are not addressed by this interface,                       }
 please                  }
 contact the system administrator at <tt>$sysadm</tt>.</p><br />              }
 <input type="checkbox" name="remember" /> Remember these settings for next login<hr />          }
 ENDACCESSOPTIONS          foreach my $hostid (@sparehosts) {
 } else {              next if ($hostid eq $lonhost);
     $r->print(<<ENDNOOPT);      my $hostname = &Apache::lonnet::hostname($hostid);
 <input type="hidden" name="imagesuppress"  value="" />      next if (($hostname eq '') || ($spareservers{$hostname}));
 <input type="hidden" name="embedsuppress"  value="" />              $spareservers{$hostname} = 1;
 <input type="hidden" name="appletsuppress"  value="" />              my $protocol = $Apache::lonnet::protocol{$hostid};
 <input type="hidden" name="fontenhance"  value="" />              $protocol = 'http' if ($protocol ne 'https');
 <input type="hidden" name="blackwhite"  value="" />              $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.
 <input type="hidden" name="remember"  value="" />                  $hostname.
 ENDNOOPT                  '/adm/login?domain='.$authdomain.'">'.
 }                  $hostname.'</a>'.
     $r->print(<<ENDLOGIN);                  ' '.&mt('(preferred)').'</span>'.$/;
      <input type="hidden" name="lextkey" value="$lextkey">          }
      <input type="hidden" name="uextkey" value="$uextkey">          if ($spares) {
               $spares.= '<br />';
      <!-- Start the sub-table for text and input alignment -->          }
      <table border=0 cellspacing=0 cellpadding=0>          my %all_hostnames = &Apache::lonnet::all_hostnames();
       <tr><td bgcolor="$sidebg" colspan=2><img src="$iconpath/$lt{'auth'}" alt="User Authentication" /></td></tr>          foreach my $hostid (sort
       <tr>      {
        <td bgcolor="$mainbg"><br /><font size=-1><b>&nbsp;&nbsp;&nbsp;$lt{'un'}:</b></font></td>   &Apache::lonnet::hostname($a) cmp
        <td bgcolor="$mainbg"><br /><input type="text" name="uname" size="10" value="$authusername" /></td>      &Apache::lonnet::hostname($b);
       </tr>      }
       <tr>      keys(%all_hostnames)) {
        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;$lt{'pw'}:</b></font></td>              next if ($hostid eq $lonhost);
        <td bgcolor="$mainbg"><input type="password" name="upass$now" size="10" /></td>              my $hostname = &Apache::lonnet::hostname($hostid);
       </tr>              next if (($hostname eq '') || ($spareservers{$hostname}));
       <tr>              $spareservers{$hostname} = 1;
        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;$lt{'dom'}:</b></font></td>              my $protocol = $Apache::lonnet::protocol{$hostid};
        <td bgcolor="$mainbg"><input type="text" name="udom" size="10" value="$authdomain" /></td>              $protocol = 'http' if ($protocol ne 'https');
       </tr>              $spares.='<br /><a href="'.$protocol.'://'.
       <tr>               $hostname.
        <td bgcolor="$mainbg">&nbsp;&nbsp;&nbsp;<a href="/adm/loginproblems.html">$lt{'help'}</a></td>               '/adm/login?domain='.$authdomain.'">'.
        <td bgcolor="$mainbg" valign="bottom" align="center">               $hostname.'</a>';
         <br />           }
         <input type="submit" value="$lt{'log'}" />           $r->print(
        </td>     '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
       </tr>    .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
      </table>    .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'
      <!-- End sub-table -->    .&mt('The LearningOnline Network with CAPA')
     </form>    .'</title></head>'
 ENDLOGIN    .'<body bgcolor="#FFFFFF">'
     if ($fullgraph) {    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
         my $helpdeskscript;    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
         my $contactblock = &contactdisplay(\%lt,$sysadm,$servadm,$version,$authdomain,\$helpdeskscript);    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
  $r->print(<<ENDDOCUMENT);          if ($spares) {
    </td>              $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
                        .'</p>'
    <!-- Row 4 Column 2 -->                       .$spares);
    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>          }
           $r->print('</body>'
    <!-- Row 4 Column 3 -->                   .'</html>'
 <td bgcolor="$mainbg">$announcements</td>          );
           return OK;
    <!-- Row 4 Column 4 -->      }
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>  
   </tr>  # ----------------------------------------------- Apparently we are in business
   <tr>      $servadm=~s/\,/\<br \/\>/g;
   
    <!-- Row 5 Column 1 -->  # ----------------------------------------------------------- Front page design
    <td bgcolor="$sidebg" valign="middle" align="left">      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
      <br />      my $font=&Apache::loncommon::designparm('login.font',$domain);
      <table border=0 cellspacing=0 cellpadding=0>      my $link=&Apache::loncommon::designparm('login.link',$domain);
       <tr>      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
        <td bgcolor="$sidebg" align="left" valign="top">      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'dom'}:&nbsp;</b></small>      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
        </td>      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
        <td bgcolor="$sidebg" align="left" valign="top">      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
         <small><tt>&nbsp;$domain</tt></small>      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
        </td>      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
       </tr>      my $img=&Apache::loncommon::designparm('login.img',$domain);
       <tr>      my $domainlogo=&Apache::loncommon::domainlogo($domain);
        <td bgcolor="$sidebg" align="left" valign="top">      my $showbanner = 1;
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'serv'}:&nbsp;</b></small>      my $showmainlogo = 1;
        </td>      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
        <td bgcolor="$sidebg" align="left" valign="top">          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
         <small><tt>&nbsp;$lonhost ($role)</tt></small>      }
        </td>      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
       </tr>          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
       <tr>      }
        <td bgcolor="$sidebg" align="left" valign="top">      my $showadminmail;
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'load'}:&nbsp;</b></small>      my @possdoms = &Apache::lonnet::current_machine_domains();
        </td>      if (grep(/^\Q$domain\E$/,@possdoms)) {
        <td bgcolor="$sidebg" align="left" valign="top">          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>      }
        </td>      my $showcoursecat =
       </tr>          &Apache::loncommon::designparm('login.coursecatalog',$domain);
       <tr>      my $shownewuserlink =
        <td bgcolor="$sidebg" align="left" valign="top">          &Apache::loncommon::designparm('login.newuser',$domain);
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'userload'}:&nbsp;</b></small>      my $showhelpdesk =
        </td>          &Apache::loncommon::designparm('login.helpdesk',$domain);
        <td bgcolor="$sidebg" align="left" valign="top">      my $now=time;
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>      my $js = (<<ENDSCRIPT);
        </td>  
       </tr>  <script type="text/javascript" language="JavaScript">
      </table>  // <![CDATA[
      <br />  function send()
     $contactblock  {
    </td>  this.document.server.elements.uname.value
   =this.document.client.elements.uname.value;
    <!-- Row 5 Column 2 -->  
    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>  this.document.server.elements.udom.value
   =this.document.client.elements.udom.value;
    <!-- Row 5 Column 3 -->  
    <td width="100%" valign="bottom" bgcolor="$mainbg">  uextkey=this.document.client.elements.uextkey.value;
 $domainlogo  lextkey=this.document.client.elements.lextkey.value;
 </td>  initkeys();
   
    <!-- Row 5 Column 4 -->  if(this.document.server.action.substr(0,5) === 'http:'){
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>      this.document.server.elements.upass0.value
   </tr>          =getCrypted(this.document.client.elements.upass$now.value);
   <tr>  } else {
       this.document.server.elements.upass0.value
    <!-- Row 6 Column 1 -->          =this.document.client.elements.upass$now.value;
    <td bgcolor="$sidebg">&nbsp;</td>  }
   
    <!-- Row 6 Column 2 -->  this.document.client.elements.uname.value='';
    <td align="left" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerleft.gif" alt="" /></td>  this.document.client.elements.upass$now.value='';
   
    <!-- Row 6 Column 3 -->  this.document.server.submit();
    <td background="$iconpath/fillbottom.gif"><img src="$iconpath/fillbottom.gif" alt="" /></td>  return false;
   }
    <!-- Row 6 Column 4 -->  
    <td align="right" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerright.gif" alt="" /></td>  function enableInput() {
   </tr>      this.document.client.elements.upass$now.removeAttribute("readOnly");
  </table>      this.document.client.elements.uname.removeAttribute("readOnly");
       this.document.client.elements.udom.removeAttribute("readOnly");
 <script type="text/javascript">      return;
 // the if prevents the script error if the browser can not handle this  }
 if ( document.client.uname ) { document.client.uname.focus(); }  
 </script>  // ]]>
 $helpdeskscript  </script>
   
 ENDDOCUMENT  ENDSCRIPT
 }  
     $r->print('</body></html>');  # --------------------------------------------------- Print login screen header
     return OK;  
 }      my %add_entries = (
          bgcolor      => "$mainbg",
 sub contactdisplay {         text         => "$font",
     my ($lt,$sysadm,$servadm,$version,$authdomain,$helpdeskscript) = @_;         link         => "$link",
     my $contactblock;         vlink        => "$vlink",
     my $showsysadm = 1;         alink        => "$alink",
     my $showservadm = 1;                 onload       => 'javascript:enableInput();',);
     my $showhelpdesk = 0;  
     my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
     if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {      @hosts = &Apache::lonnet::current_machine_ids();
         $showhelpdesk = 1;      $lonhost_in_use = $lonhost;
     }      if (@hosts > 1) {
     if ($showsysadm) {          foreach my $hostid (@hosts) {
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;'.$$lt{'sysadm'}.':</b><br />'.              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
                          '<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$sysadm.'</tt><br />';                  $lonhost_in_use = $hostid;
     }                  last;
     if ($showservadm) {              }
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;'.$$lt{'servadm'}.':</b><br />'.          }
                          '<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$servadm.'</tt><br />&nbsp;<br />';      }
     }      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
     if ($showhelpdesk) {      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;<a href="javascript:helpdesk()">'.$$lt{'helpdesk'}.'</a></b><br />';      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
         my $thisurl = &Apache::lonnet::escape('/adm/login');      if ($headextra) {
         $$helpdeskscript = <<"ENDSCRIPT";          my $omitextra;
 <script type="text/javascript">          if ($headextra_exempt ne '') {
 function helpdesk() {              my @exempt = split(',',$headextra_exempt);
     var codedom = document.client.udom.value;              my $ip = &Apache::lonnet::get_requestor_ip();
     if (codedom == '') {              if (grep(/^\Q$ip\E$/,@exempt)) {
         codedom = "$authdomain";                  $omitextra = 1;
     }              }
     var querystr = "origurl=$thisurl&codedom="+codedom;          }
     document.location.href = "/adm/helpdesk?"+querystr;          unless ($omitextra) {
     return;              my $confname = $defdom.'-domainconfig';
 }              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
 </script>                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
 ENDSCRIPT                  unless ($extra eq '-1') {
     }                      $js .= "\n".$extra."\n";
     $contactblock .= <<"ENDBLOCK";                  }
      &nbsp;&nbsp;&nbsp;$version              }
 ENDBLOCK          }
     return $contactblock;      }
 }  
        $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
          { 'redirect'       => [$expire,'/adm/roles'],
 1;   'add_entries' => \%add_entries,
 __END__   'only_body'   => 1,}));
   
   # ----------------------------------------------------------------------- Texts
   
       my %lt=&Apache::lonlocal::texthash(
             'un'       => 'Username',
             'pw'       => 'Password',
             'dom'      => 'Domain',
             'perc'     => 'percent',
             'load'     => 'Server Load',
             'userload' => 'User Load',
             'catalog'  => 'Course/Community Catalog',
             'log'      => 'Log in',
             'help'     => 'Log-in Help',
             'serv'     => 'Server',
             'servadm'  => 'Server Administration',
             'helpdesk' => 'Contact Helpdesk',
             'forgotpw' => 'Forgot password?',
             'newuser'  => 'New User?',
          );
   # -------------------------------------------------- Change password field name
   
       my $forgotpw = &forgotpwdisplay(%lt);
       $forgotpw .= '<br />' if $forgotpw;
       my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
       if ($loginhelp) {
           $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
       }
   
   # ---------------------------------------------------- Serve out DES JavaScript
       {
       my $jsh=Apache::File->new($include."/londes.js");
       $r->print(<$jsh>);
       }
   # ---------------------------------------------------------- Serve rest of page
   
       $r->print(
       '<div class="LC_Box"'
      .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
   );
   
       $r->print(<<ENDSERVERFORM);
   <form name="server" action="/adm/authenticate" method="post" target="_top">
      <input type="hidden" name="logtoken" value="$logtoken" />
      <input type="hidden" name="serverid" value="$lonhost" />
      <input type="hidden" name="uname" value="" />
      <input type="hidden" name="upass0" value="" />
      <input type="hidden" name="udom" value="" />
      <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
      <input type="hidden" name="localres" value="$env{'form.localres'}" />
     </form>
   ENDSERVERFORM
       my $coursecatalog;
       if (($showcoursecat eq '') || ($showcoursecat)) {
           $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
       }
       my $newuserlink;
       if ($shownewuserlink) {
           $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
       }
       my $logintitle =
           '<h2 class="LC_hcell"'
          .' style="background:'.$loginbox_header_bgcol.';'
          .' color:'.$loginbox_header_textcol.'">'
          .$lt{'log'}
          .'</h2>';
   
       my $noscript_warning='<noscript><span class="LC_warning"><b>'
                           .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
                           .'</b></span></noscript>';
       my $helpdeskscript;
       my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
                                          $authdomain,\$helpdeskscript,
                                          $showhelpdesk,\@possdoms);
   
       my $mobileargs;
       if ($clientmobile) {
           $mobileargs = 'autocapitalize="off" autocorrect="off"';
       }
       my $loginform=(<<LFORM);
   <form name="client" action="" onsubmit="return(send())">
     <input type="hidden" name="lextkey" value="$lextkey" />
     <input type="hidden" name="uextkey" value="$uextkey" />
     <b><label for="uname">$lt{'un'}</label>:</b><br />
     <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
     <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
     <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
     <b><label for="udom">$lt{'dom'}</label>:</b><br />
     <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
     <input type="submit" value="$lt{'log'}" />
   </form>
   LFORM
   
       if ($showbanner) {
           $r->print(<<HEADER);
   <!-- The LON-CAPA Header -->
   <div style="background:$pgbg;margin:0;width:100%;">
     <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
   </div>
   HEADER
       }
       $r->print(<<ENDTOP);
   <div style="float:left;margin-top:0;">
   <div class="LC_Box" style="background:$loginbox_bg;">
     $logintitle
     $loginform
     $noscript_warning
   </div>
    
   <div class="LC_Box" style="padding-top: 10px;">
     $loginhelp
     $forgotpw
     $contactblock
     $newuserlink
     $coursecatalog
   </div>
   </div>
   
   <div>
   ENDTOP
       if ($showmainlogo) {
           $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
       }
   $r->print(<<ENDTOP);
   $announcements
   </div>
   <hr style="clear:both;" />
   ENDTOP
       my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
       $domainrow = <<"END";
         <tr>
          <td  align="left" valign="top">
           <small><b>$lt{'dom'}:&nbsp;</b></small>
          </td>
          <td  align="left" valign="top">
           <small><tt>&nbsp;$domain</tt></small>
          </td>
         </tr>
   END
       $serverrow = <<"END";
         <tr>
          <td  align="left" valign="top">
           <small><b>$lt{'serv'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$lonhost ($role)</tt></small>
          </td>
         </tr>
   END
       if ($loadlim) {
           $loadrow = <<"END";
         <tr>
          <td align="left" valign="top">
           <small><b>$lt{'load'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
          </td>
         </tr>
   END
       }
       if ($uloadlim) {
           $userloadrow = <<"END";
         <tr>
          <td align="left" valign="top">
           <small><b>$lt{'userload'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
          </td>
         </tr>
   END
       }
       if (($version ne '') && ($version ne '<!-- VERSION -->')) {
           $versionrow = <<"END";
         <tr>
          <td colspan="2" align="left">
           <small>$version</small>
          </td>
         </tr>
   END
       }
   
       $r->print(<<ENDDOCUMENT);
       <div style="float: left;">
        <table border="0" cellspacing="0" cellpadding="0">
   $domainrow
   $serverrow
   $loadrow    
   $userloadrow
   $versionrow
        </table>
       </div>
       <div style="float: right;">
       $domainlogo
       </div>
       <br style="clear:both;" />
    </div>
   
   <script type="text/javascript">
   // <![CDATA[
   // the if prevents the script error if the browser can not handle this
   if ( document.client.uname ) { document.client.uname.focus(); }
   // ]]>
   </script>
   $helpdeskscript
   
   ENDDOCUMENT
       my %endargs = ( 'noredirectlink' => 1, );
       $r->print(&Apache::loncommon::end_page(\%endargs));
       return OK;
   }
   
   sub check_loginvia {
       my ($domain,$lonhost,$lonidsdir,$balcookie,$linkprot) = @_;
       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 = &Apache::lonnet::get_requestor_ip();  
           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,$linkprot);
                   }
               }
           }
       }
       return $output;
   }
   
   sub redirect_page {
       my ($desthost,$path,$linkprot) = @_;
       my $hostname = &Apache::lonnet::hostname($desthost);
       my $protocol = $Apache::lonnet::protocol{$desthost};
       $protocol = 'http' if ($protocol ne 'https');
       unless ($path =~ m{^/}) {
           $path = '/'.$path;
       }
       my $url = $protocol.'://'.$hostname.$path;
       if ($env{'form.firsturl'} ne '') {
           $url .='?firsturl='.$env{'form.firsturl'};
       }
       if ($linkprot) {
           my $ltoken = &Apache::lonnet::tmpput({linkprot => $linkprot},$desthost);
           if ($ltoken) {
               $url .= (($url =~ /\?/) ? '&' : '?').'ltoken='.$ltoken;
           }
       }
       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.70  
changed lines
  Added in v.1.182


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