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