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