Annotation of loncom/auth/lonlogin.pm, revision 1.182
1.160 kruse 1: # The LearningOnline Network
2: # Login Screen
3: #
1.182 ! raeburn 4: # $Id: lonlogin.pm,v 1.181 2020/10/26 01:52:15 raeburn Exp $
1.160 kruse 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/';
1.176 raeburn 40: use LONCAPA qw(:DEFAULT :match);
1.169 raeburn 41: use CGI::Cookie();
1.160 kruse 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',
1.179 raeburn 50: 'token','role','symb','iptoken','btoken','ltoken','linkkey']);
1.160 kruse 51: if (!defined($env{'form.firsturl'})) {
52: &Apache::lonacc::get_posted_cgi($r,['firsturl']);
53: }
1.172 raeburn 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: }
1.179 raeburn 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: }
1.160 kruse 63:
64: # -- check if they are a migrating user
65: if (defined($env{'form.token'})) {
66: return &Apache::migrateuser::handler($r);
67: }
68:
1.169 raeburn 69: # For "public user" - remove any exising "public" cookie, as user really wants to log-in
1.171 raeburn 70: my ($handle,$lonidsdir,$expirepub,$userdom);
1.176 raeburn 71: $lonidsdir=$r->dir_config('lonIDsDir');
1.169 raeburn 72: unless ($r->header_only) {
1.171 raeburn 73: $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
1.169 raeburn 74: if ($handle ne '') {
75: if ($handle=~/^publicuser\_/) {
76: unlink($r->dir_config('lonIDsDir')."/$handle.id");
77: undef($handle);
1.171 raeburn 78: undef($userdom);
79: $expirepub = 1;
1.169 raeburn 80: }
81: }
82: }
83:
1.160 kruse 84: &Apache::loncommon::no_cache($r);
85: &Apache::lonlocal::get_language_handle($r);
86: &Apache::loncommon::content_type($r,'text/html');
1.171 raeburn 87: if ($expirepub) {
1.170 raeburn 88: my $c = new CGI::Cookie(-name => 'lonPubID',
1.169 raeburn 89: -value => '',
90: -expires => '-10y',);
91: $r->header_out('Set-cookie' => $c);
1.171 raeburn 92: } elsif (($handle eq '') && ($userdom ne '')) {
1.173 raeburn 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: }
1.169 raeburn 101: }
1.160 kruse 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:
1.176 raeburn 113: my $lonhost = $r->dir_config('lonHostID');
1.174 raeburn 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: }
1.176 raeburn 128: my %info = (
129: balcookie => $lonhost.':'.$balancer_cookie,
130: );
1.177 raeburn 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'});
1.179 raeburn 138: } elsif ($env{'form.linkkey'}) {
139: $info{'linkkey'} = $env{'form.linkkey'};
140: delete($env{'form.linkkey'});
1.177 raeburn 141: }
1.176 raeburn 142: my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
143: if ($balancer_token) {
144: $dest .= (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;
145: }
1.174 raeburn 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:
1.171 raeburn 156: #
1.176 raeburn 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:
1.179 raeburn 161: my ($balcookie,$linkprot,$linkkey);
1.176 raeburn 162: if ($env{'form.btoken'}) {
163: my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
164: $balcookie = $info{'balcookie'};
1.177 raeburn 165: if ($balcookie) {
166: if ($info{'linkprot'}) {
167: $linkprot = $info{'linkprot'};
1.179 raeburn 168: } elsif ($info{'linkkey'}) {
169: $linkkey = $info{'linkkey'};
1.177 raeburn 170: }
171: }
1.176 raeburn 172: &Apache::lonnet::tmpdel($env{'form.btoken'});
173: delete($env{'form.btoken'});
174: }
175:
176: #
1.171 raeburn 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:
1.160 kruse 193: # -------------------------------- Prevent users from attempting to login twice
194: if ($handle ne '') {
1.169 raeburn 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 '') {
1.176 raeburn 202: $dest = $env{'form.firsturl'};
1.169 raeburn 203: }
1.177 raeburn 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'});
1.179 raeburn 225: unless (grep(/^\Q$deeplink\E$/,@proturis)) {
1.177 raeburn 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: }
1.179 raeburn 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: }
1.177 raeburn 259: }
1.169 raeburn 260: $r->print(
1.160 kruse 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: );
1.169 raeburn 267: return OK;
1.160 kruse 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'});
1.162 raeburn 282: unless ($sessiondata{'sessionserver'}) {
283: my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
284: delete($env{'form.iptoken'});
285: }
1.160 kruse 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();
1.161 raeburn 297: my $defdom = $domain;
1.160 kruse 298: if ($lonhost ne '') {
299: unless ($sessiondata{'sessionserver'}) {
1.177 raeburn 300: my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie,$linkprot);
1.160 kruse 301: if ($redirect) {
302: $r->print($redirect);
303: return OK;
304: }
305: }
306: }
307:
308: if (($sessiondata{'domain'}) &&
1.175 raeburn 309: (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
1.160 kruse 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: }
1.162 raeburn 394: if ($env{'form.iptoken'}) {
395: if (!$tokenextras) {
396: $tokenextras = '&&';
397: }
398: $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
399: }
1.177 raeburn 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: }
1.179 raeburn 410: } elsif ($env{'form.linkkey'}) {
411: if (!$tokenextras) {
412: $tokenextras = '&&&';
413: }
414: $tokenextras .= '&linkkey='.&escape($env{'form.linkkey'});
1.177 raeburn 415: }
1.160 kruse 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='';
1.180 raeburn 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) {
1.160 kruse 447: next if ($hostid eq $lonhost);
448: my $hostname = &Apache::lonnet::hostname($hostid);
1.180 raeburn 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.'://'.
1.160 kruse 454: $hostname.
455: '/adm/login?domain='.$authdomain.'">'.
456: $hostname.'</a>'.
1.180 raeburn 457: ' '.&mt('(preferred)').'</span>'.$/;
1.160 kruse 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)) {
1.180 raeburn 469: next if ($hostid eq $lonhost);
1.160 kruse 470: my $hostname = &Apache::lonnet::hostname($hostid);
1.180 raeburn 471: next if (($hostname eq '') || ($spareservers{$hostname}));
1.181 raeburn 472: $spareservers{$hostname} = 1;
1.180 raeburn 473: my $protocol = $Apache::lonnet::protocol{$hostid};
474: $protocol = 'http' if ($protocol ne 'https');
475: $spares.='<br /><a href="'.$protocol.'://'.
1.160 kruse 476: $hostname.
477: '/adm/login?domain='.$authdomain.'">'.
478: $hostname.'</a>';
479: }
480: $r->print(
1.180 raeburn 481: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
482: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
483: .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'
1.160 kruse 484: .&mt('The LearningOnline Network with CAPA')
485: .'</title></head>'
486: .'<body bgcolor="#FFFFFF">'
487: .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
1.180 raeburn 488: .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
1.160 kruse 489: .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
490: if ($spares) {
491: $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
492: .'</p>'
493: .$spares);
494: }
495: $r->print('</body>'
496: .'</html>'
497: );
498: return OK;
499: }
500:
501: # ----------------------------------------------- Apparently we are in business
502: $servadm=~s/\,/\<br \/\>/g;
503:
504: # ----------------------------------------------------------- Front page design
505: my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
506: my $font=&Apache::loncommon::designparm('login.font',$domain);
507: my $link=&Apache::loncommon::designparm('login.link',$domain);
508: my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
509: my $alink=&Apache::loncommon::designparm('login.alink',$domain);
510: my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
511: my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
512: my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
513: my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
514: my $logo=&Apache::loncommon::designparm('login.logo',$domain);
515: my $img=&Apache::loncommon::designparm('login.img',$domain);
516: my $domainlogo=&Apache::loncommon::domainlogo($domain);
517: my $showbanner = 1;
518: my $showmainlogo = 1;
519: if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
520: $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
521: }
522: if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
523: $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
524: }
525: my $showadminmail;
526: my @possdoms = &Apache::lonnet::current_machine_domains();
527: if (grep(/^\Q$domain\E$/,@possdoms)) {
528: $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
529: }
530: my $showcoursecat =
531: &Apache::loncommon::designparm('login.coursecatalog',$domain);
532: my $shownewuserlink =
533: &Apache::loncommon::designparm('login.newuser',$domain);
534: my $showhelpdesk =
535: &Apache::loncommon::designparm('login.helpdesk',$domain);
536: my $now=time;
537: my $js = (<<ENDSCRIPT);
538:
539: <script type="text/javascript" language="JavaScript">
540: // <![CDATA[
541: function send()
542: {
543: this.document.server.elements.uname.value
544: =this.document.client.elements.uname.value;
545:
546: this.document.server.elements.udom.value
547: =this.document.client.elements.udom.value;
548:
549: uextkey=this.document.client.elements.uextkey.value;
550: lextkey=this.document.client.elements.lextkey.value;
551: initkeys();
552:
553: if(this.document.server.action.substr(0,5) === 'http:'){
1.165 raeburn 554: this.document.server.elements.upass0.value
555: =getCrypted(this.document.client.elements.upass$now.value);
1.166 raeburn 556: } else {
557: this.document.server.elements.upass0.value
558: =this.document.client.elements.upass$now.value;
1.167 raeburn 559: }
1.160 kruse 560:
561: this.document.client.elements.uname.value='';
562: this.document.client.elements.upass$now.value='';
563:
564: this.document.server.submit();
565: return false;
566: }
567:
568: function enableInput() {
569: this.document.client.elements.upass$now.removeAttribute("readOnly");
570: this.document.client.elements.uname.removeAttribute("readOnly");
571: this.document.client.elements.udom.removeAttribute("readOnly");
572: return;
573: }
574:
575: // ]]>
576: </script>
577:
578: ENDSCRIPT
579:
580: # --------------------------------------------------- Print login screen header
581:
582: my %add_entries = (
583: bgcolor => "$mainbg",
584: text => "$font",
585: link => "$link",
586: vlink => "$vlink",
587: alink => "$alink",
588: onload => 'javascript:enableInput();',);
589:
1.164 raeburn 590: my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
591: @hosts = &Apache::lonnet::current_machine_ids();
592: $lonhost_in_use = $lonhost;
1.163 raeburn 593: if (@hosts > 1) {
594: foreach my $hostid (@hosts) {
595: if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
596: $lonhost_in_use = $hostid;
597: last;
598: }
599: }
600: }
1.164 raeburn 601: %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
602: $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
603: $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
1.161 raeburn 604: if ($headextra) {
605: my $omitextra;
606: if ($headextra_exempt ne '') {
607: my @exempt = split(',',$headextra_exempt);
1.182 ! raeburn 608: my $ip = &Apache::lonnet::get_requestor_ip();
1.161 raeburn 609: if (grep(/^\Q$ip\E$/,@exempt)) {
610: $omitextra = 1;
611: }
612: }
613: unless ($omitextra) {
614: my $confname = $defdom.'-domainconfig';
1.163 raeburn 615: if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
1.161 raeburn 616: my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
617: unless ($extra eq '-1') {
618: $js .= "\n".$extra."\n";
619: }
620: }
621: }
622: }
623:
1.160 kruse 624: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
625: { 'redirect' => [$expire,'/adm/roles'],
626: 'add_entries' => \%add_entries,
627: 'only_body' => 1,}));
628:
629: # ----------------------------------------------------------------------- Texts
630:
631: my %lt=&Apache::lonlocal::texthash(
632: 'un' => 'Username',
633: 'pw' => 'Password',
634: 'dom' => 'Domain',
635: 'perc' => 'percent',
636: 'load' => 'Server Load',
637: 'userload' => 'User Load',
638: 'catalog' => 'Course/Community Catalog',
639: 'log' => 'Log in',
640: 'help' => 'Log-in Help',
641: 'serv' => 'Server',
642: 'servadm' => 'Server Administration',
643: 'helpdesk' => 'Contact Helpdesk',
644: 'forgotpw' => 'Forgot password?',
645: 'newuser' => 'New User?',
646: );
647: # -------------------------------------------------- Change password field name
648:
649: my $forgotpw = &forgotpwdisplay(%lt);
650: $forgotpw .= '<br />' if $forgotpw;
651: my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
652: if ($loginhelp) {
653: $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
654: }
655:
656: # ---------------------------------------------------- Serve out DES JavaScript
657: {
658: my $jsh=Apache::File->new($include."/londes.js");
659: $r->print(<$jsh>);
660: }
661: # ---------------------------------------------------------- Serve rest of page
662:
663: $r->print(
664: '<div class="LC_Box"'
665: .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
666: );
667:
668: $r->print(<<ENDSERVERFORM);
669: <form name="server" action="/adm/authenticate" method="post" target="_top">
670: <input type="hidden" name="logtoken" value="$logtoken" />
671: <input type="hidden" name="serverid" value="$lonhost" />
672: <input type="hidden" name="uname" value="" />
673: <input type="hidden" name="upass0" value="" />
674: <input type="hidden" name="udom" value="" />
675: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
676: <input type="hidden" name="localres" value="$env{'form.localres'}" />
677: </form>
678: ENDSERVERFORM
679: my $coursecatalog;
680: if (($showcoursecat eq '') || ($showcoursecat)) {
681: $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
682: }
683: my $newuserlink;
684: if ($shownewuserlink) {
685: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
686: }
687: my $logintitle =
688: '<h2 class="LC_hcell"'
689: .' style="background:'.$loginbox_header_bgcol.';'
690: .' color:'.$loginbox_header_textcol.'">'
691: .$lt{'log'}
692: .'</h2>';
693:
694: my $noscript_warning='<noscript><span class="LC_warning"><b>'
695: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
696: .'</b></span></noscript>';
697: my $helpdeskscript;
698: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
699: $authdomain,\$helpdeskscript,
700: $showhelpdesk,\@possdoms);
701:
702: my $mobileargs;
703: if ($clientmobile) {
704: $mobileargs = 'autocapitalize="off" autocorrect="off"';
705: }
706: my $loginform=(<<LFORM);
707: <form name="client" action="" onsubmit="return(send())">
708: <input type="hidden" name="lextkey" value="$lextkey" />
709: <input type="hidden" name="uextkey" value="$uextkey" />
710: <b><label for="uname">$lt{'un'}</label>:</b><br />
711: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
712: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
713: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
714: <b><label for="udom">$lt{'dom'}</label>:</b><br />
715: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
716: <input type="submit" value="$lt{'log'}" />
717: </form>
718: LFORM
719:
720: if ($showbanner) {
721: $r->print(<<HEADER);
722: <!-- The LON-CAPA Header -->
723: <div style="background:$pgbg;margin:0;width:100%;">
1.168 raeburn 724: <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
1.160 kruse 725: </div>
726: HEADER
727: }
728: $r->print(<<ENDTOP);
729: <div style="float:left;margin-top:0;">
730: <div class="LC_Box" style="background:$loginbox_bg;">
731: $logintitle
732: $loginform
733: $noscript_warning
734: </div>
735:
736: <div class="LC_Box" style="padding-top: 10px;">
737: $loginhelp
738: $forgotpw
739: $contactblock
740: $newuserlink
741: $coursecatalog
742: </div>
743: </div>
744:
745: <div>
746: ENDTOP
747: if ($showmainlogo) {
1.168 raeburn 748: $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
1.160 kruse 749: }
750: $r->print(<<ENDTOP);
751: $announcements
752: </div>
753: <hr style="clear:both;" />
754: ENDTOP
755: my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
756: $domainrow = <<"END";
757: <tr>
758: <td align="left" valign="top">
759: <small><b>$lt{'dom'}: </b></small>
760: </td>
761: <td align="left" valign="top">
762: <small><tt> $domain</tt></small>
763: </td>
764: </tr>
765: END
766: $serverrow = <<"END";
767: <tr>
768: <td align="left" valign="top">
769: <small><b>$lt{'serv'}: </b></small>
770: </td>
771: <td align="left" valign="top">
772: <small><tt> $lonhost ($role)</tt></small>
773: </td>
774: </tr>
775: END
776: if ($loadlim) {
777: $loadrow = <<"END";
778: <tr>
779: <td align="left" valign="top">
780: <small><b>$lt{'load'}: </b></small>
781: </td>
782: <td align="left" valign="top">
783: <small><tt> $loadpercent $lt{'perc'}</tt></small>
784: </td>
785: </tr>
786: END
787: }
788: if ($uloadlim) {
789: $userloadrow = <<"END";
790: <tr>
791: <td align="left" valign="top">
792: <small><b>$lt{'userload'}: </b></small>
793: </td>
794: <td align="left" valign="top">
795: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
796: </td>
797: </tr>
798: END
799: }
800: if (($version ne '') && ($version ne '<!-- VERSION -->')) {
801: $versionrow = <<"END";
802: <tr>
803: <td colspan="2" align="left">
804: <small>$version</small>
805: </td>
806: </tr>
807: END
808: }
809:
810: $r->print(<<ENDDOCUMENT);
811: <div style="float: left;">
812: <table border="0" cellspacing="0" cellpadding="0">
813: $domainrow
814: $serverrow
815: $loadrow
816: $userloadrow
817: $versionrow
818: </table>
819: </div>
820: <div style="float: right;">
821: $domainlogo
822: </div>
823: <br style="clear:both;" />
824: </div>
825:
826: <script type="text/javascript">
827: // <![CDATA[
828: // the if prevents the script error if the browser can not handle this
829: if ( document.client.uname ) { document.client.uname.focus(); }
830: // ]]>
831: </script>
832: $helpdeskscript
833:
834: ENDDOCUMENT
835: my %endargs = ( 'noredirectlink' => 1, );
836: $r->print(&Apache::loncommon::end_page(\%endargs));
837: return OK;
838: }
839:
840: sub check_loginvia {
1.177 raeburn 841: my ($domain,$lonhost,$lonidsdir,$balcookie,$linkprot) = @_;
1.176 raeburn 842: if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
1.160 kruse 843: return;
844: }
845: my %domconfhash = &Apache::loncommon::get_domainconf($domain);
846: my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
847: my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
848: my $output;
849: if ($loginvia ne '') {
850: my $noredirect;
1.182 ! raeburn 851: my $ip = &Apache::lonnet::get_requestor_ip();
1.160 kruse 852: if ($ip eq '127.0.0.1') {
853: $noredirect = 1;
854: } else {
855: if ($loginvia_exempt ne '') {
856: my @exempt = split(',',$loginvia_exempt);
857: if (grep(/^\Q$ip\E$/,@exempt)) {
858: $noredirect = 1;
859: }
860: }
861: }
862: unless ($noredirect) {
863: my ($newhost,$path);
864: if ($loginvia =~ /:/) {
865: ($newhost,$path) = split(':',$loginvia);
866: } else {
867: $newhost = $loginvia;
868: }
869: if ($newhost ne $lonhost) {
870: if (&Apache::lonnet::hostname($newhost) ne '') {
1.176 raeburn 871: if ($balcookie) {
872: my ($balancer,$cookie) = split(/:/,$balcookie);
873: if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
874: my ($udom,$uname,$cookieid) = ($1,$2,$3);
875: unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
876: if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
877: while (my $filename=readdir($dh)) {
878: if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
879: my $handle = $1;
880: my %hash =
881: &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
882: ['request.balancercookie',
883: 'user.linkedenv']);
884: if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
885: if (unlink("$lonidsdir/$filename")) {
886: if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
887: (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
888: (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
889: unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
890: }
891: }
892: }
893: last;
894: }
895: }
896: closedir($dh);
897: }
898: }
899: }
900: }
1.177 raeburn 901: $output = &redirect_page($newhost,$path,$linkprot);
1.160 kruse 902: }
903: }
904: }
905: }
906: return $output;
907: }
908:
909: sub redirect_page {
1.177 raeburn 910: my ($desthost,$path,$linkprot) = @_;
1.178 raeburn 911: my $hostname = &Apache::lonnet::hostname($desthost);
1.160 kruse 912: my $protocol = $Apache::lonnet::protocol{$desthost};
913: $protocol = 'http' if ($protocol ne 'https');
914: unless ($path =~ m{^/}) {
915: $path = '/'.$path;
916: }
1.178 raeburn 917: my $url = $protocol.'://'.$hostname.$path;
1.160 kruse 918: if ($env{'form.firsturl'} ne '') {
919: $url .='?firsturl='.$env{'form.firsturl'};
920: }
1.177 raeburn 921: if ($linkprot) {
922: my $ltoken = &Apache::lonnet::tmpput({linkprot => $linkprot},$desthost);
923: if ($ltoken) {
924: $url .= (($url =~ /\?/) ? '&' : '?').'ltoken='.$ltoken;
925: }
926: }
1.160 kruse 927: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
928: {'redirect' => [0,$url],});
929: my $end_page = &Apache::loncommon::end_page();
930: return $start_page.$end_page;
931: }
932:
933: sub contactdisplay {
934: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
935: $possdoms) = @_;
936: my $contactblock;
937: my $origmail;
938: if (ref($possdoms) eq 'ARRAY') {
939: if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
940: $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
941: }
942: }
943: my $requestmail =
944: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
945: $authdomain,$origmail);
946: unless ($showhelpdesk eq '0') {
947: if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
948: $showhelpdesk = 1;
949: } else {
950: $showhelpdesk = 0;
951: }
952: }
953: if ($servadm && $showadminmail) {
954: $contactblock .= $$lt{'servadm'}.':<br />'.
955: '<tt>'.$servadm.'</tt><br />';
956: }
957: if ($showhelpdesk) {
958: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
959: my $thisurl = &escape('/adm/login');
960: $$helpdeskscript = <<"ENDSCRIPT";
961: <script type="text/javascript">
962: // <![CDATA[
963: function helpdesk() {
964: var possdom = document.client.udom.value;
965: var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
966: if (codedom == '') {
967: codedom = "$authdomain";
968: }
969: var querystr = "origurl=$thisurl&codedom="+codedom;
970: document.location.href = "/adm/helpdesk?"+querystr;
971: return;
972: }
973: // ]]>
974: </script>
975: ENDSCRIPT
976: }
977: return $contactblock;
978: }
979:
980: sub forgotpwdisplay {
981: my (%lt) = @_;
982: my $prompt_for_resetpw = 1;
983: if ($prompt_for_resetpw) {
984: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
985: }
986: return;
987: }
988:
989: sub coursecatalog_link {
990: my ($linkname) = @_;
991: return <<"END";
992: <a href="/adm/coursecatalog">$linkname</a>
993: END
994: }
995:
996: sub newuser_link {
997: my ($linkname) = @_;
998: return '<a href="/adm/createaccount">'.$linkname.'</a>';
999: }
1000:
1001: 1;
1002: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>