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

version 1.146, 2011/02/11 10:41:59 version 1.160, 2014/12/05 12:03:20
Line 1 Line 1
 # The LearningOnline Network  # The LearningOnline Network
 # Login Screen  # Login Screen
 #  #
 # $Id$  # $Id$
 #  #
 # Copyright Michigan State University Board of Trustees  # Copyright Michigan State University Board of Trustees
 #  #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).  # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
 #  #
 # LON-CAPA is free software; you can redistribute it and/or modify  # LON-CAPA is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by  # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or  # the Free Software Foundation; either version 2 of the License, or
 # (at your option) any later version.  # (at your option) any later version.
 #  #
 # LON-CAPA is distributed in the hope that it will be useful,  # LON-CAPA is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of  # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.  # GNU General Public License for more details.
 #  #
 # You should have received a copy of the GNU General Public License  # You should have received a copy of the GNU General Public License
 # along with LON-CAPA; if not, write to the Free Software  # along with LON-CAPA; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #  #
 # /home/httpd/html/adm/gpl.txt  # /home/httpd/html/adm/gpl.txt
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
   
 package Apache::lonlogin;  package Apache::lonlogin;
   
 use strict;  use strict;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::File ();  use Apache::File ();
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonauth();  use Apache::lonauth();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::migrateuser();  use Apache::migrateuser();
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
 use LONCAPA;  use LONCAPA;
     
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
   
     &Apache::loncommon::get_unprocessed_cgi      &Apache::loncommon::get_unprocessed_cgi
  (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},   (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
       $ENV{'REDIRECT_QUERY_STRING'}),        $ENV{'REDIRECT_QUERY_STRING'}),
  ['interface','username','domain','firsturl','localpath','localres',   ['interface','username','domain','firsturl','localpath','localres',
   'token','role','symb']);    'token','role','symb','iptoken']);
     if (!defined($env{'form.firsturl'})) {      if (!defined($env{'form.firsturl'})) {
         &Apache::lonacc::get_posted_cgi($r,['firsturl']);          &Apache::lonacc::get_posted_cgi($r,['firsturl']);
     }      }
   
 # -- check if they are a migrating user  # -- check if they are a migrating user
     if (defined($env{'form.token'})) {      if (defined($env{'form.token'})) {
  return &Apache::migrateuser::handler($r);   return &Apache::migrateuser::handler($r);
     }      }
   
     &Apache::loncommon::no_cache($r);      &Apache::loncommon::no_cache($r);
     &Apache::lonlocal::get_language_handle($r);      &Apache::lonlocal::get_language_handle($r);
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
     return OK if $r->header_only;      return OK if $r->header_only;
   
   
 # Are we re-routing?  # Are we re-routing?
     if (-e '/home/httpd/html/lon-status/reroute.txt') {      my $londocroot = $r->dir_config('lonDocRoot');
  &Apache::lonauth::reroute($r);      if (-e "$londocroot/lon-status/reroute.txt") {
  return OK;   &Apache::lonauth::reroute($r);
     }   return OK;
       }
     $env{'form.firsturl'} =~ s/(`)/'/g;  
       $env{'form.firsturl'} =~ s/(`)/'/g;
 # -------------------------------- Prevent users from attempting to login twice  
     my $handle = &Apache::lonnet::check_for_valid_session($r);  # -------------------------------- Prevent users from attempting to login twice
     if ($handle ne '') {      my $handle = &Apache::lonnet::check_for_valid_session($r);
         my $lonidsdir=$r->dir_config('lonIDsDir');      if ($handle ne '') {
         if ($handle=~/^publicuser\_/) {          my $lonidsdir=$r->dir_config('lonIDsDir');
 # For "public user" - remove it, we apparently really want to login          if ($handle=~/^publicuser\_/) {
     unlink($r->dir_config('lonIDsDir')."/$handle.id");  # For "public user" - remove it, we apparently really want to login
         } else {      unlink($r->dir_config('lonIDsDir')."/$handle.id");
 # Indeed, a valid token is found          } else {
             &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);  # Indeed, a valid token is found
     my $start_page =               &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
         &Apache::loncommon::start_page('Already logged in');      my $start_page =
     my $end_page =           &Apache::loncommon::start_page('Already logged in');
         &Apache::loncommon::end_page();      my $end_page =
             my $dest = '/adm/roles';          &Apache::loncommon::end_page();
             if ($env{'form.firsturl'} ne '') {              my $dest = '/adm/roles';
                 $dest = $env{'form.firsturl'};               if ($env{'form.firsturl'} ne '') {
             }                  $dest = $env{'form.firsturl'};
     $r->print(              }
                   $start_page      $r->print(
                  .'<h1>'.&mt('You are already logged in!').'</h1>'                    $start_page
                  .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',                   .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
                   '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'                   .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
                  .$end_page                    '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
                  );                   .$end_page
             return OK;                   );
         }              return OK;
     }          }
       }
 # ---------------------------------------------------- No valid token, continue  
   # ---------------------------------------------------- No valid token, continue
  # ---------------------------- Not possible to really login to domain "public"  
     if ($env{'form.domain'} eq 'public') {  # ---------------------------- Not possible to really login to domain "public"
  $env{'form.domain'}='';      if ($env{'form.domain'} eq 'public') {
  $env{'form.username'}='';   $env{'form.domain'}='';
     }   $env{'form.username'}='';
 # ----------------------------------------------------------- Process Interface      }
     $env{'form.interface'}=~s/\W//g;  
   # ------ Is this page requested because /adm/migrateuser detected an IP change?
     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};      my %sessiondata;
       if ($env{'form.iptoken'}) {
     my $iconpath=           %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
  &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));          my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
       }
     my $lonhost = $r->dir_config('lonHostID');  # ----------------------------------------------------------- Process Interface
     my $domain = &Apache::lonnet::default_login_domain();      $env{'form.interface'}=~s/\W//g;
     if ($lonhost ne '') {  
         my $redirect = &check_loginvia($domain,$lonhost);      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
         if ($redirect) {          &Apache::loncommon::decode_user_agent();
             $r->print($redirect);  
             return OK;      my $iconpath=
         }    &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
     }  
       my $lonhost = $r->dir_config('lonHostID');
     if (($env{'form.domain'}) &&       my $domain = &Apache::lonnet::default_login_domain();
  (&Apache::lonnet::domain($env{'form.domain'},'description'))) {      if ($lonhost ne '') {
  $domain=$env{'form.domain'};          unless ($sessiondata{'sessionserver'}) {
     }              my $redirect = &check_loginvia($domain,$lonhost);
     my $role    = $r->dir_config('lonRole');              if ($redirect) {
     my $loadlim = $r->dir_config('lonLoadLim');                  $r->print($redirect);
     my $uloadlim= $r->dir_config('lonUserLoadLim');                  return OK;
     my $servadm = $r->dir_config('lonAdmEMail');              }
     my $tabdir  = $r->dir_config('lonTabDir');          }
     my $include = $r->dir_config('lonIncludes');      }
     my $expire  = $r->dir_config('lonExpire');  
     my $version = $r->dir_config('lonVersion');      if (($sessiondata{'domain'}) &&
     my $host_name = &Apache::lonnet::hostname($lonhost);          (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
           $domain=$sessiondata{'domain'};
 # --------------------------------------------- Default values for login fields      } elsif (($env{'form.domain'}) &&
    (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
     my $authusername=($env{'form.username'}?$env{'form.username'}:'');   $domain=$env{'form.domain'};
     my $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);      }
   
 # ---------------------------------------------------------- Determine own load      my $role    = $r->dir_config('lonRole');
     my $loadavg;      my $loadlim = $r->dir_config('lonLoadLim');
     {      my $uloadlim= $r->dir_config('lonUserLoadLim');
  my $loadfile=Apache::File->new('/proc/loadavg');      my $servadm = $r->dir_config('lonAdmEMail');
  $loadavg=<$loadfile>;      my $tabdir  = $r->dir_config('lonTabDir');
     }      my $include = $r->dir_config('lonIncludes');
     $loadavg =~ s/\s.*//g;      my $expire  = $r->dir_config('lonExpire');
     my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);      my $version = $r->dir_config('lonVersion');
     unless ($loadlim) { $loadpercent='---'; }      my $host_name = &Apache::lonnet::hostname($lonhost);
     my $userloadpercent=&Apache::lonnet::userload();  
     unless ($uloadlim) { $userloadpercent='---'; }  # --------------------------------------------- Default values for login fields
      
     my $firsturl=      my ($authusername,$authdomain);
     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});      if ($sessiondata{'username'}) {
           $authusername=$sessiondata{'username'};
 # ----------------------------------------------------------- Get announcements      } else {
     my $announcements=&Apache::lonnet::getannounce();          $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
 # -------------------------------------------------------- Set login parameters          $authusername=($env{'form.username'}?$env{'form.username'}:'');
       }
     my @hexstr=('0','1','2','3','4','5','6','7',      if ($sessiondata{'domain'}) {
                 '8','9','a','b','c','d','e','f');          $authdomain=$sessiondata{'domain'};
     my $lkey='';      } else {
     for (0..7) {          $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
         $lkey.=$hexstr[rand(15)];          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
     }      }
   
     my $ukey='';  # ---------------------------------------------------------- Determine own load
     for (0..7) {      my $loadavg;
         $ukey.=$hexstr[rand(15)];      {
     }   my $loadfile=Apache::File->new('/proc/loadavg');
    $loadavg=<$loadfile>;
     my $lextkey=hex($lkey);      }
     if ($lextkey>2147483647) { $lextkey-=4294967296; }      $loadavg =~ s/\s.*//g;
   
     my $uextkey=hex($ukey);      my ($loadpercent,$userloadpercent);
     if ($uextkey>2147483647) { $uextkey-=4294967296; }      if ($loadlim) {
           $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
 # -------------------------------------------------------- Store away log token      }
     my $tokenextras;      if ($uloadlim) {
     if ($env{'form.role'}) {          $userloadpercent=&Apache::lonnet::userload();
         $tokenextras = '&role='.&escape($env{'form.role'});      }
     }  
     if ($env{'form.symb'}) {      my $firsturl=
         if (!$tokenextras) {      ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
             $tokenextras = '&';  
         }  # ----------------------------------------------------------- Get announcements
         $tokenextras .= '&symb='.&escape($env{'form.symb'});      my $announcements=&Apache::lonnet::getannounce();
     }  # -------------------------------------------------------- Set login parameters
     my $logtoken=Apache::lonnet::reply(  
        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,      my @hexstr=('0','1','2','3','4','5','6','7',
        $lonhost);                  '8','9','a','b','c','d','e','f');
       my $lkey='';
 # ------------------- If we cannot talk to ourselves, we are in serious trouble      for (0..7) {
           $lkey.=$hexstr[rand(15)];
     if ($logtoken eq 'con_lost') {      }
         my $spares='';  
  my $last;      my $ukey='';
         foreach my $hostid (sort      for (0..7) {
     {          $ukey.=$hexstr[rand(15)];
  &Apache::lonnet::hostname($a) cmp      }
     &Apache::lonnet::hostname($b);  
     }      my $lextkey=hex($lkey);
     keys(%Apache::lonnet::spareid)) {      if ($lextkey>2147483647) { $lextkey-=4294967296; }
             next if ($hostid eq $lonhost);  
     my $hostname = &Apache::lonnet::hostname($hostid);      my $uextkey=hex($ukey);
     next if ($last eq $hostname);      if ($uextkey>2147483647) { $uextkey-=4294967296; }
             $spares.='<br /><font size="+1"><a href="http://'.  
                 $hostname.  # -------------------------------------------------------- Store away log token
                 '/adm/login?domain='.$authdomain.'">'.      my $tokenextras;
                 $hostname.'</a>'.      if ($env{'form.role'}) {
                 ' '.&mt('(preferred)').'</font>'.$/;          $tokenextras = '&role='.&escape($env{'form.role'});
     $last=$hostname;      }
         }      if ($env{'form.symb'}) {
 $spares.= '<br />';          if (!$tokenextras) {
 my %all_hostnames = &Apache::lonnet::all_hostnames();              $tokenextras = '&';
 foreach my $hostid (sort          }
     {          $tokenextras .= '&symb='.&escape($env{'form.symb'});
  &Apache::lonnet::hostname($a) cmp      }
     &Apache::lonnet::hostname($b);      my $logtoken=Apache::lonnet::reply(
     }         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
     keys(%all_hostnames)) {         $lonhost);
     next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});  
     my $hostname = &Apache::lonnet::hostname($hostid);  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
     next if ($last eq $hostname);  #    we are in serious trouble
     $spares.='<br /><a href="http://'.  
  $hostname.      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
  '/adm/login?domain='.$authdomain.'">'.          if ($logtoken eq 'no_such_host') {
  $hostname.'</a>';              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
     $last=$hostname;          }
 }          my $spares='';
 $r->print(   my $last;
    '<html>'          foreach my $hostid (sort
   .'<head><title>'      {
   .&mt('The LearningOnline Network with CAPA')   &Apache::lonnet::hostname($a) cmp
   .'</title></head>'      &Apache::lonnet::hostname($b);
   .'<body bgcolor="#FFFFFF">'      }
   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'      keys(%Apache::lonnet::spareid)) {
   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'              next if ($hostid eq $lonhost);
   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>'      my $hostname = &Apache::lonnet::hostname($hostid);
   .'<p>'.&mt('Please attempt to login to one of the following servers:').'</p>'      next if (($last eq $hostname) || ($hostname eq ''));
   .$spares              $spares.='<br /><font size="+1"><a href="http://'.
   .'</body>'                  $hostname.
   .'</html>'                  '/adm/login?domain='.$authdomain.'">'.
 );                  $hostname.'</a>'.
 return OK;                  ' '.&mt('(preferred)').'</font>'.$/;
 }      $last=$hostname;
           }
 # ----------------------------------------------- Apparently we are in business          if ($spares) {
 $servadm=~s/\,/\<br \/\>/g;              $spares.= '<br />';
           }
 # ----------------------------------------------------------- Front page design          my %all_hostnames = &Apache::lonnet::all_hostnames();
 my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);          foreach my $hostid (sort
 my $font=&Apache::loncommon::designparm('login.font',$domain);      {
 my $link=&Apache::loncommon::designparm('login.link',$domain);   &Apache::lonnet::hostname($a) cmp
 my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);      &Apache::lonnet::hostname($b);
 my $alink=&Apache::loncommon::designparm('login.alink',$domain);      }
 my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);      keys(%all_hostnames)) {
 my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
 my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);              my $hostname = &Apache::lonnet::hostname($hostid);
 my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);              next if (($last eq $hostname) || ($hostname eq ''));
 my $logo=&Apache::loncommon::designparm('login.logo',$domain);              $spares.='<br /><a href="http://'.
 my $img=&Apache::loncommon::designparm('login.img',$domain);               $hostname.
 my $domainlogo=&Apache::loncommon::domainlogo($domain);               '/adm/login?domain='.$authdomain.'">'.
 my $showbanner = 1;               $hostname.'</a>';
 my $showmainlogo = 1;              $last=$hostname;
 if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {           }
     $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);           $r->print(
 }     '<html>'
 if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {    .'<head><title>'
     $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);    .&mt('The LearningOnline Network with CAPA')
 }    .'</title></head>'
 my $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);    .'<body bgcolor="#FFFFFF">'
 my $showcoursecat =    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
 &Apache::loncommon::designparm('login.coursecatalog',$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);
       }
 function enableInput() {      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
     this.document.client.elements.upass$now.removeAttribute("readOnly");          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
     this.document.client.elements.uname.removeAttribute("readOnly");      }
     this.document.client.elements.udom.removeAttribute("readOnly");      my $showadminmail;
     return;      my @possdoms = &Apache::lonnet::current_machine_domains();
 }      if (grep(/^\Q$domain\E$/,@possdoms)) {
           $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
 // ]]>      }
 </script>      my $showcoursecat =
           &Apache::loncommon::designparm('login.coursecatalog',$domain);
 ENDSCRIPT      my $shownewuserlink =
           &Apache::loncommon::designparm('login.newuser',$domain);
 # --------------------------------------------------- Print login screen header      my $showhelpdesk =
           &Apache::loncommon::designparm('login.helpdesk',$domain);
 my %add_entries = (      my $now=time;
        bgcolor      => "$mainbg",      my $js = (<<ENDSCRIPT);
        text         => "$font",  
        link         => "$link",  <script type="text/javascript" language="JavaScript">
        vlink        => "$vlink",  // <![CDATA[
        alink        => "$alink",  function send()
                onload       => 'javascript:enableInput();',);  {
   this.document.server.elements.uname.value
 $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,  =this.document.client.elements.uname.value;
        { 'redirect'       => [$expire,'/adm/roles'],   
  'add_entries' => \%add_entries,  this.document.server.elements.udom.value
  'only_body'   => 1,}));  =this.document.client.elements.udom.value;
   
 # ----------------------------------------------------------------------- Texts  uextkey=this.document.client.elements.uextkey.value;
   lextkey=this.document.client.elements.lextkey.value;
 my %lt=&Apache::lonlocal::texthash(  initkeys();
           'un'       => 'Username',  
           'pw'       => 'Password',  this.document.server.elements.upass0.value
           'dom'      => 'Domain',      =this.document.client.elements.upass$now.value.substr(0,15);
           'perc'     => 'percent',  this.document.server.elements.upass1.value
           'load'     => 'Server Load',      =this.document.client.elements.upass$now.value.substr(15,15);
           'userload' => 'User Load',  this.document.server.elements.upass2.value
           'catalog'  => 'Course/Community Catalog',      =this.document.client.elements.upass$now.value.substr(30,15);
           'log'      => 'Log in',  
           'help'     => 'Log-in Help',  if(this.document.server.action.substr(0,5) === 'http:'){
           'serv'     => 'Server',      for (var idx in [1,2,3]){
           'servadm'  => 'Server Administration',          this.document.server.elements['upass' + idx].value =
           'helpdesk' => 'Contact Helpdesk',              crypted(this.document.server.elements['upass' + idx].value);
           'forgotpw' => 'Forgot password?',      }
           'newuser'  => 'New User?',  }
        );  
 # -------------------------------------------------- Change password field name  this.document.client.elements.uname.value='';
   this.document.client.elements.upass$now.value='';
 my $forgotpw = &forgotpwdisplay(%lt);  
 $forgotpw .= '<br />' if $forgotpw;  this.document.server.submit();
 my $loginhelp = &loginhelpdisplay($authdomain,%lt);  return false;
 $loginhelp .= '<br />' if $loginhelp;  }
   
 # ---------------------------------------------------- Serve out DES JavaScript  function enableInput() {
 {      this.document.client.elements.upass$now.removeAttribute("readOnly");
 my $jsh=Apache::File->new($include."/londes.js");      this.document.client.elements.uname.removeAttribute("readOnly");
 $r->print(<$jsh>);      this.document.client.elements.udom.removeAttribute("readOnly");
 }      return;
 # ---------------------------------------------------------- Serve rest of page  }
   
 $r->print(  // ]]>
     '<div class="LC_Box"'  </script>
    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'  
 );  ENDSCRIPT
   
 #  # --------------------------------------------------- Print login screen header
 #  If the loadbalancing yielded just http:// because perhaps there's no loadbalancing?  
 #  then just us a relative link to authenticate:      my %add_entries = (
 #         bgcolor      => "$mainbg",
          text         => "$font",
 $r->print(<<ENDSERVERFORM);         link         => "$link",
 <form name="server" action="/adm/authenticate" method="post" target="_top">         vlink        => "$vlink",
    <input type="hidden" name="logtoken" value="$logtoken" />         alink        => "$alink",
    <input type="hidden" name="serverid" value="$lonhost" />                 onload       => 'javascript:enableInput();',);
    <input type="hidden" name="uname" value="" />  
    <input type="hidden" name="upass0" value="" />      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
    <input type="hidden" name="upass1" value="" />         { 'redirect'       => [$expire,'/adm/roles'],
    <input type="hidden" name="upass2" value="" />   'add_entries' => \%add_entries,
    <input type="hidden" name="udom" value="" />   'only_body'   => 1,}));
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />  
    <input type="hidden" name="localres" value="$env{'form.localres'}" />  # ----------------------------------------------------------------------- Texts
   </form>  
 ENDSERVERFORM      my %lt=&Apache::lonlocal::texthash(
 my $coursecatalog;            'un'       => 'Username',
 if (($showcoursecat eq '') || ($showcoursecat)) {            'pw'       => 'Password',
     $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';            'dom'      => 'Domain',
 }            'perc'     => 'percent',
 my $newuserlink;            'load'     => 'Server Load',
 if ($shownewuserlink) {            'userload' => 'User Load',
     $newuserlink = &newuser_link($lt{'newuser'}).'<br />';            'catalog'  => 'Course/Community Catalog',
 }            'log'      => 'Log in',
 my $logintitle =            'help'     => 'Log-in Help',
     '<h2 class="LC_hcell"'            'serv'     => 'Server',
    .' style="background:'.$loginbox_header_bgcol.';'            'servadm'  => 'Server Administration',
    .' color:'.$loginbox_header_textcol.'">'            'helpdesk' => 'Contact Helpdesk',
    .$lt{'log'}            'forgotpw' => 'Forgot password?',
    .'</h2>';            'newuser'  => 'New User?',
          );
 my $noscript_warning='<noscript><span class="LC_warning"><b>'  # -------------------------------------------------- Change password field name
                      .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')  
                     .'</b></span></noscript>';      my $forgotpw = &forgotpwdisplay(%lt);
 my $helpdeskscript;      $forgotpw .= '<br />' if $forgotpw;
 my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
                                    $authdomain,\$helpdeskscript);      if ($loginhelp) {
           $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
 my $loginform=(<<LFORM);      }
 <form name="client" action="" onsubmit="return(send())">  
   <input type="hidden" name="lextkey" value="$lextkey" />  # ---------------------------------------------------- Serve out DES JavaScript
   <input type="hidden" name="uextkey" value="$uextkey" />      {
   <b><label for="uname">$lt{'un'}</label>:</b><br />      my $jsh=Apache::File->new($include."/londes.js");
   <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" /><br />      $r->print(<$jsh>);
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />      }
   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />  # ---------------------------------------------------------- Serve rest of page
   <b><label for="udom">$lt{'dom'}</label>:</b><br />  
   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" /><br />      $r->print(
   <input type="submit" value="$lt{'log'}" />      '<div class="LC_Box"'
 </form>     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
 LFORM  );
   
     if ($showbanner) {      $r->print(<<ENDSERVERFORM);
         $r->print(<<HEADER);  <form name="server" action="/adm/authenticate" method="post" target="_top">
 <!-- The LON-CAPA Header -->     <input type="hidden" name="logtoken" value="$logtoken" />
 <div style="background:$pgbg;margin:0;width:100%;">     <input type="hidden" name="serverid" value="$lonhost" />
   <img src="$img" border="0" alt="The Learning Online Network with CAPA" />     <input type="hidden" name="uname" value="" />
 </div>     <input type="hidden" name="upass0" value="" />
 HEADER     <input type="hidden" name="upass1" value="" />
     }     <input type="hidden" name="upass2" value="" />
     $r->print(<<ENDTOP);     <input type="hidden" name="udom" value="" />
 <div style="float:left;margin-top:0;">     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
 <div class="LC_Box" style="background:$loginbox_bg;">     <input type="hidden" name="localres" value="$env{'form.localres'}" />
   $logintitle    </form>
   $loginform  ENDSERVERFORM
   $noscript_warning      my $coursecatalog;
 </div>      if (($showcoursecat eq '') || ($showcoursecat)) {
             $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
 <div class="LC_Box" style="padding-top: 10px;">      }
   $loginhelp      my $newuserlink;
   $forgotpw      if ($shownewuserlink) {
   $contactblock          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
   $newuserlink      }
   $coursecatalog      my $logintitle =
 </div>          '<h2 class="LC_hcell"'
 </div>         .' style="background:'.$loginbox_header_bgcol.';'
          .' color:'.$loginbox_header_textcol.'">'
 <div>         .$lt{'log'}
 ENDTOP         .'</h2>';
     if ($showmainlogo) {  
         $r->print(' <img src="'.$logo.'" alt="" />'."\n");      my $noscript_warning='<noscript><span class="LC_warning"><b>'
     }                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
 $r->print(<<ENDTOP);                          .'</b></span></noscript>';
 $announcements      my $helpdeskscript;
 </div>      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
 <hr style="clear:both;" />                                         $authdomain,\$helpdeskscript,
 ENDTOP                                         $showhelpdesk,\@possdoms);
   
 $r->print(<<ENDDOCUMENT);      my $mobileargs;
     <div style="float: left;">      if ($clientmobile) {
      <table border="0" cellspacing="0" cellpadding="0">          $mobileargs = 'autocapitalize="off" autocorrect="off"';
       <tr>      }
        <td  align="left" valign="top">      my $loginform=(<<LFORM);
         <small><b>$lt{'dom'}:&nbsp;</b></small>  <form name="client" action="" onsubmit="return(send())">
        </td>    <input type="hidden" name="lextkey" value="$lextkey" />
        <td  align="left" valign="top">    <input type="hidden" name="uextkey" value="$uextkey" />
         <small><tt>&nbsp;$domain</tt></small>    <b><label for="uname">$lt{'un'}</label>:</b><br />
        </td>    <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
       </tr>    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
       <tr>    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
        <td  align="left" valign="top">    <b><label for="udom">$lt{'dom'}</label>:</b><br />
         <small><b>$lt{'serv'}:&nbsp;</b></small>    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
        </td>    <input type="submit" value="$lt{'log'}" />
        <td align="left" valign="top">  </form>
         <small><tt>&nbsp;$lonhost ($role)</tt></small>  LFORM
        </td>  
       </tr>      if ($showbanner) {
       <tr>          $r->print(<<HEADER);
        <td align="left" valign="top">  <!-- The LON-CAPA Header -->
         <small><b>$lt{'load'}:&nbsp;</b></small>  <div style="background:$pgbg;margin:0;width:100%;">
        </td>    <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
        <td align="left" valign="top">  </div>
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>  HEADER
        </td>      }
       </tr>      $r->print(<<ENDTOP);
       <tr>  <div style="float:left;margin-top:0;">
        <td align="left" valign="top">  <div class="LC_Box" style="background:$loginbox_bg;">
         <small><b>$lt{'userload'}:&nbsp;</b></small>    $logintitle
        </td>    $loginform
        <td align="left" valign="top">    $noscript_warning
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>  </div>
        </td>   
       </tr>  <div class="LC_Box" style="padding-top: 10px;">
       <tr>    $loginhelp
        <td colspan="2" align="left">    $forgotpw
         <small>$version</small>    $contactblock
        </td>    $newuserlink
       </tr>    $coursecatalog
      </table>  </div>
     </div>  </div>
     <div style="float: right;">  
     $domainlogo  <div>
     </div>  ENDTOP
     <br style="clear:both;" />      if ($showmainlogo) {
  </div>          $r->print(' <img src="'.$logo.'" alt="" />'."\n");
       }
 <script type="text/javascript">  $r->print(<<ENDTOP);
 // <![CDATA[  $announcements
 // the if prevents the script error if the browser can not handle this  </div>
 if ( document.client.uname ) { document.client.uname.focus(); }  <hr style="clear:both;" />
 // ]]>  ENDTOP
 </script>      my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
 $helpdeskscript      $domainrow = <<"END";
         <tr>
 ENDDOCUMENT         <td  align="left" valign="top">
     my %endargs = ( 'noredirectlink' => 1, );          <small><b>$lt{'dom'}:&nbsp;</b></small>
     $r->print(&Apache::loncommon::end_page(\%endargs));         </td>
     return OK;         <td  align="left" valign="top">
 }          <small><tt>&nbsp;$domain</tt></small>
          </td>
 sub check_loginvia {        </tr>
     my ($domain,$lonhost) = @_;  END
     if ($domain eq '' || $lonhost eq '') {      $serverrow = <<"END";
         return;        <tr>
     }         <td  align="left" valign="top">
     my %domconfhash = &Apache::loncommon::get_domainconf($domain);          <small><b>$lt{'serv'}:&nbsp;</b></small>
     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};         </td>
     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};         <td align="left" valign="top">
     my $output;          <small><tt>&nbsp;$lonhost ($role)</tt></small>
     if ($loginvia ne '') {         </td>
         my $noredirect;        </tr>
         my $ip = $ENV{'REMOTE_ADDR'};  END
         if ($ip eq '127.0.0.1') {      if ($loadlim) {
             $noredirect = 1;          $loadrow = <<"END";
         } else {        <tr>
             if ($loginvia_exempt ne '') {         <td align="left" valign="top">
                 my @exempt = split(',',$loginvia_exempt);          <small><b>$lt{'load'}:&nbsp;</b></small>
                 if (grep(/^\Q$ip\E$/,@exempt)) {         </td>
                     $noredirect = 1;         <td align="left" valign="top">
                 }          <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
             }         </td>
         }        </tr>
         unless ($noredirect) {  END
             my ($newhost,$path);      }
             if ($loginvia =~ /:/) {      if ($uloadlim) {
                 ($newhost,$path) = split(':',$loginvia);          $userloadrow = <<"END";
             } else {        <tr>
                 $newhost = $loginvia;         <td align="left" valign="top">
             }          <small><b>$lt{'userload'}:&nbsp;</b></small>
             if ($newhost ne $lonhost) {         </td>
                 if (&Apache::lonnet::hostname($newhost) ne '') {         <td align="left" valign="top">
                     $output = &redirect_page($newhost,$path);          <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
                 }         </td>
             }        </tr>
         }  END
     }      }
     return $output;      if (($version ne '') && ($version ne '<!-- VERSION -->')) {
 }          $versionrow = <<"END";
         <tr>
 sub redirect_page {         <td colspan="2" align="left">
     my ($desthost,$path) = @_;          <small>$version</small>
     my $protocol = $Apache::lonnet::protocol{$desthost};         </td>
     $protocol = 'http' if ($protocol ne 'https');        </tr>
     unless ($path =~ m{^/}) {  END
         $path = '/'.$path;      }
     }  
     my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;      $r->print(<<ENDDOCUMENT);
     if ($env{'form.firsturl'} ne '') {      <div style="float: left;">
         $url .='?firsturl='.$env{'form.firsturl'};       <table border="0" cellspacing="0" cellpadding="0">
     }  $domainrow
     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,  $serverrow
                                                     {'redirect' => [0,$url],});  $loadrow    
     my $end_page   = &Apache::loncommon::end_page();  $userloadrow
     return $start_page.$end_page;  $versionrow
 }       </table>
       </div>
 sub contactdisplay {      <div style="float: right;">
     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript) = @_;      $domainlogo
     my $contactblock;      </div>
     my $showhelpdesk = 0;      <br style="clear:both;" />
     my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};   </div>
     if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {  
         $showhelpdesk = 1;  <script type="text/javascript">
     }  // <![CDATA[
     if ($servadm && $showadminmail) {  // the if prevents the script error if the browser can not handle this
         $contactblock .= $$lt{'servadm'}.':<br />'.  if ( document.client.uname ) { document.client.uname.focus(); }
                          '<tt>'.$servadm.'</tt><br />';  // ]]>
     }  </script>
     if ($showhelpdesk) {  $helpdeskscript
         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';  
         my $thisurl = &escape('/adm/login');  ENDDOCUMENT
         $$helpdeskscript = <<"ENDSCRIPT";      my %endargs = ( 'noredirectlink' => 1, );
 <script type="text/javascript">      $r->print(&Apache::loncommon::end_page(\%endargs));
 // <![CDATA[      return OK;
 function helpdesk() {  }
     var codedom = document.client.udom.value;  
     if (codedom == '') {  sub check_loginvia {
         codedom = "$authdomain";      my ($domain,$lonhost) = @_;
     }      if ($domain eq '' || $lonhost eq '') {
     var querystr = "origurl=$thisurl&codedom="+codedom;          return;
     document.location.href = "/adm/helpdesk?"+querystr;      }
     return;      my %domconfhash = &Apache::loncommon::get_domainconf($domain);
 }      my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
 // ]]>      my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
 </script>      my $output;
 ENDSCRIPT      if ($loginvia ne '') {
     }          my $noredirect;
     return $contactblock;          my $ip = $ENV{'REMOTE_ADDR'};
 }          if ($ip eq '127.0.0.1') {
               $noredirect = 1;
 sub forgotpwdisplay {          } else {
     my (%lt) = @_;              if ($loginvia_exempt ne '') {
     my $prompt_for_resetpw = 1;                   my @exempt = split(',',$loginvia_exempt);
     if ($prompt_for_resetpw) {                  if (grep(/^\Q$ip\E$/,@exempt)) {
         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';                      $noredirect = 1;
     }                  }
     return;              }
 }          }
           unless ($noredirect) {
 sub loginhelpdisplay {              my ($newhost,$path);
     my ($authdomain,%lt) = @_;              if ($loginvia =~ /:/) {
     my $login_help = 1;                  ($newhost,$path) = split(':',$loginvia);
     if ($login_help) {              } else {
         my $dom = $authdomain;                  $newhost = $loginvia;
         if ($dom eq '') {              }
             $dom = &Apache::lonnet::default_login_domain();              if ($newhost ne $lonhost) {
         }                  if (&Apache::lonnet::hostname($newhost) ne '') {
         my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);                      $output = &redirect_page($newhost,$path);
         my $loginhelp_url = $helpconfig{'helpsettings'}{'loginhelpurl'};                  }
         if ($loginhelp_url ne '') {              }
             return '<a href="'.$loginhelp_url.'">'.$lt{'help'}.'</a>';          }
         } else {      }
             return '<a href="/adm/loginproblems.html">'.$lt{'help'}.'</a>';      return $output;
         }  }
     }  
     return;  sub redirect_page {
 }      my ($desthost,$path) = @_;
       my $protocol = $Apache::lonnet::protocol{$desthost};
 sub coursecatalog_link {      $protocol = 'http' if ($protocol ne 'https');
     my ($linkname) = @_;      unless ($path =~ m{^/}) {
     return <<"END";          $path = '/'.$path;
       <a href="/adm/coursecatalog">$linkname</a>      }
 END      my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
 }      if ($env{'form.firsturl'} ne '') {
           $url .='?firsturl='.$env{'form.firsturl'};
 sub newuser_link {      }
     my ($linkname) = @_;      my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
     return '<a href="/adm/createaccount">'.$linkname.'</a>';                                                      {'redirect' => [0,$url],});
 }      my $end_page   = &Apache::loncommon::end_page();
       return $start_page.$end_page;
 1;  }
 __END__  
   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.146  
changed lines
  Added in v.1.160


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