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