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

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


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