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