Annotation of loncom/auth/lonlogin.pm, revision 1.158.2.13.2.12
1.1 albertel 1: # The LearningOnline Network
2: # Login Screen
1.11 www 3: #
1.158.2.13.2. 2(raebur 4:4): # $Id: lonlogin.pm,v 1.158.2.13.2.11 2023/12/29 23:49:12 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.158.2.13.2. 2(raebur 855:4): my $target = '_top';
856:4): if ($sessiondata{'linkprot'}) {
857:4): my ($linkprotector,$deeplink) = split(/:/,$sessiondata{'linkprot'},2);
858:4): if (($deeplink eq $sessiondata{'origurl'}) &&
859:4): (($sessiondata{'linkprotuser'} eq $sessiondata{'username'}.':'.$sessiondata{'domain'}) ||
860:4): ($sessiondata{'linkprotuser'} eq $sessiondata{'username'}))) {
861:4): $target = '_self';
862:4): }
863:4): }
1.151 raeburn 864: $r->print(<<ENDSERVERFORM);
1.158.2.13.2. 2(raebur 865:4): <form name="server" action="/adm/authenticate" method="post" target="$target">
1.33 www 866: <input type="hidden" name="logtoken" value="$logtoken" />
867: <input type="hidden" name="serverid" value="$lonhost" />
868: <input type="hidden" name="uname" value="" />
1.65 www 869: <input type="hidden" name="upass0" value="" />
1.33 www 870: <input type="hidden" name="udom" value="" />
1.63 albertel 871: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
872: <input type="hidden" name="localres" value="$env{'form.localres'}" />
1.14 albertel 873: </form>
1.16 www 874: ENDSERVERFORM
1.151 raeburn 875: my $coursecatalog;
876: if (($showcoursecat eq '') || ($showcoursecat)) {
877: $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
878: }
879: my $newuserlink;
880: if ($shownewuserlink) {
881: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
882: }
883: my $logintitle =
884: '<h2 class="LC_hcell"'
885: .' style="background:'.$loginbox_header_bgcol.';'
886: .' color:'.$loginbox_header_textcol.'">'
887: .$lt{'log'}
888: .'</h2>';
889:
890: my $noscript_warning='<noscript><span class="LC_warning"><b>'
891: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
892: .'</b></span></noscript>';
893: my $helpdeskscript;
894: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
1.153 raeburn 895: $authdomain,\$helpdeskscript,
896: $showhelpdesk,\@possdoms);
1.107 tempelho 897:
1.156 raeburn 898: my $mobileargs;
899: if ($clientmobile) {
900: $mobileargs = 'autocapitalize="off" autocorrect="off"';
901: }
1.151 raeburn 902: my $loginform=(<<LFORM);
1.158.2.13 raeburn 903: <form name="client" action="" onsubmit="return(send())" id="lclogin">
1.115 bisitz 904: <input type="hidden" name="lextkey" value="$lextkey" />
905: <input type="hidden" name="uextkey" value="$uextkey" />
1.108 tempelho 906: <b><label for="uname">$lt{'un'}</label>:</b><br />
1.156 raeburn 907: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
1.108 tempelho 908: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
1.139 raeburn 909: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
1.108 tempelho 910: <b><label for="udom">$lt{'dom'}</label>:</b><br />
1.156 raeburn 911: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
1.108 tempelho 912: <input type="submit" value="$lt{'log'}" />
913: </form>
914: LFORM
915:
1.109 raeburn 916: if ($showbanner) {
1.158.2.13.2. (raeburn 917:): my $alttext = &Apache::loncommon::designparm('login.alttext_img',$domain);
918:): if ($alttext eq '') {
919:): $alttext = 'The Learning Online Network with CAPA';
920:): }
1.109 raeburn 921: $r->print(<<HEADER);
922: <!-- The LON-CAPA Header -->
1.132 bisitz 923: <div style="background:$pgbg;margin:0;width:100%;">
1.158.2.13.2. (raeburn 924:): <img src="$img" border="0" alt="$alttext" class="LC_maxwidth" id="lcloginbanner" />
1.132 bisitz 925: </div>
1.109 raeburn 926: HEADER
927: }
1.158.2.13 raeburn 928:
929: my $stdauthformstyle = 'inline-block';
930: my $ssoauthstyle = 'none';
1.158.2.13.2. (raeburn 931:): my $sso_onclick;
1.158.2.13 raeburn 932: my $logintype;
933: $r->print('<div style="float:left;margin-top:0;">');
934: if ($saml_landing) {
935: $ssoauthstyle = 'inline-block';
936: $stdauthformstyle = 'none';
937: $logintype = $samlssotext;
938: my $ssologin = '/adm/sso';
939: if ($samlssourl ne '') {
940: $ssologin = $samlssourl;
941: }
1.158.2.13.2. (raeburn 942:): my $ssologin_for_js = &js_escape($ssologin);
943:): my $querystr_for_js;
1.158.2.13 raeburn 944: if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
945: my $querystring;
946: if ($env{'form.firsturl'} ne '') {
947: $querystring = 'origurl=';
948: if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
949: $querystring .= &uri_escape_utf8($env{'form.firsturl'});
950: } else {
951: $querystring .= &uri_escape($env{'form.firsturl'});
952: }
953: $querystring = &HTML::Entities::encode($querystring,"'");
954: }
1.158.2.13.2. (raeburn 955:): if ($env{'form.ltoken'} ne '') {
956:): $querystring .= (($querystring eq '')?'':'&') . 'ltoken='.
957:): &HTML::Entities::encode(&uri_escape($env{'form.ltoken'}));
958:): } elsif ($env{'form.linkkey'}) {
959:): $querystring .= (($querystring eq '')?'':'&') . 'linkkey='.
960:): &HTML::Entities::encode(&uri_escape($env{'form.linkkey'}));
961:): }
1.158.2.13 raeburn 962: if ($querystring ne '') {
963: $ssologin .= (($ssologin=~/\?/)?'&':'?') . $querystring;
1.158.2.13.2. (raeburn 964:): $querystr_for_js = &js_escape($querystring);
1.158.2.13 raeburn 965: }
966: } elsif ($logtoken ne '') {
967: $ssologin .= (($ssologin=~/\?/)?'&':'?') . 'logtoken='.$logtoken;
1.158.2.13.2. (raeburn 968:): $querystr_for_js = &js_escape('logtoken='.$logtoken);
1.158.2.13 raeburn 969: }
970: my $ssohref;
1.158.2.13.2. (raeburn 971:): if ($samlwindow) {
972:): $sso_onclick = <<"ENDJS";
973:): if (document.getElementById('LC_sso_login_link')) {
974:): var ssoelem = document.getElementById('LC_sso_login_link')
975:): ssoelem.addEventListener('click',samlWinFunction,false);
976:): var windows = {};
977:): function samlWinFunction(evt) {
978:): evt.preventDefault();
979:): var url = '$ssologin_for_js';
980:): var name = 'lcssowin';
981:): var querystr = '$querystr_for_js';
982:): if (querystr) {
983:): url += '?'+querystr+'&lcssowin=1';
984:): } else {
985:): url += '?lcssowin=1';
986:): }
987:): if ((typeof windows[name] !== 'undefined') && (!windows[name].closed)) {
988:): windows[name].close();
989:): }
990:): windows[name]=window.open(url,name,'width=350,height=600');
991:): windows[name].focus();
992:): return false;
993:): }
994:): }
995:): ENDJS
996:): }
1.158.2.13 raeburn 997: if ($samlssoimg ne '') {
1.158.2.13.2. (raeburn 998:): $ssohref = '<a href="'.$ssologin.'" title="'.$samltooltip.'" id="LC_sso_login_link">'.
999:): '<img src="'.$samlssoimg.'" alt="'.$samlssoalt.'" id="lcssobutton" /></a>';
1.158.2.13 raeburn 1000: } else {
1.158.2.13.2. (raeburn 1001:): $ssohref = '<a href="'.$ssologin.'" id="LC_sso_login_link">'.$samlssotext.'</a>';
1.158.2.13 raeburn 1002: }
1003: if (($env{'form.saml'} eq 'no') ||
1004: (($env{'form.username'} ne '') && ($env{'form.domain'} ne ''))) {
1005: $ssoauthstyle = 'none';
1006: $stdauthformstyle = 'inline-block';
1007: $logintype = $samlnonsso;
1008: }
1009: $r->print(<<ENDSAML);
1010: <p>
1011: Log-in type:
1012: <span style="font-weight:bold" id="LC_login_text">$logintype</span><br />
1013: <span><a href="javascript:toggleLClogin();" style="color:#000000">$lt{'change'}</a></span>
1014: </p>
1015: <div style="display:$ssoauthstyle" id="LC_SSO_login">
1016: <div class="LC_Box" style="padding-top: 10px;">
1017: $ssohref
1018: $noscript_warning
1019: </div>
1020: <div class="LC_Box" style="padding-top: 10px;">
1021: $loginhelp
1022: $contactblock
1023: $coursecatalog
1024: </div>
1025: </div>
1026: ENDSAML
1.158.2.13.2. (raeburn 1027:): } else {
1028:): if ($env{'form.ltoken'}) {
1029:): &Apache::lonnet::tmpdel($env{'form.ltoken'});
1030:): delete($env{'form.ltoken'});
1031:): }
1.158.2.13 raeburn 1032: }
1.158.2.13.2. (raeburn 1033:): my $in_frame_js;
1034:): if ($linkprot_for_login) {
1035:): my ($linkprotector,$linkproturi) = split(/:/,$linkprot_for_login,2);
1036:): if (($linkprotector =~ /^\d+(c|d)$/) && ($linkproturi =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$})) {
1037:): my $set_target;
1038:): if (($env{'form.retry'}) || ($env{'form.sso'})) {
1039:): if ($linkproturi eq $env{'form.firsturl'}) {
1040:): $set_target = " document.server.target = '_self';";
1041:): }
1042:): } else {
1043:): $set_target = <<ENDTARG;
1044:): var linkproturi = '$linkproturi';
1045:): var path = document.location.pathname.replace( new RegExp('^/adm/launch'),'');
1046:): if (linkproturi == path) {
1047:): document.server.target = '_self';
1048:): }
1049:): ENDTARG
1050:): }
1051:): $in_frame_js = <<ENDJS;
1052:): <script type="text/javascript">
1053:): // <![CDATA[
1054:): if ((window.self !== window.top) && (document.server.target != '_self')) {
1055:): $set_target
1056:): $sso_onclick
1057:): }
1058:): // ]]>
1059:): </script>
1060:): ENDJS
1061:): }
1062:): } elsif ($samlwindow) {
1063:): $in_frame_js = <<ENDJS;
1064:): <script type="text/javascript">
1065:): // <![CDATA[
1066:): if ((window.self !== window.top) && (document.server.target != '_self')) {
1067:): $sso_onclick
1068:): }
1069:): // ]]>
1070:): </script>
1071:): ENDJS
1072:): }
1.158.2.13 raeburn 1073:
1074: $r->print(<<ENDLOGIN);
1075: <div style="display:$stdauthformstyle;" id="LC_standard_login">
1.137 bisitz 1076: <div class="LC_Box" style="background:$loginbox_bg;">
1.112 muellerd 1077: $logintitle
1.137 bisitz 1078: $loginform
1079: $noscript_warning
1.108 tempelho 1080: </div>
1.107 tempelho 1081:
1.137 bisitz 1082: <div class="LC_Box" style="padding-top: 10px;">
1.132 bisitz 1083: $loginhelp
1084: $forgotpw
1085: $contactblock
1086: $newuserlink
1.130 bisitz 1087: $coursecatalog
1.107 tempelho 1088: </div>
1.118 tempelho 1089: </div>
1.137 bisitz 1090:
1.158.2.13 raeburn 1091: ENDLOGIN
1092: $r->print('</div><div>'."\n");
1.118 tempelho 1093: if ($showmainlogo) {
1.158.2.13.2. (raeburn 1094:): my $alttext = &Apache::loncommon::designparm('login.alttext_logo',$domain);
1095:): $r->print(' <img src="'.$logo.'" alt="'.$alttext.'" class="LC_maxwidth" id="lcloginmainlogo" />'."\n");
1.118 tempelho 1096: }
1097: $r->print(<<ENDTOP);
1098: $announcements
1.137 bisitz 1099: </div>
1100: <hr style="clear:both;" />
1.108 tempelho 1101: ENDTOP
1.147 raeburn 1102: my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
1103: $domainrow = <<"END";
1.14 albertel 1104: <tr>
1.110 muellerd 1105: <td align="left" valign="top">
1.132 bisitz 1106: <small><b>$lt{'dom'}: </b></small>
1.14 albertel 1107: </td>
1.110 muellerd 1108: <td align="left" valign="top">
1.14 albertel 1109: <small><tt> $domain</tt></small>
1110: </td>
1111: </tr>
1.147 raeburn 1112: END
1113: $serverrow = <<"END";
1.14 albertel 1114: <tr>
1.110 muellerd 1115: <td align="left" valign="top">
1.132 bisitz 1116: <small><b>$lt{'serv'}: </b></small>
1.14 albertel 1117: </td>
1.110 muellerd 1118: <td align="left" valign="top">
1.14 albertel 1119: <small><tt> $lonhost ($role)</tt></small>
1120: </td>
1121: </tr>
1.147 raeburn 1122: END
1123: if ($loadlim) {
1124: $loadrow = <<"END";
1.14 albertel 1125: <tr>
1.110 muellerd 1126: <td align="left" valign="top">
1.132 bisitz 1127: <small><b>$lt{'load'}: </b></small>
1.14 albertel 1128: </td>
1.110 muellerd 1129: <td align="left" valign="top">
1.51 www 1130: <small><tt> $loadpercent $lt{'perc'}</tt></small>
1.42 albertel 1131: </td>
1132: </tr>
1.147 raeburn 1133: END
1134: }
1135: if ($uloadlim) {
1136: $userloadrow = <<"END";
1.42 albertel 1137: <tr>
1.110 muellerd 1138: <td align="left" valign="top">
1.132 bisitz 1139: <small><b>$lt{'userload'}: </b></small>
1.42 albertel 1140: </td>
1.110 muellerd 1141: <td align="left" valign="top">
1.51 www 1142: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
1.14 albertel 1143: </td>
1144: </tr>
1.147 raeburn 1145: END
1146: }
1147: if (($version ne '') && ($version ne '<!-- VERSION -->')) {
1148: $versionrow = <<"END";
1.132 bisitz 1149: <tr>
1150: <td colspan="2" align="left">
1151: <small>$version</small>
1152: </td>
1153: </tr>
1.147 raeburn 1154: END
1155: }
1156:
1.151 raeburn 1157: $r->print(<<ENDDOCUMENT);
1.147 raeburn 1158: <div style="float: left;">
1159: <table border="0" cellspacing="0" cellpadding="0">
1160: $domainrow
1161: $serverrow
1162: $loadrow
1163: $userloadrow
1164: $versionrow
1.14 albertel 1165: </table>
1.141 raeburn 1166: </div>
1167: <div style="float: right;">
1168: $domainlogo
1169: </div>
1170: <br style="clear:both;" />
1.107 tempelho 1171: </div>
1.25 bowersj2 1172:
1.158.2.13.2. (raeburn 1173:): $in_frame_js
1.59 albertel 1174: <script type="text/javascript">
1.122 bisitz 1175: // <![CDATA[
1.59 albertel 1176: // the if prevents the script error if the browser can not handle this
1.25 bowersj2 1177: if ( document.client.uname ) { document.client.uname.focus(); }
1.122 bisitz 1178: // ]]>
1.25 bowersj2 1179: </script>
1.62 raeburn 1180: $helpdeskscript
1.14 albertel 1181:
1.1 albertel 1182: ENDDOCUMENT
1.98 raeburn 1183: my %endargs = ( 'noredirectlink' => 1, );
1184: $r->print(&Apache::loncommon::end_page(\%endargs));
1.1 albertel 1185: return OK;
1.60 raeburn 1186: }
1187:
1.133 raeburn 1188: sub check_loginvia {
1.158.2.8 raeburn 1189: my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
1190: if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
1.133 raeburn 1191: return;
1192: }
1193: my %domconfhash = &Apache::loncommon::get_domainconf($domain);
1194: my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
1195: my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
1196: my $output;
1197: if ($loginvia ne '') {
1198: my $noredirect;
1.158.2.12 raeburn 1199: my $ip = &Apache::lonnet::get_requestor_ip();
1.133 raeburn 1200: if ($ip eq '127.0.0.1') {
1201: $noredirect = 1;
1202: } else {
1203: if ($loginvia_exempt ne '') {
1204: my @exempt = split(',',$loginvia_exempt);
1205: if (grep(/^\Q$ip\E$/,@exempt)) {
1206: $noredirect = 1;
1207: }
1208: }
1209: }
1210: unless ($noredirect) {
1211: my ($newhost,$path);
1212: if ($loginvia =~ /:/) {
1213: ($newhost,$path) = split(':',$loginvia);
1214: } else {
1215: $newhost = $loginvia;
1216: }
1217: if ($newhost ne $lonhost) {
1218: if (&Apache::lonnet::hostname($newhost) ne '') {
1.158.2.8 raeburn 1219: if ($balcookie) {
1220: my ($balancer,$cookie) = split(/:/,$balcookie);
1221: if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
1222: my ($udom,$uname,$cookieid) = ($1,$2,$3);
1223: unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
1224: if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
1225: while (my $filename=readdir($dh)) {
1226: if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
1227: my $handle = $1;
1228: my %hash =
1229: &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
1230: ['request.balancercookie',
1231: 'user.linkedenv']);
1232: if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
1233: if (unlink("$lonidsdir/$filename")) {
1234: if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
1235: (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
1236: (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
1237: unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
1238: }
1239: }
1240: }
1241: last;
1242: }
1243: }
1244: closedir($dh);
1245: }
1246: }
1247: }
1248: }
1.133 raeburn 1249: $output = &redirect_page($newhost,$path);
1250: }
1251: }
1252: }
1253: }
1254: return $output;
1255: }
1256:
1.126 raeburn 1257: sub redirect_page {
1.133 raeburn 1258: my ($desthost,$path) = @_;
1.158.2.8 raeburn 1259: my $hostname = &Apache::lonnet::hostname($desthost);
1.126 raeburn 1260: my $protocol = $Apache::lonnet::protocol{$desthost};
1261: $protocol = 'http' if ($protocol ne 'https');
1.133 raeburn 1262: unless ($path =~ m{^/}) {
1263: $path = '/'.$path;
1264: }
1.158.2.8 raeburn 1265: my $url = $protocol.'://'.$hostname.$path;
1.158.2.13.2. (raeburn 1266:): my $args = {};
1267:): if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
1268:): $url = $protocol.'://'.$hostname.$env{'form.firsturl'};
1269:): if (($env{'form.ltoken'}) || ($env{'form.linkprot'} ne '') ||
1270:): ($env{'form.linkkey'} ne '')) {
1271:): my %link_info;
1272:): if ($env{'form.ltoken'}) {
1273:): %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
1274:): &Apache::lonnet::tmpdel($env{'form.ltoken'});
1275:): $args->{'only_body'} = 1;
1276:): } elsif ($env{'form.linkprot'}) {
1277:): $link_info{'linkprot'} = $env{'form.linkprot'};
0(raebur 1278:3): foreach my $item ('linkprotuser','linkprotexit','linkprotpbid','linkprotpburl') {
(raeburn 1279:): if ($env{'form.'.$item}) {
1280:): $link_info{$item} = $env{'form.'.$item};
1281:): }
1282:): }
1283:): $args->{'only_body'} = 1;
1284:): } elsif ($env{'form.linkkey'} ne '') {
1285:): $link_info{'linkkey'} = $env{'form.linkkey'};
1286:): }
1287:): my $token = &Apache::lonnet::tmpput(\%link_info,$desthost,'link');
1288:): unless (($token eq 'con_lost') || ($token eq 'refused') ||
1289:): ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
1290:): $url .= '?ltoken='.$token;
1291:): }
1292:): }
1293:): } else {
1.158.2.13 raeburn 1294: my $querystring;
1.158.2.13.2. (raeburn 1295:): if ($env{'form.firsturl'} ne '') {
1296:): if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
1297:): $querystring = &uri_escape_utf8($env{'form.firsturl'});
1298:): } else {
1299:): $querystring = &uri_escape($env{'form.firsturl'});
1300:): }
1301:): $querystring = &HTML::Entities::encode($querystring,"'");
1302:): $querystring = '?firsturl='.$querystring;
1.158.2.13 raeburn 1303: }
1.158.2.13.2. (raeburn 1304:): if ($env{'form.ltoken'}) {
1305:): my %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
1306:): &Apache::lonnet::tmpdel($env{'form.ltoken'});
1307:): my $token = &Apache::lonnet::tmpput(\%link_info,$desthost,'link');
1308:): unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
1309:): ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
1310:): unless (($path eq '/adm/roles') || ($path eq '/adm/login')) {
1311:): $url = $protocol.'://'.$hostname.'/adm/roles';
1312:): }
1313:): $querystring .= (($querystring =~/^\?/)?'&':'?') . 'ttoken='.$token;
1314:): }
1315:): }
1316:): $url .= $querystring;
1317:): }
1(raebur 1318:3): $args->{'redirect'} = [0,$url,'','',1];
(raeburn 1319:): my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,$args);
1.126 raeburn 1320: my $end_page = &Apache::loncommon::end_page();
1321: return $start_page.$end_page;
1322: }
1323:
1.60 raeburn 1324: sub contactdisplay {
1.153 raeburn 1325: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
1326: $possdoms) = @_;
1.60 raeburn 1327: my $contactblock;
1.153 raeburn 1328: my $origmail;
1329: if (ref($possdoms) eq 'ARRAY') {
1330: if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
1331: $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
1332: }
1333: }
1334: my $requestmail =
1335: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
1336: $authdomain,$origmail);
1.154 raeburn 1337: unless ($showhelpdesk eq '0') {
1338: if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
1339: $showhelpdesk = 1;
1340: } else {
1.153 raeburn 1341: $showhelpdesk = 0;
1342: }
1.62 raeburn 1343: }
1.90 raeburn 1344: if ($servadm && $showadminmail) {
1.130 bisitz 1345: $contactblock .= $$lt{'servadm'}.':<br />'.
1346: '<tt>'.$servadm.'</tt><br />';
1.90 raeburn 1347: }
1.60 raeburn 1348: if ($showhelpdesk) {
1.114 tempelho 1349: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
1.75 www 1350: my $thisurl = &escape('/adm/login');
1.62 raeburn 1351: $$helpdeskscript = <<"ENDSCRIPT";
1352: <script type="text/javascript">
1.122 bisitz 1353: // <![CDATA[
1.62 raeburn 1354: function helpdesk() {
1.155 raeburn 1355: var possdom = document.client.udom.value;
1356: var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
1.62 raeburn 1357: if (codedom == '') {
1358: codedom = "$authdomain";
1359: }
1360: var querystr = "origurl=$thisurl&codedom="+codedom;
1361: document.location.href = "/adm/helpdesk?"+querystr;
1362: return;
1363: }
1.122 bisitz 1364: // ]]>
1.62 raeburn 1365: </script>
1366: ENDSCRIPT
1.60 raeburn 1367: }
1368: return $contactblock;
1369: }
1.83 raeburn 1370:
1371: sub forgotpwdisplay {
1.84 raeburn 1372: my (%lt) = @_;
1.83 raeburn 1373: my $prompt_for_resetpw = 1;
1374: if ($prompt_for_resetpw) {
1.107 tempelho 1375: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
1.84 raeburn 1376: }
1377: return;
1378: }
1379:
1.90 raeburn 1380: sub coursecatalog_link {
1381: my ($linkname) = @_;
1382: return <<"END";
1.137 bisitz 1383: <a href="/adm/coursecatalog">$linkname</a>
1.90 raeburn 1384: END
1385: }
1386:
1.101 raeburn 1387: sub newuser_link {
1388: my ($linkname) = @_;
1.130 bisitz 1389: return '<a href="/adm/createaccount">'.$linkname.'</a>';
1.101 raeburn 1390: }
1391:
1.158.2.13 raeburn 1392: sub decode_token {
1393: my ($info) = @_;
1394: my ($firsturl,@rest)=split(/\&/,$info);
1395: my %form;
1396: if ($firsturl ne '') {
1397: $form{'firsturl'} = &unescape($firsturl);
1398: }
1399: foreach my $item (@rest) {
1400: my ($key,$value) = split(/=/,$item);
1401: $form{$key} = &unescape($value);
1402: }
1403: return %form;
1404: }
1405:
1.1 albertel 1406: 1;
1407: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>