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