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

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


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