Diff for /loncom/auth/lonlogin.pm between versions 1.125 and 1.161

version 1.125, 2009/09/11 23:04:45 version 1.161, 2015/03/03 22:06:55
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;
     
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
   
     &Apache::loncommon::get_unprocessed_cgi      &Apache::loncommon::get_unprocessed_cgi
  (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},   (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
       $ENV{'REDIRECT_QUERY_STRING'}),        $ENV{'REDIRECT_QUERY_STRING'}),
  ['interface','username','domain','firsturl','localpath','localres',   ['interface','username','domain','firsturl','localpath','localres',
   'token','role','symb']);    'token','role','symb','iptoken']);
     if (!defined($env{'form.firsturl'})) {      if (!defined($env{'form.firsturl'})) {
         &Apache::lonacc::get_posted_cgi($r,['firsturl']);          &Apache::lonacc::get_posted_cgi($r,['firsturl']);
     }      }
   
 # -- check if they are a migrating user  # -- check if they are a migrating user
     if (defined($env{'form.token'})) {      if (defined($env{'form.token'})) {
  return &Apache::migrateuser::handler($r);   return &Apache::migrateuser::handler($r);
     }      }
   
     &Apache::loncommon::no_cache($r);      &Apache::loncommon::no_cache($r);
     &Apache::lonlocal::get_language_handle($r);      &Apache::lonlocal::get_language_handle($r);
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
     return OK if $r->header_only;      return OK if $r->header_only;
   
   
 # Are we re-routing?  # Are we re-routing?
     if (-e '/home/httpd/html/lon-status/reroute.txt') {      my $londocroot = $r->dir_config('lonDocRoot');
  &Apache::lonauth::reroute($r);      if (-e "$londocroot/lon-status/reroute.txt") {
  return OK;   &Apache::lonauth::reroute($r);
     }   return OK;
       }
   
 # -------------------------------- Prevent users from attempting to login twice      $env{'form.firsturl'} =~ s/(`)/'/g;
     my $handle = &Apache::lonnet::check_for_valid_session($r);  
     if ($handle=~/^publicuser\_/) {  # -------------------------------- Prevent users from attempting to login twice
 # For "public user" - remove it, we apparently really want to login      my $handle = &Apache::lonnet::check_for_valid_session($r);
  unlink($r->dir_config('lonIDsDir')."/$handle.id");      if ($handle ne '') {
     } elsif ($handle ne '') {          my $lonidsdir=$r->dir_config('lonIDsDir');
 # Indeed, a valid token is found          if ($handle=~/^publicuser\_/) {
  my $start_page =   # For "public user" - remove it, we apparently really want to login
     &Apache::loncommon::start_page('Already logged in');      unlink($r->dir_config('lonIDsDir')."/$handle.id");
  my $end_page =           } else {
     &Apache::loncommon::end_page();  # Indeed, a valid token is found
         my $dest = '/adm/roles';              &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
         if ($env{'form.firsturl'} ne '') {      my $start_page =
             $dest = $env{'form.firsturl'};           &Apache::loncommon::start_page('Already logged in');
         }      my $end_page =
  $r->print(          &Apache::loncommon::end_page();
                   $start_page              my $dest = '/adm/roles';
                  .'<h1>'.&mt('You are already logged in!').'</h1>'              if ($env{'form.firsturl'} ne '') {
                  .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',                  $dest = $env{'form.firsturl'};
                   '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'              }
                  .'<p><a href="/adm/loginproblems.html">'.&mt('Login problems?').'</a></p>'      $r->print(
                  .$end_page                    $start_page
                  );                   .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
         return OK;                   .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
     }                    '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
                    .$end_page
 # ---------------------------------------------------- No valid token, continue                   );
               return OK;
  # ---------------------------- Not possible to really login to domain "public"          }
     if ($env{'form.domain'} eq 'public') {      }
  $env{'form.domain'}='';  
  $env{'form.username'}='';  # ---------------------------------------------------- No valid token, continue
     }  
 # ----------------------------------------------------------- Process Interface  # ---------------------------- Not possible to really login to domain "public"
     $env{'form.interface'}=~s/\W//g;      if ($env{'form.domain'} eq 'public') {
    $env{'form.domain'}='';
     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};   $env{'form.username'}='';
       }
     my $iconpath=   
  &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));  # ------ Is this page requested because /adm/migrateuser detected an IP change?
       my %sessiondata;
     my $domain = &Apache::lonnet::default_login_domain();      if ($env{'form.iptoken'}) {
     if (($env{'form.domain'}) &&           %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
  (&Apache::lonnet::domain($env{'form.domain'},'description'))) {          my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
  $domain=$env{'form.domain'};      }
     }  # ----------------------------------------------------------- Process Interface
     my $role    = $r->dir_config('lonRole');      $env{'form.interface'}=~s/\W//g;
     my $loadlim = $r->dir_config('lonLoadLim');  
     my $servadm = $r->dir_config('lonAdmEMail');      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
     my $lonhost = $r->dir_config('lonHostID');          &Apache::loncommon::decode_user_agent();
     my $tabdir  = $r->dir_config('lonTabDir');  
     my $include = $r->dir_config('lonIncludes');      my $iconpath=
     my $expire  = $r->dir_config('lonExpire');   &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
     my $version = $r->dir_config('lonVersion');  
     my $host_name = &Apache::lonnet::hostname($lonhost);      my $lonhost = $r->dir_config('lonHostID');
       my $domain = &Apache::lonnet::default_login_domain();
 # --------------------------------------------- Default values for login fields      my $defdom = $domain;
       if ($lonhost ne '') {
     my $authusername=($env{'form.username'}?$env{'form.username'}:'');          unless ($sessiondata{'sessionserver'}) {
     my $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);              my $redirect = &check_loginvia($domain,$lonhost);
               if ($redirect) {
 # ---------------------------------------------------------- Determine own load                  $r->print($redirect);
     my $loadavg;                  return OK;
     {              }
  my $loadfile=Apache::File->new('/proc/loadavg');          }
  $loadavg=<$loadfile>;      }
     }  
     $loadavg =~ s/\s.*//g;      if (($sessiondata{'domain'}) &&
     my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);          (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
     my $userloadpercent=&Apache::lonnet::userload();          $domain=$sessiondata{'domain'};
       } elsif (($env{'form.domain'}) &&
 # ------------------------------------------------------- Do the load balancing   (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
     my $otherserver= &Apache::lonnet::absolute_url($host_name);   $domain=$env{'form.domain'};
     my $firsturl=      }
     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});  
 # ---------------------------------------------------------- Are we overloaded?      my $role    = $r->dir_config('lonRole');
     if ((($userloadpercent>100.0)||($loadpercent>100.0))) {      my $loadlim = $r->dir_config('lonLoadLim');
         my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent);      my $uloadlim= $r->dir_config('lonUserLoadLim');
  if ($unloaded) { $otherserver=$unloaded; }      my $servadm = $r->dir_config('lonAdmEMail');
     }      my $tabdir  = $r->dir_config('lonTabDir');
       my $include = $r->dir_config('lonIncludes');
 # ----------------------------------------------------------- Get announcements      my $expire  = $r->dir_config('lonExpire');
     my $announcements=&Apache::lonnet::getannounce();      my $version = $r->dir_config('lonVersion');
 # -------------------------------------------------------- Set login parameters      my $host_name = &Apache::lonnet::hostname($lonhost);
   
     my @hexstr=('0','1','2','3','4','5','6','7',  # --------------------------------------------- Default values for login fields
                 '8','9','a','b','c','d','e','f');     
     my $lkey='';      my ($authusername,$authdomain);
     for (0..7) {      if ($sessiondata{'username'}) {
         $lkey.=$hexstr[rand(15)];          $authusername=$sessiondata{'username'};
     }      } else {
           $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
     my $ukey='';          $authusername=($env{'form.username'}?$env{'form.username'}:'');
     for (0..7) {      }
         $ukey.=$hexstr[rand(15)];      if ($sessiondata{'domain'}) {
     }          $authdomain=$sessiondata{'domain'};
       } else {
     my $lextkey=hex($lkey);          $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
     if ($lextkey>2147483647) { $lextkey-=4294967296; }          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
       }
     my $uextkey=hex($ukey);  
     if ($uextkey>2147483647) { $uextkey-=4294967296; }  # ---------------------------------------------------------- Determine own load
       my $loadavg;
 # -------------------------------------------------------- Store away log token      {
     my $tokenextras;   my $loadfile=Apache::File->new('/proc/loadavg');
     if ($env{'form.role'}) {   $loadavg=<$loadfile>;
         $tokenextras = '&role='.&escape($env{'form.role'});      }
     }      $loadavg =~ s/\s.*//g;
     if ($env{'form.symb'}) {  
         if (!$tokenextras) {      my ($loadpercent,$userloadpercent);
             $tokenextras = '&';      if ($loadlim) {
         }          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
         $tokenextras .= '&symb='.&escape($env{'form.symb'});      }
     }      if ($uloadlim) {
     my $logtoken=Apache::lonnet::reply(          $userloadpercent=&Apache::lonnet::userload();
        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,      }
        $lonhost);  
       my $firsturl=
 # ------------------- If we cannot talk to ourselves, we are in serious trouble      ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
   
     if ($logtoken eq 'con_lost') {  # ----------------------------------------------------------- Get announcements
         my $spares='';      my $announcements=&Apache::lonnet::getannounce();
  my $last;  # -------------------------------------------------------- Set login parameters
         foreach my $hostid (sort  
     {      my @hexstr=('0','1','2','3','4','5','6','7',
  &Apache::lonnet::hostname($a) cmp                  '8','9','a','b','c','d','e','f');
     &Apache::lonnet::hostname($b);      my $lkey='';
     }      for (0..7) {
     keys(%Apache::lonnet::spareid)) {          $lkey.=$hexstr[rand(15)];
             next if ($hostid eq $lonhost);      }
     my $hostname = &Apache::lonnet::hostname($hostid);  
     next if ($last eq $hostname);      my $ukey='';
             $spares.='<br /><font size="+1"><a href="http://'.      for (0..7) {
                 $hostname.          $ukey.=$hexstr[rand(15)];
                 '/adm/login?domain='.$authdomain.'">'.      }
                 $hostname.'</a>'.  
                 ' '.&mt('(preferred)').'</font>'.$/;      my $lextkey=hex($lkey);
     $last=$hostname;      if ($lextkey>2147483647) { $lextkey-=4294967296; }
         }  
 $spares.= '<br />';      my $uextkey=hex($ukey);
 my %all_hostnames = &Apache::lonnet::all_hostnames();      if ($uextkey>2147483647) { $uextkey-=4294967296; }
 foreach my $hostid (sort  
     {  # -------------------------------------------------------- Store away log token
  &Apache::lonnet::hostname($a) cmp      my $tokenextras;
     &Apache::lonnet::hostname($b);      if ($env{'form.role'}) {
     }          $tokenextras = '&role='.&escape($env{'form.role'});
     keys(%all_hostnames)) {      }
     next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});      if ($env{'form.symb'}) {
     my $hostname = &Apache::lonnet::hostname($hostid);          if (!$tokenextras) {
     next if ($last eq $hostname);              $tokenextras = '&';
     $spares.='<br /><a href="http://'.          }
  $hostname.          $tokenextras .= '&symb='.&escape($env{'form.symb'});
  '/adm/login?domain='.$authdomain.'">'.      }
  $hostname.'</a>';      my $logtoken=Apache::lonnet::reply(
     $last=$hostname;         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
 }         $lonhost);
 $r->print(  
    '<html>'  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
   .'<head><title>'  #    we are in serious trouble
   .&mt('The LearningOnline Network with CAPA')  
   .'</title></head>'      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
   .'<body bgcolor="#FFFFFF">'          if ($logtoken eq 'no_such_host') {
   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'          }
   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>'          my $spares='';
   .'<p>'.&mt('Please attempt to login to one of the following servers:').'</p>'   my $last;
   .$spares          foreach my $hostid (sort
   .'</body>'      {
   .'</html>'   &Apache::lonnet::hostname($a) cmp
 );      &Apache::lonnet::hostname($b);
 return OK;      }
 }      keys(%Apache::lonnet::spareid)) {
               next if ($hostid eq $lonhost);
 # ----------------------------------------------- Apparently we are in business      my $hostname = &Apache::lonnet::hostname($hostid);
 $servadm=~s/\,/\<br \/\>/g;      next if (($last eq $hostname) || ($hostname eq ''));
               $spares.='<br /><font size="+1"><a href="http://'.
 # ----------------------------------------------------------- Front page design                  $hostname.
 my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);                  '/adm/login?domain='.$authdomain.'">'.
 my $font=&Apache::loncommon::designparm('login.font',$domain);                  $hostname.'</a>'.
 my $link=&Apache::loncommon::designparm('login.link',$domain);                  ' '.&mt('(preferred)').'</font>'.$/;
 my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);      $last=$hostname;
 my $alink=&Apache::loncommon::designparm('login.alink',$domain);          }
 my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);          if ($spares) {
 my $logo=&Apache::loncommon::designparm('login.logo',$domain);              $spares.= '<br />';
 my $img=&Apache::loncommon::designparm('login.img',$domain);          }
 my $domainlogo=&Apache::loncommon::domainlogo($domain);          my %all_hostnames = &Apache::lonnet::all_hostnames();
 my $login=&Apache::loncommon::designparm('login.login',$domain);          foreach my $hostid (sort
 if ($login eq '') {      {
 $login = $iconpath.'/'.&mt('userauthentication.gif');   &Apache::lonnet::hostname($a) cmp
 }      &Apache::lonnet::hostname($b);
 my $showbanner = 1;      }
 my $showmainlogo = 1;      keys(%all_hostnames)) {
 if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
     $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);              my $hostname = &Apache::lonnet::hostname($hostid);
 }              next if (($last eq $hostname) || ($hostname eq ''));
 if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {              $spares.='<br /><a href="http://'.
     $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);               $hostname.
 }               '/adm/login?domain='.$authdomain.'">'.
 my $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);               $hostname.'</a>';
 my $showcoursecat =              $last=$hostname;
 &Apache::loncommon::designparm('login.coursecatalog',$domain);           }
 my $loginheader =&Apache::loncommon::designparm('login.loginheader',$domain);           $r->print(
 my $shownewuserlink =      '<html>'
 &Apache::loncommon::designparm('login.newuser',$domain);    .'<head><title>'
 my $now=time;    .&mt('The LearningOnline Network with CAPA')
 my $js = (<<ENDSCRIPT);    .'</title></head>'
     .'<body bgcolor="#FFFFFF">'
 <script type="text/javascript" language="JavaScript">    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
 // <![CDATA[    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
 function send()    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
 {          if ($spares) {
 this.document.server.elements.uname.value              $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
 =this.document.client.elements.uname.value;                       .'</p>'
                        .$spares);
 this.document.server.elements.udom.value          }
 =this.document.client.elements.udom.value;          $r->print('</body>'
                    .'</html>'
 uextkey=this.document.client.elements.uextkey.value;          );
 lextkey=this.document.client.elements.lextkey.value;          return OK;
 initkeys();      }
   
 this.document.server.elements.upass0.value  # ----------------------------------------------- Apparently we are in business
     =crypted(this.document.client.elements.upass$now.value.substr(0,15));      $servadm=~s/\,/\<br \/\>/g;
 this.document.server.elements.upass1.value  
     =crypted(this.document.client.elements.upass$now.value.substr(15,15));  # ----------------------------------------------------------- Front page design
 this.document.server.elements.upass2.value      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
     =crypted(this.document.client.elements.upass$now.value.substr(30,15));      my $font=&Apache::loncommon::designparm('login.font',$domain);
       my $link=&Apache::loncommon::designparm('login.link',$domain);
 this.document.client.elements.uname.value='';      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
 this.document.client.elements.upass$now.value='';      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
       my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
 this.document.server.submit();      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
 return false;      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
 }      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
 // ]]>      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
 </script>      my $img=&Apache::loncommon::designparm('login.img',$domain);
       my $domainlogo=&Apache::loncommon::domainlogo($domain);
 ENDSCRIPT      my $showbanner = 1;
       my $showmainlogo = 1;
 # --------------------------------------------------- Print login screen header      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
           $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
 my %add_entries = (      }
        bgcolor      => "$mainbg",      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
        text         => "$font",          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
        link         => "$link",      }
        vlink        => "$vlink",      my $showadminmail;
        alink        => "$alink",);      my @possdoms = &Apache::lonnet::current_machine_domains();
       if (grep(/^\Q$domain\E$/,@possdoms)) {
 $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
        { 'redirect'       => [$expire,'/adm/roles'],       }
  'add_entries' => \%add_entries,      my $showcoursecat =
  'only_body'   => 1,}));          &Apache::loncommon::designparm('login.coursecatalog',$domain);
       my $shownewuserlink =
 # ----------------------------------------------------------------------- Texts          &Apache::loncommon::designparm('login.newuser',$domain);
       my $showhelpdesk =
 my %lt=&Apache::lonlocal::texthash(          &Apache::loncommon::designparm('login.helpdesk',$domain);
   'un'  => 'Username',      my $now=time;
   'pw'  => 'Password',      my $js = (<<ENDSCRIPT);
   'dom' => 'Domain',  
   'perc' => 'percent',  <script type="text/javascript" language="JavaScript">
   'load' => 'Server Load',  // <![CDATA[
   'userload' => 'User Load',  function send()
   'catalog' => 'Course Catalog',  {
   'log' => 'Log in',  this.document.server.elements.uname.value
   'help' => 'Log-in Help',  =this.document.client.elements.uname.value;
   'serv' => 'Server',  
   'servadm' => 'Server Administration',  this.document.server.elements.udom.value
   'helpdesk' => 'Contact Helpdesk',  =this.document.client.elements.udom.value;
   'forgotpw' => 'Forgot password?',  
   'newuser'  => 'New User?',  uextkey=this.document.client.elements.uextkey.value;
   );  lextkey=this.document.client.elements.lextkey.value;
 # -------------------------------------------------- Change password field name  initkeys();
 my $forgotpw = &forgotpwdisplay(%lt);  
 my $loginhelp = &loginhelpdisplay(%lt);  this.document.server.elements.upass0.value
       =this.document.client.elements.upass$now.value.substr(0,15);
 # ---------------------------------------------------- Serve out DES JavaScript  this.document.server.elements.upass1.value
 {      =this.document.client.elements.upass$now.value.substr(15,15);
 my $jsh=Apache::File->new($include."/londes.js");  this.document.server.elements.upass2.value
 $r->print(<$jsh>);      =this.document.client.elements.upass$now.value.substr(30,15);
 }  
 # ---------------------------------------------------------- Serve rest of page  if(this.document.server.action.substr(0,5) === 'http:'){
       for (var idx in [1,2,3]){
 $r->print(          this.document.server.elements['upass' + idx].value =
   '<div class="LC_loginpage_container">');              crypted(this.document.server.elements['upass' + idx].value);
       }
 #  }
 #  If the loadbalancing yielded just http:// because perhaps there's no loadbalancing?  
 #  then just us a relative link to authenticate:  this.document.client.elements.uname.value='';
 #  this.document.client.elements.upass$now.value='';
   
 $r->print(<<ENDSERVERFORM);  this.document.server.submit();
 <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">  return false;
    <input type="hidden" name="logtoken" value="$logtoken" />  }
    <input type="hidden" name="serverid" value="$lonhost" />  
    <input type="hidden" name="uname" value="" />  function enableInput() {
    <input type="hidden" name="upass0" value="" />      this.document.client.elements.upass$now.removeAttribute("readOnly");
    <input type="hidden" name="upass1" value="" />      this.document.client.elements.uname.removeAttribute("readOnly");
    <input type="hidden" name="upass2" value="" />      this.document.client.elements.udom.removeAttribute("readOnly");
    <input type="hidden" name="udom" value="" />      return;
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />  }
    <input type="hidden" name="localres" value="$env{'form.localres'}" />  
   </form>  // ]]>
 ENDSERVERFORM  </script>
 my $coursecatalog;  
 if (($showcoursecat eq '') || ($showcoursecat)) {  ENDSCRIPT
     $coursecatalog = &coursecatalog_link($lt{'catalog'});  
 }  # --------------------------------------------------- Print login screen header
 my $newuserlink;  
 if ($shownewuserlink) {      my %add_entries = (
     $newuserlink = &newuser_link($lt{'newuser'}).'<br />';         bgcolor      => "$mainbg",
 }         text         => "$font",
 my $logintitle;         link         => "$link",
 if ($loginheader eq 'text') {         vlink        => "$vlink",
     $logintitle ='<h2>'.$lt{'log'}.'</h2>';         alink        => "$alink",
 } else {                 onload       => 'javascript:enableInput();',);
     $logintitle = '<img src="'.$login.'" alt="'.  
                   &mt('User Authentication').'" />';      my %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
 }      my $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost};
       my $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost};
 my $noscript_warning='<noscript><span class="LC_warning"><b>'      if ($headextra) {
                      .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')          my $omitextra;
                     .'</b></span></noscript>';          if ($headextra_exempt ne '') {
 my $helpdeskscript;              my @exempt = split(',',$headextra_exempt);
 my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,              my $ip = $ENV{'REMOTE_ADDR'};
                             $version,$authdomain,\$helpdeskscript);              if (grep(/^\Q$ip\E$/,@exempt)) {
                   $omitextra = 1;
 my $loginform=(<<LFORM);              }
 <form name="client" action="" onsubmit="return(send())">          }
   <input type="hidden" name="lextkey" value="$lextkey" />          unless ($omitextra) {
   <input type="hidden" name="uextkey" value="$uextkey" />              my $confname = $defdom.'-domainconfig';
   <b><label for="uname">$lt{'un'}</label>:</b><br />              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost/\E}) {
   <input type="text" name="uname" size="15" value="$authusername" /><br />                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />                  unless ($extra eq '-1') {
   <input type="password" name="upass$now" size="15" /><br />                      $js .= "\n".$extra."\n";
   <b><label for="udom">$lt{'dom'}</label>:</b><br />                  }
   <input type="text" name="udom" size="15" value="$authdomain" /><br />              }
   <input type="submit" value="$lt{'log'}" />          }
 </form>      }
 LFORM  
       $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
     if ($showbanner) {         { 'redirect'       => [$expire,'/adm/roles'],
         $r->print(<<HEADER);   'add_entries' => \%add_entries,
 <!-- The LON-CAPA Header -->   'only_body'   => 1,}));
 <table border="0" align="left" width="100%" cellspacing="0" cellpadding="1">  
  <tr>  # ----------------------------------------------------------------------- Texts
   <td align="left" valign="top" bgcolor="$pgbg">  
       <img src="$img" border="0" alt="The Learning Online Network with CAPA" />      my %lt=&Apache::lonlocal::texthash(
   </td>            'un'       => 'Username',
  </tr>            'pw'       => 'Password',
 </table>            'dom'      => 'Domain',
 HEADER            'perc'     => 'percent',
     }            'load'     => 'Server Load',
     $r->print(<<ENDTOP);            'userload' => 'User Load',
 <div class="LC_loginpage_space">&nbsp;</div>            'catalog'  => 'Course/Community Catalog',
 <div class="LC_loginpage_floatLeft">            'log'      => 'Log in',
 <div class="LC_loginpage_loginContainer">            'help'     => 'Log-in Help',
   $logintitle            'serv'     => 'Server',
    <table border="0" align="left" cellspacing="1" cellpadding="2" width="100%">            'servadm'  => 'Server Administration',
       <tr>            'helpdesk' => 'Contact Helpdesk',
    <td>            'forgotpw' => 'Forgot password?',
  $loginform            'newuser'  => 'New User?',
            </td>         );
       </tr>  # -------------------------------------------------- Change password field name
    </table>    
    $noscript_warning      my $forgotpw = &forgotpwdisplay(%lt);
 </div>      $forgotpw .= '<br />' if $forgotpw;
         my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
 <div class="LC_loginpage_loginInfo">      if ($loginhelp) {
         $loginhelp<br />          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
         $forgotpw<br />      }
  $contactblock<br />  
         $newuserlink  # ---------------------------------------------------- Serve out DES JavaScript
         $coursecatalog      {
 </div>      my $jsh=Apache::File->new($include."/londes.js");
 </div>      $r->print(<$jsh>);
 ENDTOP      }
     if ($showmainlogo) {  # ---------------------------------------------------------- Serve rest of page
         $r->print(' <img src="'.$logo.'" alt="" />'."\n");  
     }      $r->print(
 $r->print(<<ENDTOP);      '<div class="LC_Box"'
 $announcements     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
 $domainlogo  );
 <div class="LC_loginpage_space">&nbsp;</div>  
 ENDTOP      $r->print(<<ENDSERVERFORM);
   <form name="server" action="/adm/authenticate" method="post" target="_top">
 $r->print(<<ENDDOCUMENT);     <input type="hidden" name="logtoken" value="$logtoken" />
      <table border="0" cellspacing="0" cellpadding="0">     <input type="hidden" name="serverid" value="$lonhost" />
       <tr>     <input type="hidden" name="uname" value="" />
        <td  align="left" valign="top">     <input type="hidden" name="upass0" value="" />
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'dom'}:&nbsp;</b></small>     <input type="hidden" name="upass1" value="" />
        </td>     <input type="hidden" name="upass2" value="" />
        <td  align="left" valign="top">     <input type="hidden" name="udom" value="" />
         <small><tt>&nbsp;$domain</tt></small>     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
        </td>     <input type="hidden" name="localres" value="$env{'form.localres'}" />
       </tr>    </form>
       <tr>  ENDSERVERFORM
        <td  align="left" valign="top">      my $coursecatalog;
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'serv'}:&nbsp;</b></small>      if (($showcoursecat eq '') || ($showcoursecat)) {
        </td>          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
        <td align="left" valign="top">      }
         <small><tt>&nbsp;$lonhost ($role)</tt></small>      my $newuserlink;
        </td>      if ($shownewuserlink) {
       </tr>          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
       <tr>      }
        <td align="left" valign="top">      my $logintitle =
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'load'}:&nbsp;</b></small>          '<h2 class="LC_hcell"'
        </td>         .' style="background:'.$loginbox_header_bgcol.';'
        <td align="left" valign="top">         .' color:'.$loginbox_header_textcol.'">'
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>         .$lt{'log'}
        </td>         .'</h2>';
       </tr>  
       <tr>      my $noscript_warning='<noscript><span class="LC_warning"><b>'
        <td align="left" valign="top">                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'userload'}:&nbsp;</b></small>                          .'</b></span></noscript>';
        </td>      my $helpdeskscript;
        <td align="left" valign="top">      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>                                         $authdomain,\$helpdeskscript,
        </td>                                         $showhelpdesk,\@possdoms);
       </tr>  
      </table>      my $mobileargs;
  </div>      if ($clientmobile) {
           $mobileargs = 'autocapitalize="off" autocorrect="off"';
 <script type="text/javascript">      }
 // <![CDATA[      my $loginform=(<<LFORM);
 // the if prevents the script error if the browser can not handle this  <form name="client" action="" onsubmit="return(send())">
 if ( document.client.uname ) { document.client.uname.focus(); }    <input type="hidden" name="lextkey" value="$lextkey" />
 // ]]>    <input type="hidden" name="uextkey" value="$uextkey" />
 </script>    <b><label for="uname">$lt{'un'}</label>:</b><br />
 $helpdeskscript    <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 />
 ENDDOCUMENT    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
     my %endargs = ( 'noredirectlink' => 1, );    <b><label for="udom">$lt{'dom'}</label>:</b><br />
     $r->print(&Apache::loncommon::end_page(\%endargs));    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
     return OK;    <input type="submit" value="$lt{'log'}" />
 }  </form>
   LFORM
 sub contactdisplay {  
     my ($lt,$servadm,$showadminmail,$version,$authdomain,$helpdeskscript) = @_;      if ($showbanner) {
     my $contactblock;          $r->print(<<HEADER);
     my $showhelpdesk = 0;  <!-- The LON-CAPA Header -->
     my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};  <div style="background:$pgbg;margin:0;width:100%;">
     if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {    <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
         $showhelpdesk = 1;  </div>
     }  HEADER
     if ($servadm && $showadminmail) {      }
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;'.$$lt{'servadm'}.':</b><br />'.      $r->print(<<ENDTOP);
                          '<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$servadm.'</tt><br />&nbsp;<br />';  <div style="float:left;margin-top:0;">
     }  <div class="LC_Box" style="background:$loginbox_bg;">
     if ($showhelpdesk) {    $logintitle
         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';    $loginform
         my $thisurl = &escape('/adm/login');    $noscript_warning
         $$helpdeskscript = <<"ENDSCRIPT";  </div>
 <script type="text/javascript">   
 // <![CDATA[  <div class="LC_Box" style="padding-top: 10px;">
 function helpdesk() {    $loginhelp
     var codedom = document.client.udom.value;    $forgotpw
     if (codedom == '') {    $contactblock
         codedom = "$authdomain";    $newuserlink
     }    $coursecatalog
     var querystr = "origurl=$thisurl&codedom="+codedom;  </div>
     document.location.href = "/adm/helpdesk?"+querystr;  </div>
     return;  
 }  <div>
 // ]]>  ENDTOP
 </script>      if ($showmainlogo) {
 ENDSCRIPT          $r->print(' <img src="'.$logo.'" alt="" />'."\n");
     }      }
     $contactblock .= <<"ENDBLOCK";  $r->print(<<ENDTOP);
      &nbsp;&nbsp;&nbsp;$version  $announcements
 ENDBLOCK  </div>
     return $contactblock;  <hr style="clear:both;" />
 }  ENDTOP
       my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
 sub forgotpwdisplay {      $domainrow = <<"END";
     my (%lt) = @_;        <tr>
     my $prompt_for_resetpw = 1;          <td  align="left" valign="top">
     if ($prompt_for_resetpw) {          <small><b>$lt{'dom'}:&nbsp;</b></small>
         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';         </td>
     }         <td  align="left" valign="top">
     return;          <small><tt>&nbsp;$domain</tt></small>
 }         </td>
         </tr>
 sub loginhelpdisplay {  END
     my (%lt) = @_;      $serverrow = <<"END";
     my $login_help = 1;        <tr>
     if ($login_help) {         <td  align="left" valign="top">
         return '<a href="/adm/loginproblems.html">'.$lt{'help'}.'</a>';          <small><b>$lt{'serv'}:&nbsp;</b></small>
     }         </td>
     return;         <td align="left" valign="top">
 }          <small><tt>&nbsp;$lonhost ($role)</tt></small>
          </td>
 sub coursecatalog_link {        </tr>
     my ($linkname) = @_;  END
     return <<"END";      if ($loadlim) {
       <a href="/adm/coursecatalog">$linkname</a>          $loadrow = <<"END";
 END        <tr>
 }         <td align="left" valign="top">
           <small><b>$lt{'load'}:&nbsp;</b></small>
 sub newuser_link {         </td>
     my ($linkname) = @_;         <td align="left" valign="top">
     return '&nbsp;&nbsp;&nbsp;<a href="/adm/createaccount"><b>'.$linkname.'</b></a><br />';          <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
 }         </td>
         </tr>
 1;  END
 __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.125  
changed lines
  Added in v.1.161


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