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