File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.30: download - view: text, annotated - select for diffs
Tue Feb 4 15:11:44 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
The plan was to be able to pass username and domain (NOT PASSWORD!!!) in the
query string to support "Switch Server" better. Unfortunately, as expected,
the query string is not available to this module if it is called by
"/priv/username/..." as an error document.

# The LearningOnline Network
# Login Screen
#
# $Id: lonlogin.pm,v 1.30 2003/02/04 15:11:44 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# 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,
# 1/17/01 Gerd Kortemeyer
#
# 2/7/02,2/8,2/12,2/14,2/15,2/19 Josh Brunskole
# 
# 7/10/02 Jeremy Bowers

package Apache::lonlogin;

use strict;
use Apache::Constants qw(:common);
use Apache::File ();
use Apache::lonnet();
use Apache::loncommon();

sub handler {
    my $r = shift;
    $r->content_type('text/html');
    &Apache::loncommon::no_cache($r);
    $r->send_http_header;
    return OK if $r->header_only;


    &Apache::loncommon::get_unprocessed_cgi
     ($ENV{'QUERY_STRING'},['interface','username','domain']);

    $ENV{'form.interface'}=~s/\W//g;

    my $fullgraph=($ENV{'form.interface'} ne 'textual');

    my $iconpath= 'http://'.$ENV{'HTTP_HOST'}.':8080'.
                  $r->dir_config('lonIconsURL');
    my $domain  = $r->dir_config('lonDefDomain');
    my $role    = $r->dir_config('lonRole');
    my $loadlim = $r->dir_config('lonLoadLim');
    my $servadm = $r->dir_config('lonAdmEMail');
    my $sysadm  = $r->dir_config('lonSysEMail');
    my $lonhost = $r->dir_config('lonHostID');
    my $tabdir  = $r->dir_config('lonTabDir');
    my $include = $r->dir_config('lonIncludes');

# --------------------------------------------- Default values for login fields

    my $authusername=($ENV{'form.username'}?$ENV{'form.username'}:'');
    my $authdomain=($ENV{'form.domain'}?$ENV{'form.domain'}:$domain);

# ---------------------------------------------------------- Determine own load
    my $loadavg;
   {
       my $loadfile=Apache::File->new('/proc/loadavg');
       $loadavg=<$loadfile>;
   }
    $loadavg =~ s/\s.*//g;
    my $loadpercent=100*$loadavg/$loadlim;

# ------------------------------------------------------- Do the load balancing
    my $otherserver='http://'.$ENV{'SERVER_NAME'};
    my $firsturl=$ENV{'request.firsturl'};
# ---------------------------------------- Are we access server and overloaded?
    if (($role eq 'access') && ($loadpercent>100.0)) {
        $otherserver=Apache::lonnet::spareserver($loadpercent);
    }

# -------------------------------------------------------- Set login parameters

    my @hexstr=('0','1','2','3','4','5','6','7',
                '8','9','a','b','c','d','e','f');
    my $lkey='';
    for (0..7) {
        $lkey.=$hexstr[rand(15)];
    }

    my $ukey='';
    for (0..7) {
        $ukey.=$hexstr[rand(15)];
    }

    my $lextkey=hex($lkey);
    if ($lextkey>2147483647) { $lextkey-=4294967296; }

    my $uextkey=hex($ukey);
    if ($uextkey>2147483647) { $uextkey-=4294967296; }

    my $logtoken=Apache::lonnet::reply(
       'tmpput:'.$ukey.$lkey.'&'.$firsturl,
       $lonhost);
    my $domainlogo=&Apache::loncommon::domainlogo();
# --------------------------------------------------- Print login screen header
    $r->print(<<ENDHEADER);
<html>
<head>
<title>The LearningOnline Network with CAPA Login</title>
</head>
ENDHEADER
# ---------------------------------------------------- Serve out DES JavaScript
    {
	my $jsh=Apache::File->new($include."/londes.js");
        $r->print(<$jsh>);
    }

# ----------------------------------------------------------- Front page design
    my $pgbg=&Apache::loncommon::designparm('login.pgbg');
    my $font=&Apache::loncommon::designparm('login.font');
    my $link=&Apache::loncommon::designparm('login.link');
    my $vlink=&Apache::loncommon::designparm('login.vlink');
    my $alink=&Apache::loncommon::designparm('login.alink');
    my $mainbg=&Apache::loncommon::designparm('login.mainbg');
    my $sidebg=&Apache::loncommon::designparm('login.sidebg');
    my $logo=&Apache::loncommon::designparm('login.logo');
    my $img=&Apache::loncommon::designparm('login.img');


# ---------------------------------------------------------- Serve rest of page
    $r->print(<<ENDSCRIPT);

<body bgcolor="$pgbg" text="$font" link="$link" vlink="$vlink" alink="$alink"
  topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>

 <script language="JavaScript">
    function send()
    {
	this.document.server.elements.uname.value
       =this.document.client.elements.uname.value;

        this.document.server.elements.udom.value
       =this.document.client.elements.udom.value;

        uextkey=this.document.client.elements.uextkey.value;
        lextkey=this.document.client.elements.lextkey.value;
        initkeys();

        this.document.server.elements.upass.value
	    =crypted(this.document.client.elements.upass.value);

        this.document.server.submit();
	return false;
    }
 </script>
ENDSCRIPT

    if ($fullgraph) {
	$r->print(
		  '<table width="100%" cellpadding=0 cellspacing=0 border=0>');
    }

    $r->print(<<ENDSERVERFORM);
  <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">
   <input type=hidden name=logtoken value="$logtoken">
   <input type=hidden name=serverid value="$lonhost">
   <input type=hidden name=interface value="$ENV{'form.interface'}">
   <input type=hidden name=uname value="">
   <input type=hidden name=upass value="">
   <input type=hidden name=udom value="">
  </form>
ENDSERVERFORM
    if ($fullgraph) { $r->print(<<ENDTOP);
  <!-- The LON-CAPA Header -->
  <tr>

   <!-- Row 1 Columns 2-4 -->
   <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>

  <!-- The gray bar that starts the two table frames -->
  <tr>

   <!-- Row 2 Column 1 -->
   <td width=182 height=27 bgcolor="$sidebg">&nbsp;</td>

   <!-- Row 2 Column 2 -->
   <td width=27 height=27 align="left" background="$iconpath/filltop.gif"><img src="$iconpath/upperleft.gif" border=0 alt="" /></td>

   <!-- Row 2 Column 3 -->
   <td height=27 background="$iconpath/filltop.gif"><img src="$iconpath/filltop.gif" alt="" /></td>

   <!-- Row 2 Column 4 -->
   <td width=27 height=27 align="right" background="$iconpath/filltop.gif"><img src="$iconpath/upperright.gif" border=0 alt="" /></td>
  </tr>
  <tr>
   
   <!-- A cell that will hold the 'access' and 'about' buttons -->
   <!-- Row 3 Column 1 -->
   <td valign="top" height=60 align="center" bgcolor="$sidebg">
    <a href="/adm/login?interface=textual"><img src="$iconpath/accessbutton.gif" border=0 alt="Accessibility Options" /></a>
    <br />
    <a href="/adm/about.html"><img src="$iconpath/aboutlon.gif" border=0 alt="About LON-CAPA" /></a>
   </td>

   <!-- The shaded space between the two main columns -->
   <!-- Row 3 Column 2 -->
   <td width=27 height=60 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>

   <!-- The right main column holding the large LON-CAPA logo-->
   <!-- Rows 3-4 Column 3 -->
   <td align="center" valign="top" width="100%" height="100%" rowspan=2 bgcolor="$mainbg">
    <center>
     <img src="$logo" alt="" />
    </center>
   </td>

   <!-- Row 3 Column 4 -->
   <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  </tr>
  <tr>

   <!-- The entry form -->
   <!-- Row 4 Column 1 -->
   <td align="center" valign="middle" bgcolor="$sidebg">
ENDTOP
}
    $r->print(<<ENDLOGIN);
    <form name="client" onsubmit="return(send())">
     <input type="hidden" name="lextkey" value="$lextkey">
     <input type="hidden" name="uextkey" value="$uextkey">

     <!-- Start the sub-table for text and input alignment -->
     <table border=0 cellspacing=0 cellpadding=0>
      <tr><td bgcolor="$sidebg" colspan=2><img src="$iconpath/userauthentication.gif" alt="User Authentication" /></td></tr>
      <tr>
       <td bgcolor="$mainbg"><br /><font size=-1><b>&nbsp;&nbsp;&nbsp;User Name:</b></font></td>
       <td bgcolor="$mainbg"><br /><input type="text" name="uname" size="10" value="$authusername" /></td>
      </tr>
      <tr>
       <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Password:</b></font></td>
       <td bgcolor="$mainbg"><input type="password" name="upass" size="10" /></td>
      </tr>
      <tr>
       <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Domain:</b></font></td>
       <td bgcolor="$mainbg"><input type="text" name="udom" size="10" value="$authdomain" /></td>
      </tr>
      <tr>
       <td bgcolor="$mainbg">&nbsp;&nbsp;&nbsp;<a href="/adm/loginproblems.html">Help</a></td>
       <td bgcolor="$mainbg" valign="bottom" align="center">
        <br />
        <input type="submit" value="Log In" />
       </td>
      </tr>
     </table>
     <!-- End sub-table -->
    </form>
ENDLOGIN
    if ($fullgraph) {
	$r->print(<<ENDDOCUMENT);
   </td>

   <!-- Row 4 Column 2 -->
   <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>

   <!-- Row 4 Column 4 -->
   <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  </tr>
  <tr>

   <!-- Row 5 Column 1 -->
   <td bgcolor="$sidebg" valign="middle" align="left">
     <br />
     <table border=0 cellspacing=0 cellpadding=0>
      <tr>
       <td bgcolor="$sidebg" align="left" valign="top">
        <small><b>&nbsp;&nbsp;&nbsp;Domain:&nbsp;</b></small>
       </td>
       <td bgcolor="$sidebg" align="left" valign="top">
        <small><tt>&nbsp;$domain</tt></small>
       </td>
      </tr>
      <tr>
       <td bgcolor="$sidebg" align="left" valign="top">
        <small><b>&nbsp;&nbsp;&nbsp;Server:&nbsp;</b></small>
       </td>
       <td bgcolor="$sidebg" align="left" valign="top">
        <small><tt>&nbsp;$lonhost ($role)</tt></small>
       </td>
      </tr>
      <tr>
       <td bgcolor="$sidebg" align="left" valign="top">
        <small><b>&nbsp;&nbsp;&nbsp;Load:&nbsp;</b></small>
       </td>
       <td bgcolor="$sidebg" align="left" valign="top">
        <small><tt>&nbsp;$loadpercent percent</tt></small>
       </td>
      </tr>
     </table>
     <br />
    <small>
     <b>&nbsp;&nbsp;&nbsp;System Administration:</b><br />
     <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sysadm</tt><br />
     <b>&nbsp;&nbsp;&nbsp;Server Administration:</b><br />
     <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$servadm<br />&nbsp;</tt>
    </small>
   </td>

   <!-- Row 5 Column 2 -->
   <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>

   <!-- Row 5 Column 3 -->
   <td width="100%" valign="bottom" bgcolor="$mainbg">
$domainlogo
</td>

   <!-- Row 5 Column 4 -->
   <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  </tr>
  <tr>

   <!-- Row 6 Column 1 -->
   <td bgcolor="$sidebg">&nbsp;</td>

   <!-- Row 6 Column 2 -->
   <td align="left" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerleft.gif" alt="" /></td>

   <!-- Row 6 Column 3 -->
   <td background="$iconpath/fillbottom.gif"><img src="$iconpath/fillbottom.gif" alt="" /></td>

   <!-- Row 6 Column 4 -->
   <td align="right" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerright.gif" alt="" /></td>
  </tr>
 </table>

<script>
// the if prevents the script error if the browser can't handle this
if ( document.client.uname ) { document.client.uname.focus(); }
</script>

ENDDOCUMENT
}
    $r->print('</body></html>');
    return OK;
} 

1;
__END__

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