Diff for /loncom/auth/lonlogin.pm between versions 1.31 and 1.167

version 1.31, 2003/02/04 16:03:25 version 1.167, 2016/05/03 22:27:14
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/
 #  #
 # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,  
 # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9,  package Apache::lonlogin;
 # 1/17/01 Gerd Kortemeyer  
 #  use strict;
 # 2/7/02,2/8,2/12,2/14,2/15,2/19 Josh Brunskole  use Apache::Constants qw(:common);
 #   use Apache::File ();
 # 7/10/02 Jeremy Bowers  use Apache::lonnet;
   use Apache::loncommon();
 package Apache::lonlogin;  use Apache::lonauth();
   use Apache::lonlocal;
 use strict;  use Apache::migrateuser();
 use Apache::Constants qw(:common);  use lib '/home/httpd/lib/perl/';
 use Apache::File ();  use LONCAPA;
 use Apache::lonnet();   
 use Apache::loncommon();  sub handler {
       my $r = shift;
 sub handler {  
     my $r = shift;      &Apache::loncommon::get_unprocessed_cgi
     $r->content_type('text/html');   (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
     &Apache::loncommon::no_cache($r);        $ENV{'REDIRECT_QUERY_STRING'}),
     $r->send_http_header;   ['interface','username','domain','firsturl','localpath','localres',
     return OK if $r->header_only;    'token','role','symb','iptoken']);
       if (!defined($env{'form.firsturl'})) {
           &Apache::lonacc::get_posted_cgi($r,['firsturl']);
     &Apache::loncommon::get_unprocessed_cgi      }
      ($ENV{'QUERY_STRING'},['interface','username','domain','firsturl']);  
   # -- check if they are a migrating user
     $ENV{'form.interface'}=~s/\W//g;      if (defined($env{'form.token'})) {
    return &Apache::migrateuser::handler($r);
     my $fullgraph=($ENV{'form.interface'} ne 'textual');      }
   
     my $iconpath= 'http://'.$ENV{'HTTP_HOST'}.':8080'.      &Apache::loncommon::no_cache($r);
                   $r->dir_config('lonIconsURL');      &Apache::lonlocal::get_language_handle($r);
     my $domain  = $r->dir_config('lonDefDomain');      &Apache::loncommon::content_type($r,'text/html');
     my $role    = $r->dir_config('lonRole');      $r->send_http_header;
     my $loadlim = $r->dir_config('lonLoadLim');      return OK if $r->header_only;
     my $servadm = $r->dir_config('lonAdmEMail');  
     my $sysadm  = $r->dir_config('lonSysEMail');  
     my $lonhost = $r->dir_config('lonHostID');  # Are we re-routing?
     my $tabdir  = $r->dir_config('lonTabDir');      my $londocroot = $r->dir_config('lonDocRoot');
     my $include = $r->dir_config('lonIncludes');      if (-e "$londocroot/lon-status/reroute.txt") {
    &Apache::lonauth::reroute($r);
 # --------------------------------------------- Default values for login fields   return OK;
       }
     my $authusername=($ENV{'form.username'}?$ENV{'form.username'}:'');  
     my $authdomain=($ENV{'form.domain'}?$ENV{'form.domain'}:$domain);      $env{'form.firsturl'} =~ s/(`)/'/g;
   
 # ---------------------------------------------------------- Determine own load  # -------------------------------- Prevent users from attempting to login twice
     my $loadavg;      my $handle = &Apache::lonnet::check_for_valid_session($r);
    {      if ($handle ne '') {
        my $loadfile=Apache::File->new('/proc/loadavg');          my $lonidsdir=$r->dir_config('lonIDsDir');
        $loadavg=<$loadfile>;          if ($handle=~/^publicuser\_/) {
    }  # For "public user" - remove it, we apparently really want to login
     $loadavg =~ s/\s.*//g;      unlink($r->dir_config('lonIDsDir')."/$handle.id");
     my $loadpercent=100*$loadavg/$loadlim;          } else {
   # Indeed, a valid token is found
 # ------------------------------------------------------- Do the load balancing              &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
     my $otherserver='http://'.$ENV{'SERVER_NAME'};      my $start_page =
     my $firsturl=          &Apache::loncommon::start_page('Already logged in');
     ($ENV{'request.firsturl'}?$ENV{'request.firsturl'}:$ENV{'form.firsturl'});      my $end_page =
 # ---------------------------------------- Are we access server and overloaded?          &Apache::loncommon::end_page();
     if (($role eq 'access') && ($loadpercent>100.0)) {              my $dest = '/adm/roles';
         $otherserver=Apache::lonnet::spareserver($loadpercent);              if ($env{'form.firsturl'} ne '') {
     }                  $dest = $env{'form.firsturl'};
               }
 # -------------------------------------------------------- Set login parameters      $r->print(
                     $start_page
     my @hexstr=('0','1','2','3','4','5','6','7',                   .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
                 '8','9','a','b','c','d','e','f');                   .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
     my $lkey='';                    '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
     for (0..7) {                   .$end_page
         $lkey.=$hexstr[rand(15)];                   );
     }              return OK;
           }
     my $ukey='';      }
     for (0..7) {  
         $ukey.=$hexstr[rand(15)];  # ---------------------------------------------------- No valid token, continue
     }  
   # ---------------------------- Not possible to really login to domain "public"
     my $lextkey=hex($lkey);      if ($env{'form.domain'} eq 'public') {
     if ($lextkey>2147483647) { $lextkey-=4294967296; }   $env{'form.domain'}='';
    $env{'form.username'}='';
     my $uextkey=hex($ukey);      }
     if ($uextkey>2147483647) { $uextkey-=4294967296; }  
   # ------ Is this page requested because /adm/migrateuser detected an IP change?
 # -------------------------------------------------------- Store away log token      my %sessiondata;
     my $logtoken=Apache::lonnet::reply(      if ($env{'form.iptoken'}) {
        'tmpput:'.$ukey.$lkey.'&'.$firsturl,          %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
        $lonhost);          unless ($sessiondata{'sessionserver'}) {
               my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
 # ------------------- If we cannot talk to ourselves, we are in serious trouble              delete($env{'form.iptoken'});
           }
     if ($logtoken eq 'con_lost') {      }
         my $spares='';  # ----------------------------------------------------------- Process Interface
         foreach (keys %Apache::lonnet::hostname) {      $env{'form.interface'}=~s/\W//g;
             if ($_ ne $lonhost) {  
                $spares.='<br /><a href="http://'.$Apache::lonnet::hostname{$_}.      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
  '/adm/login?domain='.$authdomain.'">'.          &Apache::loncommon::decode_user_agent();
                  $Apache::lonnet::hostname{$_}.'</a>';  
                if ($Apache::lonnet::spareid{$_}) {      my $iconpath=
    $spares.=' (preferred)';   &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                }  
    }      my $lonhost = $r->dir_config('lonHostID');
         }      my $domain = &Apache::lonnet::default_login_domain();
  $r->print(<<ENDTROUBLE);      my $defdom = $domain;
 <html>      if ($lonhost ne '') {
 <head><title>The LearningOnline Network with CAPA</title></head>          unless ($sessiondata{'sessionserver'}) {
 <body bgcolor="#FFFFFF">              my $redirect = &check_loginvia($domain,$lonhost);
 <img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />              if ($redirect) {
 <h3>This LON-CAPA server is temporarily not available for login</h3>                  $r->print($redirect);
 <p>Please attempt to login to one of the following servers:</p>$spares                  return OK;
 <p>If the problem persists, please contact <tt>$servadm</tt>.</p>              }
 </body>          }
 </html>      }
 ENDTROUBLE  
         return OK;      if (($sessiondata{'domain'}) &&
     }          (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
           $domain=$sessiondata{'domain'};
 # ----------------------------------------------- Apparently we are in business      } elsif (($env{'form.domain'}) &&
    (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
     my $domainlogo=&Apache::loncommon::domainlogo();   $domain=$env{'form.domain'};
 # --------------------------------------------------- Print login screen header      }
     $r->print(<<ENDHEADER);  
 <html>      my $role    = $r->dir_config('lonRole');
 <head>      my $loadlim = $r->dir_config('lonLoadLim');
 <title>The LearningOnline Network with CAPA Login</title>      my $uloadlim= $r->dir_config('lonUserLoadLim');
 </head>      my $servadm = $r->dir_config('lonAdmEMail');
 ENDHEADER      my $tabdir  = $r->dir_config('lonTabDir');
 # ---------------------------------------------------- Serve out DES JavaScript      my $include = $r->dir_config('lonIncludes');
     {      my $expire  = $r->dir_config('lonExpire');
  my $jsh=Apache::File->new($include."/londes.js");      my $version = $r->dir_config('lonVersion');
         $r->print(<$jsh>);      my $host_name = &Apache::lonnet::hostname($lonhost);
     }  
   # --------------------------------------------- Default values for login fields
 # ----------------------------------------------------------- Front page design     
     my $pgbg=&Apache::loncommon::designparm('login.pgbg');      my ($authusername,$authdomain);
     my $font=&Apache::loncommon::designparm('login.font');      if ($sessiondata{'username'}) {
     my $link=&Apache::loncommon::designparm('login.link');          $authusername=$sessiondata{'username'};
     my $vlink=&Apache::loncommon::designparm('login.vlink');      } else {
     my $alink=&Apache::loncommon::designparm('login.alink');          $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
     my $mainbg=&Apache::loncommon::designparm('login.mainbg');          $authusername=($env{'form.username'}?$env{'form.username'}:'');
     my $sidebg=&Apache::loncommon::designparm('login.sidebg');      }
     my $logo=&Apache::loncommon::designparm('login.logo');      if ($sessiondata{'domain'}) {
     my $img=&Apache::loncommon::designparm('login.img');          $authdomain=$sessiondata{'domain'};
       } else {
           $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
 # ---------------------------------------------------------- Serve rest of page          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
     $r->print(<<ENDSCRIPT);      }
   
 <body bgcolor="$pgbg" text="$font" link="$link" vlink="$vlink" alink="$alink"  # ---------------------------------------------------------- Determine own load
   topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>      my $loadavg;
       {
  <script language="JavaScript">   my $loadfile=Apache::File->new('/proc/loadavg');
     function send()   $loadavg=<$loadfile>;
     {      }
  this.document.server.elements.uname.value      $loadavg =~ s/\s.*//g;
        =this.document.client.elements.uname.value;  
       my ($loadpercent,$userloadpercent);
         this.document.server.elements.udom.value      if ($loadlim) {
        =this.document.client.elements.udom.value;          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
       }
         uextkey=this.document.client.elements.uextkey.value;      if ($uloadlim) {
         lextkey=this.document.client.elements.lextkey.value;          $userloadpercent=&Apache::lonnet::userload();
         initkeys();      }
   
         this.document.server.elements.upass.value      my $firsturl=
     =crypted(this.document.client.elements.upass.value);      ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
   
         this.document.server.submit();  # ----------------------------------------------------------- Get announcements
  return false;      my $announcements=&Apache::lonnet::getannounce();
     }  # -------------------------------------------------------- Set login parameters
  </script>  
 ENDSCRIPT      my @hexstr=('0','1','2','3','4','5','6','7',
                   '8','9','a','b','c','d','e','f');
     if ($fullgraph) {      my $lkey='';
  $r->print(      for (0..7) {
   '<table width="100%" cellpadding=0 cellspacing=0 border=0>');          $lkey.=$hexstr[rand(15)];
     }      }
   
     $r->print(<<ENDSERVERFORM);      my $ukey='';
   <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">      for (0..7) {
    <input type=hidden name=logtoken value="$logtoken">          $ukey.=$hexstr[rand(15)];
    <input type=hidden name=serverid value="$lonhost">      }
    <input type=hidden name=interface value="$ENV{'form.interface'}">  
    <input type=hidden name=uname value="">      my $lextkey=hex($lkey);
    <input type=hidden name=upass value="">      if ($lextkey>2147483647) { $lextkey-=4294967296; }
    <input type=hidden name=udom value="">  
   </form>      my $uextkey=hex($ukey);
 ENDSERVERFORM      if ($uextkey>2147483647) { $uextkey-=4294967296; }
     if ($fullgraph) { $r->print(<<ENDTOP);  
   <!-- The LON-CAPA Header -->  # -------------------------------------------------------- Store away log token
   <tr>      my $tokenextras;
       if ($env{'form.role'}) {
    <!-- Row 1 Columns 2-4 -->          $tokenextras = '&role='.&escape($env{'form.role'});
    <td width="100%" height=75 colspan=4 align="left" valign="top" bgcolor="$pgbg"><img src="$img" border=0 alt="The Learning Online Network with CAPA" /></td>      }
   </tr>      if ($env{'form.symb'}) {
           if (!$tokenextras) {
   <!-- The gray bar that starts the two table frames -->              $tokenextras = '&';
   <tr>          }
           $tokenextras .= '&symb='.&escape($env{'form.symb'});
    <!-- Row 2 Column 1 -->      }
    <td width=182 height=27 bgcolor="$sidebg">&nbsp;</td>      if ($env{'form.iptoken'}) {
           if (!$tokenextras) {
    <!-- Row 2 Column 2 -->              $tokenextras = '&&';
    <td width=27 height=27 align="left" background="$iconpath/filltop.gif"><img src="$iconpath/upperleft.gif" border=0 alt="" /></td>          }
           $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
    <!-- Row 2 Column 3 -->      }
    <td height=27 background="$iconpath/filltop.gif"><img src="$iconpath/filltop.gif" alt="" /></td>      my $logtoken=Apache::lonnet::reply(
          'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
    <!-- Row 2 Column 4 -->         $lonhost);
    <td width=27 height=27 align="right" background="$iconpath/filltop.gif"><img src="$iconpath/upperright.gif" border=0 alt="" /></td>  
   </tr>  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
   <tr>  #    we are in serious trouble
      
    <!-- A cell that will hold the 'access' and 'about' buttons -->      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
    <!-- Row 3 Column 1 -->          if ($logtoken eq 'no_such_host') {
    <td valign="top" height=60 align="center" bgcolor="$sidebg">              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
     <a href="/adm/login?interface=textual"><img src="$iconpath/accessbutton.gif" border=0 alt="Accessibility Options" /></a>          }
     <br />          my $spares='';
     <a href="/adm/about.html"><img src="$iconpath/aboutlon.gif" border=0 alt="About LON-CAPA" /></a>   my $last;
    </td>          foreach my $hostid (sort
       {
    <!-- The shaded space between the two main columns -->   &Apache::lonnet::hostname($a) cmp
    <!-- Row 3 Column 2 -->      &Apache::lonnet::hostname($b);
    <td width=27 height=60 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>      }
       keys(%Apache::lonnet::spareid)) {
    <!-- The right main column holding the large LON-CAPA logo-->              next if ($hostid eq $lonhost);
    <!-- Rows 3-4 Column 3 -->      my $hostname = &Apache::lonnet::hostname($hostid);
    <td align="center" valign="top" width="100%" height="100%" rowspan=2 bgcolor="$mainbg">      next if (($last eq $hostname) || ($hostname eq ''));
     <center>              $spares.='<br /><font size="+1"><a href="http://'.
      <img src="$logo" alt="" />                  $hostname.
     </center>                  '/adm/login?domain='.$authdomain.'">'.
    </td>                  $hostname.'</a>'.
                   ' '.&mt('(preferred)').'</font>'.$/;
    <!-- Row 3 Column 4 -->      $last=$hostname;
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>          }
   </tr>          if ($spares) {
   <tr>              $spares.= '<br />';
           }
    <!-- The entry form -->          my %all_hostnames = &Apache::lonnet::all_hostnames();
    <!-- Row 4 Column 1 -->          foreach my $hostid (sort
    <td align="center" valign="middle" bgcolor="$sidebg">      {
 ENDTOP   &Apache::lonnet::hostname($a) cmp
 }      &Apache::lonnet::hostname($b);
     $r->print(<<ENDLOGIN);      }
     <form name="client" onsubmit="return(send())">      keys(%all_hostnames)) {
      <input type="hidden" name="lextkey" value="$lextkey">              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
      <input type="hidden" name="uextkey" value="$uextkey">              my $hostname = &Apache::lonnet::hostname($hostid);
               next if (($last eq $hostname) || ($hostname eq ''));
      <!-- Start the sub-table for text and input alignment -->              $spares.='<br /><a href="http://'.
      <table border=0 cellspacing=0 cellpadding=0>               $hostname.
       <tr><td bgcolor="$sidebg" colspan=2><img src="$iconpath/userauthentication.gif" alt="User Authentication" /></td></tr>               '/adm/login?domain='.$authdomain.'">'.
       <tr>               $hostname.'</a>';
        <td bgcolor="$mainbg"><br /><font size=-1><b>&nbsp;&nbsp;&nbsp;User Name:</b></font></td>              $last=$hostname;
        <td bgcolor="$mainbg"><br /><input type="text" name="uname" size="10" value="$authusername" /></td>           }
       </tr>           $r->print(
       <tr>     '<html>'
        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Password:</b></font></td>    .'<head><title>'
        <td bgcolor="$mainbg"><input type="password" name="upass" size="10" /></td>    .&mt('The LearningOnline Network with CAPA')
       </tr>    .'</title></head>'
       <tr>    .'<body bgcolor="#FFFFFF">'
        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Domain:</b></font></td>    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
        <td bgcolor="$mainbg"><input type="text" name="udom" size="10" value="$authdomain" /></td>    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
       </tr>    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
       <tr>          if ($spares) {
        <td bgcolor="$mainbg">&nbsp;&nbsp;&nbsp;<a href="/adm/loginproblems.html">Help</a></td>              $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
        <td bgcolor="$mainbg" valign="bottom" align="center">                       .'</p>'
         <br />                       .$spares);
         <input type="submit" value="Log In" />          }
        </td>          $r->print('</body>'
       </tr>                   .'</html>'
      </table>          );
      <!-- End sub-table -->          return OK;
     </form>      }
 ENDLOGIN  
     if ($fullgraph) {  # ----------------------------------------------- Apparently we are in business
  $r->print(<<ENDDOCUMENT);      $servadm=~s/\,/\<br \/\>/g;
    </td>  
   # ----------------------------------------------------------- Front page design
    <!-- Row 4 Column 2 -->      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>      my $font=&Apache::loncommon::designparm('login.font',$domain);
       my $link=&Apache::loncommon::designparm('login.link',$domain);
    <!-- Row 4 Column 4 -->      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
   </tr>      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
   <tr>      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
       my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
    <!-- Row 5 Column 1 -->      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
    <td bgcolor="$sidebg" valign="middle" align="left">      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
      <br />      my $img=&Apache::loncommon::designparm('login.img',$domain);
      <table border=0 cellspacing=0 cellpadding=0>      my $domainlogo=&Apache::loncommon::domainlogo($domain);
       <tr>      my $showbanner = 1;
        <td bgcolor="$sidebg" align="left" valign="top">      my $showmainlogo = 1;
         <small><b>&nbsp;&nbsp;&nbsp;Domain:&nbsp;</b></small>      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
        </td>          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
        <td bgcolor="$sidebg" align="left" valign="top">      }
         <small><tt>&nbsp;$domain</tt></small>      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
        </td>          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
       </tr>      }
       <tr>      my $showadminmail;
        <td bgcolor="$sidebg" align="left" valign="top">      my @possdoms = &Apache::lonnet::current_machine_domains();
         <small><b>&nbsp;&nbsp;&nbsp;Server:&nbsp;</b></small>      if (grep(/^\Q$domain\E$/,@possdoms)) {
        </td>          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
        <td bgcolor="$sidebg" align="left" valign="top">      }
         <small><tt>&nbsp;$lonhost ($role)</tt></small>      my $showcoursecat =
        </td>          &Apache::loncommon::designparm('login.coursecatalog',$domain);
       </tr>      my $shownewuserlink =
       <tr>          &Apache::loncommon::designparm('login.newuser',$domain);
        <td bgcolor="$sidebg" align="left" valign="top">      my $showhelpdesk =
         <small><b>&nbsp;&nbsp;&nbsp;Load:&nbsp;</b></small>          &Apache::loncommon::designparm('login.helpdesk',$domain);
        </td>      my $now=time;
        <td bgcolor="$sidebg" align="left" valign="top">      my $js = (<<ENDSCRIPT);
         <small><tt>&nbsp;$loadpercent percent</tt></small>  
        </td>  <script type="text/javascript" language="JavaScript">
       </tr>  // <![CDATA[
      </table>  function send()
      <br />  {
     <small>  this.document.server.elements.uname.value
      <b>&nbsp;&nbsp;&nbsp;System Administration:</b><br />  =this.document.client.elements.uname.value;
      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sysadm</tt><br />  
      <b>&nbsp;&nbsp;&nbsp;Server Administration:</b><br />  this.document.server.elements.udom.value
      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$servadm<br />&nbsp;</tt>  =this.document.client.elements.udom.value;
     </small>  
    </td>  uextkey=this.document.client.elements.uextkey.value;
   lextkey=this.document.client.elements.lextkey.value;
    <!-- Row 5 Column 2 -->  initkeys();
    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>  
   if(this.document.server.action.substr(0,5) === 'http:'){
    <!-- Row 5 Column 3 -->      this.document.server.elements.upass0.value
    <td width="100%" valign="bottom" bgcolor="$mainbg">          =getCrypted(this.document.client.elements.upass$now.value);
 $domainlogo  } else {
 </td>      this.document.server.elements.upass0.value
           =this.document.client.elements.upass$now.value;
    <!-- Row 5 Column 4 -->  }
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>  
   </tr>  this.document.client.elements.uname.value='';
   <tr>  this.document.client.elements.upass$now.value='';
   
    <!-- Row 6 Column 1 -->  this.document.server.submit();
    <td bgcolor="$sidebg">&nbsp;</td>  return false;
   }
    <!-- Row 6 Column 2 -->  
    <td align="left" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerleft.gif" alt="" /></td>  function enableInput() {
       this.document.client.elements.upass$now.removeAttribute("readOnly");
    <!-- Row 6 Column 3 -->      this.document.client.elements.uname.removeAttribute("readOnly");
    <td background="$iconpath/fillbottom.gif"><img src="$iconpath/fillbottom.gif" alt="" /></td>      this.document.client.elements.udom.removeAttribute("readOnly");
       return;
    <!-- Row 6 Column 4 -->  }
    <td align="right" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerright.gif" alt="" /></td>  
   </tr>  // ]]>
  </table>  </script>
   
 <script>  ENDSCRIPT
 // the if prevents the script error if the browser can't handle this  
 if ( document.client.uname ) { document.client.uname.focus(); }  # --------------------------------------------------- Print login screen header
 </script>  
       my %add_entries = (
 ENDDOCUMENT         bgcolor      => "$mainbg",
 }         text         => "$font",
     $r->print('</body></html>');         link         => "$link",
     return OK;         vlink        => "$vlink",
 }          alink        => "$alink",
                  onload       => 'javascript:enableInput();',);
 1;  
 __END__      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
       @hosts = &Apache::lonnet::current_machine_ids();
       $lonhost_in_use = $lonhost;
       if (@hosts > 1) {
           foreach my $hostid (@hosts) {
               if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
                   $lonhost_in_use = $hostid;
                   last;
               }
           }
       }
       %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
       $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
       $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
       if ($headextra) {
           my $omitextra;
           if ($headextra_exempt ne '') {
               my @exempt = split(',',$headextra_exempt);
               my $ip = $ENV{'REMOTE_ADDR'};
               if (grep(/^\Q$ip\E$/,@exempt)) {
                   $omitextra = 1;
               }
           }
           unless ($omitextra) {
               my $confname = $defdom.'-domainconfig';
               if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
                   my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
                   unless ($extra eq '-1') {
                       $js .= "\n".$extra."\n";
                   }
               }
           }
       }
   
       $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
          { 'redirect'       => [$expire,'/adm/roles'],
    'add_entries' => \%add_entries,
    'only_body'   => 1,}));
   
   # ----------------------------------------------------------------------- Texts
   
       my %lt=&Apache::lonlocal::texthash(
             'un'       => 'Username',
             'pw'       => 'Password',
             'dom'      => 'Domain',
             'perc'     => 'percent',
             'load'     => 'Server Load',
             'userload' => 'User Load',
             'catalog'  => 'Course/Community Catalog',
             'log'      => 'Log in',
             'help'     => 'Log-in Help',
             'serv'     => 'Server',
             'servadm'  => 'Server Administration',
             'helpdesk' => 'Contact Helpdesk',
             'forgotpw' => 'Forgot password?',
             'newuser'  => 'New User?',
          );
   # -------------------------------------------------- Change password field name
   
       my $forgotpw = &forgotpwdisplay(%lt);
       $forgotpw .= '<br />' if $forgotpw;
       my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
       if ($loginhelp) {
           $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
       }
   
   # ---------------------------------------------------- Serve out DES JavaScript
       {
       my $jsh=Apache::File->new($include."/londes.js");
       $r->print(<$jsh>);
       }
   # ---------------------------------------------------------- Serve rest of page
   
       $r->print(
       '<div class="LC_Box"'
      .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
   );
   
       $r->print(<<ENDSERVERFORM);
   <form name="server" action="/adm/authenticate" method="post" target="_top">
      <input type="hidden" name="logtoken" value="$logtoken" />
      <input type="hidden" name="serverid" value="$lonhost" />
      <input type="hidden" name="uname" value="" />
      <input type="hidden" name="upass0" value="" />
      <input type="hidden" name="udom" value="" />
      <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
      <input type="hidden" name="localres" value="$env{'form.localres'}" />
     </form>
   ENDSERVERFORM
       my $coursecatalog;
       if (($showcoursecat eq '') || ($showcoursecat)) {
           $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
       }
       my $newuserlink;
       if ($shownewuserlink) {
           $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
       }
       my $logintitle =
           '<h2 class="LC_hcell"'
          .' style="background:'.$loginbox_header_bgcol.';'
          .' color:'.$loginbox_header_textcol.'">'
          .$lt{'log'}
          .'</h2>';
   
       my $noscript_warning='<noscript><span class="LC_warning"><b>'
                           .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
                           .'</b></span></noscript>';
       my $helpdeskscript;
       my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
                                          $authdomain,\$helpdeskscript,
                                          $showhelpdesk,\@possdoms);
   
       my $mobileargs;
       if ($clientmobile) {
           $mobileargs = 'autocapitalize="off" autocorrect="off"';
       }
       my $loginform=(<<LFORM);
   <form name="client" action="" onsubmit="return(send())">
     <input type="hidden" name="lextkey" value="$lextkey" />
     <input type="hidden" name="uextkey" value="$uextkey" />
     <b><label for="uname">$lt{'un'}</label>:</b><br />
     <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
     <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 />
     <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
     <input type="submit" value="$lt{'log'}" />
   </form>
   LFORM
   
       if ($showbanner) {
           $r->print(<<HEADER);
   <!-- The LON-CAPA Header -->
   <div style="background:$pgbg;margin:0;width:100%;">
     <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
   </div>
   HEADER
       }
       $r->print(<<ENDTOP);
   <div style="float:left;margin-top:0;">
   <div class="LC_Box" style="background:$loginbox_bg;">
     $logintitle
     $loginform
     $noscript_warning
   </div>
    
   <div class="LC_Box" style="padding-top: 10px;">
     $loginhelp
     $forgotpw
     $contactblock
     $newuserlink
     $coursecatalog
   </div>
   </div>
   
   <div>
   ENDTOP
       if ($showmainlogo) {
           $r->print(' <img src="'.$logo.'" alt="" />'."\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.31  
changed lines
  Added in v.1.167


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