File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.44.2.1: download - view: text, annotated - select for diffs
Tue Aug 26 19:47:33 2003 UTC (20 years, 9 months ago) by albertel
Branches: version_1_0_1
Diff to branchpoint 1.44: preferred, unified
- backport 1.46

    1: # The LearningOnline Network
    2: # Login Screen
    3: #
    4: # $Id: lonlogin.pm,v 1.44.2.1 2003/08/26 19:47:33 albertel 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'}.'&'.$ENV{'request.querystring'},
   54:       ['interface','username','domain','firsturl','localpath','localres']);
   55:  
   56: # ----------------------------------------------------------- Process Interface
   57:     $ENV{'form.interface'}=~s/\W//g;
   58: 
   59:     my $textbrowsers=$r->dir_config('lonTextBrowsers');
   60:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
   61:     
   62:     foreach (split(/\:/,$textbrowsers)) {
   63: 	if ($httpbrowser=~/$_/i) {
   64: 	    $ENV{'form.interface'}='textual';
   65:         }
   66:     }
   67: 
   68:     my $fullgraph=($ENV{'form.interface'} ne 'textual');
   69:     my $port_to_use=$r->dir_config('lonhttpdPort');
   70:     if (!defined($port_to_use)) {
   71: 	$port_to_use='8080';
   72:     }
   73:     my $iconpath= 'http://'.$ENV{'HTTP_HOST'}.':'.$port_to_use.
   74:                   $r->dir_config('lonIconsURL');
   75:     my $domain  = $r->dir_config('lonDefDomain');
   76:     if (($ENV{'form.domain'}) && 
   77: 	 ($Apache::lonnet::domaindescription{$ENV{'form.domain'}})) {
   78: 	$domain=$ENV{'form.domain'};
   79:     }
   80:     my $role    = $r->dir_config('lonRole');
   81:     my $loadlim = $r->dir_config('lonLoadLim');
   82:     my $servadm = $r->dir_config('lonAdmEMail');
   83:     my $sysadm  = $r->dir_config('lonSysEMail');
   84:     my $lonhost = $r->dir_config('lonHostID');
   85:     my $tabdir  = $r->dir_config('lonTabDir');
   86:     my $include = $r->dir_config('lonIncludes');
   87:     my $expire  = $r->dir_config('lonExpire');
   88:     my $version = $r->dir_config('lonVersion');
   89: 
   90: # --------------------------------------------- Default values for login fields
   91: 
   92:     my $authusername=($ENV{'form.username'}?$ENV{'form.username'}:'');
   93:     my $authdomain=($ENV{'form.domain'}?$ENV{'form.domain'}:$domain);
   94: 
   95: # ---------------------------------------------------------- Determine own load
   96:     my $loadavg;
   97:     {
   98: 	my $loadfile=Apache::File->new('/proc/loadavg');
   99: 	$loadavg=<$loadfile>;
  100:     }
  101:     $loadavg =~ s/\s.*//g;
  102:     my $loadpercent=100*$loadavg/$loadlim;
  103:     my $userloadpercent=&Apache::lonnet::userload();
  104: 
  105: # ------------------------------------------------------- Do the load balancing
  106:     my $otherserver='http://'.$ENV{'SERVER_NAME'};
  107:     my $firsturl=
  108:     ($ENV{'request.firsturl'}?$ENV{'request.firsturl'}:$ENV{'form.firsturl'});
  109: # ---------------------------------------- Are we access server and overloaded?
  110:     if (($role eq 'access') &&
  111: 	(($userloadpercent>100.0)||($loadpercent>100.0))) {
  112:         $otherserver=Apache::lonnet::spareserver($loadpercent,$userloadpercent);
  113:     }
  114: 
  115: # -------------------------------------------------------- Set login parameters
  116: 
  117:     my @hexstr=('0','1','2','3','4','5','6','7',
  118:                 '8','9','a','b','c','d','e','f');
  119:     my $lkey='';
  120:     for (0..7) {
  121:         $lkey.=$hexstr[rand(15)];
  122:     }
  123: 
  124:     my $ukey='';
  125:     for (0..7) {
  126:         $ukey.=$hexstr[rand(15)];
  127:     }
  128: 
  129:     my $lextkey=hex($lkey);
  130:     if ($lextkey>2147483647) { $lextkey-=4294967296; }
  131: 
  132:     my $uextkey=hex($ukey);
  133:     if ($uextkey>2147483647) { $uextkey-=4294967296; }
  134: 
  135: # -------------------------------------------------------- Store away log token
  136:     my $logtoken=Apache::lonnet::reply(
  137:        'tmpput:'.$ukey.$lkey.'&'.$firsturl,
  138:        $lonhost);
  139: 
  140: # ------------------- If we cannot talk to ourselves, we are in serious trouble
  141: 
  142:     if ($logtoken eq 'con_lost') {
  143:         my $spares='';
  144:         foreach (keys %Apache::lonnet::hostname) {
  145:             if ($_ ne $lonhost) {
  146:                $spares.='<br /><a href="http://'.$Apache::lonnet::hostname{$_}.
  147: 		 '/adm/login?domain='.$authdomain.'">'.
  148:                  $Apache::lonnet::hostname{$_}.'</a>';
  149:                if ($Apache::lonnet::spareid{$_}) {
  150: 		   $spares.=' (preferred)';
  151:                }
  152: 	   }
  153:         }
  154: 	$r->print(<<ENDTROUBLE);
  155: <html>
  156: <head><title>The LearningOnline Network with CAPA</title></head>
  157: <body bgcolor="#FFFFFF">
  158: <img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />
  159: <h3>This LON-CAPA server is temporarily not available for login</h3>
  160: <p>Please attempt to login to one of the following servers:</p>$spares
  161: <p>If the problem persists, please contact <tt>$servadm</tt>.</p>
  162: </body>
  163: </html>
  164: ENDTROUBLE
  165:         return OK;
  166:     }
  167: 
  168: # ----------------------------------------------- Apparently we are in business
  169: 
  170:     my $domainlogo=&Apache::loncommon::domainlogo();
  171:     $servadm=~s/\,/\<br \/\>/g;
  172:     $sysadm=~s/\,/\<br \/\>/g;
  173: 
  174: # --------------------------------------------------- Print login screen header
  175:     $r->print(<<ENDHEADER);
  176: <html>
  177: <head>
  178: <meta HTTP-EQUIV="Refresh" CONTENT="$expire; url=/adm/roles" />
  179: <title>The LearningOnline Network with CAPA Login</title>
  180: </head>
  181: ENDHEADER
  182: # ---------------------------------------------------- Serve out DES JavaScript
  183:     {
  184: 	my $jsh=Apache::File->new($include."/londes.js");
  185:         $r->print(<$jsh>);
  186:     }
  187: 
  188: # ----------------------------------------------------------- Front page design
  189:     my $pgbg=
  190:       ($fullgraph?&Apache::loncommon::designparm('login.pgbg',$domain):'#FFFFFF');
  191:     my $font=
  192:       ($fullgraph?&Apache::loncommon::designparm('login.font',$domain):'#000000');
  193:     my $link=
  194:       ($fullgraph?&Apache::loncommon::designparm('login.link',$domain):'#0000FF');
  195:     my $vlink=
  196:       ($fullgraph?&Apache::loncommon::designparm('login.vlink',$domain):'#0000FF');
  197:     my $alink=&Apache::loncommon::designparm('login.alink',$domain);
  198:     my $mainbg=
  199:       ($fullgraph?&Apache::loncommon::designparm('login.mainbg',$domain):'#FFFFFF');
  200:     my $sidebg=
  201:       ($fullgraph?&Apache::loncommon::designparm('login.sidebg',$domain):'#FFFFFF');
  202:     my $logo=&Apache::loncommon::designparm('login.logo',$domain);
  203:     my $img=&Apache::loncommon::designparm('login.img',$domain);
  204: 
  205: 
  206: # ---------------------------------------------------------- Serve rest of page
  207:     $r->print(<<ENDSCRIPT);
  208: 
  209: <body bgcolor="$pgbg" text="$font" link="$link" vlink="$vlink" alink="$alink"
  210:   topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
  211: 
  212:  <script language="JavaScript">
  213:     function send()
  214:     {
  215: 	this.document.server.elements.uname.value
  216:        =this.document.client.elements.uname.value;
  217: 
  218:         this.document.server.elements.udom.value
  219:        =this.document.client.elements.udom.value;
  220: 
  221:         this.document.server.elements.imagesuppress.value
  222:        =this.document.client.elements.imagesuppress.checked;
  223: 
  224:         this.document.server.elements.embedsuppress.value
  225:        =this.document.client.elements.embedsuppress.checked;
  226: 
  227:         this.document.server.elements.appletsuppress.value
  228:        =this.document.client.elements.appletsuppress.checked;
  229: 
  230:         this.document.server.elements.fontenhance.value
  231:        =this.document.client.elements.fontenhance.checked;
  232: 
  233:         this.document.server.elements.blackwhite.value
  234:        =this.document.client.elements.blackwhite.checked;
  235: 
  236:         this.document.server.elements.remember.value
  237:        =this.document.client.elements.remember.checked;
  238: 
  239:         uextkey=this.document.client.elements.uextkey.value;
  240:         lextkey=this.document.client.elements.lextkey.value;
  241:         initkeys();
  242: 
  243:         this.document.server.elements.upass.value
  244: 	    =crypted(this.document.client.elements.upass.value);
  245: 
  246:         this.document.server.submit();
  247: 	return false;
  248:     }
  249:  </script>
  250: ENDSCRIPT
  251: 
  252:     if ($fullgraph) {
  253: 	$r->print(
  254: 		  '<table width="100%" cellpadding=0 cellspacing=0 border=0>');
  255:     }
  256: 
  257:     $r->print(<<ENDSERVERFORM);
  258:   <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">
  259:    <input type="hidden" name="logtoken" value="$logtoken" />
  260:    <input type="hidden" name="serverid" value="$lonhost" />
  261:    <input type="hidden" name="interface" value="$ENV{'form.interface'}" />
  262:    <input type="hidden" name="uname" value="" />
  263:    <input type="hidden" name="upass" value="" />
  264:    <input type="hidden" name="udom" value="" />
  265:    <input type="hidden" name="imagesuppress"  value="" />
  266:    <input type="hidden" name="appletsuppress"  value="" />
  267:    <input type="hidden" name="embedsuppress"  value="" />
  268:    <input type="hidden" name="fontenhance"  value="" />
  269:    <input type="hidden" name="blackwhite"  value="" />
  270:    <input type="hidden" name="remember"  value="" />
  271:    <input type="hidden" name="localpath" value="$ENV{'form.localpath'}" />
  272:    <input type="hidden" name="localres" value="$ENV{'form.localres'}" />
  273:   </form>
  274: ENDSERVERFORM
  275:     if ($fullgraph) { $r->print(<<ENDTOP);
  276:   <!-- The LON-CAPA Header -->
  277:   <tr>
  278: 
  279:    <!-- Row 1 Columns 2-4 -->
  280:    <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>
  281:   </tr>
  282: 
  283:   <!-- The gray bar that starts the two table frames -->
  284:   <tr>
  285: 
  286:    <!-- Row 2 Column 1 -->
  287:    <td width=182 height=27 bgcolor="$sidebg">&nbsp;</td>
  288: 
  289:    <!-- Row 2 Column 2 -->
  290:    <td width=27 height=27 align="left" background="$iconpath/filltop.gif"><img src="$iconpath/upperleft.gif" border=0 alt="" /></td>
  291: 
  292:    <!-- Row 2 Column 3 -->
  293:    <td height=27 background="$iconpath/filltop.gif"><img src="$iconpath/filltop.gif" alt="" /></td>
  294: 
  295:    <!-- Row 2 Column 4 -->
  296:    <td width=27 height=27 align="right" background="$iconpath/filltop.gif"><img src="$iconpath/upperright.gif" border=0 alt="" /></td>
  297:   </tr>
  298:   <tr>
  299:    
  300:    <!-- A cell that will hold the 'access' and 'about' buttons -->
  301:    <!-- Row 3 Column 1 -->
  302:    <td valign="top" height=60 align="center" bgcolor="$sidebg">
  303:     <a href="/adm/login?interface=textual"><img src="$iconpath/accessbutton.gif" border=0 alt="Accessibility Options" /></a>
  304:     <br />
  305:     <a href="/adm/about.html"><img src="$iconpath/aboutlon.gif" border=0 alt="About LON-CAPA" /></a>
  306:    </td>
  307: 
  308:    <!-- The shaded space between the two main columns -->
  309:    <!-- Row 3 Column 2 -->
  310:    <td width=27 height=60 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
  311: 
  312:    <!-- The right main column holding the large LON-CAPA logo-->
  313:    <!-- Rows 3-4 Column 3 -->
  314:    <td align="center" valign="top" width="100%" height="100%" rowspan=2 bgcolor="$mainbg">
  315:     <center>
  316:      <img src="$logo" alt="" />
  317:     </center>
  318:    </td>
  319: 
  320:    <!-- Row 3 Column 4 -->
  321:    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  322:   </tr>
  323:   <tr>
  324: 
  325:    <!-- The entry form -->
  326:    <!-- Row 4 Column 1 -->
  327:    <td align="center" valign="middle" bgcolor="$sidebg">
  328: ENDTOP
  329: } else {
  330:     $r->print('<h1>The Learning<i>Online</i> Network with CAPA</h1><h2>Text-based Interface Login</h2>');
  331: }
  332:     $r->print('<form name="client" onsubmit="return(send())">');
  333:     unless ($fullgraph) {
  334:         $r->print(<<ENDACCESSOPTIONS);
  335: <h3>Select Accessibility Options</h3>
  336: <input type="checkbox" name="imagesuppress" /> Suppress rendering of images<br />
  337: <input type="checkbox" name="appletsuppress" /> Suppress Java applets<br />
  338: <input type="checkbox" name="embedsuppress" /> Suppress rendering of embedded multimedia<br />
  339: <input type="checkbox" name="fontenhance" /> Increase font size<br />
  340: <input type="checkbox" name="blackwhite" /> Switch to black and white mode<br />
  341: <p>If you have accessibility needs that are not addressed by this interface, 
  342: please
  343: contact the system administrator at <tt>$sysadm</tt>.</p><br />
  344: <input type="checkbox" name="remember" /> Remember these settings for next login<hr />
  345: ENDACCESSOPTIONS
  346: } else {
  347:     $r->print(<<ENDNOOPT);
  348: <input type="hidden" name="imagesuppress"  value="" />
  349: <input type="hidden" name="embedsuppress"  value="" />
  350: <input type="hidden" name="appletsuppress"  value="" />
  351: <input type="hidden" name="fontenhance"  value="" />
  352: <input type="hidden" name="blackwhite"  value="" />
  353: <input type="hidden" name="remember"  value="" />
  354: ENDNOOPT
  355: }
  356:     $r->print(<<ENDLOGIN);
  357:      <input type="hidden" name="lextkey" value="$lextkey">
  358:      <input type="hidden" name="uextkey" value="$uextkey">
  359: 
  360:      <!-- Start the sub-table for text and input alignment -->
  361:      <table border=0 cellspacing=0 cellpadding=0>
  362:       <tr><td bgcolor="$sidebg" colspan=2><img src="$iconpath/userauthentication.gif" alt="User Authentication" /></td></tr>
  363:       <tr>
  364:        <td bgcolor="$mainbg"><br /><font size=-1><b>&nbsp;&nbsp;&nbsp;User Name:</b></font></td>
  365:        <td bgcolor="$mainbg"><br /><input type="text" name="uname" size="10" value="$authusername" /></td>
  366:       </tr>
  367:       <tr>
  368:        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Password:</b></font></td>
  369:        <td bgcolor="$mainbg"><input type="password" name="upass" size="10" /></td>
  370:       </tr>
  371:       <tr>
  372:        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Domain:</b></font></td>
  373:        <td bgcolor="$mainbg"><input type="text" name="udom" size="10" value="$authdomain" /></td>
  374:       </tr>
  375:       <tr>
  376:        <td bgcolor="$mainbg">&nbsp;&nbsp;&nbsp;<a href="/adm/loginproblems.html">Help</a></td>
  377:        <td bgcolor="$mainbg" valign="bottom" align="center">
  378:         <br />
  379:         <input type="submit" value="Log In" />
  380:        </td>
  381:       </tr>
  382:      </table>
  383:      <!-- End sub-table -->
  384:     </form>
  385: ENDLOGIN
  386:     if ($fullgraph) {
  387: 	$r->print(<<ENDDOCUMENT);
  388:    </td>
  389: 
  390:    <!-- Row 4 Column 2 -->
  391:    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
  392: 
  393:    <!-- Row 4 Column 4 -->
  394:    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  395:   </tr>
  396:   <tr>
  397: 
  398:    <!-- Row 5 Column 1 -->
  399:    <td bgcolor="$sidebg" valign="middle" align="left">
  400:      <br />
  401:      <table border=0 cellspacing=0 cellpadding=0>
  402:       <tr>
  403:        <td bgcolor="$sidebg" align="left" valign="top">
  404:         <small><b>&nbsp;&nbsp;&nbsp;Domain:&nbsp;</b></small>
  405:        </td>
  406:        <td bgcolor="$sidebg" align="left" valign="top">
  407:         <small><tt>&nbsp;$domain</tt></small>
  408:        </td>
  409:       </tr>
  410:       <tr>
  411:        <td bgcolor="$sidebg" align="left" valign="top">
  412:         <small><b>&nbsp;&nbsp;&nbsp;Server:&nbsp;</b></small>
  413:        </td>
  414:        <td bgcolor="$sidebg" align="left" valign="top">
  415:         <small><tt>&nbsp;$lonhost ($role)</tt></small>
  416:        </td>
  417:       </tr>
  418:       <tr>
  419:        <td bgcolor="$sidebg" align="left" valign="top">
  420:         <small><b>&nbsp;&nbsp;&nbsp;Load:&nbsp;</b></small>
  421:        </td>
  422:        <td bgcolor="$sidebg" align="left" valign="top">
  423:         <small><tt>&nbsp;$loadpercent percent</tt></small>
  424:        </td>
  425:       </tr>
  426:       <tr>
  427:        <td bgcolor="$sidebg" align="left" valign="top">
  428:         <small><b>&nbsp;&nbsp;&nbsp;User&nbsp;Load:&nbsp;</b></small>
  429:        </td>
  430:        <td bgcolor="$sidebg" align="left" valign="top">
  431:         <small><tt>&nbsp;$userloadpercent percent</tt></small>
  432:        </td>
  433:       </tr>
  434:      </table>
  435:      <br />
  436:     <small>
  437:      <b>&nbsp;&nbsp;&nbsp;System Administration:</b><br />
  438:      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sysadm</tt><br />
  439:      <b>&nbsp;&nbsp;&nbsp;Server Administration:</b><br />
  440:      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$servadm</tt><br />&nbsp;<br />
  441:      &nbsp;&nbsp;&nbsp;$version
  442:     </small>
  443:    </td>
  444: 
  445:    <!-- Row 5 Column 2 -->
  446:    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
  447: 
  448:    <!-- Row 5 Column 3 -->
  449:    <td width="100%" valign="bottom" bgcolor="$mainbg">
  450: $domainlogo
  451: </td>
  452: 
  453:    <!-- Row 5 Column 4 -->
  454:    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  455:   </tr>
  456:   <tr>
  457: 
  458:    <!-- Row 6 Column 1 -->
  459:    <td bgcolor="$sidebg">&nbsp;</td>
  460: 
  461:    <!-- Row 6 Column 2 -->
  462:    <td align="left" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerleft.gif" alt="" /></td>
  463: 
  464:    <!-- Row 6 Column 3 -->
  465:    <td background="$iconpath/fillbottom.gif"><img src="$iconpath/fillbottom.gif" alt="" /></td>
  466: 
  467:    <!-- Row 6 Column 4 -->
  468:    <td align="right" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerright.gif" alt="" /></td>
  469:   </tr>
  470:  </table>
  471: 
  472: <script>
  473: // the if prevents the script error if the browser can't handle this
  474: if ( document.client.uname ) { document.client.uname.focus(); }
  475: </script>
  476: 
  477: ENDDOCUMENT
  478: }
  479:     $r->print('</body></html>');
  480:     return OK;
  481: } 
  482: 
  483: 1;
  484: __END__

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