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

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


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