Diff for /loncom/auth/lonlogin.pm between versions 1.127 and 1.169

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


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