Annotation of loncom/auth/lonlogin.pm, revision 1.34

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

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