Annotation of nsdl/nsdlloncapaorg/lonlogin.pm, revision 1.3

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

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