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

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


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