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

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


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