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

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

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


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