Diff for /loncom/auth/lonlogin.pm between versions 1.126 and 1.166

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


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