1: # The LearningOnline Network
2: # Login Screen
3: #
4: # $Id: lonlogin.pm,v 1.122 2009/05/22 17:01:28 bisitz 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 Apache::File ();
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonauth();
37: use Apache::lonlocal;
38: use Apache::migrateuser();
39: use lib '/home/httpd/lib/perl/';
40: use LONCAPA;
41:
42: sub handler {
43: my $r = shift;
44:
45: &Apache::loncommon::get_unprocessed_cgi
46: (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
47: $ENV{'REDIRECT_QUERY_STRING'}),
48: ['interface','username','domain','firsturl','localpath','localres',
49: 'token']);
50: if (!defined($env{'form.firsturl'})) {
51: &Apache::lonacc::get_posted_cgi($r,['firsturl']);
52: }
53:
54: # -- check if they are a migrating user
55: if (defined($env{'form.token'})) {
56: return &Apache::migrateuser::handler($r);
57: }
58:
59: &Apache::loncommon::no_cache($r);
60: &Apache::lonlocal::get_language_handle($r);
61: &Apache::loncommon::content_type($r,'text/html');
62: $r->send_http_header;
63: return OK if $r->header_only;
64:
65:
66: # Are we re-routing?
67: if (-e '/home/httpd/html/lon-status/reroute.txt') {
68: &Apache::lonauth::reroute($r);
69: return OK;
70: }
71:
72:
73: # -------------------------------- Prevent users from attempting to login twice
74: my $handle = &Apache::lonnet::check_for_valid_session($r);
75: if ($handle=~/^publicuser\_/) {
76: # For "public user" - remove it, we apparently really want to login
77: unlink($r->dir_config('lonIDsDir')."/$handle.id");
78: } elsif ($handle ne '') {
79: # Indeed, a valid token is found
80: my $start_page =
81: &Apache::loncommon::start_page('Already logged in');
82: my $end_page =
83: &Apache::loncommon::end_page();
84: $r->print(
85: $start_page
86: .'<h1>'.&mt('You are already logged in!').'</h1>'
87: .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
88: '<a href="/adm/roles">','</a>','<a href="/adm/logout">','</a>').'</p>'
89: .'<p><a href="/adm/loginproblems.html">'.&mt('Login problems?').'</a></p>'
90: .$end_page
91: );
92: return OK;
93: }
94:
95: # ---------------------------------------------------- No valid token, continue
96:
97: # ---------------------------- Not possible to really login to domain "public"
98: if ($env{'form.domain'} eq 'public') {
99: $env{'form.domain'}='';
100: $env{'form.username'}='';
101: }
102: # ----------------------------------------------------------- Process Interface
103: $env{'form.interface'}=~s/\W//g;
104:
105: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
106:
107: my $iconpath=
108: &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
109:
110: my $domain = &Apache::lonnet::default_login_domain();
111: if (($env{'form.domain'}) &&
112: (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
113: $domain=$env{'form.domain'};
114: }
115: my $role = $r->dir_config('lonRole');
116: my $loadlim = $r->dir_config('lonLoadLim');
117: my $servadm = $r->dir_config('lonAdmEMail');
118: my $lonhost = $r->dir_config('lonHostID');
119: my $tabdir = $r->dir_config('lonTabDir');
120: my $include = $r->dir_config('lonIncludes');
121: my $expire = $r->dir_config('lonExpire');
122: my $version = $r->dir_config('lonVersion');
123: my $host_name = &Apache::lonnet::hostname($lonhost);
124:
125: # --------------------------------------------- Default values for login fields
126:
127: my $authusername=($env{'form.username'}?$env{'form.username'}:'');
128: my $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
129:
130: # ---------------------------------------------------------- Determine own load
131: my $loadavg;
132: {
133: my $loadfile=Apache::File->new('/proc/loadavg');
134: $loadavg=<$loadfile>;
135: }
136: $loadavg =~ s/\s.*//g;
137: my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
138: my $userloadpercent=&Apache::lonnet::userload();
139:
140: # ------------------------------------------------------- Do the load balancing
141: my $otherserver= &Apache::lonnet::absolute_url($host_name);
142: my $firsturl=
143: ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
144: # ---------------------------------------------------------- Are we overloaded?
145: if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
146: my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent);
147: if ($unloaded) { $otherserver=$unloaded; }
148: }
149:
150: # ----------------------------------------------------------- Get announcements
151: my $announcements=&Apache::lonnet::getannounce();
152: # -------------------------------------------------------- Set login parameters
153:
154: my @hexstr=('0','1','2','3','4','5','6','7',
155: '8','9','a','b','c','d','e','f');
156: my $lkey='';
157: for (0..7) {
158: $lkey.=$hexstr[rand(15)];
159: }
160:
161: my $ukey='';
162: for (0..7) {
163: $ukey.=$hexstr[rand(15)];
164: }
165:
166: my $lextkey=hex($lkey);
167: if ($lextkey>2147483647) { $lextkey-=4294967296; }
168:
169: my $uextkey=hex($ukey);
170: if ($uextkey>2147483647) { $uextkey-=4294967296; }
171:
172: # -------------------------------------------------------- Store away log token
173: my $logtoken=Apache::lonnet::reply(
174: 'tmpput:'.$ukey.$lkey.'&'.$firsturl,
175: $lonhost);
176:
177: # ------------------- If we cannot talk to ourselves, we are in serious trouble
178:
179: if ($logtoken eq 'con_lost') {
180: my $spares='';
181: my $last;
182: foreach my $hostid (sort
183: {
184: &Apache::lonnet::hostname($a) cmp
185: &Apache::lonnet::hostname($b);
186: }
187: keys(%Apache::lonnet::spareid)) {
188: next if ($hostid eq $lonhost);
189: my $hostname = &Apache::lonnet::hostname($hostid);
190: next if ($last eq $hostname);
191: $spares.='<br /><font size="+1"><a href="http://'.
192: $hostname.
193: '/adm/login?domain='.$authdomain.'">'.
194: $hostname.'</a>'.
195: ' '.&mt('(preferred)').'</font>'.$/;
196: $last=$hostname;
197: }
198: $spares.= '<br />';
199: my %all_hostnames = &Apache::lonnet::all_hostnames();
200: foreach my $hostid (sort
201: {
202: &Apache::lonnet::hostname($a) cmp
203: &Apache::lonnet::hostname($b);
204: }
205: keys(%all_hostnames)) {
206: next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
207: my $hostname = &Apache::lonnet::hostname($hostid);
208: next if ($last eq $hostname);
209: $spares.='<br /><a href="http://'.
210: $hostname.
211: '/adm/login?domain='.$authdomain.'">'.
212: $hostname.'</a>';
213: $last=$hostname;
214: }
215: $r->print(
216: '<html>'
217: .'<head><title>'
218: .&mt('The LearningOnline Network with CAPA')
219: .'</title></head>'
220: .'<body bgcolor="#FFFFFF">'
221: .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
222: .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
223: .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>'
224: .'<p>'.&mt('Please attempt to login to one of the following servers:').'</p>'
225: .$spares
226: .'</body>'
227: .'</html>'
228: );
229: return OK;
230: }
231:
232: # ----------------------------------------------- Apparently we are in business
233: $servadm=~s/\,/\<br \/\>/g;
234:
235: # ----------------------------------------------------------- Front page design
236: my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
237: my $font=&Apache::loncommon::designparm('login.font',$domain);
238: my $link=&Apache::loncommon::designparm('login.link',$domain);
239: my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
240: my $alink=&Apache::loncommon::designparm('login.alink',$domain);
241: my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
242: my $logo=&Apache::loncommon::designparm('login.logo',$domain);
243: my $img=&Apache::loncommon::designparm('login.img',$domain);
244: my $domainlogo=&Apache::loncommon::domainlogo($domain);
245: my $login=&Apache::loncommon::designparm('login.login',$domain);
246: if ($login eq '') {
247: $login = $iconpath.'/'.&mt('userauthentication.gif');
248: }
249: my $showbanner = 1;
250: my $showmainlogo = 1;
251: if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
252: $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
253: }
254: if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
255: $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
256: }
257: my $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
258: my $showcoursecat =
259: &Apache::loncommon::designparm('login.coursecatalog',$domain);
260: my $loginheader =&Apache::loncommon::designparm('login.loginheader',$domain);
261: my $shownewuserlink =
262: &Apache::loncommon::designparm('login.newuser',$domain);
263: my $now=time;
264: my $js = (<<ENDSCRIPT);
265:
266: <script type="text/javascript" language="JavaScript">
267: // <![CDATA[
268: function send()
269: {
270: this.document.server.elements.uname.value
271: =this.document.client.elements.uname.value;
272:
273: this.document.server.elements.udom.value
274: =this.document.client.elements.udom.value;
275:
276: uextkey=this.document.client.elements.uextkey.value;
277: lextkey=this.document.client.elements.lextkey.value;
278: initkeys();
279:
280: this.document.server.elements.upass0.value
281: =crypted(this.document.client.elements.upass$now.value.substr(0,15));
282: this.document.server.elements.upass1.value
283: =crypted(this.document.client.elements.upass$now.value.substr(15,15));
284: this.document.server.elements.upass2.value
285: =crypted(this.document.client.elements.upass$now.value.substr(30,15));
286:
287: this.document.client.elements.uname.value='';
288: this.document.client.elements.upass$now.value='';
289:
290: this.document.server.submit();
291: return false;
292: }
293: // ]]>
294: </script>
295:
296: ENDSCRIPT
297:
298: # --------------------------------------------------- Print login screen header
299:
300: my %add_entries = (
301: bgcolor => "$mainbg",
302: text => "$font",
303: link => "$link",
304: vlink => "$vlink",
305: alink => "$alink",);
306:
307: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
308: { 'redirect' => [$expire,'/adm/roles'],
309: 'add_entries' => \%add_entries,
310: 'only_body' => 1,}));
311:
312: # ----------------------------------------------------------------------- Texts
313:
314: my %lt=&Apache::lonlocal::texthash(
315: 'un' => 'Username',
316: 'pw' => 'Password',
317: 'dom' => 'Domain',
318: 'perc' => 'percent',
319: 'load' => 'Server Load',
320: 'userload' => 'User Load',
321: 'catalog' => 'Course Catalog',
322: 'log' => 'Log in',
323: 'help' => 'Log-in Help',
324: 'serv' => 'Server',
325: 'servadm' => 'Server Administration',
326: 'helpdesk' => 'Contact Helpdesk',
327: 'forgotpw' => 'Forgot password?',
328: 'newuser' => 'New User?',
329: );
330: # -------------------------------------------------- Change password field name
331: my $forgotpw = &forgotpwdisplay(%lt);
332: my $loginhelp = &loginhelpdisplay(%lt);
333:
334: # ---------------------------------------------------- Serve out DES JavaScript
335: {
336: my $jsh=Apache::File->new($include."/londes.js");
337: $r->print(<$jsh>);
338: }
339: # ---------------------------------------------------------- Serve rest of page
340:
341: $r->print(
342: '<div class="LC_loginpage_container">');
343:
344: #
345: # If the loadbalancing yielded just http:// because perhaps there's no loadbalancing?
346: # then just us a relative link to authenticate:
347: #
348:
349: $r->print(<<ENDSERVERFORM);
350: <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">
351: <input type="hidden" name="logtoken" value="$logtoken" />
352: <input type="hidden" name="serverid" value="$lonhost" />
353: <input type="hidden" name="uname" value="" />
354: <input type="hidden" name="upass0" value="" />
355: <input type="hidden" name="upass1" value="" />
356: <input type="hidden" name="upass2" value="" />
357: <input type="hidden" name="udom" value="" />
358: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
359: <input type="hidden" name="localres" value="$env{'form.localres'}" />
360: </form>
361: ENDSERVERFORM
362: my $coursecatalog;
363: if (($showcoursecat eq '') || ($showcoursecat)) {
364: $coursecatalog = &coursecatalog_link($lt{'catalog'});
365: }
366: my $newuserlink;
367: if ($shownewuserlink) {
368: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
369: }
370: my $logintitle;
371: if ($loginheader eq 'text') {
372: $logintitle ='<h2>'.$lt{'log'}.'</h2>';
373: } else {
374: $logintitle = '<img src="'.$login.'" alt="'.
375: &mt('User Authentication').'" />';
376: }
377:
378: my $noscript_warning='<noscript><span class="LC_warning"><b>'
379: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
380: .'</b></span></noscript>';
381: my $helpdeskscript;
382: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
383: $version,$authdomain,\$helpdeskscript);
384:
385: my $loginform=(<<LFORM);
386: <form name="client" action="" onsubmit="return(send())">
387: <input type="hidden" name="lextkey" value="$lextkey" />
388: <input type="hidden" name="uextkey" value="$uextkey" />
389: <b><label for="uname">$lt{'un'}</label>:</b><br />
390: <input type="text" name="uname" size="15" value="$authusername" /><br />
391: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
392: <input type="password" name="upass$now" size="15" /><br />
393: <b><label for="udom">$lt{'dom'}</label>:</b><br />
394: <input type="text" name="udom" size="15" value="$authdomain" /><br />
395: <input type="submit" value="$lt{'log'}" />
396: </form>
397: LFORM
398:
399: if ($showbanner) {
400: $r->print(<<HEADER);
401: <!-- The LON-CAPA Header -->
402: <table border="0" align="left" width="100%" cellspacing="0" cellpadding="1">
403: <tr>
404: <td align="left" valign="top" bgcolor="$pgbg">
405: <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
406: </td>
407: </tr>
408: </table>
409: HEADER
410: }
411: $r->print(<<ENDTOP);
412: <div class="LC_loginpage_space"> </div>
413: <div class="LC_loginpage_floatLeft">
414: <div class="LC_loginpage_loginContainer">
415: $logintitle
416: <table border="0" align="left" cellspacing="1" cellpadding="2" width="100%">
417: <tr>
418: <td>
419: $loginform
420: </td>
421: </tr>
422: </table>
423: $noscript_warning
424: </div>
425:
426: <div class="LC_loginpage_loginInfo">
427: $loginhelp<br />
428: $forgotpw<br />
429: $contactblock<br />
430: $newuserlink
431: $coursecatalog
432: </div>
433: </div>
434: ENDTOP
435: if ($showmainlogo) {
436: $r->print(' <img src="'.$logo.'" alt="" />'."\n");
437: }
438: $r->print(<<ENDTOP);
439: $announcements
440: $domainlogo
441: <div class="LC_loginpage_space"> </div>
442: ENDTOP
443:
444: $r->print(<<ENDDOCUMENT);
445: <table border="0" cellspacing="0" cellpadding="0">
446: <tr>
447: <td align="left" valign="top">
448: <small><b> $lt{'dom'}: </b></small>
449: </td>
450: <td align="left" valign="top">
451: <small><tt> $domain</tt></small>
452: </td>
453: </tr>
454: <tr>
455: <td align="left" valign="top">
456: <small><b> $lt{'serv'}: </b></small>
457: </td>
458: <td align="left" valign="top">
459: <small><tt> $lonhost ($role)</tt></small>
460: </td>
461: </tr>
462: <tr>
463: <td align="left" valign="top">
464: <small><b> $lt{'load'}: </b></small>
465: </td>
466: <td align="left" valign="top">
467: <small><tt> $loadpercent $lt{'perc'}</tt></small>
468: </td>
469: </tr>
470: <tr>
471: <td align="left" valign="top">
472: <small><b> $lt{'userload'}: </b></small>
473: </td>
474: <td align="left" valign="top">
475: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
476: </td>
477: </tr>
478: </table>
479: </div>
480:
481: <script type="text/javascript">
482: // <![CDATA[
483: // the if prevents the script error if the browser can not handle this
484: if ( document.client.uname ) { document.client.uname.focus(); }
485: // ]]>
486: </script>
487: $helpdeskscript
488:
489: ENDDOCUMENT
490: my %endargs = ( 'noredirectlink' => 1, );
491: $r->print(&Apache::loncommon::end_page(\%endargs));
492: return OK;
493: }
494:
495: sub contactdisplay {
496: my ($lt,$servadm,$showadminmail,$version,$authdomain,$helpdeskscript) = @_;
497: my $contactblock;
498: my $showhelpdesk = 0;
499: my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
500: if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {
501: $showhelpdesk = 1;
502: }
503: if ($servadm && $showadminmail) {
504: $contactblock .= '<b> '.$$lt{'servadm'}.':</b><br />'.
505: '<tt> '.$servadm.'</tt><br /> <br />';
506: }
507: if ($showhelpdesk) {
508: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
509: my $thisurl = &escape('/adm/login');
510: $$helpdeskscript = <<"ENDSCRIPT";
511: <script type="text/javascript">
512: // <![CDATA[
513: function helpdesk() {
514: var codedom = document.client.udom.value;
515: if (codedom == '') {
516: codedom = "$authdomain";
517: }
518: var querystr = "origurl=$thisurl&codedom="+codedom;
519: document.location.href = "/adm/helpdesk?"+querystr;
520: return;
521: }
522: // ]]>
523: </script>
524: ENDSCRIPT
525: }
526: $contactblock .= <<"ENDBLOCK";
527: $version
528: ENDBLOCK
529: return $contactblock;
530: }
531:
532: sub forgotpwdisplay {
533: my (%lt) = @_;
534: my $prompt_for_resetpw = 1;
535: if ($prompt_for_resetpw) {
536: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
537: }
538: return;
539: }
540:
541: sub loginhelpdisplay {
542: my (%lt) = @_;
543: my $login_help = 1;
544: if ($login_help) {
545: return '<a href="/adm/loginproblems.html">'.$lt{'help'}.'</a>';
546: }
547: return;
548: }
549:
550: sub coursecatalog_link {
551: my ($linkname) = @_;
552: return <<"END";
553: <a href="/adm/coursecatalog">$linkname</a>
554: END
555: }
556:
557: sub newuser_link {
558: my ($linkname) = @_;
559: return ' <a href="/adm/createaccount"><b>'.$linkname.'</b></a><br />';
560: }
561:
562: 1;
563: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>