Diff for /loncom/auth/lonlogin.pm between versions 1.132 and 1.170

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


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