File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.22: download - view: text, annotated - select for diffs
Tue Sep 17 19:45:11 2002 UTC (21 years, 8 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Changes to fix handling of spare.tab.  Firstly, do not omit self from
spare.tab.  Secondly, compare load averages to self (initially) when
determining which server to offload onto.

    1: # The LearningOnline Network
    2: # Login Screen
    3: #
    4: # $Id: lonlogin.pm,v 1.22 2002/09/17 19:45:11 matthew Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
   29: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9,
   30: # 1/17/01 Gerd Kortemeyer
   31: #
   32: # 2/7/02,2/8,2/12,2/14,2/15,2/19 Josh Brunskole
   33: # 
   34: # 7/10/02 Jeremy Bowers
   35: 
   36: package Apache::lonlogin;
   37: 
   38: use strict;
   39: use Apache::Constants qw(:common);
   40: use Apache::File ();
   41: use Apache::lonnet();
   42: use Apache::loncommon();
   43: 
   44: sub handler {
   45:     my $r = shift;
   46:     $r->content_type('text/html');
   47:     &Apache::loncommon::no_cache($r);
   48:     $r->send_http_header;
   49:     return OK if $r->header_only;
   50: 
   51: 
   52:     &Apache::loncommon::get_unprocessed_cgi
   53:                          ($ENV{'QUERY_STRING'},['interface']);
   54: 
   55:     $ENV{'form.interface'}=~s/\W//g;
   56: 
   57:     my $fullgraph=($ENV{'form.interface'} ne 'textual');
   58: 
   59:     my $iconpath= $r->dir_config('lonIconsURL');
   60:     my $domain  = $r->dir_config('lonDefDomain');
   61:     my $role    = $r->dir_config('lonRole');
   62:     my $loadlim = $r->dir_config('lonLoadLim');
   63:     my $servadm = $r->dir_config('lonAdmEMail');
   64:     my $sysadm  = $r->dir_config('lonSysEMail');
   65:     my $lonhost = $r->dir_config('lonHostID');
   66:     my $tabdir  = $r->dir_config('lonTabDir');
   67:     my $include = $r->dir_config('lonIncludes');
   68: 
   69:     my $loadavg;
   70:    {
   71:        my $loadfile=Apache::File->new('/proc/loadavg');
   72:        $loadavg=<$loadfile>;
   73:    }
   74:     $loadavg =~ s/\s.*//g;
   75:     my $loadpercent=100*$loadavg/$loadlim;
   76: 
   77:     my $otherserver='http://'.$ENV{'SERVER_NAME'};
   78:     my $firsturl=$ENV{'request.firsturl'};
   79: # ---------------------------------------- Are we access server and overloaded?
   80:     if (($loadpercent>100.0)) {
   81:         $otherserver=Apache::lonnet::spareserver($loadpercent);
   82:     }
   83: 
   84: # -------------------------------------------------------- Set login parameters
   85: 
   86:     my @hexstr=('0','1','2','3','4','5','6','7',
   87:                 '8','9','a','b','c','d','e','f');
   88:     my $lkey='';
   89:     for (0..7) {
   90:         $lkey.=$hexstr[rand(15)];
   91:     }
   92: 
   93:     my $ukey='';
   94:     for (0..7) {
   95:         $ukey.=$hexstr[rand(15)];
   96:     }
   97: 
   98:     my $lextkey=hex($lkey);
   99:     if ($lextkey>2147483647) { $lextkey-=4294967296; }
  100: 
  101:     my $uextkey=hex($ukey);
  102:     if ($uextkey>2147483647) { $uextkey-=4294967296; }
  103: 
  104:     my $logtoken=Apache::lonnet::reply(
  105:        'tmpput:'.$ukey.$lkey.'&'.$firsturl,
  106:        $lonhost);
  107:     my $domainlogo=&Apache::loncommon::domainlogo();
  108: # --------------------------------------------------- Print login screen header
  109:     $r->print(<<ENDHEADER);
  110: <html>
  111: <head>
  112: <title>The LearningOnline Network with CAPA Login</title>
  113: </head>
  114: ENDHEADER
  115: # ---------------------------------------------------- Serve out DES JavaScript
  116:     {
  117: 	my $jsh=Apache::File->new($include."/londes.js");
  118:         $r->print(<$jsh>);
  119:     }
  120: 
  121: # ----------------------------------------------------------- Front page design
  122:     my $pgbg=&Apache::loncommon::designparm('login.pgbg');
  123:     my $font=&Apache::loncommon::designparm('login.font');
  124:     my $link=&Apache::loncommon::designparm('login.link');
  125:     my $vlink=&Apache::loncommon::designparm('login.vlink');
  126:     my $alink=&Apache::loncommon::designparm('login.alink');
  127:     my $mainbg=&Apache::loncommon::designparm('login.mainbg');
  128:     my $sidebg=&Apache::loncommon::designparm('login.sidebg');
  129:     my $logo=&Apache::loncommon::designparm('login.logo');
  130:     my $img=&Apache::loncommon::designparm('login.img');
  131: 
  132: 
  133: # ---------------------------------------------------------- Serve rest of page
  134:     $r->print(<<ENDSCRIPT);
  135: 
  136: <body bgcolor="$pgbg" text="$font" link="$link" vlink="$vlink" alink="$alink"
  137:  onLoad="init();" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
  138: 
  139:  <script language="JavaScript">
  140:     function send()
  141:     {
  142: 	this.document.server.elements.uname.value
  143:        =this.document.client.elements.uname.value;
  144: 
  145:         this.document.server.elements.udom.value
  146:        =this.document.client.elements.udom.value;
  147: 
  148:         uextkey=this.document.client.elements.uextkey.value;
  149:         lextkey=this.document.client.elements.lextkey.value;
  150:         initkeys();
  151: 
  152:         this.document.server.elements.upass.value
  153: 	    =crypted(this.document.client.elements.upass.value);
  154: 
  155:         this.document.server.submit();
  156: 	return false;
  157:     }
  158:  </script>
  159: ENDSCRIPT
  160: 
  161:     if ($fullgraph) {
  162: 	$r->print(
  163: 		  '<table width="100%" cellpadding=0 cellspacing=0 border=0>');
  164:     }
  165: 
  166:     $r->print(<<ENDSERVERFORM);
  167:   <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">
  168:    <input type=hidden name=logtoken value="$logtoken">
  169:    <input type=hidden name=serverid value="$lonhost">
  170:    <input type=hidden name=interface value="$ENV{'form.interface'}">
  171:    <input type=hidden name=uname value="">
  172:    <input type=hidden name=upass value="">
  173:    <input type=hidden name=udom value="">
  174:   </form>
  175: ENDSERVERFORM
  176:     if ($fullgraph) { $r->print(<<ENDTOP);
  177:   <!-- The LON-CAPA Header -->
  178:   <tr>
  179: 
  180:    <!-- Row 1 Columns 2-4 -->
  181:    <td width="100%" height=75 colspan=4 align="left" valign="top" bgcolor="#006600"><img src="$img" border=0 alt="The Learning Online Network with CAPA" /></td>
  182:   </tr>
  183: 
  184:   <!-- The gray bar that starts the two table frames -->
  185:   <tr>
  186: 
  187:    <!-- Row 2 Column 1 -->
  188:    <td width=182 height=27 bgcolor="$sidebg">&nbsp;</td>
  189: 
  190:    <!-- Row 2 Column 2 -->
  191:    <td width=27 height=27 align="left" background="$iconpath/filltop.gif"><img src="$iconpath/upperleft.gif" border=0 alt="" /></td>
  192: 
  193:    <!-- Row 2 Column 3 -->
  194:    <td height=27 background="$iconpath/filltop.gif"><img src="$iconpath/filltop.gif" alt="" /></td>
  195: 
  196:    <!-- Row 2 Column 4 -->
  197:    <td width=27 height=27 align="right" background="$iconpath/filltop.gif"><img src="$iconpath/upperright.gif" border=0 alt="" /></td>
  198:   </tr>
  199:   <tr>
  200:    
  201:    <!-- A cell that will hold the 'access' and 'about' buttons -->
  202:    <!-- Row 3 Column 1 -->
  203:    <td valign="top" height=60 align="center" bgcolor="$sidebg">
  204:     <a href="/adm/login?interface=textual"><img src="$iconpath/accessbutton.gif" border=0 alt="Accessibility Options" /></a>
  205:     <br />
  206:     <a href="/adm/about.html"><img src="$iconpath/aboutlon.gif" border=0 alt="About LON-CAPA" /></a>
  207:    </td>
  208: 
  209:    <!-- The shaded space between the two main columns -->
  210:    <!-- Row 3 Column 2 -->
  211:    <td width=27 height=60 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
  212: 
  213:    <!-- The right main column holding the large LON-CAPA logo-->
  214:    <!-- Rows 3-4 Column 3 -->
  215:    <td align="center" valign="top" width="100%" height="100%" rowspan=2 bgcolor="$mainbg">
  216:     <center>
  217:      <img src="$logo" alt="" />
  218:     </center>
  219:    </td>
  220: 
  221:    <!-- Row 3 Column 4 -->
  222:    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  223:   </tr>
  224:   <tr>
  225: 
  226:    <!-- The entry form -->
  227:    <!-- Row 4 Column 1 -->
  228:    <td align="center" valign="middle" bgcolor="$sidebg">
  229: ENDTOP
  230: }
  231:     $r->print(<<ENDLOGIN);
  232:     <form name="client" onsubmit="return(send())">
  233:      <input type="hidden" name="lextkey" value="$lextkey">
  234:      <input type="hidden" name="uextkey" value="$uextkey">
  235: 
  236:      <!-- Start the sub-table for text and input alignment -->
  237:      <table border=0 cellspacing=0 cellpadding=0>
  238:       <tr><td bgcolor="$sidebg" colspan=2><img src="$iconpath/userauthentication.gif" alt="User Authentication" /></td></tr>
  239:       <tr>
  240:        <td bgcolor="$mainbg"><br /><font size=-1><b>&nbsp;&nbsp;&nbsp;User Name:</b></font></td>
  241:        <td bgcolor="$mainbg"><br /><input type="text" name="uname" size="10" /></td>
  242:       </tr>
  243:       <tr>
  244:        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Password:</b></font></td>
  245:        <td bgcolor="$mainbg"><input type="password" name="upass" size="10" /></td>
  246:       </tr>
  247:       <tr>
  248:        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Domain:</b></font></td>
  249:        <td bgcolor="$mainbg"><input type="text" name="udom" size="10" value=$domain /></td>
  250:       </tr>
  251:       <tr>
  252:        <td bgcolor="$mainbg" valign="bottom" align="center" colspan=2>
  253:         <br />
  254:         <input type="submit" value="Log In" />
  255:        </td>
  256:       </tr>
  257:      </table>
  258:      <!-- End sub-table -->
  259:     </form>
  260: ENDLOGIN
  261:     if ($fullgraph) {
  262: 	$r->print(<<ENDDOCUMENT);
  263:    </td>
  264: 
  265:    <!-- Row 4 Column 2 -->
  266:    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
  267: 
  268:    <!-- Row 4 Column 4 -->
  269:    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  270:   </tr>
  271:   <tr>
  272: 
  273:    <!-- Row 5 Column 1 -->
  274:    <td bgcolor="$sidebg" valign="middle" align="left">
  275:      <br />
  276:      <table border=0 cellspacing=0 cellpadding=0>
  277:       <tr>
  278:        <td bgcolor="$sidebg" align="left" valign="top">
  279:         <small><b>&nbsp;&nbsp;&nbsp;Domain:&nbsp;</b></small>
  280:        </td>
  281:        <td bgcolor="$sidebg" align="left" valign="top">
  282:         <small><tt>&nbsp;$domain</tt></small>
  283:        </td>
  284:       </tr>
  285:       <tr>
  286:        <td bgcolor="$sidebg" align="left" valign="top">
  287:         <small><b>&nbsp;&nbsp;&nbsp;Server:&nbsp;</b></small>
  288:        </td>
  289:        <td bgcolor="$sidebg" align="left" valign="top">
  290:         <small><tt>&nbsp;$lonhost ($role)</tt></small>
  291:        </td>
  292:       </tr>
  293:       <tr>
  294:        <td bgcolor="$sidebg" align="left" valign="top">
  295:         <small><b>&nbsp;&nbsp;&nbsp;Load:&nbsp;</b></small>
  296:        </td>
  297:        <td bgcolor="$sidebg" align="left" valign="top">
  298:         <small><tt>&nbsp;$loadpercent percent</tt></small>
  299:        </td>
  300:       </tr>
  301:      </table>
  302:      <br />
  303:     <small>
  304:      <b>&nbsp;&nbsp;&nbsp;System Administration:</b><br />
  305:      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sysadm</tt><br />
  306:      <b>&nbsp;&nbsp;&nbsp;Server Administration:</b><br />
  307:      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$servadm<br />&nbsp;</tt>
  308:     </small>
  309:    </td>
  310: 
  311:    <!-- Row 5 Column 2 -->
  312:    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
  313: 
  314:    <!-- Row 5 Column 3 -->
  315:    <td width="100%" valign="bottom" bgcolor="$mainbg">
  316: $domainlogo
  317: </td>
  318: 
  319:    <!-- Row 5 Column 4 -->
  320:    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  321:   </tr>
  322:   <tr>
  323: 
  324:    <!-- Row 6 Column 1 -->
  325:    <td bgcolor="$sidebg">&nbsp;</td>
  326: 
  327:    <!-- Row 6 Column 2 -->
  328:    <td align="left" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerleft.gif" alt="" /></td>
  329: 
  330:    <!-- Row 6 Column 3 -->
  331:    <td background="$iconpath/fillbottom.gif"><img src="$iconpath/fillbottom.gif" alt="" /></td>
  332: 
  333:    <!-- Row 6 Column 4 -->
  334:    <td align="right" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerright.gif" alt="" /></td>
  335:   </tr>
  336:  </table>
  337: 
  338: ENDDOCUMENT
  339: }
  340:     $r->print('</body></html>');
  341:     return OK;
  342: } 
  343: 
  344: 1;
  345: __END__

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