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

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


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