Diff for /loncom/auth/lonlogin.pm between versions 1.124 and 1.172

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


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