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

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


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