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

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

Removed from v.1.109  
changed lines
  Added in v.1.170


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