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