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

version 1.110, 2008/12/03 13:07:15 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 $textcol =           if ($logtoken eq 'no_such_host') {
 ($fullgraph?&Apache::loncommon::designparm('login.textcol',$domain):'#000000');              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
 my $bgcol =          }
 ($fullgraph?&Apache::loncommon::designparm('login.bgcol',$domain):'#FFFFFF');          my $spares='';
 my $logo=&Apache::loncommon::designparm('login.logo',$domain);   my $last;
 my $img=&Apache::loncommon::designparm('login.img',$domain);          foreach my $hostid (sort
 my $domainlogo=&Apache::loncommon::domainlogo($domain);      {
 my $login=&Apache::loncommon::designparm('login.login',$domain);   &Apache::lonnet::hostname($a) cmp
 if ($login eq '') {      &Apache::lonnet::hostname($b);
 $login = $iconpath.'/'.&mt('userauthentication.gif');      }
 }      keys(%Apache::lonnet::spareid)) {
 my $showbanner = 1;              next if ($hostid eq $lonhost);
 my $showmainlogo = 1;      my $hostname = &Apache::lonnet::hostname($hostid);
 if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {      next if (($last eq $hostname) || ($hostname eq ''));
     $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);              $spares.='<br /><font size="+1"><a href="http://'.
 }                  $hostname.
 if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {                  '/adm/login?domain='.$authdomain.'">'.
     $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);                  $hostname.'</a>'.
 }                  ' '.&mt('(preferred)').'</font>'.$/;
 my $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);      $last=$hostname;
 my $showcoursecat =          }
 &Apache::loncommon::designparm('login.coursecatalog',$domain);          if ($spares) {
 my $loginheader =&Apache::loncommon::designparm('login.loginheader',$domain);              $spares.= '<br />';
 my $shownewuserlink =           }
 &Apache::loncommon::designparm('login.newuser',$domain);          my %all_hostnames = &Apache::lonnet::all_hostnames();
 my $now=time;          foreach my $hostid (sort
 my $js = (<<ENDSCRIPT);      {
    &Apache::lonnet::hostname($a) cmp
 <script language="JavaScript">      &Apache::lonnet::hostname($b);
 function send()      }
 {      keys(%all_hostnames)) {
 this.document.server.elements.uname.value              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
 =this.document.client.elements.uname.value;              my $hostname = &Apache::lonnet::hostname($hostid);
               next if (($last eq $hostname) || ($hostname eq ''));
 this.document.server.elements.udom.value              $spares.='<br /><a href="http://'.
 =this.document.client.elements.udom.value;               $hostname.
                '/adm/login?domain='.$authdomain.'">'.
 uextkey=this.document.client.elements.uextkey.value;               $hostname.'</a>';
 lextkey=this.document.client.elements.lextkey.value;              $last=$hostname;
 initkeys();           }
            $r->print(
 this.document.server.elements.upass0.value     '<html>'
     =crypted(this.document.client.elements.upass$now.value.substr(0,15));    .'<head><title>'
 this.document.server.elements.upass1.value    .&mt('The LearningOnline Network with CAPA')
     =crypted(this.document.client.elements.upass$now.value.substr(15,15));    .'</title></head>'
 this.document.server.elements.upass2.value    .'<body bgcolor="#FFFFFF">'
     =crypted(this.document.client.elements.upass$now.value.substr(30,15));    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
     .'<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>');
 this.document.client.elements.upass$now.value='';          if ($spares) {
               $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
 this.document.server.submit();                       .'</p>'
 return false;                       .$spares);
 }          }
 </script>          $r->print('</body>'
                    .'</html>'
 ENDSCRIPT          );
           return OK;
 # --------------------------------------------------- Print login screen header      }
   
 my %add_entries = (topmargin    => "0",  # ----------------------------------------------- Apparently we are in business
        leftmargin   => "0",      $servadm=~s/\,/\<br \/\>/g;
        marginheight => "0",  
        marginwidth  => "0",  # ----------------------------------------------------------- Front page design
        bgcolor      => "$mainbg",      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
        text         => "$font",      my $font=&Apache::loncommon::designparm('login.font',$domain);
        link         => "$link",      my $link=&Apache::loncommon::designparm('login.link',$domain);
        vlink        => "$vlink",      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
        alink        => "$alink",);      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
       my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
 $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
        { 'redirect'       => [$expire,'/adm/roles'],       my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
  'add_entries' => \%add_entries,      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
  'only_body'   => 1,}));      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
       my $img=&Apache::loncommon::designparm('login.img',$domain);
 # ----------------------------------------------------------------------- Texts      my $domainlogo=&Apache::loncommon::domainlogo($domain);
       my $showbanner = 1;
 my %lt=&Apache::lonlocal::texthash(      my $showmainlogo = 1;
   'un'  => 'Username',      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
   'pw'  => 'Password',          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
   'dom' => 'Domain',      }
   'perc' => 'percent',      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
   'load' => 'Server Load',          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
   'userload' => 'User Load',      }
   'about'  => 'About LON-CAPA',      my $showadminmail;
   'catalog' => 'Course Catalog',      my @possdoms = &Apache::lonnet::current_machine_domains();
   'log' => 'Log in',      if (grep(/^\Q$domain\E$/,@possdoms)) {
   'help' => 'Log-in Help',          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
   'serv' => 'Server',      }
   'servadm' => 'Server Administration',      my $showcoursecat =
   'helpdesk' => 'Contact Helpdesk',          &Apache::loncommon::designparm('login.coursecatalog',$domain);
   'forgotpw' => 'Forgot password?',      my $shownewuserlink =
   'newuser'  => 'New User?',          &Apache::loncommon::designparm('login.newuser',$domain);
   'options_headline' => 'Select Accessibility Options',      my $showhelpdesk =
   'sprs_img' => 'Suppress rendering of images',          &Apache::loncommon::designparm('login.helpdesk',$domain);
   'sprs_applet' => 'Suppress Java applets',      my $now=time;
   'sprs_embed' => 'Suppress rendering of embedded multimedia',      my $js = (<<ENDSCRIPT);
   'sprs_font' => 'Increase font size',  
   'sprs_blackwhite' => 'Switch to black and white mode',  <script type="text/javascript" language="JavaScript">
   'remember' => 'Remember these settings for next login');  // <![CDATA[
 # -------------------------------------------------- Change password field name  function send()
 my $forgotpw = &forgotpwdisplay(%lt);  {
 my $loginhelp = &loginhelpdisplay(%lt);  this.document.server.elements.uname.value
   =this.document.client.elements.uname.value;
 # ---------------------------------------------------- Serve out DES JavaScript  
 {  this.document.server.elements.udom.value
 my $jsh=Apache::File->new($include."/londes.js");  =this.document.client.elements.udom.value;
 $r->print(<$jsh>);  
 }  uextkey=this.document.client.elements.uextkey.value;
 # ---------------------------------------------------------- Serve rest of page  lextkey=this.document.client.elements.lextkey.value;
   initkeys();
 if ($fullgraph) {  
 $r->print(  if(this.document.server.action.substr(0,5) === 'http:'){
   '<div class="LC_loginpage_container">');      this.document.server.elements.upass0.value
 }          =getCrypted(this.document.client.elements.upass$now.value);
   } else {
 $r->print(<<ENDSERVERFORM);      this.document.server.elements.upass0.value
 <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">          =this.document.client.elements.upass$now.value;
    <input type="hidden" name="logtoken" value="$logtoken" />  }
    <input type="hidden" name="serverid" value="$lonhost" />  
    <input type="hidden" name="uname" value="" />  this.document.client.elements.uname.value='';
    <input type="hidden" name="upass0" value="" />  this.document.client.elements.upass$now.value='';
    <input type="hidden" name="upass1" value="" />  
    <input type="hidden" name="upass2" value="" />  this.document.server.submit();
    <input type="hidden" name="udom" value="" />  return false;
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />  }
    <input type="hidden" name="localres" value="$env{'form.localres'}" />  
   </form>  function enableInput() {
 ENDSERVERFORM      this.document.client.elements.upass$now.removeAttribute("readOnly");
 my $coursecatalog;      this.document.client.elements.uname.removeAttribute("readOnly");
 if (($showcoursecat eq '') || ($showcoursecat)) {      this.document.client.elements.udom.removeAttribute("readOnly");
     $coursecatalog = &coursecatalog_link($lt{'catalog'});      return;
 }  }
 my $newuserlink;  
 if ($shownewuserlink) {  // ]]>
     $newuserlink = &newuser_link($lt{'newuser'});  </script>
 }  
 my $logintitle;  ENDSCRIPT
 if ($loginheader eq 'text') {  
     $logintitle = $lt{'log'};  # --------------------------------------------------- Print login screen header
 } else {  
     $logintitle = '<img src="'.$login.'" alt="'.      my %add_entries = (
                   &mt('User Authentication').'" />';         bgcolor      => "$mainbg",
 }         text         => "$font",
          link         => "$link",
 my $noscript_warning='<noscript><span class="LC_warning"><b>'         vlink        => "$vlink",
                      .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')         alink        => "$alink",
                     .'</b></span></noscript>';                 onload       => 'javascript:enableInput();',);
 my $helpdeskscript;  
 my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
                             $version,$authdomain,\$helpdeskscript);      @hosts = &Apache::lonnet::current_machine_ids();
       $lonhost_in_use = $lonhost;
 my $loginform=(<<LFORM);      if (@hosts > 1) {
 <form name="client" onsubmit="return(send())">          foreach my $hostid (@hosts) {
   <input type="hidden" name="lextkey" value="$lextkey">              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
   <input type="hidden" name="uextkey" value="$uextkey">                  $lonhost_in_use = $hostid;
   <b><label for="uname">$lt{'un'}</label>:</b><br />                  last;
   <input type="text" name="uname" size="10" value="$authusername" /><br />              }
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />          }
   <input type="password" name="upass$now" size="10" /><br />      }
   <b><label for="udom">$lt{'dom'}</label>:</b><br />      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
   <input type="text" name="udom" size="10" value="$authdomain" /><br />      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
   <input type="submit" value="$lt{'log'}" />      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
 </form>      if ($headextra) {
 LFORM          my $omitextra;
           if ($headextra_exempt ne '') {
 if ($fullgraph) {              my @exempt = split(',',$headextra_exempt);
     if ($showbanner) {              my $ip = $ENV{'REMOTE_ADDR'};
         $r->print(<<HEADER);              if (grep(/^\Q$ip\E$/,@exempt)) {
 <!-- The LON-CAPA Header -->                  $omitextra = 1;
 <table border="0" align="left" width="100%" cellspacing="0" cellpadding="1">              }
  <tr>          }
   <td align="left" valign="top" bgcolor="$pgbg">          unless ($omitextra) {
       <img src="$img" border=0 alt="The Learning Online Network with CAPA" />              my $confname = $defdom.'-domainconfig';
   </td>              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
  </tr>                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
 </table>                  unless ($extra eq '-1') {
 HEADER                      $js .= "\n".$extra."\n";
     }                  }
     if ($showmainlogo) {              }
         $r->print('<div class="LC_loginpage_space">&nbsp;</div>'."\n".          }
                   '    <img src="'.$logo.'" alt="" />'."\n");      }
     }  
     $r->print(<<ENDTOP);      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
 <div class="LC_loginpage_loginContainer">         { 'redirect'       => [$expire,'/adm/roles'],
  <fieldset class="LC_loginpage_fieldset">   'add_entries' => \%add_entries,
   <legend class="LC_loginpage_legend">$logintitle</legend>   'only_body'   => 1,}));
    <table border="0" align="left" cellspacing="1" cellpadding="1" width="100%">  
       <tr>  # ----------------------------------------------------------------------- Texts
       <td width="50%" align="center" valign="top">  
  $domainlogo      my %lt=&Apache::lonlocal::texthash(
    </td>            'un'       => 'Username',
    <td>            'pw'       => 'Password',
  $loginform            'dom'      => 'Domain',
            </td>            'perc'     => 'percent',
       </tr>            'load'     => 'Server Load',
    </table>              'userload' => 'User Load',
    $noscript_warning            'catalog'  => 'Course/Community Catalog',
  </fieldset>            'log'      => 'Log in',
 </div>            'help'     => 'Log-in Help',
               'serv'     => 'Server',
 <div class="LC_loginpage_loginInfo">            'servadm'  => 'Server Administration',
         $loginhelp<br />            'helpdesk' => 'Contact Helpdesk',
         $forgotpw<br /><br />            'forgotpw' => 'Forgot password?',
         $newuserlink<br />            'newuser'  => 'New User?',
         $coursecatalog<br /><br />         );
         <a href="/adm/about.html"><b>$lt{'about'}</b></a><br />  # -------------------------------------------------- Change password field name
         $helpdeskscript  
 </div>      my $forgotpw = &forgotpwdisplay(%lt);
       $forgotpw .= '<br />' if $forgotpw;
 <div class="LC_loginpage_space">&nbsp;</div>      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
 $announcements      if ($loginhelp) {
 ENDTOP          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
 }      }
   
 if($announcements){$r->print('<div class="LC_loginpage_space">&nbsp;</div>');}  # ---------------------------------------------------- Serve out DES JavaScript
       {
 if ($fullgraph) {      my $jsh=Apache::File->new($include."/londes.js");
 $r->print(<<ENDDOCUMENT);      $r->print(<$jsh>);
      <table border=0 cellspacing=0 cellpadding=0>      }
       <tr>  # ---------------------------------------------------------- Serve rest of page
        <td  align="left" valign="top">  
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'dom'}:&nbsp;</b></small>      $r->print(
        </td>      '<div class="LC_Box"'
        <td  align="left" valign="top">     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
         <small><tt>&nbsp;$domain</tt></small>  );
        </td>  
       </tr>      $r->print(<<ENDSERVERFORM);
       <tr>  <form name="server" action="/adm/authenticate" method="post" target="_top">
        <td  align="left" valign="top">     <input type="hidden" name="logtoken" value="$logtoken" />
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'serv'}:&nbsp;</b></small>     <input type="hidden" name="serverid" value="$lonhost" />
        </td>     <input type="hidden" name="uname" value="" />
        <td align="left" valign="top">     <input type="hidden" name="upass0" value="" />
         <small><tt>&nbsp;$lonhost ($role)</tt></small>     <input type="hidden" name="udom" value="" />
        </td>     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
       </tr>     <input type="hidden" name="localres" value="$env{'form.localres'}" />
       <tr>    </form>
        <td align="left" valign="top">  ENDSERVERFORM
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'load'}:&nbsp;</b></small>      my $coursecatalog;
        </td>      if (($showcoursecat eq '') || ($showcoursecat)) {
        <td align="left" valign="top">          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>      }
        </td>      my $newuserlink;
       </tr>      if ($shownewuserlink) {
       <tr>          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
        <td align="left" valign="top">      }
         <small><b>&nbsp;&nbsp;&nbsp;$lt{'userload'}:&nbsp;</b></small>      my $logintitle =
        </td>          '<h2 class="LC_hcell"'
        <td align="left" valign="top">         .' style="background:'.$loginbox_header_bgcol.';'
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>         .' color:'.$loginbox_header_textcol.'">'
        </td>         .$lt{'log'}
       </tr>         .'</h2>';
      </table>  
            my $noscript_warning='<noscript><span class="LC_warning"><b>'
     $contactblock                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
                           .'</b></span></noscript>';
  </div>      my $helpdeskscript;
       my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
 <script type="text/javascript">                                         $authdomain,\$helpdeskscript,
 // the if prevents the script error if the browser can not handle this                                         $showhelpdesk,\@possdoms);
 if ( document.client.uname ) { document.client.uname.focus(); }  
 </script>      my $mobileargs;
 $helpdeskscript      if ($clientmobile) {
           $mobileargs = 'autocapitalize="off" autocorrect="off"';
 ENDDOCUMENT      }
 }      my $loginform=(<<LFORM);
     my %endargs = ( 'noredirectlink' => 1, );  <form name="client" action="" onsubmit="return(send())">
     $r->print(&Apache::loncommon::end_page(\%endargs));    <input type="hidden" name="lextkey" value="$lextkey" />
     return OK;    <input type="hidden" name="uextkey" value="$uextkey" />
 }    <b><label for="uname">$lt{'un'}</label>:</b><br />
     <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
 sub contactdisplay {    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
     my ($lt,$servadm,$showadminmail,$version,$authdomain,$helpdeskscript) = @_;    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
     my $contactblock;    <b><label for="udom">$lt{'dom'}</label>:</b><br />
     my $showhelpdesk = 0;    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
     my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};    <input type="submit" value="$lt{'log'}" />
     if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {  </form>
         $showhelpdesk = 1;  LFORM
     }  
     if ($servadm && $showadminmail) {      if ($showbanner) {
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;'.$$lt{'servadm'}.':</b><br />'.          $r->print(<<HEADER);
                          '<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$servadm.'</tt><br />&nbsp;<br />';  <!-- The LON-CAPA Header -->
     }  <div style="background:$pgbg;margin:0;width:100%;">
     if ($showhelpdesk) {    <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
         $contactblock .= '<b>&nbsp;&nbsp;&nbsp;<a href="javascript:helpdesk()"><font size="+1">'.$lt->{'helpdesk'}.'</font></a></b><br />';  </div>
         my $thisurl = &escape('/adm/login');  HEADER
         $$helpdeskscript = <<"ENDSCRIPT";      }
 <script type="text/javascript">      $r->print(<<ENDTOP);
 function helpdesk() {  <div style="float:left;margin-top:0;">
     var codedom = document.client.udom.value;  <div class="LC_Box" style="background:$loginbox_bg;">
     if (codedom == '') {    $logintitle
         codedom = "$authdomain";    $loginform
     }    $noscript_warning
     var querystr = "origurl=$thisurl&codedom="+codedom;  </div>
     document.location.href = "/adm/helpdesk?"+querystr;   
     return;  <div class="LC_Box" style="padding-top: 10px;">
 }    $loginhelp
 </script>    $forgotpw
 ENDSCRIPT    $contactblock
     }    $newuserlink
     $contactblock .= <<"ENDBLOCK";    $coursecatalog
      &nbsp;&nbsp;&nbsp;$version  </div>
 ENDBLOCK  </div>
     return $contactblock;  
 }  <div>
   ENDTOP
 sub forgotpwdisplay {      if ($showmainlogo) {
     my (%lt) = @_;          $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
     my $prompt_for_resetpw = 1;       }
     if ($prompt_for_resetpw) {  $r->print(<<ENDTOP);
         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';  $announcements
     }  </div>
     return;  <hr style="clear:both;" />
 }  ENDTOP
       my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
 sub loginhelpdisplay {      $domainrow = <<"END";
     my (%lt) = @_;        <tr>
     my $login_help = 1;         <td  align="left" valign="top">
     if ($login_help) {          <small><b>$lt{'dom'}:&nbsp;</b></small>
         return '<a href="/adm/loginproblems.html">'.$lt{'help'}.'</a>';         </td>
     }         <td  align="left" valign="top">
     return;          <small><tt>&nbsp;$domain</tt></small>
 }         </td>
         </tr>
 sub coursecatalog_link {  END
     my ($linkname) = @_;      $serverrow = <<"END";
     return <<"END";        <tr>
       <a href="/adm/coursecatalog">$linkname</a>         <td  align="left" valign="top">
 END          <small><b>$lt{'serv'}:&nbsp;</b></small>
 }         </td>
          <td align="left" valign="top">
 sub newuser_link {          <small><tt>&nbsp;$lonhost ($role)</tt></small>
     my ($linkname) = @_;         </td>
     return '&nbsp;&nbsp;&nbsp;<a href="/adm/createaccount"><b>'.$linkname.'</b></a><br />';        </tr>
 }  END
       if ($loadlim) {
 1;          $loadrow = <<"END";
 __END__        <tr>
          <td align="left" valign="top">
           <small><b>$lt{'load'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
          </td>
         </tr>
   END
       }
       if ($uloadlim) {
           $userloadrow = <<"END";
         <tr>
          <td align="left" valign="top">
           <small><b>$lt{'userload'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
          </td>
         </tr>
   END
       }
       if (($version ne '') && ($version ne '<!-- VERSION -->')) {
           $versionrow = <<"END";
         <tr>
          <td colspan="2" align="left">
           <small>$version</small>
          </td>
         </tr>
   END
       }
   
       $r->print(<<ENDDOCUMENT);
       <div style="float: left;">
        <table border="0" cellspacing="0" cellpadding="0">
   $domainrow
   $serverrow
   $loadrow    
   $userloadrow
   $versionrow
        </table>
       </div>
       <div style="float: right;">
       $domainlogo
       </div>
       <br style="clear:both;" />
    </div>
   
   <script type="text/javascript">
   // <![CDATA[
   // the if prevents the script error if the browser can not handle this
   if ( document.client.uname ) { document.client.uname.focus(); }
   // ]]>
   </script>
   $helpdeskscript
   
   ENDDOCUMENT
       my %endargs = ( 'noredirectlink' => 1, );
       $r->print(&Apache::loncommon::end_page(\%endargs));
       return OK;
   }
   
   sub check_loginvia {
       my ($domain,$lonhost) = @_;
       if ($domain eq '' || $lonhost eq '') {
           return;
       }
       my %domconfhash = &Apache::loncommon::get_domainconf($domain);
       my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
       my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
       my $output;
       if ($loginvia ne '') {
           my $noredirect;
           my $ip = $ENV{'REMOTE_ADDR'};
           if ($ip eq '127.0.0.1') {
               $noredirect = 1;
           } else {
               if ($loginvia_exempt ne '') {
                   my @exempt = split(',',$loginvia_exempt);
                   if (grep(/^\Q$ip\E$/,@exempt)) {
                       $noredirect = 1;
                   }
               }
           }
           unless ($noredirect) {
               my ($newhost,$path);
               if ($loginvia =~ /:/) {
                   ($newhost,$path) = split(':',$loginvia);
               } else {
                   $newhost = $loginvia;
               }
               if ($newhost ne $lonhost) {
                   if (&Apache::lonnet::hostname($newhost) ne '') {
                       $output = &redirect_page($newhost,$path);
                   }
               }
           }
       }
       return $output;
   }
   
   sub redirect_page {
       my ($desthost,$path) = @_;
       my $protocol = $Apache::lonnet::protocol{$desthost};
       $protocol = 'http' if ($protocol ne 'https');
       unless ($path =~ m{^/}) {
           $path = '/'.$path;
       }
       my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
       if ($env{'form.firsturl'} ne '') {
           $url .='?firsturl='.$env{'form.firsturl'};
       }
       my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
                                                       {'redirect' => [0,$url],});
       my $end_page   = &Apache::loncommon::end_page();
       return $start_page.$end_page;
   }
   
   sub contactdisplay {
       my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
           $possdoms) = @_;
       my $contactblock;
       my $origmail;
       if (ref($possdoms) eq 'ARRAY') {
           if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
               $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
           }
       }
       my $requestmail =
           &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
                                                    $authdomain,$origmail);
       unless ($showhelpdesk eq '0') {
           if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
               $showhelpdesk = 1;
           } else {
               $showhelpdesk = 0;
           }
       }
       if ($servadm && $showadminmail) {
           $contactblock .= $$lt{'servadm'}.':<br />'.
                            '<tt>'.$servadm.'</tt><br />';
       }
       if ($showhelpdesk) {
           $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
           my $thisurl = &escape('/adm/login');
           $$helpdeskscript = <<"ENDSCRIPT";
   <script type="text/javascript">
   // <![CDATA[
   function helpdesk() {
       var possdom = document.client.udom.value;
       var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
       if (codedom == '') {
           codedom = "$authdomain";
       }
       var querystr = "origurl=$thisurl&codedom="+codedom;
       document.location.href = "/adm/helpdesk?"+querystr;
       return;
   }
   // ]]>
   </script>
   ENDSCRIPT
       }
       return $contactblock;
   }
   
   sub forgotpwdisplay {
       my (%lt) = @_;
       my $prompt_for_resetpw = 1;
       if ($prompt_for_resetpw) {
           return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
       }
       return;
   }
   
   sub coursecatalog_link {
       my ($linkname) = @_;
       return <<"END";
         <a href="/adm/coursecatalog">$linkname</a>
   END
   }
   
   sub newuser_link {
       my ($linkname) = @_;
       return '<a href="/adm/createaccount">'.$linkname.'</a>';
   }
   
   1;
   __END__

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


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