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