File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.48: download - view: text, annotated - select for diffs
Tue Sep 2 22:28:19 2003 UTC (20 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- need to tell it what domain

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

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