File:
[LON-CAPA] /
loncom /
auth /
lonlogin.pm
Revision
1.180:
download - view:
text,
annotated -
select for diffs
Fri Oct 16 23:27:45 2020 UTC (3 years, 10 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- When server is unavailable for login because of local lonc/lond problem:
- Reinstate pre-2.2.2 behavior whereby list of other potential servers
featured "preferred" servers first.
- "Preferred" list from domain config for "User session hosting/offloading"
for the server, instead of from spare.tab file.
- satisfy w3c validation
- links are to https or http as appropriate from data in dns_hosts.tab
1: # The LearningOnline Network
2: # Login Screen
3: #
4: # $Id: lonlogin.pm,v 1.180 2020/10/16 23:27: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 qw(:DEFAULT :match);
41: use CGI::Cookie();
42:
43: sub handler {
44: my $r = shift;
45:
46: &Apache::loncommon::get_unprocessed_cgi
47: (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
48: $ENV{'REDIRECT_QUERY_STRING'}),
49: ['interface','username','domain','firsturl','localpath','localres',
50: 'token','role','symb','iptoken','btoken','ltoken','linkkey']);
51: if (!defined($env{'form.firsturl'})) {
52: &Apache::lonacc::get_posted_cgi($r,['firsturl']);
53: }
54: if (!defined($env{'form.firsturl'})) {
55: if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {
56: $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};
57: }
58: }
59: if (($env{'form.firsturl'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) &&
60: (!$env{'form.ltoken'}) && (!$env{'form.linkkey'})) {
61: &Apache::lonacc::get_posted_cgi($r,['linkkey']);
62: }
63:
64: # -- check if they are a migrating user
65: if (defined($env{'form.token'})) {
66: return &Apache::migrateuser::handler($r);
67: }
68:
69: # For "public user" - remove any exising "public" cookie, as user really wants to log-in
70: my ($handle,$lonidsdir,$expirepub,$userdom);
71: $lonidsdir=$r->dir_config('lonIDsDir');
72: unless ($r->header_only) {
73: $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
74: if ($handle ne '') {
75: if ($handle=~/^publicuser\_/) {
76: unlink($r->dir_config('lonIDsDir')."/$handle.id");
77: undef($handle);
78: undef($userdom);
79: $expirepub = 1;
80: }
81: }
82: }
83:
84: &Apache::loncommon::no_cache($r);
85: &Apache::lonlocal::get_language_handle($r);
86: &Apache::loncommon::content_type($r,'text/html');
87: if ($expirepub) {
88: my $c = new CGI::Cookie(-name => 'lonPubID',
89: -value => '',
90: -expires => '-10y',);
91: $r->header_out('Set-cookie' => $c);
92: } elsif (($handle eq '') && ($userdom ne '')) {
93: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
94: foreach my $name (keys(%cookies)) {
95: next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
96: my $c = new CGI::Cookie(-name => $name,
97: -value => '',
98: -expires => '-10y',);
99: $r->headers_out->add('Set-cookie' => $c);
100: }
101: }
102: $r->send_http_header;
103: return OK if $r->header_only;
104:
105:
106: # Are we re-routing?
107: my $londocroot = $r->dir_config('lonDocRoot');
108: if (-e "$londocroot/lon-status/reroute.txt") {
109: &Apache::lonauth::reroute($r);
110: return OK;
111: }
112:
113: my $lonhost = $r->dir_config('lonHostID');
114: $env{'form.firsturl'} =~ s/(`)/'/g;
115:
116: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
117:
118: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
119: if ($found_server) {
120: my $hostname = &Apache::lonnet::hostname($found_server);
121: if ($hostname ne '') {
122: my $protocol = $Apache::lonnet::protocol{$found_server};
123: $protocol = 'http' if ($protocol ne 'https');
124: my $dest = '/adm/roles';
125: if ($env{'form.firsturl'} ne '') {
126: $dest = $env{'form.firsturl'};
127: }
128: my %info = (
129: balcookie => $lonhost.':'.$balancer_cookie,
130: );
131: if ($env{'form.ltoken'}) {
132: my %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
133: if ($link_info{'linkprot'}) {
134: $info{'linkprot'} = $link_info{'linkprot'};
135: }
136: &Apache::lonnet::tmpdel($env{'form.ltoken'});
137: delete($env{'form.ltoken'});
138: } elsif ($env{'form.linkkey'}) {
139: $info{'linkkey'} = $env{'form.linkkey'};
140: delete($env{'form.linkkey'});
141: }
142: my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
143: if ($balancer_token) {
144: $dest .= (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;
145: }
146: my $url = $protocol.'://'.$hostname.$dest;
147: my $start_page =
148: &Apache::loncommon::start_page('Switching Server ...',undef,
149: {'redirect' => [0,$url],});
150: my $end_page = &Apache::loncommon::end_page();
151: $r->print($start_page.$end_page);
152: return OK;
153: }
154: }
155:
156: #
157: # Check if a LON-CAPA load balancer sent user here because user's browser sent
158: # it a balancer cookie for an active session on this server.
159: #
160:
161: my ($balcookie,$linkprot,$linkkey);
162: if ($env{'form.btoken'}) {
163: my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
164: $balcookie = $info{'balcookie'};
165: if ($balcookie) {
166: if ($info{'linkprot'}) {
167: $linkprot = $info{'linkprot'};
168: } elsif ($info{'linkkey'}) {
169: $linkkey = $info{'linkkey'};
170: }
171: }
172: &Apache::lonnet::tmpdel($env{'form.btoken'});
173: delete($env{'form.btoken'});
174: }
175:
176: #
177: # If browser sent an old cookie for which the session file had been removed
178: # check if configuration for user's domain has a portal URL set. If so
179: # switch user's log-in to the portal.
180: #
181:
182: if (($handle eq '') && ($userdom ne '')) {
183: my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
184: if ($domdefaults{'portal_def'} =~ /^https?\:/) {
185: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
186: {'redirect' => [0,$domdefaults{'portal_def'}],});
187: my $end_page = &Apache::loncommon::end_page();
188: $r->print($start_page.$end_page);
189: return OK;
190: }
191: }
192:
193: # -------------------------------- Prevent users from attempting to login twice
194: if ($handle ne '') {
195: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
196: my $start_page =
197: &Apache::loncommon::start_page('Already logged in');
198: my $end_page =
199: &Apache::loncommon::end_page();
200: my $dest = '/adm/roles';
201: if ($env{'form.firsturl'} ne '') {
202: $dest = $env{'form.firsturl'};
203: }
204: if (($env{'form.ltoken'}) || ($linkprot)) {
205: unless ($linkprot) {
206: my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
207: $linkprot = $info{'linkprot'};
208: my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'});
209: delete($env{'form.ltoken'});
210: }
211: if ($linkprot) {
212: my ($linkprotector,$deeplink) = split(/:/,$linkprot,2);
213: if ($env{'user.linkprotector'}) {
214: my @protectors = split(/,/,$env{'user.linkprotector'});
215: unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
216: push(@protectors,$linkprotector);
217: @protectors = sort { $a <=> $b } @protectors;
218: &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
219: }
220: } else {
221: &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
222: }
223: if ($env{'user.linkproturi'}) {
224: my @proturis = split(/,/,$env{'user.linkproturi'});
225: unless (grep(/^\Q$deeplink\E$/,@proturis)) {
226: push(@proturis,$deeplink);
227: @proturis = sort @proturis;
228: &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
229: }
230: } else {
231: &Apache::lonnet::appenv({'user.linkproturi' => $deeplink});
232: }
233: }
234: } elsif (($env{'form.linkkey'}) || ($linkkey)) {
235: if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
236: if ($linkkey eq '') {
237: $linkkey = $env{'form.linkkey'};
238: }
239: if ($env{'user.deeplinkkey'}) {
240: my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
241: unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
242: push(@linkkeys,$linkkey);
243: &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});
244: }
245: } else {
246: &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
247: }
248: my $deeplink = $env{'form.firsturl'};
249: if ($env{'user.keyedlinkuri'}) {
250: my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
251: unless (grep(/^\Q$deeplink\E$/,@keyeduris)) {
252: push(@keyeduris,$deeplink);
253: &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
254: }
255: } else {
256: &Apache::lonnet::appenv({'user.keyedlinkuri' => $deeplink});
257: }
258: }
259: }
260: $r->print(
261: $start_page
262: .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
263: .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
264: '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
265: .$end_page
266: );
267: return OK;
268: }
269:
270: # ---------------------------------------------------- No valid token, continue
271:
272: # ---------------------------- Not possible to really login to domain "public"
273: if ($env{'form.domain'} eq 'public') {
274: $env{'form.domain'}='';
275: $env{'form.username'}='';
276: }
277:
278: # ------ Is this page requested because /adm/migrateuser detected an IP change?
279: my %sessiondata;
280: if ($env{'form.iptoken'}) {
281: %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
282: unless ($sessiondata{'sessionserver'}) {
283: my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
284: delete($env{'form.iptoken'});
285: }
286: }
287: # ----------------------------------------------------------- Process Interface
288: $env{'form.interface'}=~s/\W//g;
289:
290: (undef,undef,undef,undef,undef,undef,my $clientmobile) =
291: &Apache::loncommon::decode_user_agent();
292:
293: my $iconpath=
294: &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
295:
296: my $domain = &Apache::lonnet::default_login_domain();
297: my $defdom = $domain;
298: if ($lonhost ne '') {
299: unless ($sessiondata{'sessionserver'}) {
300: my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie,$linkprot);
301: if ($redirect) {
302: $r->print($redirect);
303: return OK;
304: }
305: }
306: }
307:
308: if (($sessiondata{'domain'}) &&
309: (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
310: $domain=$sessiondata{'domain'};
311: } elsif (($env{'form.domain'}) &&
312: (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
313: $domain=$env{'form.domain'};
314: }
315:
316: my $role = $r->dir_config('lonRole');
317: my $loadlim = $r->dir_config('lonLoadLim');
318: my $uloadlim= $r->dir_config('lonUserLoadLim');
319: my $servadm = $r->dir_config('lonAdmEMail');
320: my $tabdir = $r->dir_config('lonTabDir');
321: my $include = $r->dir_config('lonIncludes');
322: my $expire = $r->dir_config('lonExpire');
323: my $version = $r->dir_config('lonVersion');
324: my $host_name = &Apache::lonnet::hostname($lonhost);
325:
326: # --------------------------------------------- Default values for login fields
327:
328: my ($authusername,$authdomain);
329: if ($sessiondata{'username'}) {
330: $authusername=$sessiondata{'username'};
331: } else {
332: $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
333: $authusername=($env{'form.username'}?$env{'form.username'}:'');
334: }
335: if ($sessiondata{'domain'}) {
336: $authdomain=$sessiondata{'domain'};
337: } else {
338: $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
339: $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
340: }
341:
342: # ---------------------------------------------------------- Determine own load
343: my $loadavg;
344: {
345: my $loadfile=Apache::File->new('/proc/loadavg');
346: $loadavg=<$loadfile>;
347: }
348: $loadavg =~ s/\s.*//g;
349:
350: my ($loadpercent,$userloadpercent);
351: if ($loadlim) {
352: $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
353: }
354: if ($uloadlim) {
355: $userloadpercent=&Apache::lonnet::userload();
356: }
357:
358: my $firsturl=
359: ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
360:
361: # ----------------------------------------------------------- Get announcements
362: my $announcements=&Apache::lonnet::getannounce();
363: # -------------------------------------------------------- Set login parameters
364:
365: my @hexstr=('0','1','2','3','4','5','6','7',
366: '8','9','a','b','c','d','e','f');
367: my $lkey='';
368: for (0..7) {
369: $lkey.=$hexstr[rand(15)];
370: }
371:
372: my $ukey='';
373: for (0..7) {
374: $ukey.=$hexstr[rand(15)];
375: }
376:
377: my $lextkey=hex($lkey);
378: if ($lextkey>2147483647) { $lextkey-=4294967296; }
379:
380: my $uextkey=hex($ukey);
381: if ($uextkey>2147483647) { $uextkey-=4294967296; }
382:
383: # -------------------------------------------------------- Store away log token
384: my $tokenextras;
385: if ($env{'form.role'}) {
386: $tokenextras = '&role='.&escape($env{'form.role'});
387: }
388: if ($env{'form.symb'}) {
389: if (!$tokenextras) {
390: $tokenextras = '&';
391: }
392: $tokenextras .= '&symb='.&escape($env{'form.symb'});
393: }
394: if ($env{'form.iptoken'}) {
395: if (!$tokenextras) {
396: $tokenextras = '&&';
397: }
398: $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
399: }
400: if ($env{'form.ltoken'}) {
401: my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
402: &Apache::lonnet::tmpdel($env{'form.ltoken'});
403: delete($env{'form.ltoken'});
404: if ($info{'linkprot'}) {
405: if (!$tokenextras) {
406: $tokenextras = '&&&';
407: }
408: $tokenextras .= '&linkprot='.&escape($info{'linkprot'});
409: }
410: } elsif ($env{'form.linkkey'}) {
411: if (!$tokenextras) {
412: $tokenextras = '&&&';
413: }
414: $tokenextras .= '&linkkey='.&escape($env{'form.linkkey'});
415: }
416: my $logtoken=Apache::lonnet::reply(
417: 'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
418: $lonhost);
419:
420: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
421: # we are in serious trouble
422:
423: if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
424: if ($logtoken eq 'no_such_host') {
425: &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
426: }
427: my $spares='';
428: my (@sparehosts,%spareservers);
429: my $sparesref = &Apache::lonnet::this_host_spares($defdom);
430: if (ref($sparesref) eq 'HASH') {
431: foreach my $key (keys(%{$sparesref})) {
432: if (ref($sparesref->{$key}) eq 'ARRAY') {
433: my @sorted = sort { &Apache::lonnet::hostname($a) cmp
434: &Apache::lonnet::hostname($b);
435: } @{$sparesref->{$key}};
436: if (@sorted) {
437: if ($key eq 'primary') {
438: unshift(@sparehosts,@sorted);
439: } elsif ($key eq 'default') {
440: push(@sparehosts,@sorted);
441: }
442: }
443: }
444: }
445: }
446: foreach my $hostid (@sparehosts) {
447: next if ($hostid eq $lonhost);
448: my $hostname = &Apache::lonnet::hostname($hostid);
449: next if (($hostname eq '') || ($spareservers{$hostname}));
450: $spareservers{$hostname} = 1;
451: my $protocol = $Apache::lonnet::protocol{$hostid};
452: $protocol = 'http' if ($protocol ne 'https');
453: $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.
454: $hostname.
455: '/adm/login?domain='.$authdomain.'">'.
456: $hostname.'</a>'.
457: ' '.&mt('(preferred)').'</span>'.$/;
458: }
459: if ($spares) {
460: $spares.= '<br />';
461: }
462: my %all_hostnames = &Apache::lonnet::all_hostnames();
463: foreach my $hostid (sort
464: {
465: &Apache::lonnet::hostname($a) cmp
466: &Apache::lonnet::hostname($b);
467: }
468: keys(%all_hostnames)) {
469: next if ($hostid eq $lonhost);
470: my $hostname = &Apache::lonnet::hostname($hostid);
471: next if (($hostname eq '') || ($spareservers{$hostname}));
472: my $protocol = $Apache::lonnet::protocol{$hostid};
473: $protocol = 'http' if ($protocol ne 'https');
474: $spares.='<br /><a href="'.$protocol.'://'.
475: $hostname.
476: '/adm/login?domain='.$authdomain.'">'.
477: $hostname.'</a>';
478: }
479: $r->print(
480: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
481: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
482: .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'
483: .&mt('The LearningOnline Network with CAPA')
484: .'</title></head>'
485: .'<body bgcolor="#FFFFFF">'
486: .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
487: .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
488: .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
489: if ($spares) {
490: $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
491: .'</p>'
492: .$spares);
493: }
494: $r->print('</body>'
495: .'</html>'
496: );
497: return OK;
498: }
499:
500: # ----------------------------------------------- Apparently we are in business
501: $servadm=~s/\,/\<br \/\>/g;
502:
503: # ----------------------------------------------------------- Front page design
504: my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
505: my $font=&Apache::loncommon::designparm('login.font',$domain);
506: my $link=&Apache::loncommon::designparm('login.link',$domain);
507: my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
508: my $alink=&Apache::loncommon::designparm('login.alink',$domain);
509: my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
510: my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
511: my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
512: my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
513: my $logo=&Apache::loncommon::designparm('login.logo',$domain);
514: my $img=&Apache::loncommon::designparm('login.img',$domain);
515: my $domainlogo=&Apache::loncommon::domainlogo($domain);
516: my $showbanner = 1;
517: my $showmainlogo = 1;
518: if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
519: $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
520: }
521: if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
522: $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
523: }
524: my $showadminmail;
525: my @possdoms = &Apache::lonnet::current_machine_domains();
526: if (grep(/^\Q$domain\E$/,@possdoms)) {
527: $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
528: }
529: my $showcoursecat =
530: &Apache::loncommon::designparm('login.coursecatalog',$domain);
531: my $shownewuserlink =
532: &Apache::loncommon::designparm('login.newuser',$domain);
533: my $showhelpdesk =
534: &Apache::loncommon::designparm('login.helpdesk',$domain);
535: my $now=time;
536: my $js = (<<ENDSCRIPT);
537:
538: <script type="text/javascript" language="JavaScript">
539: // <![CDATA[
540: function send()
541: {
542: this.document.server.elements.uname.value
543: =this.document.client.elements.uname.value;
544:
545: this.document.server.elements.udom.value
546: =this.document.client.elements.udom.value;
547:
548: uextkey=this.document.client.elements.uextkey.value;
549: lextkey=this.document.client.elements.lextkey.value;
550: initkeys();
551:
552: if(this.document.server.action.substr(0,5) === 'http:'){
553: this.document.server.elements.upass0.value
554: =getCrypted(this.document.client.elements.upass$now.value);
555: } else {
556: this.document.server.elements.upass0.value
557: =this.document.client.elements.upass$now.value;
558: }
559:
560: this.document.client.elements.uname.value='';
561: this.document.client.elements.upass$now.value='';
562:
563: this.document.server.submit();
564: return false;
565: }
566:
567: function enableInput() {
568: this.document.client.elements.upass$now.removeAttribute("readOnly");
569: this.document.client.elements.uname.removeAttribute("readOnly");
570: this.document.client.elements.udom.removeAttribute("readOnly");
571: return;
572: }
573:
574: // ]]>
575: </script>
576:
577: ENDSCRIPT
578:
579: # --------------------------------------------------- Print login screen header
580:
581: my %add_entries = (
582: bgcolor => "$mainbg",
583: text => "$font",
584: link => "$link",
585: vlink => "$vlink",
586: alink => "$alink",
587: onload => 'javascript:enableInput();',);
588:
589: my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
590: @hosts = &Apache::lonnet::current_machine_ids();
591: $lonhost_in_use = $lonhost;
592: if (@hosts > 1) {
593: foreach my $hostid (@hosts) {
594: if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
595: $lonhost_in_use = $hostid;
596: last;
597: }
598: }
599: }
600: %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
601: $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
602: $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
603: if ($headextra) {
604: my $omitextra;
605: if ($headextra_exempt ne '') {
606: my @exempt = split(',',$headextra_exempt);
607: my $ip = $ENV{'REMOTE_ADDR'};
608: if (grep(/^\Q$ip\E$/,@exempt)) {
609: $omitextra = 1;
610: }
611: }
612: unless ($omitextra) {
613: my $confname = $defdom.'-domainconfig';
614: if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
615: my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
616: unless ($extra eq '-1') {
617: $js .= "\n".$extra."\n";
618: }
619: }
620: }
621: }
622:
623: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
624: { 'redirect' => [$expire,'/adm/roles'],
625: 'add_entries' => \%add_entries,
626: 'only_body' => 1,}));
627:
628: # ----------------------------------------------------------------------- Texts
629:
630: my %lt=&Apache::lonlocal::texthash(
631: 'un' => 'Username',
632: 'pw' => 'Password',
633: 'dom' => 'Domain',
634: 'perc' => 'percent',
635: 'load' => 'Server Load',
636: 'userload' => 'User Load',
637: 'catalog' => 'Course/Community Catalog',
638: 'log' => 'Log in',
639: 'help' => 'Log-in Help',
640: 'serv' => 'Server',
641: 'servadm' => 'Server Administration',
642: 'helpdesk' => 'Contact Helpdesk',
643: 'forgotpw' => 'Forgot password?',
644: 'newuser' => 'New User?',
645: );
646: # -------------------------------------------------- Change password field name
647:
648: my $forgotpw = &forgotpwdisplay(%lt);
649: $forgotpw .= '<br />' if $forgotpw;
650: my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
651: if ($loginhelp) {
652: $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
653: }
654:
655: # ---------------------------------------------------- Serve out DES JavaScript
656: {
657: my $jsh=Apache::File->new($include."/londes.js");
658: $r->print(<$jsh>);
659: }
660: # ---------------------------------------------------------- Serve rest of page
661:
662: $r->print(
663: '<div class="LC_Box"'
664: .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
665: );
666:
667: $r->print(<<ENDSERVERFORM);
668: <form name="server" action="/adm/authenticate" method="post" target="_top">
669: <input type="hidden" name="logtoken" value="$logtoken" />
670: <input type="hidden" name="serverid" value="$lonhost" />
671: <input type="hidden" name="uname" value="" />
672: <input type="hidden" name="upass0" value="" />
673: <input type="hidden" name="udom" value="" />
674: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
675: <input type="hidden" name="localres" value="$env{'form.localres'}" />
676: </form>
677: ENDSERVERFORM
678: my $coursecatalog;
679: if (($showcoursecat eq '') || ($showcoursecat)) {
680: $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
681: }
682: my $newuserlink;
683: if ($shownewuserlink) {
684: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
685: }
686: my $logintitle =
687: '<h2 class="LC_hcell"'
688: .' style="background:'.$loginbox_header_bgcol.';'
689: .' color:'.$loginbox_header_textcol.'">'
690: .$lt{'log'}
691: .'</h2>';
692:
693: my $noscript_warning='<noscript><span class="LC_warning"><b>'
694: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
695: .'</b></span></noscript>';
696: my $helpdeskscript;
697: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
698: $authdomain,\$helpdeskscript,
699: $showhelpdesk,\@possdoms);
700:
701: my $mobileargs;
702: if ($clientmobile) {
703: $mobileargs = 'autocapitalize="off" autocorrect="off"';
704: }
705: my $loginform=(<<LFORM);
706: <form name="client" action="" onsubmit="return(send())">
707: <input type="hidden" name="lextkey" value="$lextkey" />
708: <input type="hidden" name="uextkey" value="$uextkey" />
709: <b><label for="uname">$lt{'un'}</label>:</b><br />
710: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
711: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
712: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
713: <b><label for="udom">$lt{'dom'}</label>:</b><br />
714: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
715: <input type="submit" value="$lt{'log'}" />
716: </form>
717: LFORM
718:
719: if ($showbanner) {
720: $r->print(<<HEADER);
721: <!-- The LON-CAPA Header -->
722: <div style="background:$pgbg;margin:0;width:100%;">
723: <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
724: </div>
725: HEADER
726: }
727: $r->print(<<ENDTOP);
728: <div style="float:left;margin-top:0;">
729: <div class="LC_Box" style="background:$loginbox_bg;">
730: $logintitle
731: $loginform
732: $noscript_warning
733: </div>
734:
735: <div class="LC_Box" style="padding-top: 10px;">
736: $loginhelp
737: $forgotpw
738: $contactblock
739: $newuserlink
740: $coursecatalog
741: </div>
742: </div>
743:
744: <div>
745: ENDTOP
746: if ($showmainlogo) {
747: $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
748: }
749: $r->print(<<ENDTOP);
750: $announcements
751: </div>
752: <hr style="clear:both;" />
753: ENDTOP
754: my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
755: $domainrow = <<"END";
756: <tr>
757: <td align="left" valign="top">
758: <small><b>$lt{'dom'}: </b></small>
759: </td>
760: <td align="left" valign="top">
761: <small><tt> $domain</tt></small>
762: </td>
763: </tr>
764: END
765: $serverrow = <<"END";
766: <tr>
767: <td align="left" valign="top">
768: <small><b>$lt{'serv'}: </b></small>
769: </td>
770: <td align="left" valign="top">
771: <small><tt> $lonhost ($role)</tt></small>
772: </td>
773: </tr>
774: END
775: if ($loadlim) {
776: $loadrow = <<"END";
777: <tr>
778: <td align="left" valign="top">
779: <small><b>$lt{'load'}: </b></small>
780: </td>
781: <td align="left" valign="top">
782: <small><tt> $loadpercent $lt{'perc'}</tt></small>
783: </td>
784: </tr>
785: END
786: }
787: if ($uloadlim) {
788: $userloadrow = <<"END";
789: <tr>
790: <td align="left" valign="top">
791: <small><b>$lt{'userload'}: </b></small>
792: </td>
793: <td align="left" valign="top">
794: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
795: </td>
796: </tr>
797: END
798: }
799: if (($version ne '') && ($version ne '<!-- VERSION -->')) {
800: $versionrow = <<"END";
801: <tr>
802: <td colspan="2" align="left">
803: <small>$version</small>
804: </td>
805: </tr>
806: END
807: }
808:
809: $r->print(<<ENDDOCUMENT);
810: <div style="float: left;">
811: <table border="0" cellspacing="0" cellpadding="0">
812: $domainrow
813: $serverrow
814: $loadrow
815: $userloadrow
816: $versionrow
817: </table>
818: </div>
819: <div style="float: right;">
820: $domainlogo
821: </div>
822: <br style="clear:both;" />
823: </div>
824:
825: <script type="text/javascript">
826: // <![CDATA[
827: // the if prevents the script error if the browser can not handle this
828: if ( document.client.uname ) { document.client.uname.focus(); }
829: // ]]>
830: </script>
831: $helpdeskscript
832:
833: ENDDOCUMENT
834: my %endargs = ( 'noredirectlink' => 1, );
835: $r->print(&Apache::loncommon::end_page(\%endargs));
836: return OK;
837: }
838:
839: sub check_loginvia {
840: my ($domain,$lonhost,$lonidsdir,$balcookie,$linkprot) = @_;
841: if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
842: return;
843: }
844: my %domconfhash = &Apache::loncommon::get_domainconf($domain);
845: my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
846: my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
847: my $output;
848: if ($loginvia ne '') {
849: my $noredirect;
850: my $ip = $ENV{'REMOTE_ADDR'};
851: if ($ip eq '127.0.0.1') {
852: $noredirect = 1;
853: } else {
854: if ($loginvia_exempt ne '') {
855: my @exempt = split(',',$loginvia_exempt);
856: if (grep(/^\Q$ip\E$/,@exempt)) {
857: $noredirect = 1;
858: }
859: }
860: }
861: unless ($noredirect) {
862: my ($newhost,$path);
863: if ($loginvia =~ /:/) {
864: ($newhost,$path) = split(':',$loginvia);
865: } else {
866: $newhost = $loginvia;
867: }
868: if ($newhost ne $lonhost) {
869: if (&Apache::lonnet::hostname($newhost) ne '') {
870: if ($balcookie) {
871: my ($balancer,$cookie) = split(/:/,$balcookie);
872: if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
873: my ($udom,$uname,$cookieid) = ($1,$2,$3);
874: unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
875: if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
876: while (my $filename=readdir($dh)) {
877: if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
878: my $handle = $1;
879: my %hash =
880: &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
881: ['request.balancercookie',
882: 'user.linkedenv']);
883: if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
884: if (unlink("$lonidsdir/$filename")) {
885: if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
886: (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
887: (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
888: unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
889: }
890: }
891: }
892: last;
893: }
894: }
895: closedir($dh);
896: }
897: }
898: }
899: }
900: $output = &redirect_page($newhost,$path,$linkprot);
901: }
902: }
903: }
904: }
905: return $output;
906: }
907:
908: sub redirect_page {
909: my ($desthost,$path,$linkprot) = @_;
910: my $hostname = &Apache::lonnet::hostname($desthost);
911: my $protocol = $Apache::lonnet::protocol{$desthost};
912: $protocol = 'http' if ($protocol ne 'https');
913: unless ($path =~ m{^/}) {
914: $path = '/'.$path;
915: }
916: my $url = $protocol.'://'.$hostname.$path;
917: if ($env{'form.firsturl'} ne '') {
918: $url .='?firsturl='.$env{'form.firsturl'};
919: }
920: if ($linkprot) {
921: my $ltoken = &Apache::lonnet::tmpput({linkprot => $linkprot},$desthost);
922: if ($ltoken) {
923: $url .= (($url =~ /\?/) ? '&' : '?').'ltoken='.$ltoken;
924: }
925: }
926: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
927: {'redirect' => [0,$url],});
928: my $end_page = &Apache::loncommon::end_page();
929: return $start_page.$end_page;
930: }
931:
932: sub contactdisplay {
933: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
934: $possdoms) = @_;
935: my $contactblock;
936: my $origmail;
937: if (ref($possdoms) eq 'ARRAY') {
938: if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
939: $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
940: }
941: }
942: my $requestmail =
943: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
944: $authdomain,$origmail);
945: unless ($showhelpdesk eq '0') {
946: if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
947: $showhelpdesk = 1;
948: } else {
949: $showhelpdesk = 0;
950: }
951: }
952: if ($servadm && $showadminmail) {
953: $contactblock .= $$lt{'servadm'}.':<br />'.
954: '<tt>'.$servadm.'</tt><br />';
955: }
956: if ($showhelpdesk) {
957: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
958: my $thisurl = &escape('/adm/login');
959: $$helpdeskscript = <<"ENDSCRIPT";
960: <script type="text/javascript">
961: // <![CDATA[
962: function helpdesk() {
963: var possdom = document.client.udom.value;
964: var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
965: if (codedom == '') {
966: codedom = "$authdomain";
967: }
968: var querystr = "origurl=$thisurl&codedom="+codedom;
969: document.location.href = "/adm/helpdesk?"+querystr;
970: return;
971: }
972: // ]]>
973: </script>
974: ENDSCRIPT
975: }
976: return $contactblock;
977: }
978:
979: sub forgotpwdisplay {
980: my (%lt) = @_;
981: my $prompt_for_resetpw = 1;
982: if ($prompt_for_resetpw) {
983: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
984: }
985: return;
986: }
987:
988: sub coursecatalog_link {
989: my ($linkname) = @_;
990: return <<"END";
991: <a href="/adm/coursecatalog">$linkname</a>
992: END
993: }
994:
995: sub newuser_link {
996: my ($linkname) = @_;
997: return '<a href="/adm/createaccount">'.$linkname.'</a>';
998: }
999:
1000: 1;
1001: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>