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

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


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