File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.49: download - view: text, annotated - select for diffs
Thu Sep 11 20:54:11 2003 UTC (20 years, 8 months ago) by www
Branches: MAIN
CVS tags: HEAD
Also have login handlers detect re-reouting.

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

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