Diff for /loncom/auth/lonlogin.pm between versions 1.123 and 1.171

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


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