1: # The LearningOnline Network
2: # Login Screen
3: #
4: # $Id: lonlogin.pm,v 1.36 2003/02/20 01:35:27 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: # ----------------------------------------------------------- Process Interface
56: $ENV{'form.interface'}=~s/\W//g;
57:
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:
67: my $fullgraph=($ENV{'form.interface'} ne 'textual');
68:
69: my $iconpath= 'http://'.$ENV{'HTTP_HOST'}.':8080'.
70: $r->dir_config('lonIconsURL');
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');
78: my $include = $r->dir_config('lonIncludes');
79:
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
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:
94: # ------------------------------------------------------- Do the load balancing
95: my $otherserver='http://'.$ENV{'SERVER_NAME'};
96: my $firsturl=
97: ($ENV{'request.firsturl'}?$ENV{'request.firsturl'}:$ENV{'form.firsturl'});
98: # ---------------------------------------- Are we access server and overloaded?
99: if (($role eq 'access') && ($loadpercent>100.0)) {
100: $otherserver=Apache::lonnet::spareserver($loadpercent);
101: }
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);
118: if ($lextkey>2147483647) { $lextkey-=4294967296; }
119:
120: my $uextkey=hex($ukey);
121: if ($uextkey>2147483647) { $uextkey-=4294967296; }
122:
123: # -------------------------------------------------------- Store away log token
124: my $logtoken=Apache::lonnet::reply(
125: 'tmpput:'.$ukey.$lkey.'&'.$firsturl,
126: $lonhost);
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:
158: my $domainlogo=&Apache::loncommon::domainlogo();
159: # --------------------------------------------------- Print login screen header
160: $r->print(<<ENDHEADER);
161: <html>
162: <head>
163: <title>The LearningOnline Network with CAPA Login</title>
164: </head>
165: ENDHEADER
166: # ---------------------------------------------------- Serve out DES JavaScript
167: {
168: my $jsh=Apache::File->new($include."/londes.js");
169: $r->print(<$jsh>);
170: }
171:
172: # ----------------------------------------------------------- Front page design
173: my $pgbg=
174: ($fullgraph?&Apache::loncommon::designparm('login.pgbg'):'#FFFFFF');
175: my $font=
176: ($fullgraph?&Apache::loncommon::designparm('login.font'):'#000000');
177: my $link=
178: ($fullgraph?&Apache::loncommon::designparm('login.link'):'#0000FF');
179: my $vlink=
180: ($fullgraph?&Apache::loncommon::designparm('login.vlink'):'#0000FF');
181: my $alink=&Apache::loncommon::designparm('login.alink');
182: my $mainbg=
183: ($fullgraph?&Apache::loncommon::designparm('login.mainbg'):'#FFFFFF');
184: my $sidebg=
185: ($fullgraph?&Apache::loncommon::designparm('login.sidebg'):'#FFFFFF');
186: my $logo=&Apache::loncommon::designparm('login.logo');
187: my $img=&Apache::loncommon::designparm('login.img');
188:
189:
190: # ---------------------------------------------------------- Serve rest of page
191: $r->print(<<ENDSCRIPT);
192:
193: <body bgcolor="$pgbg" text="$font" link="$link" vlink="$vlink" alink="$alink"
194: topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
195:
196: <script language="JavaScript">
197: function send()
198: {
199: this.document.server.elements.uname.value
200: =this.document.client.elements.uname.value;
201:
202: this.document.server.elements.udom.value
203: =this.document.client.elements.udom.value;
204:
205: this.document.server.elements.imagesuppress.value
206: =this.document.client.elements.imagesuppress.checked;
207:
208: this.document.server.elements.embedsuppress.value
209: =this.document.client.elements.embedsuppress.checked;
210:
211: this.document.server.elements.appletsuppress.value
212: =this.document.client.elements.appletsuppress.checked;
213:
214: this.document.server.elements.fontenhance.value
215: =this.document.client.elements.fontenhance.checked;
216:
217: this.document.server.elements.blackwhite.value
218: =this.document.client.elements.blackwhite.checked;
219:
220: this.document.server.elements.remember.value
221: =this.document.client.elements.remember.checked;
222:
223: uextkey=this.document.client.elements.uextkey.value;
224: lextkey=this.document.client.elements.lextkey.value;
225: initkeys();
226:
227: this.document.server.elements.upass.value
228: =crypted(this.document.client.elements.upass.value);
229:
230: this.document.server.submit();
231: return false;
232: }
233: </script>
234: ENDSCRIPT
235:
236: if ($fullgraph) {
237: $r->print(
238: '<table width="100%" cellpadding=0 cellspacing=0 border=0>');
239: }
240:
241: $r->print(<<ENDSERVERFORM);
242: <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">
243: <input type="hidden" name="logtoken" value="$logtoken" />
244: <input type="hidden" name="serverid" value="$lonhost" />
245: <input type="hidden" name="interface" value="$ENV{'form.interface'}" />
246: <input type="hidden" name="uname" value="" />
247: <input type="hidden" name="upass" value="" />
248: <input type="hidden" name="udom" value="" />
249: <input type="hidden" name="imagesuppress" value="" />
250: <input type="hidden" name="appletsuppress" value="" />
251: <input type="hidden" name="embedsuppress" value="" />
252: <input type="hidden" name="fontenhance" value="" />
253: <input type="hidden" name="blackwhite" value="" />
254: <input type="hidden" name="remember" value="" />
255: </form>
256: ENDSERVERFORM
257: if ($fullgraph) { $r->print(<<ENDTOP);
258: <!-- The LON-CAPA Header -->
259: <tr>
260:
261: <!-- Row 1 Columns 2-4 -->
262: <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>
263: </tr>
264:
265: <!-- The gray bar that starts the two table frames -->
266: <tr>
267:
268: <!-- Row 2 Column 1 -->
269: <td width=182 height=27 bgcolor="$sidebg"> </td>
270:
271: <!-- Row 2 Column 2 -->
272: <td width=27 height=27 align="left" background="$iconpath/filltop.gif"><img src="$iconpath/upperleft.gif" border=0 alt="" /></td>
273:
274: <!-- Row 2 Column 3 -->
275: <td height=27 background="$iconpath/filltop.gif"><img src="$iconpath/filltop.gif" alt="" /></td>
276:
277: <!-- Row 2 Column 4 -->
278: <td width=27 height=27 align="right" background="$iconpath/filltop.gif"><img src="$iconpath/upperright.gif" border=0 alt="" /></td>
279: </tr>
280: <tr>
281:
282: <!-- A cell that will hold the 'access' and 'about' buttons -->
283: <!-- Row 3 Column 1 -->
284: <td valign="top" height=60 align="center" bgcolor="$sidebg">
285: <a href="/adm/login?interface=textual"><img src="$iconpath/accessbutton.gif" border=0 alt="Accessibility Options" /></a>
286: <br />
287: <a href="/adm/about.html"><img src="$iconpath/aboutlon.gif" border=0 alt="About LON-CAPA" /></a>
288: </td>
289:
290: <!-- The shaded space between the two main columns -->
291: <!-- Row 3 Column 2 -->
292: <td width=27 height=60 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
293:
294: <!-- The right main column holding the large LON-CAPA logo-->
295: <!-- Rows 3-4 Column 3 -->
296: <td align="center" valign="top" width="100%" height="100%" rowspan=2 bgcolor="$mainbg">
297: <center>
298: <img src="$logo" alt="" />
299: </center>
300: </td>
301:
302: <!-- Row 3 Column 4 -->
303: <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
304: </tr>
305: <tr>
306:
307: <!-- The entry form -->
308: <!-- Row 4 Column 1 -->
309: <td align="center" valign="middle" bgcolor="$sidebg">
310: ENDTOP
311: } else {
312: $r->print('<h1>The Learning<i>Online</i> Network with CAPA</h1><h2>Text-based Interface Login</h2>');
313: }
314: $r->print('<form name="client" onsubmit="return(send())">');
315: unless ($fullgraph) {
316: $r->print(<<ENDACCESSOPTIONS);
317: <h3>Select Accessibility Options</h3>
318: <input type="checkbox" name="imagesuppress" /> Suppress rendering of images<br />
319: <input type="checkbox" name="appletsuppress" /> Suppress Java applets<br />
320: <input type="checkbox" name="embedsuppress" /> Suppress rendering of embedded multimedia<br />
321: <input type="checkbox" name="fontenhance" /> Increase font size<br />
322: <input type="checkbox" name="blackwhite" /> Switch to black and white mode<br />
323: <p>If you have accessibility needs that are not addressed by this interface,
324: please
325: contact the system administrator at <tt>$sysadm</tt>.</p><br />
326: <input type="checkbox" name="remember" /> Remember these settings for next login<hr />
327: ENDACCESSOPTIONS
328: } else {
329: $r->print(<<ENDNOOPT);
330: <input type="hidden" name="imagesuppress" value="" />
331: <input type="hidden" name="embedsuppress" value="" />
332: <input type="hidden" name="appletsuppress" value="" />
333: <input type="hidden" name="fontenhance" value="" />
334: <input type="hidden" name="blackwhite" value="" />
335: <input type="hidden" name="remember" value="" />
336: ENDNOOPT
337: }
338: $r->print(<<ENDLOGIN);
339: <input type="hidden" name="lextkey" value="$lextkey">
340: <input type="hidden" name="uextkey" value="$uextkey">
341:
342: <!-- Start the sub-table for text and input alignment -->
343: <table border=0 cellspacing=0 cellpadding=0>
344: <tr><td bgcolor="$sidebg" colspan=2><img src="$iconpath/userauthentication.gif" alt="User Authentication" /></td></tr>
345: <tr>
346: <td bgcolor="$mainbg"><br /><font size=-1><b> User Name:</b></font></td>
347: <td bgcolor="$mainbg"><br /><input type="text" name="uname" size="10" value="$authusername" /></td>
348: </tr>
349: <tr>
350: <td bgcolor="$mainbg"><font size=-1><b> Password:</b></font></td>
351: <td bgcolor="$mainbg"><input type="password" name="upass" size="10" /></td>
352: </tr>
353: <tr>
354: <td bgcolor="$mainbg"><font size=-1><b> Domain:</b></font></td>
355: <td bgcolor="$mainbg"><input type="text" name="udom" size="10" value="$authdomain" /></td>
356: </tr>
357: <tr>
358: <td bgcolor="$mainbg"> <a href="/adm/loginproblems.html">Help</a></td>
359: <td bgcolor="$mainbg" valign="bottom" align="center">
360: <br />
361: <input type="submit" value="Log In" />
362: </td>
363: </tr>
364: </table>
365: <!-- End sub-table -->
366: </form>
367: ENDLOGIN
368: if ($fullgraph) {
369: $r->print(<<ENDDOCUMENT);
370: </td>
371:
372: <!-- Row 4 Column 2 -->
373: <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
374:
375: <!-- Row 4 Column 4 -->
376: <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
377: </tr>
378: <tr>
379:
380: <!-- Row 5 Column 1 -->
381: <td bgcolor="$sidebg" valign="middle" align="left">
382: <br />
383: <table border=0 cellspacing=0 cellpadding=0>
384: <tr>
385: <td bgcolor="$sidebg" align="left" valign="top">
386: <small><b> Domain: </b></small>
387: </td>
388: <td bgcolor="$sidebg" align="left" valign="top">
389: <small><tt> $domain</tt></small>
390: </td>
391: </tr>
392: <tr>
393: <td bgcolor="$sidebg" align="left" valign="top">
394: <small><b> Server: </b></small>
395: </td>
396: <td bgcolor="$sidebg" align="left" valign="top">
397: <small><tt> $lonhost ($role)</tt></small>
398: </td>
399: </tr>
400: <tr>
401: <td bgcolor="$sidebg" align="left" valign="top">
402: <small><b> Load: </b></small>
403: </td>
404: <td bgcolor="$sidebg" align="left" valign="top">
405: <small><tt> $loadpercent percent</tt></small>
406: </td>
407: </tr>
408: </table>
409: <br />
410: <small>
411: <b> System Administration:</b><br />
412: <tt> $sysadm</tt><br />
413: <b> Server Administration:</b><br />
414: <tt> $servadm<br /> </tt>
415: </small>
416: </td>
417:
418: <!-- Row 5 Column 2 -->
419: <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>
420:
421: <!-- Row 5 Column 3 -->
422: <td width="100%" valign="bottom" bgcolor="$mainbg">
423: $domainlogo
424: </td>
425:
426: <!-- Row 5 Column 4 -->
427: <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>
428: </tr>
429: <tr>
430:
431: <!-- Row 6 Column 1 -->
432: <td bgcolor="$sidebg"> </td>
433:
434: <!-- Row 6 Column 2 -->
435: <td align="left" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerleft.gif" alt="" /></td>
436:
437: <!-- Row 6 Column 3 -->
438: <td background="$iconpath/fillbottom.gif"><img src="$iconpath/fillbottom.gif" alt="" /></td>
439:
440: <!-- Row 6 Column 4 -->
441: <td align="right" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerright.gif" alt="" /></td>
442: </tr>
443: </table>
444:
445: <script>
446: // the if prevents the script error if the browser can't handle this
447: if ( document.client.uname ) { document.client.uname.focus(); }
448: </script>
449:
450: ENDDOCUMENT
451: }
452: $r->print('</body></html>');
453: return OK;
454: }
455:
456: 1;
457: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>