Diff for /loncom/auth/lonlogin.pm between versions 1.85 and 1.180

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


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