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

version 1.125, 2009/09/11 23:04:45 version 1.160, 2014/12/05 12:03:20
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      if ($lonhost ne '') {
           unless ($sessiondata{'sessionserver'}) {
     my $authusername=($env{'form.username'}?$env{'form.username'}:'');              my $redirect = &check_loginvia($domain,$lonhost);
     my $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);              if ($redirect) {
                   $r->print($redirect);
 # ---------------------------------------------------------- Determine own load                  return OK;
     my $loadavg;              }
     {          }
  my $loadfile=Apache::File->new('/proc/loadavg');      }
  $loadavg=<$loadfile>;  
     }      if (($sessiondata{'domain'}) &&
     $loadavg =~ s/\s.*//g;          (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
     my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);          $domain=$sessiondata{'domain'};
     my $userloadpercent=&Apache::lonnet::userload();      } elsif (($env{'form.domain'}) &&
    (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
 # ------------------------------------------------------- Do the load balancing   $domain=$env{'form.domain'};
     my $otherserver= &Apache::lonnet::absolute_url($host_name);      }
     my $firsturl=  
     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});      my $role    = $r->dir_config('lonRole');
 # ---------------------------------------------------------- Are we overloaded?      my $loadlim = $r->dir_config('lonLoadLim');
     if ((($userloadpercent>100.0)||($loadpercent>100.0))) {      my $uloadlim= $r->dir_config('lonUserLoadLim');
         my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent);      my $servadm = $r->dir_config('lonAdmEMail');
  if ($unloaded) { $otherserver=$unloaded; }      my $tabdir  = $r->dir_config('lonTabDir');
     }      my $include = $r->dir_config('lonIncludes');
       my $expire  = $r->dir_config('lonExpire');
 # ----------------------------------------------------------- Get announcements      my $version = $r->dir_config('lonVersion');
     my $announcements=&Apache::lonnet::getannounce();      my $host_name = &Apache::lonnet::hostname($lonhost);
 # -------------------------------------------------------- Set login parameters  
   # --------------------------------------------- Default values for login fields
     my @hexstr=('0','1','2','3','4','5','6','7',     
                 '8','9','a','b','c','d','e','f');      my ($authusername,$authdomain);
     my $lkey='';      if ($sessiondata{'username'}) {
     for (0..7) {          $authusername=$sessiondata{'username'};
         $lkey.=$hexstr[rand(15)];      } else {
     }          $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
           $authusername=($env{'form.username'}?$env{'form.username'}:'');
     my $ukey='';      }
     for (0..7) {      if ($sessiondata{'domain'}) {
         $ukey.=$hexstr[rand(15)];          $authdomain=$sessiondata{'domain'};
     }      } else {
           $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
     my $lextkey=hex($lkey);          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
     if ($lextkey>2147483647) { $lextkey-=4294967296; }      }
   
     my $uextkey=hex($ukey);  # ---------------------------------------------------------- Determine own load
     if ($uextkey>2147483647) { $uextkey-=4294967296; }      my $loadavg;
       {
 # -------------------------------------------------------- Store away log token   my $loadfile=Apache::File->new('/proc/loadavg');
     my $tokenextras;   $loadavg=<$loadfile>;
     if ($env{'form.role'}) {      }
         $tokenextras = '&role='.&escape($env{'form.role'});      $loadavg =~ s/\s.*//g;
     }  
     if ($env{'form.symb'}) {      my ($loadpercent,$userloadpercent);
         if (!$tokenextras) {      if ($loadlim) {
             $tokenextras = '&';          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
         }      }
         $tokenextras .= '&symb='.&escape($env{'form.symb'});      if ($uloadlim) {
     }          $userloadpercent=&Apache::lonnet::userload();
     my $logtoken=Apache::lonnet::reply(      }
        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,  
        $lonhost);      my $firsturl=
       ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
 # ------------------- If we cannot talk to ourselves, we are in serious trouble  
   # ----------------------------------------------------------- Get announcements
     if ($logtoken eq 'con_lost') {      my $announcements=&Apache::lonnet::getannounce();
         my $spares='';  # -------------------------------------------------------- Set login parameters
  my $last;  
         foreach my $hostid (sort      my @hexstr=('0','1','2','3','4','5','6','7',
     {                  '8','9','a','b','c','d','e','f');
  &Apache::lonnet::hostname($a) cmp      my $lkey='';
     &Apache::lonnet::hostname($b);      for (0..7) {
     }          $lkey.=$hexstr[rand(15)];
     keys(%Apache::lonnet::spareid)) {      }
             next if ($hostid eq $lonhost);  
     my $hostname = &Apache::lonnet::hostname($hostid);      my $ukey='';
     next if ($last eq $hostname);      for (0..7) {
             $spares.='<br /><font size="+1"><a href="http://'.          $ukey.=$hexstr[rand(15)];
                 $hostname.      }
                 '/adm/login?domain='.$authdomain.'">'.  
                 $hostname.'</a>'.      my $lextkey=hex($lkey);
                 ' '.&mt('(preferred)').'</font>'.$/;      if ($lextkey>2147483647) { $lextkey-=4294967296; }
     $last=$hostname;  
         }      my $uextkey=hex($ukey);
 $spares.= '<br />';      if ($uextkey>2147483647) { $uextkey-=4294967296; }
 my %all_hostnames = &Apache::lonnet::all_hostnames();  
 foreach my $hostid (sort  # -------------------------------------------------------- Store away log token
     {      my $tokenextras;
  &Apache::lonnet::hostname($a) cmp      if ($env{'form.role'}) {
     &Apache::lonnet::hostname($b);          $tokenextras = '&role='.&escape($env{'form.role'});
     }      }
     keys(%all_hostnames)) {      if ($env{'form.symb'}) {
     next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});          if (!$tokenextras) {
     my $hostname = &Apache::lonnet::hostname($hostid);              $tokenextras = '&';
     next if ($last eq $hostname);          }
     $spares.='<br /><a href="http://'.          $tokenextras .= '&symb='.&escape($env{'form.symb'});
  $hostname.      }
  '/adm/login?domain='.$authdomain.'">'.      my $logtoken=Apache::lonnet::reply(
  $hostname.'</a>';         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
     $last=$hostname;         $lonhost);
 }  
 $r->print(  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
    '<html>'  #    we are in serious trouble
   .'<head><title>'  
   .&mt('The LearningOnline Network with CAPA')      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
   .'</title></head>'          if ($logtoken eq 'no_such_host') {
   .'<body bgcolor="#FFFFFF">'              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'          }
   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'          my $spares='';
   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>'   my $last;
   .'<p>'.&mt('Please attempt to login to one of the following servers:').'</p>'          foreach my $hostid (sort
   .$spares      {
   .'</body>'   &Apache::lonnet::hostname($a) cmp
   .'</html>'      &Apache::lonnet::hostname($b);
 );      }
 return OK;      keys(%Apache::lonnet::spareid)) {
 }              next if ($hostid eq $lonhost);
       my $hostname = &Apache::lonnet::hostname($hostid);
 # ----------------------------------------------- Apparently we are in business      next if (($last eq $hostname) || ($hostname eq ''));
 $servadm=~s/\,/\<br \/\>/g;              $spares.='<br /><font size="+1"><a href="http://'.
                   $hostname.
 # ----------------------------------------------------------- Front page design                  '/adm/login?domain='.$authdomain.'">'.
 my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);                  $hostname.'</a>'.
 my $font=&Apache::loncommon::designparm('login.font',$domain);                  ' '.&mt('(preferred)').'</font>'.$/;
 my $link=&Apache::loncommon::designparm('login.link',$domain);      $last=$hostname;
 my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);          }
 my $alink=&Apache::loncommon::designparm('login.alink',$domain);          if ($spares) {
 my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);              $spares.= '<br />';
 my $logo=&Apache::loncommon::designparm('login.logo',$domain);          }
 my $img=&Apache::loncommon::designparm('login.img',$domain);          my %all_hostnames = &Apache::lonnet::all_hostnames();
 my $domainlogo=&Apache::loncommon::domainlogo($domain);          foreach my $hostid (sort
 my $login=&Apache::loncommon::designparm('login.login',$domain);      {
 if ($login eq '') {   &Apache::lonnet::hostname($a) cmp
 $login = $iconpath.'/'.&mt('userauthentication.gif');      &Apache::lonnet::hostname($b);
 }      }
 my $showbanner = 1;      keys(%all_hostnames)) {
 my $showmainlogo = 1;              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
 if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {              my $hostname = &Apache::lonnet::hostname($hostid);
     $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);              next if (($last eq $hostname) || ($hostname eq ''));
 }              $spares.='<br /><a href="http://'.
 if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {               $hostname.
     $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);               '/adm/login?domain='.$authdomain.'">'.
 }               $hostname.'</a>';
 my $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);              $last=$hostname;
 my $showcoursecat =           }
 &Apache::loncommon::designparm('login.coursecatalog',$domain);           $r->print(
 my $loginheader =&Apache::loncommon::designparm('login.loginheader',$domain);     '<html>'
 my $shownewuserlink =     .'<head><title>'
 &Apache::loncommon::designparm('login.newuser',$domain);    .&mt('The LearningOnline Network with CAPA')
 my $now=time;    .'</title></head>'
 my $js = (<<ENDSCRIPT);    .'<body bgcolor="#FFFFFF">'
     .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
 <script type="text/javascript" language="JavaScript">    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
 // <![CDATA[    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
 function send()          if ($spares) {
 {              $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
 this.document.server.elements.uname.value                       .'</p>'
 =this.document.client.elements.uname.value;                       .$spares);
           }
 this.document.server.elements.udom.value          $r->print('</body>'
 =this.document.client.elements.udom.value;                   .'</html>'
           );
 uextkey=this.document.client.elements.uextkey.value;          return OK;
 lextkey=this.document.client.elements.lextkey.value;      }
 initkeys();  
   # ----------------------------------------------- Apparently we are in business
 this.document.server.elements.upass0.value      $servadm=~s/\,/\<br \/\>/g;
     =crypted(this.document.client.elements.upass$now.value.substr(0,15));  
 this.document.server.elements.upass1.value  # ----------------------------------------------------------- Front page design
     =crypted(this.document.client.elements.upass$now.value.substr(15,15));      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
 this.document.server.elements.upass2.value      my $font=&Apache::loncommon::designparm('login.font',$domain);
     =crypted(this.document.client.elements.upass$now.value.substr(30,15));      my $link=&Apache::loncommon::designparm('login.link',$domain);
       my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
 this.document.client.elements.uname.value='';      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
 this.document.client.elements.upass$now.value='';      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
       my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
 this.document.server.submit();      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
 return false;      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
 }      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
 // ]]>      my $img=&Apache::loncommon::designparm('login.img',$domain);
 </script>      my $domainlogo=&Apache::loncommon::domainlogo($domain);
       my $showbanner = 1;
 ENDSCRIPT      my $showmainlogo = 1;
       if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
 # --------------------------------------------------- Print login screen header          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
       }
 my %add_entries = (      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
        bgcolor      => "$mainbg",          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
        text         => "$font",      }
        link         => "$link",      my $showadminmail;
        vlink        => "$vlink",      my @possdoms = &Apache::lonnet::current_machine_domains();
        alink        => "$alink",);      if (grep(/^\Q$domain\E$/,@possdoms)) {
           $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
 $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,      }
        { 'redirect'       => [$expire,'/adm/roles'],       my $showcoursecat =
  'add_entries' => \%add_entries,          &Apache::loncommon::designparm('login.coursecatalog',$domain);
  'only_body'   => 1,}));      my $shownewuserlink =
           &Apache::loncommon::designparm('login.newuser',$domain);
 # ----------------------------------------------------------------------- Texts      my $showhelpdesk =
           &Apache::loncommon::designparm('login.helpdesk',$domain);
 my %lt=&Apache::lonlocal::texthash(      my $now=time;
   'un'  => 'Username',      my $js = (<<ENDSCRIPT);
   'pw'  => 'Password',  
   'dom' => 'Domain',  <script type="text/javascript" language="JavaScript">
   'perc' => 'percent',  // <![CDATA[
   'load' => 'Server Load',  function send()
   'userload' => 'User Load',  {
   'catalog' => 'Course Catalog',  this.document.server.elements.uname.value
   'log' => 'Log in',  =this.document.client.elements.uname.value;
   'help' => 'Log-in Help',  
   'serv' => 'Server',  this.document.server.elements.udom.value
   'servadm' => 'Server Administration',  =this.document.client.elements.udom.value;
   'helpdesk' => 'Contact Helpdesk',  
   'forgotpw' => 'Forgot password?',  uextkey=this.document.client.elements.uextkey.value;
   'newuser'  => 'New User?',  lextkey=this.document.client.elements.lextkey.value;
   );  initkeys();
 # -------------------------------------------------- Change password field name  
 my $forgotpw = &forgotpwdisplay(%lt);  this.document.server.elements.upass0.value
 my $loginhelp = &loginhelpdisplay(%lt);      =this.document.client.elements.upass$now.value.substr(0,15);
   this.document.server.elements.upass1.value
 # ---------------------------------------------------- Serve out DES JavaScript      =this.document.client.elements.upass$now.value.substr(15,15);
 {  this.document.server.elements.upass2.value
 my $jsh=Apache::File->new($include."/londes.js");      =this.document.client.elements.upass$now.value.substr(30,15);
 $r->print(<$jsh>);  
 }  if(this.document.server.action.substr(0,5) === 'http:'){
 # ---------------------------------------------------------- Serve rest of page      for (var idx in [1,2,3]){
           this.document.server.elements['upass' + idx].value =
 $r->print(              crypted(this.document.server.elements['upass' + idx].value);
   '<div class="LC_loginpage_container">');      }
   }
 #  
 #  If the loadbalancing yielded just http:// because perhaps there's no loadbalancing?  this.document.client.elements.uname.value='';
 #  then just us a relative link to authenticate:  this.document.client.elements.upass$now.value='';
 #  
   this.document.server.submit();
 $r->print(<<ENDSERVERFORM);  return false;
 <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">  }
    <input type="hidden" name="logtoken" value="$logtoken" />  
    <input type="hidden" name="serverid" value="$lonhost" />  function enableInput() {
    <input type="hidden" name="uname" value="" />      this.document.client.elements.upass$now.removeAttribute("readOnly");
    <input type="hidden" name="upass0" value="" />      this.document.client.elements.uname.removeAttribute("readOnly");
    <input type="hidden" name="upass1" value="" />      this.document.client.elements.udom.removeAttribute("readOnly");
    <input type="hidden" name="upass2" value="" />      return;
    <input type="hidden" name="udom" value="" />  }
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />  
    <input type="hidden" name="localres" value="$env{'form.localres'}" />  // ]]>
   </form>  </script>
 ENDSERVERFORM  
 my $coursecatalog;  ENDSCRIPT
 if (($showcoursecat eq '') || ($showcoursecat)) {  
     $coursecatalog = &coursecatalog_link($lt{'catalog'});  # --------------------------------------------------- Print login screen header
 }  
 my $newuserlink;      my %add_entries = (
 if ($shownewuserlink) {         bgcolor      => "$mainbg",
     $newuserlink = &newuser_link($lt{'newuser'}).'<br />';         text         => "$font",
 }         link         => "$link",
 my $logintitle;         vlink        => "$vlink",
 if ($loginheader eq 'text') {         alink        => "$alink",
     $logintitle ='<h2>'.$lt{'log'}.'</h2>';                 onload       => 'javascript:enableInput();',);
 } else {  
     $logintitle = '<img src="'.$login.'" alt="'.      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
                   &mt('User Authentication').'" />';         { 'redirect'       => [$expire,'/adm/roles'],
 }   'add_entries' => \%add_entries,
    'only_body'   => 1,}));
 my $noscript_warning='<noscript><span class="LC_warning"><b>'  
                      .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')  # ----------------------------------------------------------------------- Texts
                     .'</b></span></noscript>';  
 my $helpdeskscript;      my %lt=&Apache::lonlocal::texthash(
 my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,            'un'       => 'Username',
                             $version,$authdomain,\$helpdeskscript);            'pw'       => 'Password',
             'dom'      => 'Domain',
 my $loginform=(<<LFORM);            'perc'     => 'percent',
 <form name="client" action="" onsubmit="return(send())">            'load'     => 'Server Load',
   <input type="hidden" name="lextkey" value="$lextkey" />            'userload' => 'User Load',
   <input type="hidden" name="uextkey" value="$uextkey" />            'catalog'  => 'Course/Community Catalog',
   <b><label for="uname">$lt{'un'}</label>:</b><br />            'log'      => 'Log in',
   <input type="text" name="uname" size="15" value="$authusername" /><br />            'help'     => 'Log-in Help',
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />            'serv'     => 'Server',
   <input type="password" name="upass$now" size="15" /><br />            'servadm'  => 'Server Administration',
   <b><label for="udom">$lt{'dom'}</label>:</b><br />            'helpdesk' => 'Contact Helpdesk',
   <input type="text" name="udom" size="15" value="$authdomain" /><br />            'forgotpw' => 'Forgot password?',
   <input type="submit" value="$lt{'log'}" />            'newuser'  => 'New User?',
 </form>         );
 LFORM  # -------------------------------------------------- Change password field name
   
     if ($showbanner) {      my $forgotpw = &forgotpwdisplay(%lt);
         $r->print(<<HEADER);      $forgotpw .= '<br />' if $forgotpw;
 <!-- The LON-CAPA Header -->      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
 <table border="0" align="left" width="100%" cellspacing="0" cellpadding="1">      if ($loginhelp) {
  <tr>          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
   <td align="left" valign="top" bgcolor="$pgbg">      }
       <img src="$img" border="0" alt="The Learning Online Network with CAPA" />  
   </td>  # ---------------------------------------------------- Serve out DES JavaScript
  </tr>      {
 </table>      my $jsh=Apache::File->new($include."/londes.js");
 HEADER      $r->print(<$jsh>);
     }      }
     $r->print(<<ENDTOP);  # ---------------------------------------------------------- Serve rest of page
 <div class="LC_loginpage_space">&nbsp;</div>  
 <div class="LC_loginpage_floatLeft">      $r->print(
 <div class="LC_loginpage_loginContainer">      '<div class="LC_Box"'
   $logintitle     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
    <table border="0" align="left" cellspacing="1" cellpadding="2" width="100%">  );
       <tr>  
    <td>      $r->print(<<ENDSERVERFORM);
  $loginform  <form name="server" action="/adm/authenticate" method="post" target="_top">
            </td>     <input type="hidden" name="logtoken" value="$logtoken" />
       </tr>     <input type="hidden" name="serverid" value="$lonhost" />
    </table>       <input type="hidden" name="uname" value="" />
    $noscript_warning     <input type="hidden" name="upass0" value="" />
 </div>     <input type="hidden" name="upass1" value="" />
        <input type="hidden" name="upass2" value="" />
 <div class="LC_loginpage_loginInfo">     <input type="hidden" name="udom" value="" />
         $loginhelp<br />     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
         $forgotpw<br />     <input type="hidden" name="localres" value="$env{'form.localres'}" />
  $contactblock<br />    </form>
         $newuserlink  ENDSERVERFORM
         $coursecatalog      my $coursecatalog;
 </div>      if (($showcoursecat eq '') || ($showcoursecat)) {
 </div>          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
 ENDTOP      }
     if ($showmainlogo) {      my $newuserlink;
         $r->print(' <img src="'.$logo.'" alt="" />'."\n");      if ($shownewuserlink) {
     }          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
 $r->print(<<ENDTOP);      }
 $announcements      my $logintitle =
 $domainlogo          '<h2 class="LC_hcell"'
 <div class="LC_loginpage_space">&nbsp;</div>         .' style="background:'.$loginbox_header_bgcol.';'
 ENDTOP         .' color:'.$loginbox_header_textcol.'">'
          .$lt{'log'}
 $r->print(<<ENDDOCUMENT);         .'</h2>';
      <table border="0" cellspacing="0" cellpadding="0">  
       <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{'dom'}:&nbsp;</b></small>                          .'</b></span></noscript>';
        </td>      my $helpdeskscript;
        <td  align="left" valign="top">      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
         <small><tt>&nbsp;$domain</tt></small>                                         $authdomain,\$helpdeskscript,
        </td>                                         $showhelpdesk,\@possdoms);
       </tr>  
       <tr>      my $mobileargs;
        <td  align="left" valign="top">      if ($clientmobile) {
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'serv'}:&nbsp;</b></small>          $mobileargs = 'autocapitalize="off" autocorrect="off"';
        </td>      }
        <td align="left" valign="top">      my $loginform=(<<LFORM);
         <small><tt>&nbsp;$lonhost ($role)</tt></small>  <form name="client" action="" onsubmit="return(send())">
        </td>    <input type="hidden" name="lextkey" value="$lextkey" />
       </tr>    <input type="hidden" name="uextkey" value="$uextkey" />
       <tr>    <b><label for="uname">$lt{'un'}</label>:</b><br />
        <td align="left" valign="top">    <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'load'}:&nbsp;</b></small>    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
        </td>    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
        <td align="left" valign="top">    <b><label for="udom">$lt{'dom'}</label>:</b><br />
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
        </td>    <input type="submit" value="$lt{'log'}" />
       </tr>  </form>
       <tr>  LFORM
        <td align="left" valign="top">  
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'userload'}:&nbsp;</b></small>      if ($showbanner) {
        </td>          $r->print(<<HEADER);
        <td align="left" valign="top">  <!-- The LON-CAPA Header -->
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>  <div style="background:$pgbg;margin:0;width:100%;">
        </td>    <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
       </tr>  </div>
      </table>  HEADER
  </div>      }
       $r->print(<<ENDTOP);
 <script type="text/javascript">  <div style="float:left;margin-top:0;">
 // <![CDATA[  <div class="LC_Box" style="background:$loginbox_bg;">
 // the if prevents the script error if the browser can not handle this    $logintitle
 if ( document.client.uname ) { document.client.uname.focus(); }    $loginform
 // ]]>    $noscript_warning
 </script>  </div>
 $helpdeskscript   
   <div class="LC_Box" style="padding-top: 10px;">
 ENDDOCUMENT    $loginhelp
     my %endargs = ( 'noredirectlink' => 1, );    $forgotpw
     $r->print(&Apache::loncommon::end_page(\%endargs));    $contactblock
     return OK;    $newuserlink
 }    $coursecatalog
   </div>
 sub contactdisplay {  </div>
     my ($lt,$servadm,$showadminmail,$version,$authdomain,$helpdeskscript) = @_;  
     my $contactblock;  <div>
     my $showhelpdesk = 0;  ENDTOP
     my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};      if ($showmainlogo) {
     if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {          $r->print(' <img src="'.$logo.'" alt="" />'."\n");
         $showhelpdesk = 1;      }
     }  $r->print(<<ENDTOP);
     if ($servadm && $showadminmail) {  $announcements
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;'.$$lt{'servadm'}.':</b><br />'.  </div>
                          '<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$servadm.'</tt><br />&nbsp;<br />';  <hr style="clear:both;" />
     }  ENDTOP
     if ($showhelpdesk) {      my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';      $domainrow = <<"END";
         my $thisurl = &escape('/adm/login');        <tr>
         $$helpdeskscript = <<"ENDSCRIPT";         <td  align="left" valign="top">
 <script type="text/javascript">          <small><b>$lt{'dom'}:&nbsp;</b></small>
 // <![CDATA[         </td>
 function helpdesk() {         <td  align="left" valign="top">
     var codedom = document.client.udom.value;          <small><tt>&nbsp;$domain</tt></small>
     if (codedom == '') {         </td>
         codedom = "$authdomain";        </tr>
     }  END
     var querystr = "origurl=$thisurl&codedom="+codedom;      $serverrow = <<"END";
     document.location.href = "/adm/helpdesk?"+querystr;        <tr>
     return;         <td  align="left" valign="top">
 }          <small><b>$lt{'serv'}:&nbsp;</b></small>
 // ]]>         </td>
 </script>         <td align="left" valign="top">
 ENDSCRIPT          <small><tt>&nbsp;$lonhost ($role)</tt></small>
     }         </td>
     $contactblock .= <<"ENDBLOCK";        </tr>
      &nbsp;&nbsp;&nbsp;$version  END
 ENDBLOCK      if ($loadlim) {
     return $contactblock;          $loadrow = <<"END";
 }        <tr>
          <td align="left" valign="top">
 sub forgotpwdisplay {          <small><b>$lt{'load'}:&nbsp;</b></small>
     my (%lt) = @_;         </td>
     my $prompt_for_resetpw = 1;          <td align="left" valign="top">
     if ($prompt_for_resetpw) {          <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';         </td>
     }        </tr>
     return;  END
 }      }
       if ($uloadlim) {
 sub loginhelpdisplay {          $userloadrow = <<"END";
     my (%lt) = @_;        <tr>
     my $login_help = 1;         <td align="left" valign="top">
     if ($login_help) {          <small><b>$lt{'userload'}:&nbsp;</b></small>
         return '<a href="/adm/loginproblems.html">'.$lt{'help'}.'</a>';         </td>
     }         <td align="left" valign="top">
     return;          <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
 }         </td>
         </tr>
 sub coursecatalog_link {  END
     my ($linkname) = @_;      }
     return <<"END";      if (($version ne '') && ($version ne '<!-- VERSION -->')) {
       <a href="/adm/coursecatalog">$linkname</a>          $versionrow = <<"END";
 END        <tr>
 }         <td colspan="2" align="left">
           <small>$version</small>
 sub newuser_link {         </td>
     my ($linkname) = @_;        </tr>
     return '&nbsp;&nbsp;&nbsp;<a href="/adm/createaccount"><b>'.$linkname.'</b></a><br />';  END
 }      }
   
 1;      $r->print(<<ENDDOCUMENT);
 __END__      <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.160


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