Diff for /loncom/auth/lonlogin.pm between versions 1.120 and 1.173

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

Removed from v.1.120  
changed lines
  Added in v.1.173


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