File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.31: download - view: text, annotated - select for diffs
Tue Feb 4 16:03:25 2003 UTC (21 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
Give people some options if lonc/lond is down on current server.

    1: # The LearningOnline Network
    2: # Login Screen
    3: #
    4: # $Id: lonlogin.pm,v 1.31 2003/02/04 16:03:25 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
   29: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9,
   30: # 1/17/01 Gerd Kortemeyer
   31: #
   32: # 2/7/02,2/8,2/12,2/14,2/15,2/19 Josh Brunskole
   33: # 
   34: # 7/10/02 Jeremy Bowers
   35: 
   36: package Apache::lonlogin;
   37: 
   38: use strict;
   39: use Apache::Constants qw(:common);
   40: use Apache::File ();
   41: use Apache::lonnet();
   42: use Apache::loncommon();
   43: 
   44: sub handler {
   45:     my $r = shift;
   46:     $r->content_type('text/html');
   47:     &Apache::loncommon::no_cache($r);
   48:     $r->send_http_header;
   49:     return OK if $r->header_only;
   50: 
   51: 
   52:     &Apache::loncommon::get_unprocessed_cgi
   53:      ($ENV{'QUERY_STRING'},['interface','username','domain','firsturl']);
   54: 
   55:     $ENV{'form.interface'}=~s/\W//g;
   56: 
   57:     my $fullgraph=($ENV{'form.interface'} ne 'textual');
   58: 
   59:     my $iconpath= 'http://'.$ENV{'HTTP_HOST'}.':8080'.
   60:                   $r->dir_config('lonIconsURL');
   61:     my $domain  = $r->dir_config('lonDefDomain');
   62:     my $role    = $r->dir_config('lonRole');
   63:     my $loadlim = $r->dir_config('lonLoadLim');
   64:     my $servadm = $r->dir_config('lonAdmEMail');
   65:     my $sysadm  = $r->dir_config('lonSysEMail');
   66:     my $lonhost = $r->dir_config('lonHostID');
   67:     my $tabdir  = $r->dir_config('lonTabDir');
   68:     my $include = $r->dir_config('lonIncludes');
   69: 
   70: # --------------------------------------------- Default values for login fields
   71: 
   72:     my $authusername=($ENV{'form.username'}?$ENV{'form.username'}:'');
   73:     my $authdomain=($ENV{'form.domain'}?$ENV{'form.domain'}:$domain);
   74: 
   75: # ---------------------------------------------------------- Determine own load
   76:     my $loadavg;
   77:    {
   78:        my $loadfile=Apache::File->new('/proc/loadavg');
   79:        $loadavg=<$loadfile>;
   80:    }
   81:     $loadavg =~ s/\s.*//g;
   82:     my $loadpercent=100*$loadavg/$loadlim;
   83: 
   84: # ------------------------------------------------------- Do the load balancing
   85:     my $otherserver='http://'.$ENV{'SERVER_NAME'};
   86:     my $firsturl=
   87:     ($ENV{'request.firsturl'}?$ENV{'request.firsturl'}:$ENV{'form.firsturl'});
   88: # ---------------------------------------- Are we access server and overloaded?
   89:     if (($role eq 'access') && ($loadpercent>100.0)) {
   90:         $otherserver=Apache::lonnet::spareserver($loadpercent);
   91:     }
   92: 
   93: # -------------------------------------------------------- Set login parameters
   94: 
   95:     my @hexstr=('0','1','2','3','4','5','6','7',
   96:                 '8','9','a','b','c','d','e','f');
   97:     my $lkey='';
   98:     for (0..7) {
   99:         $lkey.=$hexstr[rand(15)];
  100:     }
  101: 
  102:     my $ukey='';
  103:     for (0..7) {
  104:         $ukey.=$hexstr[rand(15)];
  105:     }
  106: 
  107:     my $lextkey=hex($lkey);
  108:     if ($lextkey>2147483647) { $lextkey-=4294967296; }
  109: 
  110:     my $uextkey=hex($ukey);
  111:     if ($uextkey>2147483647) { $uextkey-=4294967296; }
  112: 
  113: # -------------------------------------------------------- Store away log token
  114:     my $logtoken=Apache::lonnet::reply(
  115:        'tmpput:'.$ukey.$lkey.'&'.$firsturl,
  116:        $lonhost);
  117: 
  118: # ------------------- If we cannot talk to ourselves, we are in serious trouble
  119: 
  120:     if ($logtoken eq 'con_lost') {
  121:         my $spares='';
  122:         foreach (keys %Apache::lonnet::hostname) {
  123:             if ($_ ne $lonhost) {
  124:                $spares.='<br /><a href="http://'.$Apache::lonnet::hostname{$_}.
  125: 		 '/adm/login?domain='.$authdomain.'">'.
  126:                  $Apache::lonnet::hostname{$_}.'</a>';
  127:                if ($Apache::lonnet::spareid{$_}) {
  128: 		   $spares.=' (preferred)';
  129:                }
  130: 	   }
  131:         }
  132: 	$r->print(<<ENDTROUBLE);
  133: <html>
  134: <head><title>The LearningOnline Network with CAPA</title></head>
  135: <body bgcolor="#FFFFFF">
  136: <img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />
  137: <h3>This LON-CAPA server is temporarily not available for login</h3>
  138: <p>Please attempt to login to one of the following servers:</p>$spares
  139: <p>If the problem persists, please contact <tt>$servadm</tt>.</p>
  140: </body>
  141: </html>
  142: ENDTROUBLE
  143:         return OK;
  144:     }
  145: 
  146: # ----------------------------------------------- Apparently we are in business
  147: 
  148:     my $domainlogo=&Apache::loncommon::domainlogo();
  149: # --------------------------------------------------- Print login screen header
  150:     $r->print(<<ENDHEADER);
  151: <html>
  152: <head>
  153: <title>The LearningOnline Network with CAPA Login</title>
  154: </head>
  155: ENDHEADER
  156: # ---------------------------------------------------- Serve out DES JavaScript
  157:     {
  158: 	my $jsh=Apache::File->new($include."/londes.js");
  159:         $r->print(<$jsh>);
  160:     }
  161: 
  162: # ----------------------------------------------------------- Front page design
  163:     my $pgbg=&Apache::loncommon::designparm('login.pgbg');
  164:     my $font=&Apache::loncommon::designparm('login.font');
  165:     my $link=&Apache::loncommon::designparm('login.link');
  166:     my $vlink=&Apache::loncommon::designparm('login.vlink');
  167:     my $alink=&Apache::loncommon::designparm('login.alink');
  168:     my $mainbg=&Apache::loncommon::designparm('login.mainbg');
  169:     my $sidebg=&Apache::loncommon::designparm('login.sidebg');
  170:     my $logo=&Apache::loncommon::designparm('login.logo');
  171:     my $img=&Apache::loncommon::designparm('login.img');
  172: 
  173: 
  174: # ---------------------------------------------------------- Serve rest of page
  175:     $r->print(<<ENDSCRIPT);
  176: 
  177: <body bgcolor="$pgbg" text="$font" link="$link" vlink="$vlink" alink="$alink"
  178:   topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
  179: 
  180:  <script language="JavaScript">
  181:     function send()
  182:     {
  183: 	this.document.server.elements.uname.value
  184:        =this.document.client.elements.uname.value;
  185: 
  186:         this.document.server.elements.udom.value
  187:        =this.document.client.elements.udom.value;
  188: 
  189:         uextkey=this.document.client.elements.uextkey.value;
  190:         lextkey=this.document.client.elements.lextkey.value;
  191:         initkeys();
  192: 
  193:         this.document.server.elements.upass.value
  194: 	    =crypted(this.document.client.elements.upass.value);
  195: 
  196:         this.document.server.submit();
  197: 	return false;
  198:     }
  199:  </script>
  200: ENDSCRIPT
  201: 
  202:     if ($fullgraph) {
  203: 	$r->print(
  204: 		  '<table width="100%" cellpadding=0 cellspacing=0 border=0>');
  205:     }
  206: 
  207:     $r->print(<<ENDSERVERFORM);
  208:   <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">
  209:    <input type=hidden name=logtoken value="$logtoken">
  210:    <input type=hidden name=serverid value="$lonhost">
  211:    <input type=hidden name=interface value="$ENV{'form.interface'}">
  212:    <input type=hidden name=uname value="">
  213:    <input type=hidden name=upass value="">
  214:    <input type=hidden name=udom value="">
  215:   </form>
  216: ENDSERVERFORM
  217:     if ($fullgraph) { $r->print(<<ENDTOP);
  218:   <!-- The LON-CAPA Header -->
  219:   <tr>
  220: 
  221:    <!-- Row 1 Columns 2-4 -->
  222:    <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>
  223:   </tr>
  224: 
  225:   <!-- The gray bar that starts the two table frames -->
  226:   <tr>
  227: 
  228:    <!-- Row 2 Column 1 -->
  229:    <td width=182 height=27 bgcolor="$sidebg">&nbsp;</td>
  230: 
  231:    <!-- Row 2 Column 2 -->
  232:    <td width=27 height=27 align="left" background="$iconpath/filltop.gif"><img src="$iconpath/upperleft.gif" border=0 alt="" /></td>
  233: 
  234:    <!-- Row 2 Column 3 -->
  235:    <td height=27 background="$iconpath/filltop.gif"><img src="$iconpath/filltop.gif" alt="" /></td>
  236: 
  237:    <!-- Row 2 Column 4 -->
  238:    <td width=27 height=27 align="right" background="$iconpath/filltop.gif"><img src="$iconpath/upperright.gif" border=0 alt="" /></td>
  239:   </tr>
  240:   <tr>
  241:    
  242:    <!-- A cell that will hold the 'access' and 'about' buttons -->
  243:    <!-- Row 3 Column 1 -->
  244:    <td valign="top" height=60 align="center" bgcolor="$sidebg">
  245:     <a href="/adm/login?interface=textual"><img src="$iconpath/accessbutton.gif" border=0 alt="Accessibility Options" /></a>
  246:     <br />
  247:     <a href="/adm/about.html"><img src="$iconpath/aboutlon.gif" border=0 alt="About LON-CAPA" /></a>
  248:    </td>
  249: 
  250:    <!-- The shaded space between the two main columns -->
  251:    <!-- Row 3 Column 2 -->
  252:    <td width=27 height=60 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
  253: 
  254:    <!-- The right main column holding the large LON-CAPA logo-->
  255:    <!-- Rows 3-4 Column 3 -->
  256:    <td align="center" valign="top" width="100%" height="100%" rowspan=2 bgcolor="$mainbg">
  257:     <center>
  258:      <img src="$logo" alt="" />
  259:     </center>
  260:    </td>
  261: 
  262:    <!-- Row 3 Column 4 -->
  263:    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  264:   </tr>
  265:   <tr>
  266: 
  267:    <!-- The entry form -->
  268:    <!-- Row 4 Column 1 -->
  269:    <td align="center" valign="middle" bgcolor="$sidebg">
  270: ENDTOP
  271: }
  272:     $r->print(<<ENDLOGIN);
  273:     <form name="client" onsubmit="return(send())">
  274:      <input type="hidden" name="lextkey" value="$lextkey">
  275:      <input type="hidden" name="uextkey" value="$uextkey">
  276: 
  277:      <!-- Start the sub-table for text and input alignment -->
  278:      <table border=0 cellspacing=0 cellpadding=0>
  279:       <tr><td bgcolor="$sidebg" colspan=2><img src="$iconpath/userauthentication.gif" alt="User Authentication" /></td></tr>
  280:       <tr>
  281:        <td bgcolor="$mainbg"><br /><font size=-1><b>&nbsp;&nbsp;&nbsp;User Name:</b></font></td>
  282:        <td bgcolor="$mainbg"><br /><input type="text" name="uname" size="10" value="$authusername" /></td>
  283:       </tr>
  284:       <tr>
  285:        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Password:</b></font></td>
  286:        <td bgcolor="$mainbg"><input type="password" name="upass" size="10" /></td>
  287:       </tr>
  288:       <tr>
  289:        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Domain:</b></font></td>
  290:        <td bgcolor="$mainbg"><input type="text" name="udom" size="10" value="$authdomain" /></td>
  291:       </tr>
  292:       <tr>
  293:        <td bgcolor="$mainbg">&nbsp;&nbsp;&nbsp;<a href="/adm/loginproblems.html">Help</a></td>
  294:        <td bgcolor="$mainbg" valign="bottom" align="center">
  295:         <br />
  296:         <input type="submit" value="Log In" />
  297:        </td>
  298:       </tr>
  299:      </table>
  300:      <!-- End sub-table -->
  301:     </form>
  302: ENDLOGIN
  303:     if ($fullgraph) {
  304: 	$r->print(<<ENDDOCUMENT);
  305:    </td>
  306: 
  307:    <!-- Row 4 Column 2 -->
  308:    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
  309: 
  310:    <!-- Row 4 Column 4 -->
  311:    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  312:   </tr>
  313:   <tr>
  314: 
  315:    <!-- Row 5 Column 1 -->
  316:    <td bgcolor="$sidebg" valign="middle" align="left">
  317:      <br />
  318:      <table border=0 cellspacing=0 cellpadding=0>
  319:       <tr>
  320:        <td bgcolor="$sidebg" align="left" valign="top">
  321:         <small><b>&nbsp;&nbsp;&nbsp;Domain:&nbsp;</b></small>
  322:        </td>
  323:        <td bgcolor="$sidebg" align="left" valign="top">
  324:         <small><tt>&nbsp;$domain</tt></small>
  325:        </td>
  326:       </tr>
  327:       <tr>
  328:        <td bgcolor="$sidebg" align="left" valign="top">
  329:         <small><b>&nbsp;&nbsp;&nbsp;Server:&nbsp;</b></small>
  330:        </td>
  331:        <td bgcolor="$sidebg" align="left" valign="top">
  332:         <small><tt>&nbsp;$lonhost ($role)</tt></small>
  333:        </td>
  334:       </tr>
  335:       <tr>
  336:        <td bgcolor="$sidebg" align="left" valign="top">
  337:         <small><b>&nbsp;&nbsp;&nbsp;Load:&nbsp;</b></small>
  338:        </td>
  339:        <td bgcolor="$sidebg" align="left" valign="top">
  340:         <small><tt>&nbsp;$loadpercent percent</tt></small>
  341:        </td>
  342:       </tr>
  343:      </table>
  344:      <br />
  345:     <small>
  346:      <b>&nbsp;&nbsp;&nbsp;System Administration:</b><br />
  347:      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sysadm</tt><br />
  348:      <b>&nbsp;&nbsp;&nbsp;Server Administration:</b><br />
  349:      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$servadm<br />&nbsp;</tt>
  350:     </small>
  351:    </td>
  352: 
  353:    <!-- Row 5 Column 2 -->
  354:    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
  355: 
  356:    <!-- Row 5 Column 3 -->
  357:    <td width="100%" valign="bottom" bgcolor="$mainbg">
  358: $domainlogo
  359: </td>
  360: 
  361:    <!-- Row 5 Column 4 -->
  362:    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
  363:   </tr>
  364:   <tr>
  365: 
  366:    <!-- Row 6 Column 1 -->
  367:    <td bgcolor="$sidebg">&nbsp;</td>
  368: 
  369:    <!-- Row 6 Column 2 -->
  370:    <td align="left" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerleft.gif" alt="" /></td>
  371: 
  372:    <!-- Row 6 Column 3 -->
  373:    <td background="$iconpath/fillbottom.gif"><img src="$iconpath/fillbottom.gif" alt="" /></td>
  374: 
  375:    <!-- Row 6 Column 4 -->
  376:    <td align="right" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerright.gif" alt="" /></td>
  377:   </tr>
  378:  </table>
  379: 
  380: <script>
  381: // the if prevents the script error if the browser can't handle this
  382: if ( document.client.uname ) { document.client.uname.focus(); }
  383: </script>
  384: 
  385: ENDDOCUMENT
  386: }
  387:     $r->print('</body></html>');
  388:     return OK;
  389: } 
  390: 
  391: 1;
  392: __END__

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