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