File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.40: download - view: text, annotated - select for diffs
Thu Apr 3 21:53:51 2003 UTC (21 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- forgot a part when commiting a configuarable lonhttpd port

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

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