File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.45: download - view: text, annotated - select for diffs
Tue Aug 12 19:46:04 2003 UTC (20 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #815: Frontpage announcements can now be entered by
Superusers and Domain Coordinators
on a per-machine-base from "CLDR (Calendar/Announce)".

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

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