1: # The LearningOnline Network
2: # Login Screen
3: #
4: # $Id: lonlogin.pm,v 1.158.2.13.2.8 2023/01/23 00:52:44 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 URI::Escape;
42: use HTML::Entities();
43: use CGI::Cookie();
44:
45: sub handler {
46: my $r = shift;
47:
48: &Apache::loncommon::get_unprocessed_cgi
49: (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
50: $ENV{'REDIRECT_QUERY_STRING'}),
51: ['interface','username','domain','firsturl','localpath','localres',
52: 'token','role','symb','iptoken','btoken','ltoken','ttoken','linkkey',
53: 'saml','sso','retry','display']);
54:
55: # -- check if they are a migrating user
56: if (defined($env{'form.token'})) {
57: return &Apache::migrateuser::handler($r);
58: }
59:
60: my $lonhost = $r->dir_config('lonHostID');
61: if ($env{'form.ttoken'}) {
62: my %info = &Apache::lonnet::tmpget($env{'form.ttoken'});
63: &Apache::lonnet::tmpdel($env{'form.ttoken'});
64: if ($info{'origurl'}) {
65: $env{'form.firsturl'} = $info{'origurl'};
66: }
67: if ($info{'ltoken'}) {
68: $env{'form.ltoken'} = $info{'ltoken'};
69: } elsif ($info{'linkprot'}) {
70: $env{'form.linkprot'} = $info{'linkprot'};
71: foreach my $item ('linkprotuser','linkprotexit') {
72: if ($info{$item} ne '') {
73: $env{'form.'.$item} = $info{$item};
74: }
75: }
76: } elsif ($info{'linkkey'} ne '') {
77: $env{'form.linkkey'} = $info{'linkkey'};
78: }
79: } elsif (($env{'form.sso'}) || ($env{'form.retry'})) {
80: my $infotoken;
81: if ($env{'form.sso'}) {
82: $infotoken = $env{'form.sso'};
83: } else {
84: $infotoken = $env{'form.retry'};
85: }
86: my $data = &Apache::lonnet::reply('tmpget:'.$infotoken,$lonhost);
87: unless (($data=~/^error/) || ($data eq 'con_lost') ||
88: ($data eq 'no_such_host')) {
89: my %info = &decode_token($data);
90: foreach my $item (keys(%info)) {
91: $env{'form.'.$item} = $info{$item};
92: }
93: &Apache::lonnet::tmpdel($infotoken);
94: }
95: } else {
96: if (!defined($env{'form.firsturl'})) {
97: &Apache::lonacc::get_posted_cgi($r,['firsturl']);
98: }
99: if (!defined($env{'form.firsturl'})) {
100: if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {
101: $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};
102: }
103: }
104: if (($env{'form.firsturl'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) &&
105: (!$env{'form.ltoken'}) && (!$env{'form.linkprot'}) && (!$env{'form.linkkey'})) {
106: &Apache::lonacc::get_posted_cgi($r,['linkkey']);
107: }
108: if ($env{'form.firsturl'} eq '/adm/logout') {
109: delete($env{'form.firsturl'});
110: }
111: }
112:
113: # For "public user" - remove any exising "public" cookie, as user really wants to log-in
114: my ($handle,$lonidsdir,$expirepub,$userdom);
115: $lonidsdir=$r->dir_config('lonIDsDir');
116: unless ($r->header_only) {
117: $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
118: if ($handle ne '') {
119: if ($handle=~/^publicuser\_/) {
120: unlink($r->dir_config('lonIDsDir')."/$handle.id");
121: undef($handle);
122: undef($userdom);
123: $expirepub = 1;
124: }
125: }
126: }
127:
128: &Apache::loncommon::no_cache($r);
129: &Apache::lonlocal::get_language_handle($r);
130: &Apache::loncommon::content_type($r,'text/html');
131: if ($expirepub) {
132: my $c = new CGI::Cookie(-name => 'lonPubID',
133: -value => '',
134: -expires => '-10y',);
135: $r->header_out('Set-cookie' => $c);
136: } elsif (($handle eq '') && ($userdom ne '')) {
137: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
138: foreach my $name (keys(%cookies)) {
139: next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
140: my $c = new CGI::Cookie(-name => $name,
141: -value => '',
142: -expires => '-10y',);
143: $r->headers_out->add('Set-cookie' => $c);
144: }
145: }
146: $r->send_http_header;
147: return OK if $r->header_only;
148:
149:
150: # Are we re-routing?
151: my $londocroot = $r->dir_config('lonDocRoot');
152: if (-e "$londocroot/lon-status/reroute.txt") {
153: &Apache::lonauth::reroute($r);
154: return OK;
155: }
156:
157: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
158:
159: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
160: if ($found_server) {
161: my $hostname = &Apache::lonnet::hostname($found_server);
162: if ($hostname ne '') {
163: my $protocol = $Apache::lonnet::protocol{$found_server};
164: $protocol = 'http' if ($protocol ne 'https');
165: my $dest = '/adm/roles';
166: if ($env{'form.firsturl'} ne '') {
167: $dest = &HTML::Entities::encode($env{'form.firsturl'},'\'"<>&');
168: }
169: my %info = (
170: balcookie => $lonhost.':'.$balancer_cookie,
171: );
172: if ($env{'form.role'}) {
173: $info{'role'} = $env{'form.role'};
174: }
175: if ($env{'form.symb'}) {
176: $info{'symb'} = $env{'form.symb'};
177: }
178: if (($env{'form.firsturl'} eq '/adm/email') && ($env{'form.display'} ne '')) {
179: if ($env{'form.sso'}) {
180: if ($env{'form.mailrecip'}) {
181: $info{'display'} = &escape($env{'form.display'});
182: $info{'mailrecip'} = &escape($env{'form.mailrecip'});
183: }
184: } else {
185: if (($env{'form.username'}) && ($env{'form.domain'})) {
186: $info{'display'} = &escape($env{'form.display'});
187: $info{'mailrecipient'} = &escape($env{'form.username'}.':'.$env{'form.domain'});
188: }
189: }
190: }
191: my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
192: unless (($balancer_token eq 'con_lost') || ($balancer_token eq 'refused') ||
193: ($balancer_token eq 'unknown_cmd') || ($balancer_token eq 'no_such_host')) {
194: $dest .= (($dest=~/\?/)?'&':'?') . 'btoken='.$balancer_token;
195: }
196: if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
197: my %link_info;
198: if ($env{'form.ltoken'}) {
199: $link_info{'ltoken'} = $env{'form.ltoken'};
200: } elsif ($env{'form.linkprot'}) {
201: $link_info{'linkprot'} = $env{'form.linkprot'};
202: foreach my $item ('linkprotuser','linkprotexit') {
203: if ($env{'form.'.$item} ne '') {
204: $link_info{$item} = $env{'form.'.$item};
205: }
206: }
207: } elsif ($env{'form.linkkey'} ne '') {
208: $link_info{'linkkey'} = $env{'form.linkkey'};
209: }
210: if (keys(%link_info)) {
211: $link_info{'origurl'} = $env{'form.firsturl'};
212: my $token = &Apache::lonnet::tmpput(\%link_info,$found_server,'link');
213: unless (($token eq 'con_lost') || ($token eq 'refused') ||
214: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
215: $dest .= (($dest=~/\?/)?'&':'?') . 'ttoken='.$token;
216: }
217: }
218: }
219: unless ($found_server eq $lonhost) {
220: my $alias = &Apache::lonnet::use_proxy_alias($r,$found_server);
221: $hostname = $alias if ($alias ne '');
222: }
223: my $url = $protocol.'://'.$hostname.$dest;
224: my $start_page =
225: &Apache::loncommon::start_page('Switching Server ...',undef,
226: {'redirect' => [0,$url],});
227: my $end_page = &Apache::loncommon::end_page();
228: $r->print($start_page.$end_page);
229: return OK;
230: }
231: }
232:
233: #
234: # Check if a LON-CAPA load balancer sent user here because user's browser sent
235: # it a balancer cookie for an active session on this server.
236: #
237:
238: my $balcookie;
239: if ($env{'form.btoken'}) {
240: my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
241: $balcookie = $info{'balcookie'};
242: &Apache::lonnet::tmpdel($env{'form.btoken'});
243: delete($env{'form.btoken'});
244: if (($env{'form.firsturl'} eq '/adm/email') &&
245: (exists($info{'display'})) && (exists($info{'mailrecip'}))) {
246: $env{'form.display'} = &unescape($info{'display'});
247: $env{'form.mailrecip'} = &unescape($info{'mailrecip'});
248: }
249: }
250:
251: #
252: # If browser sent an old cookie for which the session file had been removed
253: # check if configuration for user's domain has a portal URL set. If so
254: # switch user's log-in to the portal.
255: #
256:
257: if (($handle eq '') && ($userdom ne '')) {
258: my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
259: if ($domdefaults{'portal_def'} =~ /^https?\:/) {
260: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
261: {'redirect' => [0,$domdefaults{'portal_def'}],});
262: my $end_page = &Apache::loncommon::end_page();
263: $r->print($start_page.$end_page);
264: return OK;
265: }
266: }
267:
268: # -------------------------------- Prevent users from attempting to login twice
269: if ($handle ne '') {
270: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
271: my $start_page =
272: &Apache::loncommon::start_page('Already logged in');
273: my $end_page =
274: &Apache::loncommon::end_page();
275: my $dest = '/adm/roles';
276: if ($env{'form.firsturl'} ne '') {
277: $dest = &HTML::Entities::encode($env{'form.firsturl'},'\'"<>&');
278: }
279: if (($env{'form.ltoken'}) || ($env{'form.linkprot'})) {
280: my ($linkprot,$linkprotuser,$linkprotexit);
281: if ($env{'form.ltoken'}) {
282: my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
283: $linkprot = $info{'linkprot'};
284: if ($info{'linkprotuser'} ne '') {
285: $linkprotuser = $info{'linkprotuser'};
286: }
287: if ($info{'linkprotexit'} ne '') {
288: $linkprotexit = $info{'linkprotexit'};
289: }
290: } else {
291: $linkprot = $env{'form.linkprot'};
292: $linkprotuser = $env{'form.linkprotuser'};
293: $linkprotexit = $env{'form.linkprotexit'};
294: }
295: if ($linkprot) {
296: my ($linkprotector,$deeplink) = split(/:/,$linkprot,2);
297: if (($deeplink =~ m{^/tiny/$match_domain/\w+$}) &&
298: ($linkprotuser ne '') && ($linkprotuser ne $env{'user.name'}.':'.$env{'user.domain'})) {
299: my $ip = &Apache::lonnet::get_requestor_ip();
300: my %linkprotinfo = (
301: origurl => $deeplink,
302: linkprot => $linkprot,
303: linkprotuser => $linkprotuser,
304: linkprotexit => $linkprotexit,
305: );
306: if ($env{'form.ltoken'}) {
307: my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'});
308: }
309: &Apache::migrateuser::logout($r,$ip,$handle,undef,undef,\%linkprotinfo);
310: return OK;
311: }
312: if ($env{'user.linkprotector'}) {
313: my @protectors = split(/,/,$env{'user.linkprotector'});
314: unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
315: push(@protectors,$linkprotector);
316: @protectors = sort { $a <=> $b } @protectors;
317: &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
318: }
319: } else {
320: &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
321: }
322: if ($env{'user.linkproturi'}) {
323: my @proturis = split(/,/,$env{'user.linkproturi'});
324: unless (grep(/^\Q$deeplink\E$/,@proturis)) {
325: push(@proturis,$deeplink);
326: @proturis = sort @proturis;
327: &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
328: }
329: } else {
330: &Apache::lonnet::appenv({'user.linkproturi' => $deeplink});
331: }
332: }
333: } elsif ($env{'form.linkkey'} ne '') {
334: if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
335: my $linkkey = $env{'form.linkkey'};
336: if ($env{'user.deeplinkkey'}) {
337: my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
338: unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
339: push(@linkkeys,$linkkey);
340: &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});
341: }
342: } else {
343: &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
344: }
345: my $deeplink = $env{'form.firsturl'};
346: if ($env{'user.keyedlinkuri'}) {
347: my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
348: unless (grep(/^\Q$deeplink\E$/,@keyeduris)) {
349: push(@keyeduris,$deeplink);
350: &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
351: }
352: } else {
353: &Apache::lonnet::appenv({'user.keyedlinkuri' => $deeplink});
354: }
355: }
356: }
357: if ($env{'form.ltoken'}) {
358: my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'});
359: }
360: if (($env{'form.firsturl'} eq '/adm/email') && ($env{'form.display'})) {
361: if ($env{'form.mailrecip'}) {
362: if ($env{'form.mailrecip'} eq "$env{'user.name'}:$env{'user.domain'}") {
363: $dest .= (($dest=~/\?/)?'&':'?') . 'display='.&escape($env{'form.display'}).
364: '&mailrecip='.&escape($env{'form.mailrecip'});
365: }
366: } elsif (($env{'form.username'} eq $env{'user.name'}) && ($env{'form.domain'} eq $env{'user.domain'})) {
367: $dest .= (($dest=~/\?/)?'&':'?') . 'display='.&escape($env{'form.display'}).
368: '&mailrecip='.&escape("$env{'user.name'}:$env{'form.domain'}");
369: }
370: }
371: $r->print(
372: $start_page
373: .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
374: .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
375: '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
376: .$end_page
377: );
378: return OK;
379: }
380:
381: # ---------------------------------------------------- No valid token, continue
382:
383: # ---------------------------- Not possible to really login to domain "public"
384: if ($env{'form.domain'} eq 'public') {
385: $env{'form.domain'}='';
386: $env{'form.username'}='';
387: }
388:
389: # ------ Is this page requested because /adm/migrateuser detected an IP change?
390: my %sessiondata;
391: if ($env{'form.iptoken'}) {
392: %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
393: unless ($sessiondata{'sessionserver'}) {
394: my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
395: delete($env{'form.iptoken'});
396: }
397: }
398: # ----------------------------------------------------------- Process Interface
399: $env{'form.interface'}=~s/\W//g;
400:
401: (undef,undef,undef,undef,undef,undef,my $clientmobile) =
402: &Apache::loncommon::decode_user_agent($r);
403:
404: my $iconpath=
405: &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
406:
407: my $domain = &Apache::lonnet::default_login_domain();
408: my $defdom = $domain;
409: if ($lonhost ne '') {
410: unless ($sessiondata{'sessionserver'}) {
411: my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);
412: if ($redirect) {
413: $r->print($redirect);
414: return OK;
415: }
416: }
417: }
418:
419: if (($sessiondata{'domain'}) &&
420: (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
421: $domain=$sessiondata{'domain'};
422: } elsif (($env{'form.domain'}) &&
423: (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
424: $domain=$env{'form.domain'};
425: }
426:
427: my $role = $r->dir_config('lonRole');
428: my $loadlim = $r->dir_config('lonLoadLim');
429: my $uloadlim= $r->dir_config('lonUserLoadLim');
430: my $servadm = $r->dir_config('lonAdmEMail');
431: my $tabdir = $r->dir_config('lonTabDir');
432: my $include = $r->dir_config('lonIncludes');
433: my $expire = $r->dir_config('lonExpire');
434: my $version = $r->dir_config('lonVersion');
435: my $host_name = &Apache::lonnet::hostname($lonhost);
436:
437: # --------------------------------------------- Default values for login fields
438:
439: my ($authusername,$authdomain);
440: if ($sessiondata{'username'}) {
441: $authusername=$sessiondata{'username'};
442: } else {
443: $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
444: $authusername=($env{'form.username'}?$env{'form.username'}:'');
445: }
446: if ($sessiondata{'domain'}) {
447: $authdomain=$sessiondata{'domain'};
448: } else {
449: $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
450: $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
451: }
452:
453: # ---------------------------------------------------------- Determine own load
454: my $loadavg;
455: {
456: my $loadfile=Apache::File->new('/proc/loadavg');
457: $loadavg=<$loadfile>;
458: }
459: $loadavg =~ s/\s.*//g;
460:
461: my ($loadpercent,$userloadpercent);
462: if ($loadlim) {
463: $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
464: }
465: if ($uloadlim) {
466: $userloadpercent=&Apache::lonnet::userload();
467: }
468:
469: my $firsturl=
470: ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
471:
472: # ----------------------------------------------------------- Get announcements
473: my $announcements=&Apache::lonnet::getannounce();
474: # -------------------------------------------------------- Set login parameters
475:
476: my @hexstr=('0','1','2','3','4','5','6','7',
477: '8','9','a','b','c','d','e','f');
478: my $lkey='';
479: for (0..7) {
480: $lkey.=$hexstr[rand(15)];
481: }
482:
483: my $ukey='';
484: for (0..7) {
485: $ukey.=$hexstr[rand(15)];
486: }
487:
488: my $lextkey=hex($lkey);
489: if ($lextkey>2147483647) { $lextkey-=4294967296; }
490:
491: my $uextkey=hex($ukey);
492: if ($uextkey>2147483647) { $uextkey-=4294967296; }
493:
494: # -------------------------------------------------------- Store away log token
495: my ($tokenextras,$tokentype,$linkprot_for_login);
496: my @names = ('role','symb','iptoken','ltoken','linkprotuser','linkprotexit','linkprot','linkkey','display');
497: foreach my $name (@names) {
498: if ($env{'form.'.$name} ne '') {
499: if ($name eq 'ltoken') {
500: my %info = &Apache::lonnet::tmpget($env{'form.'.$name});
501: if ($info{'linkprot'}) {
502: $linkprot_for_login = $info{'linkprot'};
503: $tokenextras .= '&linkprot='.&escape($info{'linkprot'});
504: foreach my $item ('linkprotuser','linkprotexit') {
505: if ($info{$item}) {
506: $tokenextras .= '&'.$item.'='.&escape($info{$item});
507: }
508: }
509: $tokentype = 'link';
510: last;
511: }
512: } elsif ($env{'form.display'} && ($env{'form.firsturl'} eq '/adm/email')) {
513: if (($env{'form.mailrecip'}) ||
514: ($env{'form.username'} =~ /^$match_username$/) && ($env{'form.domain'} =~ /^$match_domain$/)) {
515: $tokenextras .= '&'.$name.'='.&escape($env{'form.display'});
516: if ($env{'form.mailrecip'}) {
517: $tokenextras .= '&mailrecip='.&escape($env{'form.mailrecip'});
518: } else {
519: $tokenextras .= '&mailrecip='.&escape($env{'form.username'}.':'.$env{'form.domain'});
520: }
521: }
522: } else {
523: $tokenextras .= '&'.$name.'='.&escape($env{'form.'.$name});
524: if (($name eq 'linkkey') || ($name eq 'linkprot')) {
525: if ((($env{'form.retry'}) || ($env{'form.sso'})) &&
526: (!$env{'form.ltoken'}) && ($name eq 'linkprot')) {
527: $linkprot_for_login = $env{'form.linkprot'};
528: }
529: $tokentype = 'link';
530: }
531: }
532: }
533: }
534: if ($tokentype) {
535: $tokenextras .= ":$tokentype";
536: }
537: my $logtoken=Apache::lonnet::reply(
538: 'tmpput:'.$ukey.$lkey.'&'.&escape($firsturl).$tokenextras,
539: $lonhost);
540:
541: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
542: # we are in serious trouble
543:
544: if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
545: if ($logtoken eq 'no_such_host') {
546: &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
547: }
548: if ($env{'form.ltoken'}) {
549: &Apache::lonnet::tmpdel($env{'form.ltoken'});
550: delete($env{'form.ltoken'});
551: }
552: my $spares='';
553: my (@sparehosts,%spareservers);
554: my $sparesref = &Apache::lonnet::this_host_spares($defdom);
555: if (ref($sparesref) eq 'HASH') {
556: foreach my $key (keys(%{$sparesref})) {
557: if (ref($sparesref->{$key}) eq 'ARRAY') {
558: my @sorted = sort { &Apache::lonnet::hostname($a) cmp
559: &Apache::lonnet::hostname($b);
560: } @{$sparesref->{$key}};
561: if (@sorted) {
562: if ($key eq 'primary') {
563: unshift(@sparehosts,@sorted);
564: } elsif ($key eq 'default') {
565: push(@sparehosts,@sorted);
566: }
567: }
568: }
569: }
570: }
571: foreach my $hostid (@sparehosts) {
572: next if ($hostid eq $lonhost);
573: my $hostname = &Apache::lonnet::hostname($hostid);
574: next if (($hostname eq '') || ($spareservers{$hostname}));
575: $spareservers{$hostname} = 1;
576: my $protocol = $Apache::lonnet::protocol{$hostid};
577: $protocol = 'http' if ($protocol ne 'https');
578: $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.
579: $hostname.
580: '/adm/login?domain='.$authdomain.'">'.
581: $hostname.'</a>'.
582: ' '.&mt('(preferred)').'</span>'.$/;
583: }
584: if ($spares) {
585: $spares.= '<br />';
586: }
587: my %all_hostnames = &Apache::lonnet::all_hostnames();
588: foreach my $hostid (sort
589: {
590: &Apache::lonnet::hostname($a) cmp
591: &Apache::lonnet::hostname($b);
592: }
593: keys(%all_hostnames)) {
594: next if ($hostid eq $lonhost);
595: my $hostname = &Apache::lonnet::hostname($hostid);
596: next if (($hostname eq '') || ($spareservers{$hostname}));
597: $spareservers{$hostname} = 1;
598: my $protocol = $Apache::lonnet::protocol{$hostid};
599: $protocol = 'http' if ($protocol ne 'https');
600: $spares.='<br /><a href="'.$protocol.'://'.
601: $hostname.
602: '/adm/login?domain='.$authdomain.'">'.
603: $hostname.'</a>';
604: }
605: $r->print(
606: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
607: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
608: .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'
609: .&mt('The LearningOnline Network with CAPA')
610: .'</title></head>'
611: .'<body bgcolor="#FFFFFF">'
612: .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
613: .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
614: .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
615: if ($spares) {
616: $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
617: .'</p>'
618: .$spares);
619: }
620: $r->print('</body>'
621: .'</html>'
622: );
623: return OK;
624: }
625:
626: # ----------------------------------------------- Apparently we are in business
627: $servadm=~s/\,/\<br \/\>/g;
628:
629: # ----------------------------------------------------------- Front page design
630: my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
631: my $font=&Apache::loncommon::designparm('login.font',$domain);
632: my $link=&Apache::loncommon::designparm('login.link',$domain);
633: my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
634: my $alink=&Apache::loncommon::designparm('login.alink',$domain);
635: my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
636: my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
637: my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
638: my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
639: my $logo=&Apache::loncommon::designparm('login.logo',$domain);
640: my $img=&Apache::loncommon::designparm('login.img',$domain);
641: my $domainlogo=&Apache::loncommon::domainlogo($domain);
642: my $showbanner = 1;
643: my $showmainlogo = 1;
644: if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
645: $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
646: }
647: if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
648: $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
649: }
650: my $showadminmail;
651: my @possdoms = &Apache::lonnet::current_machine_domains();
652: if (grep(/^\Q$domain\E$/,@possdoms)) {
653: $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
654: }
655: my $showcoursecat =
656: &Apache::loncommon::designparm('login.coursecatalog',$domain);
657: my $shownewuserlink =
658: &Apache::loncommon::designparm('login.newuser',$domain);
659: my $showhelpdesk =
660: &Apache::loncommon::designparm('login.helpdesk',$domain);
661: my $now=time;
662: my $js = (<<ENDSCRIPT);
663:
664: <script type="text/javascript" language="JavaScript">
665: // <![CDATA[
666: function send()
667: {
668: this.document.server.elements.uname.value
669: =this.document.client.elements.uname.value;
670:
671: this.document.server.elements.udom.value
672: =this.document.client.elements.udom.value;
673:
674: uextkey=this.document.client.elements.uextkey.value;
675: lextkey=this.document.client.elements.lextkey.value;
676: initkeys();
677:
678: this.document.server.elements.upass0.value
679: =getCrypted(this.document.client.elements.upass$now.value);
680:
681: this.document.client.elements.uname.value='';
682: this.document.client.elements.upass$now.value='';
683:
684: this.document.server.submit();
685: return false;
686: }
687:
688: function enableInput() {
689: this.document.client.elements.upass$now.removeAttribute("readOnly");
690: this.document.client.elements.uname.removeAttribute("readOnly");
691: this.document.client.elements.udom.removeAttribute("readOnly");
692: return;
693: }
694:
695: // ]]>
696: </script>
697:
698: ENDSCRIPT
699:
700: my ($lonhost_in_use,@hosts,%defaultdomconf,$saml_prefix,$saml_landing,
701: $samlssotext,$samlnonsso,$samlssoimg,$samlssoalt,$samlssourl,$samltooltip,
702: $samlwindow);
703: %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
704: @hosts = &Apache::lonnet::current_machine_ids();
705: $lonhost_in_use = $lonhost;
706: if (@hosts > 1) {
707: foreach my $hostid (@hosts) {
708: if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
709: $lonhost_in_use = $hostid;
710: last;
711: }
712: }
713: }
714: $saml_prefix = $defdom.'.login.saml_';
715: if ($defaultdomconf{$saml_prefix.$lonhost_in_use}) {
716: $saml_landing = 1;
717: $samlssotext = $defaultdomconf{$saml_prefix.'text_'.$lonhost_in_use};
718: $samlnonsso = $defaultdomconf{$saml_prefix.'notsso_'.$lonhost_in_use};
719: $samlssoimg = $defaultdomconf{$saml_prefix.'img_'.$lonhost_in_use};
720: $samlssoalt = $defaultdomconf{$saml_prefix.'alt_'.$lonhost_in_use};
721: $samlssourl = $defaultdomconf{$saml_prefix.'url_'.$lonhost_in_use};
722: $samltooltip = $defaultdomconf{$saml_prefix.'title_'.$lonhost_in_use};
723: $samlwindow = $defaultdomconf{$saml_prefix.'window_'.$lonhost_in_use};
724: }
725: if ($saml_landing) {
726: if ($samlssotext eq '') {
727: $samlssotext = 'SSO Login';
728: }
729: if ($samlnonsso eq '') {
730: $samlnonsso = 'Non-SSO Login';
731: }
732: $js .= <<"ENDSAMLJS";
733:
734: <script type="text/javascript">
735: // <![CDATA[
736: function toggleLClogin() {
737: if (document.getElementById('LC_standard_login')) {
738: if (document.getElementById('LC_standard_login').style.display == 'none') {
739: document.getElementById('LC_standard_login').style.display = 'inline-block';
740: if (document.getElementById('LC_login_text')) {
741: document.getElementById('LC_login_text').innerHTML = '$samlnonsso';
742: }
743: if ( document.client.uname ) { document.client.uname.focus(); }
744: if (document.getElementById('LC_SSO_login')) {
745: document.getElementById('LC_SSO_login').style.display = 'none';
746: }
747: } else {
748: document.getElementById('LC_standard_login').style.display = 'none';
749: if (document.getElementById('LC_login_text')) {
750: document.getElementById('LC_login_text').innerHTML = '$samlssotext';
751: }
752: if (document.getElementById('LC_SSO_login')) {
753: document.getElementById('LC_SSO_login').style.display = 'inline-block';
754: }
755: }
756: }
757: return;
758: }
759:
760: // ]]>
761: </script>
762:
763: ENDSAMLJS
764: }
765:
766: # --------------------------------------------------- Print login screen header
767:
768: my %add_entries = (
769: bgcolor => "$mainbg",
770: text => "$font",
771: link => "$link",
772: vlink => "$vlink",
773: alink => "$alink",
774: onload => 'javascript:enableInput();',);
775:
776: my ($headextra,$headextra_exempt);
777: $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
778: $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
779: if ($headextra) {
780: my $omitextra;
781: if ($headextra_exempt ne '') {
782: my @exempt = split(',',$headextra_exempt);
783: my $ip = &Apache::lonnet::get_requestor_ip();
784: if (grep(/^\Q$ip\E$/,@exempt)) {
785: $omitextra = 1;
786: }
787: }
788: unless ($omitextra) {
789: my $confname = $defdom.'-domainconfig';
790: if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
791: my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
792: unless ($extra eq '-1') {
793: $js .= "\n".$extra."\n";
794: }
795: }
796: }
797: }
798:
799: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
800: { 'redirect' => [$expire,'/adm/roles'],
801: 'add_entries' => \%add_entries,
802: 'only_body' => 1,}));
803:
804: # ----------------------------------------------------------------------- Texts
805:
806: my %lt=&Apache::lonlocal::texthash(
807: 'un' => 'Username',
808: 'pw' => 'Password',
809: 'dom' => 'Domain',
810: 'perc' => 'percent',
811: 'load' => 'Server Load',
812: 'userload' => 'User Load',
813: 'catalog' => 'Course/Community Catalog',
814: 'log' => 'Log in',
815: 'help' => 'Log-in Help',
816: 'serv' => 'Server',
817: 'servadm' => 'Server Administration',
818: 'helpdesk' => 'Contact Helpdesk',
819: 'forgotpw' => 'Forgot password?',
820: 'newuser' => 'New User?',
821: 'change' => 'Change?',
822: );
823: # -------------------------------------------------- Change password field name
824:
825: my $forgotpw = &forgotpwdisplay(%lt);
826: $forgotpw .= '<br />' if $forgotpw;
827: my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
828: if ($loginhelp) {
829: $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
830: }
831:
832: # ---------------------------------------------------- Serve out DES JavaScript
833: {
834: my $jsh=Apache::File->new($include."/londes.js");
835: $r->print(<$jsh>);
836: }
837: # ---------------------------------------------------------- Serve rest of page
838:
839: $r->print(
840: '<div class="LC_Box"'
841: .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
842: );
843:
844: $r->print(<<ENDSERVERFORM);
845: <form name="server" action="/adm/authenticate" method="post" target="_top">
846: <input type="hidden" name="logtoken" value="$logtoken" />
847: <input type="hidden" name="serverid" value="$lonhost" />
848: <input type="hidden" name="uname" value="" />
849: <input type="hidden" name="upass0" value="" />
850: <input type="hidden" name="udom" value="" />
851: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
852: <input type="hidden" name="localres" value="$env{'form.localres'}" />
853: </form>
854: ENDSERVERFORM
855: my $coursecatalog;
856: if (($showcoursecat eq '') || ($showcoursecat)) {
857: $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
858: }
859: my $newuserlink;
860: if ($shownewuserlink) {
861: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
862: }
863: my $logintitle =
864: '<h2 class="LC_hcell"'
865: .' style="background:'.$loginbox_header_bgcol.';'
866: .' color:'.$loginbox_header_textcol.'">'
867: .$lt{'log'}
868: .'</h2>';
869:
870: my $noscript_warning='<noscript><span class="LC_warning"><b>'
871: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
872: .'</b></span></noscript>';
873: my $helpdeskscript;
874: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
875: $authdomain,\$helpdeskscript,
876: $showhelpdesk,\@possdoms);
877:
878: my $mobileargs;
879: if ($clientmobile) {
880: $mobileargs = 'autocapitalize="off" autocorrect="off"';
881: }
882: my $loginform=(<<LFORM);
883: <form name="client" action="" onsubmit="return(send())" id="lclogin">
884: <input type="hidden" name="lextkey" value="$lextkey" />
885: <input type="hidden" name="uextkey" value="$uextkey" />
886: <b><label for="uname">$lt{'un'}</label>:</b><br />
887: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
888: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
889: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
890: <b><label for="udom">$lt{'dom'}</label>:</b><br />
891: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
892: <input type="submit" value="$lt{'log'}" />
893: </form>
894: LFORM
895:
896: if ($showbanner) {
897: my $alttext = &Apache::loncommon::designparm('login.alttext_img',$domain);
898: if ($alttext eq '') {
899: $alttext = 'The Learning Online Network with CAPA';
900: }
901: $r->print(<<HEADER);
902: <!-- The LON-CAPA Header -->
903: <div style="background:$pgbg;margin:0;width:100%;">
904: <img src="$img" border="0" alt="$alttext" class="LC_maxwidth" id="lcloginbanner" />
905: </div>
906: HEADER
907: }
908:
909: my $stdauthformstyle = 'inline-block';
910: my $ssoauthstyle = 'none';
911: my $sso_onclick;
912: my $logintype;
913: $r->print('<div style="float:left;margin-top:0;">');
914: if ($saml_landing) {
915: $ssoauthstyle = 'inline-block';
916: $stdauthformstyle = 'none';
917: $logintype = $samlssotext;
918: my $ssologin = '/adm/sso';
919: if ($samlssourl ne '') {
920: $ssologin = $samlssourl;
921: }
922: my $ssologin_for_js = &js_escape($ssologin);
923: my $querystr_for_js;
924: if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
925: my $querystring;
926: if ($env{'form.firsturl'} ne '') {
927: $querystring = 'origurl=';
928: if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
929: $querystring .= &uri_escape_utf8($env{'form.firsturl'});
930: } else {
931: $querystring .= &uri_escape($env{'form.firsturl'});
932: }
933: $querystring = &HTML::Entities::encode($querystring,"'");
934: }
935: if ($env{'form.ltoken'} ne '') {
936: $querystring .= (($querystring eq '')?'':'&') . 'ltoken='.
937: &HTML::Entities::encode(&uri_escape($env{'form.ltoken'}));
938: } elsif ($env{'form.linkkey'}) {
939: $querystring .= (($querystring eq '')?'':'&') . 'linkkey='.
940: &HTML::Entities::encode(&uri_escape($env{'form.linkkey'}));
941: }
942: if ($querystring ne '') {
943: $ssologin .= (($ssologin=~/\?/)?'&':'?') . $querystring;
944: $querystr_for_js = &js_escape($querystring);
945: }
946: } elsif ($logtoken ne '') {
947: $ssologin .= (($ssologin=~/\?/)?'&':'?') . 'logtoken='.$logtoken;
948: $querystr_for_js = &js_escape('logtoken='.$logtoken);
949: }
950: my $ssohref;
951: if ($samlwindow) {
952: $sso_onclick = <<"ENDJS";
953: if (document.getElementById('LC_sso_login_link')) {
954: var ssoelem = document.getElementById('LC_sso_login_link')
955: ssoelem.addEventListener('click',samlWinFunction,false);
956: var windows = {};
957: function samlWinFunction(evt) {
958: evt.preventDefault();
959: var url = '$ssologin_for_js';
960: var name = 'lcssowin';
961: var querystr = '$querystr_for_js';
962: if (querystr) {
963: url += '?'+querystr+'&lcssowin=1';
964: } else {
965: url += '?lcssowin=1';
966: }
967: if ((typeof windows[name] !== 'undefined') && (!windows[name].closed)) {
968: windows[name].close();
969: }
970: windows[name]=window.open(url,name,'width=350,height=600');
971: windows[name].focus();
972: return false;
973: }
974: }
975: ENDJS
976: }
977: if ($samlssoimg ne '') {
978: $ssohref = '<a href="'.$ssologin.'" title="'.$samltooltip.'" id="LC_sso_login_link">'.
979: '<img src="'.$samlssoimg.'" alt="'.$samlssoalt.'" id="lcssobutton" /></a>';
980: } else {
981: $ssohref = '<a href="'.$ssologin.'" id="LC_sso_login_link">'.$samlssotext.'</a>';
982: }
983: if (($env{'form.saml'} eq 'no') ||
984: (($env{'form.username'} ne '') && ($env{'form.domain'} ne ''))) {
985: $ssoauthstyle = 'none';
986: $stdauthformstyle = 'inline-block';
987: $logintype = $samlnonsso;
988: }
989: $r->print(<<ENDSAML);
990: <p>
991: Log-in type:
992: <span style="font-weight:bold" id="LC_login_text">$logintype</span><br />
993: <span><a href="javascript:toggleLClogin();" style="color:#000000">$lt{'change'}</a></span>
994: </p>
995: <div style="display:$ssoauthstyle" id="LC_SSO_login">
996: <div class="LC_Box" style="padding-top: 10px;">
997: $ssohref
998: $noscript_warning
999: </div>
1000: <div class="LC_Box" style="padding-top: 10px;">
1001: $loginhelp
1002: $contactblock
1003: $coursecatalog
1004: </div>
1005: </div>
1006: ENDSAML
1007: } else {
1008: if ($env{'form.ltoken'}) {
1009: &Apache::lonnet::tmpdel($env{'form.ltoken'});
1010: delete($env{'form.ltoken'});
1011: }
1012: }
1013: my $in_frame_js;
1014: if ($linkprot_for_login) {
1015: my ($linkprotector,$linkproturi) = split(/:/,$linkprot_for_login,2);
1016: if (($linkprotector =~ /^\d+(c|d)$/) && ($linkproturi =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$})) {
1017: my $set_target;
1018: if (($env{'form.retry'}) || ($env{'form.sso'})) {
1019: if ($linkproturi eq $env{'form.firsturl'}) {
1020: $set_target = " document.server.target = '_self';";
1021: }
1022: } else {
1023: $set_target = <<ENDTARG;
1024: var linkproturi = '$linkproturi';
1025: var path = document.location.pathname.replace( new RegExp('^/adm/launch'),'');
1026: if (linkproturi == path) {
1027: document.server.target = '_self';
1028: }
1029: ENDTARG
1030: }
1031: $in_frame_js = <<ENDJS;
1032: <script type="text/javascript">
1033: // <![CDATA[
1034: if ((window.self !== window.top) && (document.server.target != '_self')) {
1035: $set_target
1036: $sso_onclick
1037: }
1038: // ]]>
1039: </script>
1040: ENDJS
1041: }
1042: } elsif ($samlwindow) {
1043: $in_frame_js = <<ENDJS;
1044: <script type="text/javascript">
1045: // <![CDATA[
1046: if ((window.self !== window.top) && (document.server.target != '_self')) {
1047: $sso_onclick
1048: }
1049: // ]]>
1050: </script>
1051: ENDJS
1052: }
1053:
1054: $r->print(<<ENDLOGIN);
1055: <div style="display:$stdauthformstyle;" id="LC_standard_login">
1056: <div class="LC_Box" style="background:$loginbox_bg;">
1057: $logintitle
1058: $loginform
1059: $noscript_warning
1060: </div>
1061:
1062: <div class="LC_Box" style="padding-top: 10px;">
1063: $loginhelp
1064: $forgotpw
1065: $contactblock
1066: $newuserlink
1067: $coursecatalog
1068: </div>
1069: </div>
1070:
1071: ENDLOGIN
1072: $r->print('</div><div>'."\n");
1073: if ($showmainlogo) {
1074: my $alttext = &Apache::loncommon::designparm('login.alttext_logo',$domain);
1075: $r->print(' <img src="'.$logo.'" alt="'.$alttext.'" class="LC_maxwidth" id="lcloginmainlogo" />'."\n");
1076: }
1077: $r->print(<<ENDTOP);
1078: $announcements
1079: </div>
1080: <hr style="clear:both;" />
1081: ENDTOP
1082: my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
1083: $domainrow = <<"END";
1084: <tr>
1085: <td align="left" valign="top">
1086: <small><b>$lt{'dom'}: </b></small>
1087: </td>
1088: <td align="left" valign="top">
1089: <small><tt> $domain</tt></small>
1090: </td>
1091: </tr>
1092: END
1093: $serverrow = <<"END";
1094: <tr>
1095: <td align="left" valign="top">
1096: <small><b>$lt{'serv'}: </b></small>
1097: </td>
1098: <td align="left" valign="top">
1099: <small><tt> $lonhost ($role)</tt></small>
1100: </td>
1101: </tr>
1102: END
1103: if ($loadlim) {
1104: $loadrow = <<"END";
1105: <tr>
1106: <td align="left" valign="top">
1107: <small><b>$lt{'load'}: </b></small>
1108: </td>
1109: <td align="left" valign="top">
1110: <small><tt> $loadpercent $lt{'perc'}</tt></small>
1111: </td>
1112: </tr>
1113: END
1114: }
1115: if ($uloadlim) {
1116: $userloadrow = <<"END";
1117: <tr>
1118: <td align="left" valign="top">
1119: <small><b>$lt{'userload'}: </b></small>
1120: </td>
1121: <td align="left" valign="top">
1122: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
1123: </td>
1124: </tr>
1125: END
1126: }
1127: if (($version ne '') && ($version ne '<!-- VERSION -->')) {
1128: $versionrow = <<"END";
1129: <tr>
1130: <td colspan="2" align="left">
1131: <small>$version</small>
1132: </td>
1133: </tr>
1134: END
1135: }
1136:
1137: $r->print(<<ENDDOCUMENT);
1138: <div style="float: left;">
1139: <table border="0" cellspacing="0" cellpadding="0">
1140: $domainrow
1141: $serverrow
1142: $loadrow
1143: $userloadrow
1144: $versionrow
1145: </table>
1146: </div>
1147: <div style="float: right;">
1148: $domainlogo
1149: </div>
1150: <br style="clear:both;" />
1151: </div>
1152:
1153: $in_frame_js
1154: <script type="text/javascript">
1155: // <![CDATA[
1156: // the if prevents the script error if the browser can not handle this
1157: if ( document.client.uname ) { document.client.uname.focus(); }
1158: // ]]>
1159: </script>
1160: $helpdeskscript
1161:
1162: ENDDOCUMENT
1163: my %endargs = ( 'noredirectlink' => 1, );
1164: $r->print(&Apache::loncommon::end_page(\%endargs));
1165: return OK;
1166: }
1167:
1168: sub check_loginvia {
1169: my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
1170: if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
1171: return;
1172: }
1173: my %domconfhash = &Apache::loncommon::get_domainconf($domain);
1174: my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
1175: my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
1176: my $output;
1177: if ($loginvia ne '') {
1178: my $noredirect;
1179: my $ip = &Apache::lonnet::get_requestor_ip();
1180: if ($ip eq '127.0.0.1') {
1181: $noredirect = 1;
1182: } else {
1183: if ($loginvia_exempt ne '') {
1184: my @exempt = split(',',$loginvia_exempt);
1185: if (grep(/^\Q$ip\E$/,@exempt)) {
1186: $noredirect = 1;
1187: }
1188: }
1189: }
1190: unless ($noredirect) {
1191: my ($newhost,$path);
1192: if ($loginvia =~ /:/) {
1193: ($newhost,$path) = split(':',$loginvia);
1194: } else {
1195: $newhost = $loginvia;
1196: }
1197: if ($newhost ne $lonhost) {
1198: if (&Apache::lonnet::hostname($newhost) ne '') {
1199: if ($balcookie) {
1200: my ($balancer,$cookie) = split(/:/,$balcookie);
1201: if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
1202: my ($udom,$uname,$cookieid) = ($1,$2,$3);
1203: unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
1204: if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
1205: while (my $filename=readdir($dh)) {
1206: if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
1207: my $handle = $1;
1208: my %hash =
1209: &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
1210: ['request.balancercookie',
1211: 'user.linkedenv']);
1212: if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
1213: if (unlink("$lonidsdir/$filename")) {
1214: if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
1215: (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
1216: (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
1217: unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
1218: }
1219: }
1220: }
1221: last;
1222: }
1223: }
1224: closedir($dh);
1225: }
1226: }
1227: }
1228: }
1229: $output = &redirect_page($newhost,$path);
1230: }
1231: }
1232: }
1233: }
1234: return $output;
1235: }
1236:
1237: sub redirect_page {
1238: my ($desthost,$path) = @_;
1239: my $hostname = &Apache::lonnet::hostname($desthost);
1240: my $protocol = $Apache::lonnet::protocol{$desthost};
1241: $protocol = 'http' if ($protocol ne 'https');
1242: unless ($path =~ m{^/}) {
1243: $path = '/'.$path;
1244: }
1245: my $url = $protocol.'://'.$hostname.$path;
1246: my $args = {};
1247: if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
1248: $url = $protocol.'://'.$hostname.$env{'form.firsturl'};
1249: if (($env{'form.ltoken'}) || ($env{'form.linkprot'} ne '') ||
1250: ($env{'form.linkkey'} ne '')) {
1251: my %link_info;
1252: if ($env{'form.ltoken'}) {
1253: %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
1254: &Apache::lonnet::tmpdel($env{'form.ltoken'});
1255: $args->{'only_body'} = 1;
1256: } elsif ($env{'form.linkprot'}) {
1257: $link_info{'linkprot'} = $env{'form.linkprot'};
1258: foreach my $item ('linkprotuser','linkprotexit') {
1259: if ($env{'form.'.$item}) {
1260: $link_info{$item} = $env{'form.'.$item};
1261: }
1262: }
1263: $args->{'only_body'} = 1;
1264: } elsif ($env{'form.linkkey'} ne '') {
1265: $link_info{'linkkey'} = $env{'form.linkkey'};
1266: }
1267: my $token = &Apache::lonnet::tmpput(\%link_info,$desthost,'link');
1268: unless (($token eq 'con_lost') || ($token eq 'refused') ||
1269: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
1270: $url .= '?ltoken='.$token;
1271: }
1272: }
1273: } else {
1274: my $querystring;
1275: if ($env{'form.firsturl'} ne '') {
1276: if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
1277: $querystring = &uri_escape_utf8($env{'form.firsturl'});
1278: } else {
1279: $querystring = &uri_escape($env{'form.firsturl'});
1280: }
1281: $querystring = &HTML::Entities::encode($querystring,"'");
1282: $querystring = '?firsturl='.$querystring;
1283: }
1284: if ($env{'form.ltoken'}) {
1285: my %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
1286: &Apache::lonnet::tmpdel($env{'form.ltoken'});
1287: my $token = &Apache::lonnet::tmpput(\%link_info,$desthost,'link');
1288: unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
1289: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
1290: unless (($path eq '/adm/roles') || ($path eq '/adm/login')) {
1291: $url = $protocol.'://'.$hostname.'/adm/roles';
1292: }
1293: $querystring .= (($querystring =~/^\?/)?'&':'?') . 'ttoken='.$token;
1294: }
1295: }
1296: $url .= $querystring;
1297: }
1298: $args->{'redirect'} = [0,$url];
1299: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,$args);
1300: my $end_page = &Apache::loncommon::end_page();
1301: return $start_page.$end_page;
1302: }
1303:
1304: sub contactdisplay {
1305: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
1306: $possdoms) = @_;
1307: my $contactblock;
1308: my $origmail;
1309: if (ref($possdoms) eq 'ARRAY') {
1310: if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
1311: $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
1312: }
1313: }
1314: my $requestmail =
1315: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
1316: $authdomain,$origmail);
1317: unless ($showhelpdesk eq '0') {
1318: if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
1319: $showhelpdesk = 1;
1320: } else {
1321: $showhelpdesk = 0;
1322: }
1323: }
1324: if ($servadm && $showadminmail) {
1325: $contactblock .= $$lt{'servadm'}.':<br />'.
1326: '<tt>'.$servadm.'</tt><br />';
1327: }
1328: if ($showhelpdesk) {
1329: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
1330: my $thisurl = &escape('/adm/login');
1331: $$helpdeskscript = <<"ENDSCRIPT";
1332: <script type="text/javascript">
1333: // <![CDATA[
1334: function helpdesk() {
1335: var possdom = document.client.udom.value;
1336: var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
1337: if (codedom == '') {
1338: codedom = "$authdomain";
1339: }
1340: var querystr = "origurl=$thisurl&codedom="+codedom;
1341: document.location.href = "/adm/helpdesk?"+querystr;
1342: return;
1343: }
1344: // ]]>
1345: </script>
1346: ENDSCRIPT
1347: }
1348: return $contactblock;
1349: }
1350:
1351: sub forgotpwdisplay {
1352: my (%lt) = @_;
1353: my $prompt_for_resetpw = 1;
1354: if ($prompt_for_resetpw) {
1355: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
1356: }
1357: return;
1358: }
1359:
1360: sub coursecatalog_link {
1361: my ($linkname) = @_;
1362: return <<"END";
1363: <a href="/adm/coursecatalog">$linkname</a>
1364: END
1365: }
1366:
1367: sub newuser_link {
1368: my ($linkname) = @_;
1369: return '<a href="/adm/createaccount">'.$linkname.'</a>';
1370: }
1371:
1372: sub decode_token {
1373: my ($info) = @_;
1374: my ($firsturl,@rest)=split(/\&/,$info);
1375: my %form;
1376: if ($firsturl ne '') {
1377: $form{'firsturl'} = &unescape($firsturl);
1378: }
1379: foreach my $item (@rest) {
1380: my ($key,$value) = split(/=/,$item);
1381: $form{$key} = &unescape($value);
1382: }
1383: return %form;
1384: }
1385:
1386: 1;
1387: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>