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