Diff for /loncom/auth/lonlogin.pm between versions 1.114 and 1.165

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

Removed from v.1.114  
changed lines
  Added in v.1.165


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