Annotation of loncom/auth/lonlogin.pm, revision 1.158.2.13.2.6
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.5 2022/06/01 12:21:06 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,
662: $samlssotext,$samlnonsso,$samlssoimg,$samlssoalt,$samlssourl,$samltooltip);
663: %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
1.158.2.4 raeburn 664: @hosts = &Apache::lonnet::current_machine_ids();
665: $lonhost_in_use = $lonhost;
666: if (@hosts > 1) {
667: foreach my $hostid (@hosts) {
668: if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
669: $lonhost_in_use = $hostid;
670: last;
671: }
672: }
673: }
1.158.2.13 raeburn 674: $saml_prefix = $defdom.'.login.saml_';
675: if ($defaultdomconf{$saml_prefix.$lonhost_in_use}) {
676: $saml_landing = 1;
677: $samlssotext = $defaultdomconf{$saml_prefix.'text_'.$lonhost_in_use};
678: $samlnonsso = $defaultdomconf{$saml_prefix.'notsso_'.$lonhost_in_use};
679: $samlssoimg = $defaultdomconf{$saml_prefix.'img_'.$lonhost_in_use};
680: $samlssoalt = $defaultdomconf{$saml_prefix.'alt_'.$lonhost_in_use};
681: $samlssourl = $defaultdomconf{$saml_prefix.'url_'.$lonhost_in_use};
682: $samltooltip = $defaultdomconf{$saml_prefix.'title_'.$lonhost_in_use};
683: }
684: if ($saml_landing) {
685: if ($samlssotext eq '') {
686: $samlssotext = 'SSO Login';
687: }
688: if ($samlnonsso eq '') {
689: $samlnonsso = 'Non-SSO Login';
690: }
691: $js .= <<"ENDSAMLJS";
692:
693: <script type="text/javascript">
694: // <![CDATA[
695: function toggleLClogin() {
696: if (document.getElementById('LC_standard_login')) {
697: if (document.getElementById('LC_standard_login').style.display == 'none') {
698: document.getElementById('LC_standard_login').style.display = 'inline-block';
699: if (document.getElementById('LC_login_text')) {
700: document.getElementById('LC_login_text').innerHTML = '$samlnonsso';
701: }
1.158.2.13.2. (raeburn 702:): if ( document.client.uname ) { document.client.uname.focus(); }
1.158.2.13 raeburn 703: if (document.getElementById('LC_SSO_login')) {
704: document.getElementById('LC_SSO_login').style.display = 'none';
705: }
706: } else {
707: document.getElementById('LC_standard_login').style.display = 'none';
708: if (document.getElementById('LC_login_text')) {
709: document.getElementById('LC_login_text').innerHTML = '$samlssotext';
710: }
711: if (document.getElementById('LC_SSO_login')) {
712: document.getElementById('LC_SSO_login').style.display = 'inline-block';
713: }
714: }
715: }
716: return;
717: }
718:
719: // ]]>
720: </script>
721:
722: ENDSAMLJS
723: }
724:
725: # --------------------------------------------------- Print login screen header
726:
727: my %add_entries = (
728: bgcolor => "$mainbg",
729: text => "$font",
730: link => "$link",
731: vlink => "$vlink",
732: alink => "$alink",
733: onload => 'javascript:enableInput();',);
734:
735: my ($headextra,$headextra_exempt);
1.158.2.4 raeburn 736: $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
737: $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
1.158.2.1 raeburn 738: if ($headextra) {
739: my $omitextra;
740: if ($headextra_exempt ne '') {
741: my @exempt = split(',',$headextra_exempt);
1.158.2.12 raeburn 742: my $ip = &Apache::lonnet::get_requestor_ip();
1.158.2.1 raeburn 743: if (grep(/^\Q$ip\E$/,@exempt)) {
744: $omitextra = 1;
745: }
746: }
747: unless ($omitextra) {
748: my $confname = $defdom.'-domainconfig';
1.158.2.4 raeburn 749: if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
1.158.2.1 raeburn 750: my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
751: unless ($extra eq '-1') {
752: $js .= "\n".$extra."\n";
753: }
754: }
755: }
756: }
757:
1.151 raeburn 758: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
1.107 tempelho 759: { 'redirect' => [$expire,'/adm/roles'],
760: 'add_entries' => \%add_entries,
761: 'only_body' => 1,}));
1.98 raeburn 762:
763: # ----------------------------------------------------------------------- Texts
764:
1.151 raeburn 765: my %lt=&Apache::lonlocal::texthash(
1.129 bisitz 766: 'un' => 'Username',
767: 'pw' => 'Password',
768: 'dom' => 'Domain',
769: 'perc' => 'percent',
770: 'load' => 'Server Load',
771: 'userload' => 'User Load',
772: 'catalog' => 'Course/Community Catalog',
773: 'log' => 'Log in',
774: 'help' => 'Log-in Help',
775: 'serv' => 'Server',
776: 'servadm' => 'Server Administration',
777: 'helpdesk' => 'Contact Helpdesk',
778: 'forgotpw' => 'Forgot password?',
779: 'newuser' => 'New User?',
1.158.2.13 raeburn 780: 'change' => 'Change?',
1.129 bisitz 781: );
1.98 raeburn 782: # -------------------------------------------------- Change password field name
1.131 jms 783:
1.151 raeburn 784: my $forgotpw = &forgotpwdisplay(%lt);
785: $forgotpw .= '<br />' if $forgotpw;
1.152 raeburn 786: my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
787: if ($loginhelp) {
788: $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
789: }
1.98 raeburn 790:
791: # ---------------------------------------------------- Serve out DES JavaScript
1.151 raeburn 792: {
793: my $jsh=Apache::File->new($include."/londes.js");
794: $r->print(<$jsh>);
795: }
1.98 raeburn 796: # ---------------------------------------------------------- Serve rest of page
797:
1.151 raeburn 798: $r->print(
1.137 bisitz 799: '<div class="LC_Box"'
800: .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
801: );
1.6 www 802:
1.151 raeburn 803: $r->print(<<ENDSERVERFORM);
1.140 raeburn 804: <form name="server" action="/adm/authenticate" method="post" target="_top">
1.33 www 805: <input type="hidden" name="logtoken" value="$logtoken" />
806: <input type="hidden" name="serverid" value="$lonhost" />
807: <input type="hidden" name="uname" value="" />
1.65 www 808: <input type="hidden" name="upass0" value="" />
1.33 www 809: <input type="hidden" name="udom" value="" />
1.63 albertel 810: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
811: <input type="hidden" name="localres" value="$env{'form.localres'}" />
1.14 albertel 812: </form>
1.16 www 813: ENDSERVERFORM
1.151 raeburn 814: my $coursecatalog;
815: if (($showcoursecat eq '') || ($showcoursecat)) {
816: $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
817: }
818: my $newuserlink;
819: if ($shownewuserlink) {
820: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
821: }
822: my $logintitle =
823: '<h2 class="LC_hcell"'
824: .' style="background:'.$loginbox_header_bgcol.';'
825: .' color:'.$loginbox_header_textcol.'">'
826: .$lt{'log'}
827: .'</h2>';
828:
829: my $noscript_warning='<noscript><span class="LC_warning"><b>'
830: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
831: .'</b></span></noscript>';
832: my $helpdeskscript;
833: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
1.153 raeburn 834: $authdomain,\$helpdeskscript,
835: $showhelpdesk,\@possdoms);
1.107 tempelho 836:
1.156 raeburn 837: my $mobileargs;
838: if ($clientmobile) {
839: $mobileargs = 'autocapitalize="off" autocorrect="off"';
840: }
1.151 raeburn 841: my $loginform=(<<LFORM);
1.158.2.13 raeburn 842: <form name="client" action="" onsubmit="return(send())" id="lclogin">
1.115 bisitz 843: <input type="hidden" name="lextkey" value="$lextkey" />
844: <input type="hidden" name="uextkey" value="$uextkey" />
1.108 tempelho 845: <b><label for="uname">$lt{'un'}</label>:</b><br />
1.156 raeburn 846: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
1.108 tempelho 847: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
1.139 raeburn 848: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
1.108 tempelho 849: <b><label for="udom">$lt{'dom'}</label>:</b><br />
1.156 raeburn 850: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
1.108 tempelho 851: <input type="submit" value="$lt{'log'}" />
852: </form>
853: LFORM
854:
1.109 raeburn 855: if ($showbanner) {
1.158.2.13.2. (raeburn 856:): my $alttext = &Apache::loncommon::designparm('login.alttext_img',$domain);
857:): if ($alttext eq '') {
858:): $alttext = 'The Learning Online Network with CAPA';
859:): }
1.109 raeburn 860: $r->print(<<HEADER);
861: <!-- The LON-CAPA Header -->
1.132 bisitz 862: <div style="background:$pgbg;margin:0;width:100%;">
1.158.2.13.2. (raeburn 863:): <img src="$img" border="0" alt="$alttext" class="LC_maxwidth" id="lcloginbanner" />
1.132 bisitz 864: </div>
1.109 raeburn 865: HEADER
866: }
1.158.2.13 raeburn 867:
868: my $stdauthformstyle = 'inline-block';
869: my $ssoauthstyle = 'none';
870: my $logintype;
871: $r->print('<div style="float:left;margin-top:0;">');
872: if ($saml_landing) {
873: $ssoauthstyle = 'inline-block';
874: $stdauthformstyle = 'none';
875: $logintype = $samlssotext;
876: my $ssologin = '/adm/sso';
877: if ($samlssourl ne '') {
878: $ssologin = $samlssourl;
879: }
880: if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
881: my $querystring;
882: if ($env{'form.firsturl'} ne '') {
883: $querystring = 'origurl=';
884: if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
885: $querystring .= &uri_escape_utf8($env{'form.firsturl'});
886: } else {
887: $querystring .= &uri_escape($env{'form.firsturl'});
888: }
889: $querystring = &HTML::Entities::encode($querystring,"'");
890: }
1.158.2.13.2. (raeburn 891:): if ($env{'form.ltoken'} ne '') {
892:): $querystring .= (($querystring eq '')?'':'&') . 'ltoken='.
893:): &HTML::Entities::encode(&uri_escape($env{'form.ltoken'}));
894:): } elsif ($env{'form.linkkey'}) {
895:): $querystring .= (($querystring eq '')?'':'&') . 'linkkey='.
896:): &HTML::Entities::encode(&uri_escape($env{'form.linkkey'}));
897:): }
1.158.2.13 raeburn 898: if ($querystring ne '') {
899: $ssologin .= (($ssologin=~/\?/)?'&':'?') . $querystring;
900: }
901: } elsif ($logtoken ne '') {
902: $ssologin .= (($ssologin=~/\?/)?'&':'?') . 'logtoken='.$logtoken;
903: }
904: my $ssohref;
905: if ($samlssoimg ne '') {
1.158.2.13.2. (raeburn 906:): $ssohref = '<a href="'.$ssologin.'" title="'.$samltooltip.'">'.
907:): '<img src="'.$samlssoimg.'" alt="'.$samlssoalt.'" id="lcssobutton" /></a>';
1.158.2.13 raeburn 908: } else {
909: $ssohref = '<a href="'.$ssologin.'">'.$samlssotext.'</a>';
910: }
911: if (($env{'form.saml'} eq 'no') ||
912: (($env{'form.username'} ne '') && ($env{'form.domain'} ne ''))) {
913: $ssoauthstyle = 'none';
914: $stdauthformstyle = 'inline-block';
915: $logintype = $samlnonsso;
916: }
917: $r->print(<<ENDSAML);
918: <p>
919: Log-in type:
920: <span style="font-weight:bold" id="LC_login_text">$logintype</span><br />
921: <span><a href="javascript:toggleLClogin();" style="color:#000000">$lt{'change'}</a></span>
922: </p>
923: <div style="display:$ssoauthstyle" id="LC_SSO_login">
924: <div class="LC_Box" style="padding-top: 10px;">
925: $ssohref
926: $noscript_warning
927: </div>
928: <div class="LC_Box" style="padding-top: 10px;">
929: $loginhelp
930: $contactblock
931: $coursecatalog
932: </div>
933: </div>
934: ENDSAML
1.158.2.13.2. (raeburn 935:): } else {
936:): if ($env{'form.ltoken'}) {
937:): &Apache::lonnet::tmpdel($env{'form.ltoken'});
938:): delete($env{'form.ltoken'});
939:): }
1.158.2.13 raeburn 940: }
1.158.2.13.2. (raeburn 941:): my $in_frame_js;
942:): if ($linkprot_for_login) {
943:): my ($linkprotector,$linkproturi) = split(/:/,$linkprot_for_login,2);
944:): if (($linkprotector =~ /^\d+(c|d)$/) && ($linkproturi =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$})) {
945:): my $set_target;
946:): if (($env{'form.retry'}) || ($env{'form.sso'})) {
947:): if ($linkproturi eq $env{'form.firsturl'}) {
948:): $set_target = " document.server.target = '_self';";
949:): }
950:): } else {
951:): $set_target = <<ENDTARG;
952:): var linkproturi = '$linkproturi';
953:): var path = document.location.pathname.replace( new RegExp('^/adm/launch'),'');
954:): if (linkproturi == path) {
955:): document.server.target = '_self';
956:): }
957:): ENDTARG
958:): }
959:): $in_frame_js = <<ENDJS;
960:): <script type="text/javascript">
961:): // <![CDATA[
962:): if ((window.self !== window.top) && (document.server.target != '_self')) {
963:): $set_target
964:): }
965:): // ]]>
966:): </script>
967:): ENDJS
968:): }
969:): }
1.158.2.13 raeburn 970:
971: $r->print(<<ENDLOGIN);
972: <div style="display:$stdauthformstyle;" id="LC_standard_login">
1.137 bisitz 973: <div class="LC_Box" style="background:$loginbox_bg;">
1.112 muellerd 974: $logintitle
1.137 bisitz 975: $loginform
976: $noscript_warning
1.108 tempelho 977: </div>
1.107 tempelho 978:
1.137 bisitz 979: <div class="LC_Box" style="padding-top: 10px;">
1.132 bisitz 980: $loginhelp
981: $forgotpw
982: $contactblock
983: $newuserlink
1.130 bisitz 984: $coursecatalog
1.107 tempelho 985: </div>
1.118 tempelho 986: </div>
1.137 bisitz 987:
1.158.2.13 raeburn 988: ENDLOGIN
989: $r->print('</div><div>'."\n");
1.118 tempelho 990: if ($showmainlogo) {
1.158.2.13.2. (raeburn 991:): my $alttext = &Apache::loncommon::designparm('login.alttext_logo',$domain);
992:): $r->print(' <img src="'.$logo.'" alt="'.$alttext.'" class="LC_maxwidth" id="lcloginmainlogo" />'."\n");
1.118 tempelho 993: }
994: $r->print(<<ENDTOP);
995: $announcements
1.137 bisitz 996: </div>
997: <hr style="clear:both;" />
1.108 tempelho 998: ENDTOP
1.147 raeburn 999: my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
1000: $domainrow = <<"END";
1.14 albertel 1001: <tr>
1.110 muellerd 1002: <td align="left" valign="top">
1.132 bisitz 1003: <small><b>$lt{'dom'}: </b></small>
1.14 albertel 1004: </td>
1.110 muellerd 1005: <td align="left" valign="top">
1.14 albertel 1006: <small><tt> $domain</tt></small>
1007: </td>
1008: </tr>
1.147 raeburn 1009: END
1010: $serverrow = <<"END";
1.14 albertel 1011: <tr>
1.110 muellerd 1012: <td align="left" valign="top">
1.132 bisitz 1013: <small><b>$lt{'serv'}: </b></small>
1.14 albertel 1014: </td>
1.110 muellerd 1015: <td align="left" valign="top">
1.14 albertel 1016: <small><tt> $lonhost ($role)</tt></small>
1017: </td>
1018: </tr>
1.147 raeburn 1019: END
1020: if ($loadlim) {
1021: $loadrow = <<"END";
1.14 albertel 1022: <tr>
1.110 muellerd 1023: <td align="left" valign="top">
1.132 bisitz 1024: <small><b>$lt{'load'}: </b></small>
1.14 albertel 1025: </td>
1.110 muellerd 1026: <td align="left" valign="top">
1.51 www 1027: <small><tt> $loadpercent $lt{'perc'}</tt></small>
1.42 albertel 1028: </td>
1029: </tr>
1.147 raeburn 1030: END
1031: }
1032: if ($uloadlim) {
1033: $userloadrow = <<"END";
1.42 albertel 1034: <tr>
1.110 muellerd 1035: <td align="left" valign="top">
1.132 bisitz 1036: <small><b>$lt{'userload'}: </b></small>
1.42 albertel 1037: </td>
1.110 muellerd 1038: <td align="left" valign="top">
1.51 www 1039: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
1.14 albertel 1040: </td>
1041: </tr>
1.147 raeburn 1042: END
1043: }
1044: if (($version ne '') && ($version ne '<!-- VERSION -->')) {
1045: $versionrow = <<"END";
1.132 bisitz 1046: <tr>
1047: <td colspan="2" align="left">
1048: <small>$version</small>
1049: </td>
1050: </tr>
1.147 raeburn 1051: END
1052: }
1053:
1.151 raeburn 1054: $r->print(<<ENDDOCUMENT);
1.147 raeburn 1055: <div style="float: left;">
1056: <table border="0" cellspacing="0" cellpadding="0">
1057: $domainrow
1058: $serverrow
1059: $loadrow
1060: $userloadrow
1061: $versionrow
1.14 albertel 1062: </table>
1.141 raeburn 1063: </div>
1064: <div style="float: right;">
1065: $domainlogo
1066: </div>
1067: <br style="clear:both;" />
1.107 tempelho 1068: </div>
1.25 bowersj2 1069:
1.158.2.13.2. (raeburn 1070:): $in_frame_js
1.59 albertel 1071: <script type="text/javascript">
1.122 bisitz 1072: // <![CDATA[
1.59 albertel 1073: // the if prevents the script error if the browser can not handle this
1.25 bowersj2 1074: if ( document.client.uname ) { document.client.uname.focus(); }
1.122 bisitz 1075: // ]]>
1.25 bowersj2 1076: </script>
1.62 raeburn 1077: $helpdeskscript
1.14 albertel 1078:
1.1 albertel 1079: ENDDOCUMENT
1.98 raeburn 1080: my %endargs = ( 'noredirectlink' => 1, );
1081: $r->print(&Apache::loncommon::end_page(\%endargs));
1.1 albertel 1082: return OK;
1.60 raeburn 1083: }
1084:
1.133 raeburn 1085: sub check_loginvia {
1.158.2.8 raeburn 1086: my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
1087: if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
1.133 raeburn 1088: return;
1089: }
1090: my %domconfhash = &Apache::loncommon::get_domainconf($domain);
1091: my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
1092: my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
1093: my $output;
1094: if ($loginvia ne '') {
1095: my $noredirect;
1.158.2.12 raeburn 1096: my $ip = &Apache::lonnet::get_requestor_ip();
1.133 raeburn 1097: if ($ip eq '127.0.0.1') {
1098: $noredirect = 1;
1099: } else {
1100: if ($loginvia_exempt ne '') {
1101: my @exempt = split(',',$loginvia_exempt);
1102: if (grep(/^\Q$ip\E$/,@exempt)) {
1103: $noredirect = 1;
1104: }
1105: }
1106: }
1107: unless ($noredirect) {
1108: my ($newhost,$path);
1109: if ($loginvia =~ /:/) {
1110: ($newhost,$path) = split(':',$loginvia);
1111: } else {
1112: $newhost = $loginvia;
1113: }
1114: if ($newhost ne $lonhost) {
1115: if (&Apache::lonnet::hostname($newhost) ne '') {
1.158.2.8 raeburn 1116: if ($balcookie) {
1117: my ($balancer,$cookie) = split(/:/,$balcookie);
1118: if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
1119: my ($udom,$uname,$cookieid) = ($1,$2,$3);
1120: unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
1121: if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
1122: while (my $filename=readdir($dh)) {
1123: if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
1124: my $handle = $1;
1125: my %hash =
1126: &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
1127: ['request.balancercookie',
1128: 'user.linkedenv']);
1129: if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
1130: if (unlink("$lonidsdir/$filename")) {
1131: if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
1132: (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
1133: (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
1134: unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
1135: }
1136: }
1137: }
1138: last;
1139: }
1140: }
1141: closedir($dh);
1142: }
1143: }
1144: }
1145: }
1.133 raeburn 1146: $output = &redirect_page($newhost,$path);
1147: }
1148: }
1149: }
1150: }
1151: return $output;
1152: }
1153:
1.126 raeburn 1154: sub redirect_page {
1.133 raeburn 1155: my ($desthost,$path) = @_;
1.158.2.8 raeburn 1156: my $hostname = &Apache::lonnet::hostname($desthost);
1.126 raeburn 1157: my $protocol = $Apache::lonnet::protocol{$desthost};
1158: $protocol = 'http' if ($protocol ne 'https');
1.133 raeburn 1159: unless ($path =~ m{^/}) {
1160: $path = '/'.$path;
1161: }
1.158.2.8 raeburn 1162: my $url = $protocol.'://'.$hostname.$path;
1.158.2.13.2. (raeburn 1163:): my $args = {};
1164:): if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
1165:): $url = $protocol.'://'.$hostname.$env{'form.firsturl'};
1166:): if (($env{'form.ltoken'}) || ($env{'form.linkprot'} ne '') ||
1167:): ($env{'form.linkkey'} ne '')) {
1168:): my %link_info;
1169:): if ($env{'form.ltoken'}) {
1170:): %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
1171:): &Apache::lonnet::tmpdel($env{'form.ltoken'});
1172:): $args->{'only_body'} = 1;
1173:): } elsif ($env{'form.linkprot'}) {
1174:): $link_info{'linkprot'} = $env{'form.linkprot'};
1175:): foreach my $item ('linkprotuser','linkprotexit') {
1176:): if ($env{'form.'.$item}) {
1177:): $link_info{$item} = $env{'form.'.$item};
1178:): }
1179:): }
1180:): $args->{'only_body'} = 1;
1181:): } elsif ($env{'form.linkkey'} ne '') {
1182:): $link_info{'linkkey'} = $env{'form.linkkey'};
1183:): }
1184:): my $token = &Apache::lonnet::tmpput(\%link_info,$desthost,'link');
1185:): unless (($token eq 'con_lost') || ($token eq 'refused') ||
1186:): ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
1187:): $url .= '?ltoken='.$token;
1188:): }
1189:): }
1190:): } else {
1.158.2.13 raeburn 1191: my $querystring;
1.158.2.13.2. (raeburn 1192:): if ($env{'form.firsturl'} ne '') {
1193:): if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
1194:): $querystring = &uri_escape_utf8($env{'form.firsturl'});
1195:): } else {
1196:): $querystring = &uri_escape($env{'form.firsturl'});
1197:): }
1198:): $querystring = &HTML::Entities::encode($querystring,"'");
1199:): $querystring = '?firsturl='.$querystring;
1.158.2.13 raeburn 1200: }
1.158.2.13.2. (raeburn 1201:): if ($env{'form.ltoken'}) {
1202:): my %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
1203:): &Apache::lonnet::tmpdel($env{'form.ltoken'});
1204:): my $token = &Apache::lonnet::tmpput(\%link_info,$desthost,'link');
1205:): unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
1206:): ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
1207:): unless (($path eq '/adm/roles') || ($path eq '/adm/login')) {
1208:): $url = $protocol.'://'.$hostname.'/adm/roles';
1209:): }
1210:): $querystring .= (($querystring =~/^\?/)?'&':'?') . 'ttoken='.$token;
1211:): }
1212:): }
1213:): $url .= $querystring;
1214:): }
1215:): $args->{'redirect'} = [0,$url];
1216:): my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,$args);
1.126 raeburn 1217: my $end_page = &Apache::loncommon::end_page();
1218: return $start_page.$end_page;
1219: }
1220:
1.60 raeburn 1221: sub contactdisplay {
1.153 raeburn 1222: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
1223: $possdoms) = @_;
1.60 raeburn 1224: my $contactblock;
1.153 raeburn 1225: my $origmail;
1226: if (ref($possdoms) eq 'ARRAY') {
1227: if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
1228: $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
1229: }
1230: }
1231: my $requestmail =
1232: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
1233: $authdomain,$origmail);
1.154 raeburn 1234: unless ($showhelpdesk eq '0') {
1235: if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
1236: $showhelpdesk = 1;
1237: } else {
1.153 raeburn 1238: $showhelpdesk = 0;
1239: }
1.62 raeburn 1240: }
1.90 raeburn 1241: if ($servadm && $showadminmail) {
1.130 bisitz 1242: $contactblock .= $$lt{'servadm'}.':<br />'.
1243: '<tt>'.$servadm.'</tt><br />';
1.90 raeburn 1244: }
1.60 raeburn 1245: if ($showhelpdesk) {
1.114 tempelho 1246: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
1.75 www 1247: my $thisurl = &escape('/adm/login');
1.62 raeburn 1248: $$helpdeskscript = <<"ENDSCRIPT";
1249: <script type="text/javascript">
1.122 bisitz 1250: // <![CDATA[
1.62 raeburn 1251: function helpdesk() {
1.155 raeburn 1252: var possdom = document.client.udom.value;
1253: var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
1.62 raeburn 1254: if (codedom == '') {
1255: codedom = "$authdomain";
1256: }
1257: var querystr = "origurl=$thisurl&codedom="+codedom;
1258: document.location.href = "/adm/helpdesk?"+querystr;
1259: return;
1260: }
1.122 bisitz 1261: // ]]>
1.62 raeburn 1262: </script>
1263: ENDSCRIPT
1.60 raeburn 1264: }
1265: return $contactblock;
1266: }
1.83 raeburn 1267:
1268: sub forgotpwdisplay {
1.84 raeburn 1269: my (%lt) = @_;
1.83 raeburn 1270: my $prompt_for_resetpw = 1;
1271: if ($prompt_for_resetpw) {
1.107 tempelho 1272: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
1.84 raeburn 1273: }
1274: return;
1275: }
1276:
1.90 raeburn 1277: sub coursecatalog_link {
1278: my ($linkname) = @_;
1279: return <<"END";
1.137 bisitz 1280: <a href="/adm/coursecatalog">$linkname</a>
1.90 raeburn 1281: END
1282: }
1283:
1.101 raeburn 1284: sub newuser_link {
1285: my ($linkname) = @_;
1.130 bisitz 1286: return '<a href="/adm/createaccount">'.$linkname.'</a>';
1.101 raeburn 1287: }
1288:
1.158.2.13 raeburn 1289: sub decode_token {
1290: my ($info) = @_;
1291: my ($firsturl,@rest)=split(/\&/,$info);
1292: my %form;
1293: if ($firsturl ne '') {
1294: $form{'firsturl'} = &unescape($firsturl);
1295: }
1296: foreach my $item (@rest) {
1297: my ($key,$value) = split(/=/,$item);
1298: $form{$key} = &unescape($value);
1299: }
1300: return %form;
1301: }
1302:
1.1 albertel 1303: 1;
1304: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>