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