Annotation of loncom/auth/lonlogin.pm, revision 1.208
1.160 kruse 1: # The LearningOnline Network
2: # Login Screen
3: #
1.208 ! raeburn 4: # $Id: lonlogin.pm,v 1.207 2023/11/21 19:52:18 raeburn Exp $
1.160 kruse 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::lonlogin;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::File ();
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonauth();
37: use Apache::lonlocal;
38: use Apache::migrateuser();
39: use lib '/home/httpd/lib/perl/';
1.176 raeburn 40: use LONCAPA qw(:DEFAULT :match);
1.188 raeburn 41: use URI::Escape;
42: use HTML::Entities();
1.169 raeburn 43: use CGI::Cookie();
1.160 kruse 44:
45: sub handler {
46: my $r = shift;
47:
48: &Apache::loncommon::get_unprocessed_cgi
49: (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
50: $ENV{'REDIRECT_QUERY_STRING'}),
51: ['interface','username','domain','firsturl','localpath','localres',
1.193 raeburn 52: 'token','role','symb','iptoken','btoken','ltoken','ttoken','linkkey',
1.204 raeburn 53: 'saml','sso','retry','display']);
1.193 raeburn 54:
55: # -- check if they are a migrating user
56: if (defined($env{'form.token'})) {
57: return &Apache::migrateuser::handler($r);
58: }
59:
1.192 raeburn 60: my $lonhost = $r->dir_config('lonHostID');
1.193 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'};
1.206 raeburn 71: foreach my $item ('linkprotuser','linkprotexit','linkprotpbid','linkprotpburl') {
1.201 raeburn 72: if ($info{$item} ne '') {
73: $env{'form.'.$item} = $info{$item};
74: }
1.199 raeburn 75: }
1.193 raeburn 76: } elsif ($info{'linkkey'} ne '') {
77: $env{'form.linkkey'} = $info{'linkkey'};
78: }
79: } elsif (($env{'form.sso'}) || ($env{'form.retry'})) {
1.192 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: }
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+$}) &&
1.193 raeburn 105: (!$env{'form.ltoken'}) && (!$env{'form.linkprot'}) && (!$env{'form.linkkey'})) {
1.192 raeburn 106: &Apache::lonacc::get_posted_cgi($r,['linkkey']);
107: }
108: if ($env{'form.firsturl'} eq '/adm/logout') {
109: delete($env{'form.firsturl'});
1.172 raeburn 110: }
111: }
1.160 kruse 112:
1.169 raeburn 113: # For "public user" - remove any exising "public" cookie, as user really wants to log-in
1.171 raeburn 114: my ($handle,$lonidsdir,$expirepub,$userdom);
1.176 raeburn 115: $lonidsdir=$r->dir_config('lonIDsDir');
1.169 raeburn 116: unless ($r->header_only) {
1.171 raeburn 117: $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
1.169 raeburn 118: if ($handle ne '') {
119: if ($handle=~/^publicuser\_/) {
120: unlink($r->dir_config('lonIDsDir')."/$handle.id");
121: undef($handle);
1.171 raeburn 122: undef($userdom);
123: $expirepub = 1;
1.169 raeburn 124: }
125: }
126: }
127:
1.160 kruse 128: &Apache::loncommon::no_cache($r);
129: &Apache::lonlocal::get_language_handle($r);
130: &Apache::loncommon::content_type($r,'text/html');
1.171 raeburn 131: if ($expirepub) {
1.170 raeburn 132: my $c = new CGI::Cookie(-name => 'lonPubID',
1.169 raeburn 133: -value => '',
134: -expires => '-10y',);
135: $r->header_out('Set-cookie' => $c);
1.171 raeburn 136: } elsif (($handle eq '') && ($userdom ne '')) {
1.173 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.169 raeburn 145: }
1.160 kruse 146: $r->send_http_header;
147: return OK if $r->header_only;
148:
149:
150: # Are we re-routing?
151: my $londocroot = $r->dir_config('lonDocRoot');
152: if (-e "$londocroot/lon-status/reroute.txt") {
153: &Apache::lonauth::reroute($r);
154: return OK;
155: }
156:
1.174 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.193 raeburn 167: $dest = &HTML::Entities::encode($env{'form.firsturl'},'\'"<>&');
1.174 raeburn 168: }
1.176 raeburn 169: my %info = (
170: balcookie => $lonhost.':'.$balancer_cookie,
171: );
1.193 raeburn 172: if ($env{'form.role'}) {
173: $info{'role'} = $env{'form.role'};
174: }
175: if ($env{'form.symb'}) {
176: $info{'symb'} = $env{'form.symb'};
1.177 raeburn 177: }
1.204 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'});
1.205 raeburn 187: $info{'mailrecip'} = &escape($env{'form.username'}.':'.$env{'form.domain'});
1.204 raeburn 188: }
189: }
190: }
1.176 raeburn 191: my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
1.193 raeburn 192: unless (($balancer_token eq 'con_lost') || ($balancer_token eq 'refused') ||
193: ($balancer_token eq 'unknown_cmd') || ($balancer_token eq 'no_such_host')) {
1.187 raeburn 194: $dest .= (($dest=~/\?/)?'&':'?') . 'btoken='.$balancer_token;
1.176 raeburn 195: }
1.193 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'};
1.206 raeburn 202: foreach my $item ('linkprotuser','linkprotexit','linkprotpbid','linkprotpburl') {
1.201 raeburn 203: if ($env{'form.'.$item} ne '') {
204: $link_info{$item} = $env{'form.'.$item};
205: }
1.199 raeburn 206: }
1.193 raeburn 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.183 raeburn 219: unless ($found_server eq $lonhost) {
220: my $alias = &Apache::lonnet::use_proxy_alias($r,$found_server);
221: $hostname = $alias if ($alias ne '');
222: }
1.174 raeburn 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:
1.171 raeburn 233: #
1.176 raeburn 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:
1.193 raeburn 238: my $balcookie;
1.176 raeburn 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.204 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.176 raeburn 249: }
250:
251: #
1.171 raeburn 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.160 kruse 268: # -------------------------------- Prevent users from attempting to login twice
269: if ($handle ne '') {
1.169 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.193 raeburn 277: $dest = &HTML::Entities::encode($env{'form.firsturl'},'\'"<>&');
1.169 raeburn 278: }
1.193 raeburn 279: if (($env{'form.ltoken'}) || ($env{'form.linkprot'})) {
1.206 raeburn 280: my ($linkprot,$linkprotuser,$linkprotexit,$linkprotpbid,$linkprotpburl);
1.193 raeburn 281: if ($env{'form.ltoken'}) {
1.177 raeburn 282: my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
283: $linkprot = $info{'linkprot'};
1.199 raeburn 284: if ($info{'linkprotuser'} ne '') {
285: $linkprotuser = $info{'linkprotuser'};
1.201 raeburn 286: }
287: if ($info{'linkprotexit'} ne '') {
288: $linkprotexit = $info{'linkprotexit'};
289: }
1.206 raeburn 290: if ($info{'linkprotpbid'} ne '') {
291: $linkprotpbid = $info{'linkprotpbid'};
292: }
293: if ($info{'linkprotpburl'} ne '') {
294: $linkprotpburl = $info{'linkprotpburl'};
295: }
1.193 raeburn 296: } else {
297: $linkprot = $env{'form.linkprot'};
1.199 raeburn 298: $linkprotuser = $env{'form.linkprotuser'};
1.201 raeburn 299: $linkprotexit = $env{'form.linkprotexit'};
1.206 raeburn 300: $linkprotpbid = $env{'form.linkprotpbid'};
301: $linkprotpburl = $env{'form.linkprotpburl'};
1.177 raeburn 302: }
303: if ($linkprot) {
304: my ($linkprotector,$deeplink) = split(/:/,$linkprot,2);
1.199 raeburn 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,
1.201 raeburn 312: linkprotexit => $linkprotexit,
1.206 raeburn 313: linkprotpbid => $linkprotpbid,
314: linkprotpburl => $linkprotpburl,
315: );
1.200 raeburn 316: if ($env{'form.ltoken'}) {
317: my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'});
318: }
1.199 raeburn 319: &Apache::migrateuser::logout($r,$ip,$handle,undef,undef,\%linkprotinfo);
320: return OK;
321: }
1.177 raeburn 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'});
1.179 raeburn 334: unless (grep(/^\Q$deeplink\E$/,@proturis)) {
1.177 raeburn 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: }
1.193 raeburn 343: } elsif ($env{'form.linkkey'} ne '') {
1.179 raeburn 344: if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
1.193 raeburn 345: my $linkkey = $env{'form.linkkey'};
1.179 raeburn 346: if ($env{'user.deeplinkkey'}) {
347: my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
348: unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
349: push(@linkkeys,$linkkey);
1.193 raeburn 350: &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});
1.179 raeburn 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: }
1.177 raeburn 366: }
1.200 raeburn 367: if ($env{'form.ltoken'}) {
368: my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'});
369: }
1.204 raeburn 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.169 raeburn 381: $r->print(
1.160 kruse 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: );
1.169 raeburn 388: return OK;
1.160 kruse 389: }
390:
391: # ---------------------------------------------------- No valid token, continue
392:
393: # ---------------------------- Not possible to really login to domain "public"
394: if ($env{'form.domain'} eq 'public') {
395: $env{'form.domain'}='';
396: $env{'form.username'}='';
397: }
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.162 raeburn 403: unless ($sessiondata{'sessionserver'}) {
404: my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
405: delete($env{'form.iptoken'});
406: }
1.160 kruse 407: }
408: # ----------------------------------------------------------- Process Interface
409: $env{'form.interface'}=~s/\W//g;
410:
411: (undef,undef,undef,undef,undef,undef,my $clientmobile) =
1.192 raeburn 412: &Apache::loncommon::decode_user_agent($r);
1.160 kruse 413:
414: my $iconpath=
415: &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
416:
417: my $domain = &Apache::lonnet::default_login_domain();
1.161 raeburn 418: my $defdom = $domain;
1.160 kruse 419: if ($lonhost ne '') {
420: unless ($sessiondata{'sessionserver'}) {
1.193 raeburn 421: my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);
1.160 kruse 422: if ($redirect) {
423: $r->print($redirect);
424: return OK;
425: }
426: }
427: }
428:
429: if (($sessiondata{'domain'}) &&
1.175 raeburn 430: (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
1.160 kruse 431: $domain=$sessiondata{'domain'};
432: } elsif (($env{'form.domain'}) &&
433: (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
434: $domain=$env{'form.domain'};
435: }
436:
437: my $role = $r->dir_config('lonRole');
438: my $loadlim = $r->dir_config('lonLoadLim');
439: my $uloadlim= $r->dir_config('lonUserLoadLim');
440: my $servadm = $r->dir_config('lonAdmEMail');
441: my $tabdir = $r->dir_config('lonTabDir');
442: my $include = $r->dir_config('lonIncludes');
443: my $expire = $r->dir_config('lonExpire');
444: my $version = $r->dir_config('lonVersion');
445: my $host_name = &Apache::lonnet::hostname($lonhost);
446:
447: # --------------------------------------------- Default values for login fields
448:
449: my ($authusername,$authdomain);
450: if ($sessiondata{'username'}) {
451: $authusername=$sessiondata{'username'};
452: } else {
453: $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
454: $authusername=($env{'form.username'}?$env{'form.username'}:'');
455: }
456: if ($sessiondata{'domain'}) {
457: $authdomain=$sessiondata{'domain'};
458: } else {
459: $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
460: $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
461: }
462:
463: # ---------------------------------------------------------- Determine own load
464: my $loadavg;
465: {
466: my $loadfile=Apache::File->new('/proc/loadavg');
467: $loadavg=<$loadfile>;
468: }
469: $loadavg =~ s/\s.*//g;
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: }
478:
479: my $firsturl=
480: ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
481:
482: # ----------------------------------------------------------- Get announcements
483: my $announcements=&Apache::lonnet::getannounce();
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);
499: if ($lextkey>2147483647) { $lextkey-=4294967296; }
500:
501: my $uextkey=hex($ukey);
502: if ($uextkey>2147483647) { $uextkey-=4294967296; }
503:
504: # -------------------------------------------------------- Store away log token
1.196 raeburn 505: my ($tokenextras,$tokentype,$linkprot_for_login);
1.206 raeburn 506: my @names = ('role','symb','iptoken','ltoken','linkprotuser','linkprotexit',
507: 'linkprot','linkkey','display','linkprotpbid','linkprotpburl');
1.192 raeburn 508: foreach my $name (@names) {
509: if ($env{'form.'.$name} ne '') {
510: if ($name eq 'ltoken') {
1.193 raeburn 511: my %info = &Apache::lonnet::tmpget($env{'form.'.$name});
1.192 raeburn 512: if ($info{'linkprot'}) {
1.196 raeburn 513: $linkprot_for_login = $info{'linkprot'};
1.192 raeburn 514: $tokenextras .= '&linkprot='.&escape($info{'linkprot'});
1.206 raeburn 515: foreach my $item ('linkprotuser','linkprotexit','linkprotpbid','linkprotpburl') {
1.201 raeburn 516: if ($info{$item}) {
517: $tokenextras .= '&'.$item.'='.&escape($info{$item});
518: }
1.199 raeburn 519: }
1.192 raeburn 520: $tokentype = 'link';
521: last;
522: }
1.204 raeburn 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: }
1.192 raeburn 533: } else {
534: $tokenextras .= '&'.$name.'='.&escape($env{'form.'.$name});
1.193 raeburn 535: if (($name eq 'linkkey') || ($name eq 'linkprot')) {
1.198 raeburn 536: if ((($env{'form.retry'}) || ($env{'form.sso'})) &&
537: (!$env{'form.ltoken'}) && ($name eq 'linkprot')) {
1.196 raeburn 538: $linkprot_for_login = $env{'form.linkprot'};
539: }
1.192 raeburn 540: $tokentype = 'link';
541: }
542: }
1.160 kruse 543: }
544: }
1.192 raeburn 545: if ($tokentype) {
546: $tokenextras .= ":$tokentype";
1.177 raeburn 547: }
1.160 kruse 548: my $logtoken=Apache::lonnet::reply(
1.193 raeburn 549: 'tmpput:'.$ukey.$lkey.'&'.&escape($firsturl).$tokenextras,
1.160 kruse 550: $lonhost);
551:
552: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
553: # we are in serious trouble
554:
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.191 raeburn 559: if ($env{'form.ltoken'}) {
560: &Apache::lonnet::tmpdel($env{'form.ltoken'});
561: delete($env{'form.ltoken'});
562: }
1.160 kruse 563: my $spares='';
1.180 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.160 kruse 583: next if ($hostid eq $lonhost);
584: my $hostname = &Apache::lonnet::hostname($hostid);
1.180 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.160 kruse 590: $hostname.
591: '/adm/login?domain='.$authdomain.'">'.
592: $hostname.'</a>'.
1.180 raeburn 593: ' '.&mt('(preferred)').'</span>'.$/;
1.160 kruse 594: }
595: if ($spares) {
596: $spares.= '<br />';
597: }
598: my %all_hostnames = &Apache::lonnet::all_hostnames();
599: foreach my $hostid (sort
600: {
601: &Apache::lonnet::hostname($a) cmp
602: &Apache::lonnet::hostname($b);
603: }
604: keys(%all_hostnames)) {
1.180 raeburn 605: next if ($hostid eq $lonhost);
1.160 kruse 606: my $hostname = &Apache::lonnet::hostname($hostid);
1.180 raeburn 607: next if (($hostname eq '') || ($spareservers{$hostname}));
1.181 raeburn 608: $spareservers{$hostname} = 1;
1.180 raeburn 609: my $protocol = $Apache::lonnet::protocol{$hostid};
610: $protocol = 'http' if ($protocol ne 'https');
611: $spares.='<br /><a href="'.$protocol.'://'.
1.160 kruse 612: $hostname.
613: '/adm/login?domain='.$authdomain.'">'.
614: $hostname.'</a>';
615: }
616: $r->print(
1.180 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.160 kruse 620: .&mt('The LearningOnline Network with CAPA')
621: .'</title></head>'
622: .'<body bgcolor="#FFFFFF">'
623: .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
1.180 raeburn 624: .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
1.160 kruse 625: .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
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: }
636:
637: # ----------------------------------------------- Apparently we are in business
638: $servadm=~s/\,/\<br \/\>/g;
639:
640: # ----------------------------------------------------------- Front page design
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: }
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: }
666: my $showcoursecat =
667: &Apache::loncommon::designparm('login.coursecatalog',$domain);
668: my $shownewuserlink =
669: &Apache::loncommon::designparm('login.newuser',$domain);
670: my $showhelpdesk =
671: &Apache::loncommon::designparm('login.helpdesk',$domain);
672: my $now=time;
673: my $js = (<<ENDSCRIPT);
674:
675: <script type="text/javascript" language="JavaScript">
676: // <![CDATA[
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: if(this.document.server.action.substr(0,5) === 'http:'){
1.165 raeburn 690: this.document.server.elements.upass0.value
691: =getCrypted(this.document.client.elements.upass$now.value);
1.166 raeburn 692: } else {
693: this.document.server.elements.upass0.value
694: =this.document.client.elements.upass$now.value;
1.167 raeburn 695: }
1.160 kruse 696:
697: this.document.client.elements.uname.value='';
698: this.document.client.elements.upass$now.value='';
699:
700: this.document.server.submit();
701: return false;
702: }
703:
704: function enableInput() {
705: this.document.client.elements.upass$now.removeAttribute("readOnly");
706: this.document.client.elements.uname.removeAttribute("readOnly");
707: this.document.client.elements.udom.removeAttribute("readOnly");
708: return;
709: }
710:
711: // ]]>
712: </script>
713:
714: ENDSCRIPT
715:
1.184 raeburn 716: my ($lonhost_in_use,@hosts,%defaultdomconf,$saml_prefix,$saml_landing,
1.202 raeburn 717: $samlssotext,$samlnonsso,$samlssoimg,$samlssoalt,$samlssourl,$samltooltip,
1.203 raeburn 718: $samlwindow);
1.184 raeburn 719: %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
720: @hosts = &Apache::lonnet::current_machine_ids();
721: $lonhost_in_use = $lonhost;
722: if (@hosts > 1) {
723: foreach my $hostid (@hosts) {
724: if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
725: $lonhost_in_use = $hostid;
726: last;
727: }
728: }
729: }
730: $saml_prefix = $defdom.'.login.saml_';
731: if ($defaultdomconf{$saml_prefix.$lonhost_in_use}) {
732: $saml_landing = 1;
733: $samlssotext = $defaultdomconf{$saml_prefix.'text_'.$lonhost_in_use};
734: $samlnonsso = $defaultdomconf{$saml_prefix.'notsso_'.$lonhost_in_use};
735: $samlssoimg = $defaultdomconf{$saml_prefix.'img_'.$lonhost_in_use};
736: $samlssoalt = $defaultdomconf{$saml_prefix.'alt_'.$lonhost_in_use};
737: $samlssourl = $defaultdomconf{$saml_prefix.'url_'.$lonhost_in_use};
738: $samltooltip = $defaultdomconf{$saml_prefix.'title_'.$lonhost_in_use};
1.202 raeburn 739: $samlwindow = $defaultdomconf{$saml_prefix.'window_'.$lonhost_in_use};
1.184 raeburn 740: }
741: if ($saml_landing) {
742: if ($samlssotext eq '') {
743: $samlssotext = 'SSO Login';
744: }
745: if ($samlnonsso eq '') {
746: $samlnonsso = 'Non-SSO Login';
747: }
748: $js .= <<"ENDSAMLJS";
749:
750: <script type="text/javascript">
751: // <![CDATA[
752: function toggleLClogin() {
753: if (document.getElementById('LC_standard_login')) {
754: if (document.getElementById('LC_standard_login').style.display == 'none') {
755: document.getElementById('LC_standard_login').style.display = 'inline-block';
756: if (document.getElementById('LC_login_text')) {
757: document.getElementById('LC_login_text').innerHTML = '$samlnonsso';
758: }
1.195 raeburn 759: if ( document.client.uname ) { document.client.uname.focus(); }
1.184 raeburn 760: if (document.getElementById('LC_SSO_login')) {
761: document.getElementById('LC_SSO_login').style.display = 'none';
762: }
763: } else {
764: document.getElementById('LC_standard_login').style.display = 'none';
765: if (document.getElementById('LC_login_text')) {
766: document.getElementById('LC_login_text').innerHTML = '$samlssotext';
767: }
768: if (document.getElementById('LC_SSO_login')) {
769: document.getElementById('LC_SSO_login').style.display = 'inline-block';
770: }
771: }
772: }
773: return;
774: }
775:
776: // ]]>
777: </script>
778:
779: ENDSAMLJS
780: }
781:
1.160 kruse 782: # --------------------------------------------------- Print login screen header
783:
784: my %add_entries = (
785: bgcolor => "$mainbg",
786: text => "$font",
787: link => "$link",
788: vlink => "$vlink",
789: alink => "$alink",
790: onload => 'javascript:enableInput();',);
791:
1.186 raeburn 792: my ($headextra,$headextra_exempt);
1.164 raeburn 793: $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
794: $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
1.161 raeburn 795: if ($headextra) {
796: my $omitextra;
797: if ($headextra_exempt ne '') {
798: my @exempt = split(',',$headextra_exempt);
1.182 raeburn 799: my $ip = &Apache::lonnet::get_requestor_ip();
1.161 raeburn 800: if (grep(/^\Q$ip\E$/,@exempt)) {
801: $omitextra = 1;
802: }
803: }
804: unless ($omitextra) {
805: my $confname = $defdom.'-domainconfig';
1.163 raeburn 806: if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
1.161 raeburn 807: my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
808: unless ($extra eq '-1') {
809: $js .= "\n".$extra."\n";
810: }
811: }
812: }
813: }
814:
1.160 kruse 815: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
816: { 'redirect' => [$expire,'/adm/roles'],
817: 'add_entries' => \%add_entries,
818: 'only_body' => 1,}));
819:
820: # ----------------------------------------------------------------------- Texts
821:
822: my %lt=&Apache::lonlocal::texthash(
823: 'un' => 'Username',
824: 'pw' => 'Password',
825: 'dom' => 'Domain',
826: 'perc' => 'percent',
827: 'load' => 'Server Load',
828: 'userload' => 'User Load',
829: 'catalog' => 'Course/Community Catalog',
830: 'log' => 'Log in',
831: 'help' => 'Log-in Help',
832: 'serv' => 'Server',
833: 'servadm' => 'Server Administration',
834: 'helpdesk' => 'Contact Helpdesk',
835: 'forgotpw' => 'Forgot password?',
836: 'newuser' => 'New User?',
1.184 raeburn 837: 'change' => 'Change?',
1.160 kruse 838: );
839: # -------------------------------------------------- Change password field name
840:
841: my $forgotpw = &forgotpwdisplay(%lt);
842: $forgotpw .= '<br />' if $forgotpw;
843: my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
844: if ($loginhelp) {
845: $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
846: }
847:
848: # ---------------------------------------------------- Serve out DES JavaScript
849: {
850: my $jsh=Apache::File->new($include."/londes.js");
851: $r->print(<$jsh>);
852: }
853: # ---------------------------------------------------------- Serve rest of page
854:
855: $r->print(
856: '<div class="LC_Box"'
857: .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
858: );
859:
1.208 ! raeburn 860: my $target = '_top';
! 861: if ($sessiondata{'linkprot'}) {
! 862: my ($linkprotector,$deeplink) = split(/:/,$sessiondata{'linkprot'},2);
! 863: if (($deeplink eq $sessiondata{'origurl'}) &&
! 864: (($sessiondata{'linkprotuser'} eq $sessiondata{'username'}.':'.$sessiondata{'domain'}) ||
! 865: ($sessiondata{'linkprotuser'} eq $sessiondata{'username'}))) {
! 866: $target = '_self';
! 867: }
! 868: }
1.160 kruse 869: $r->print(<<ENDSERVERFORM);
1.208 ! raeburn 870: <form name="server" action="/adm/authenticate" method="post" target="$target">
1.160 kruse 871: <input type="hidden" name="logtoken" value="$logtoken" />
872: <input type="hidden" name="serverid" value="$lonhost" />
873: <input type="hidden" name="uname" value="" />
874: <input type="hidden" name="upass0" value="" />
875: <input type="hidden" name="udom" value="" />
876: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
877: <input type="hidden" name="localres" value="$env{'form.localres'}" />
878: </form>
879: ENDSERVERFORM
880: my $coursecatalog;
881: if (($showcoursecat eq '') || ($showcoursecat)) {
882: $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
883: }
884: my $newuserlink;
885: if ($shownewuserlink) {
886: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
887: }
888: my $logintitle =
889: '<h2 class="LC_hcell"'
890: .' style="background:'.$loginbox_header_bgcol.';'
891: .' color:'.$loginbox_header_textcol.'">'
892: .$lt{'log'}
893: .'</h2>';
894:
895: my $noscript_warning='<noscript><span class="LC_warning"><b>'
896: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
897: .'</b></span></noscript>';
898: my $helpdeskscript;
899: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
900: $authdomain,\$helpdeskscript,
901: $showhelpdesk,\@possdoms);
902:
903: my $mobileargs;
904: if ($clientmobile) {
905: $mobileargs = 'autocapitalize="off" autocorrect="off"';
906: }
907: my $loginform=(<<LFORM);
1.184 raeburn 908: <form name="client" action="" onsubmit="return(send())" id="lclogin">
1.160 kruse 909: <input type="hidden" name="lextkey" value="$lextkey" />
910: <input type="hidden" name="uextkey" value="$uextkey" />
911: <b><label for="uname">$lt{'un'}</label>:</b><br />
912: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
913: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
914: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
915: <b><label for="udom">$lt{'dom'}</label>:</b><br />
916: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
917: <input type="submit" value="$lt{'log'}" />
918: </form>
919: LFORM
920:
921: if ($showbanner) {
1.194 raeburn 922: my $alttext = &Apache::loncommon::designparm('login.alttext_img',$domain);
923: if ($alttext eq '') {
924: $alttext = 'The Learning Online Network with CAPA';
925: }
1.160 kruse 926: $r->print(<<HEADER);
927: <!-- The LON-CAPA Header -->
928: <div style="background:$pgbg;margin:0;width:100%;">
1.194 raeburn 929: <img src="$img" border="0" alt="$alttext" class="LC_maxwidth" id="lcloginbanner" />
1.160 kruse 930: </div>
931: HEADER
932: }
1.184 raeburn 933:
934: my $stdauthformstyle = 'inline-block';
935: my $ssoauthstyle = 'none';
1.202 raeburn 936: my $sso_onclick;
1.184 raeburn 937: my $logintype;
938: $r->print('<div style="float:left;margin-top:0;">');
939: if ($saml_landing) {
940: $ssoauthstyle = 'inline-block';
941: $stdauthformstyle = 'none';
942: $logintype = $samlssotext;
943: my $ssologin = '/adm/sso';
944: if ($samlssourl ne '') {
945: $ssologin = $samlssourl;
946: }
1.202 raeburn 947: my $ssologin_for_js = &js_escape($ssologin);
948: my $querystr_for_js;
1.192 raeburn 949: if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
950: my $querystring;
951: if ($env{'form.firsturl'} ne '') {
952: $querystring = 'origurl=';
953: if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
954: $querystring .= &uri_escape_utf8($env{'form.firsturl'});
955: } else {
956: $querystring .= &uri_escape($env{'form.firsturl'});
957: }
958: $querystring = &HTML::Entities::encode($querystring,"'");
959: }
960: if ($env{'form.ltoken'} ne '') {
961: $querystring .= (($querystring eq '')?'':'&') . 'ltoken='.
962: &HTML::Entities::encode(&uri_escape($env{'form.ltoken'}));
963: } elsif ($env{'form.linkkey'}) {
964: $querystring .= (($querystring eq '')?'':'&') . 'linkkey='.
965: &HTML::Entities::encode(&uri_escape($env{'form.linkkey'}));
966: }
967: if ($querystring ne '') {
968: $ssologin .= (($ssologin=~/\?/)?'&':'?') . $querystring;
1.202 raeburn 969: $querystr_for_js = &js_escape($querystring);
1.188 raeburn 970: }
1.192 raeburn 971: } elsif ($logtoken ne '') {
972: $ssologin .= (($ssologin=~/\?/)?'&':'?') . 'logtoken='.$logtoken;
1.202 raeburn 973: $querystr_for_js = &js_escape('logtoken='.$logtoken);
1.191 raeburn 974: }
1.184 raeburn 975: my $ssohref;
1.202 raeburn 976: if ($samlwindow) {
977: $sso_onclick = <<"ENDJS";
978: if (document.getElementById('LC_sso_login_link')) {
979: var ssoelem = document.getElementById('LC_sso_login_link')
980: ssoelem.addEventListener('click',samlWinFunction,false);
981: var windows = {};
982: function samlWinFunction(evt) {
983: evt.preventDefault();
984: var url = '$ssologin_for_js';
985: var name = 'lcssowin';
986: var querystr = '$querystr_for_js';
987: if (querystr) {
988: url += '?'+querystr+'&lcssowin=1';
989: } else {
990: url += '?lcssowin=1';
991: }
992: if ((typeof windows[name] !== 'undefined') && (!windows[name].closed)) {
993: windows[name].close();
994: }
995: windows[name]=window.open(url,name,'width=350,height=600');
996: windows[name].focus();
997: return false;
998: }
999: }
1000: ENDJS
1001: }
1.184 raeburn 1002: if ($samlssoimg ne '') {
1.202 raeburn 1003: $ssohref = '<a href="'.$ssologin.'" title="'.$samltooltip.'" id="LC_sso_login_link">'.
1.194 raeburn 1004: '<img src="'.$samlssoimg.'" alt="'.$samlssoalt.'" id="lcssobutton" /></a>';
1.184 raeburn 1005: } else {
1.202 raeburn 1006: $ssohref = '<a href="'.$ssologin.'" id="LC_sso_login_link">'.$samlssotext.'</a>';
1.184 raeburn 1007: }
1008: if (($env{'form.saml'} eq 'no') ||
1009: (($env{'form.username'} ne '') && ($env{'form.domain'} ne ''))) {
1010: $ssoauthstyle = 'none';
1011: $stdauthformstyle = 'inline-block';
1012: $logintype = $samlnonsso;
1013: }
1014: $r->print(<<ENDSAML);
1015: <p>
1016: Log-in type:
1017: <span style="font-weight:bold" id="LC_login_text">$logintype</span><br />
1018: <span><a href="javascript:toggleLClogin();" style="color:#000000">$lt{'change'}</a></span>
1019: </p>
1020: <div style="display:$ssoauthstyle" id="LC_SSO_login">
1021: <div class="LC_Box" style="padding-top: 10px;">
1022: $ssohref
1023: $noscript_warning
1024: </div>
1025: <div class="LC_Box" style="padding-top: 10px;">
1026: $loginhelp
1027: $contactblock
1028: $coursecatalog
1029: </div>
1030: </div>
1031: ENDSAML
1.191 raeburn 1032: } else {
1033: if ($env{'form.ltoken'}) {
1034: &Apache::lonnet::tmpdel($env{'form.ltoken'});
1035: delete($env{'form.ltoken'});
1036: }
1.184 raeburn 1037: }
1.196 raeburn 1038: my $in_frame_js;
1039: if ($linkprot_for_login) {
1040: my ($linkprotector,$linkproturi) = split(/:/,$linkprot_for_login,2);
1041: if (($linkprotector =~ /^\d+(c|d)$/) && ($linkproturi =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$})) {
1042: my $set_target;
1.198 raeburn 1043: if (($env{'form.retry'}) || ($env{'form.sso'})) {
1.196 raeburn 1044: if ($linkproturi eq $env{'form.firsturl'}) {
1045: $set_target = " document.server.target = '_self';";
1046: }
1047: } else {
1048: $set_target = <<ENDTARG;
1049: var linkproturi = '$linkproturi';
1050: var path = document.location.pathname.replace( new RegExp('^/adm/launch'),'');
1051: if (linkproturi == path) {
1052: document.server.target = '_self';
1053: }
1054: ENDTARG
1055: }
1056: $in_frame_js = <<ENDJS;
1057: <script type="text/javascript">
1058: // <![CDATA[
1059: if ((window.self !== window.top) && (document.server.target != '_self')) {
1060: $set_target
1.202 raeburn 1061: $sso_onclick
1.196 raeburn 1062: }
1063: // ]]>
1064: </script>
1065: ENDJS
1066: }
1.202 raeburn 1067: } elsif ($samlwindow) {
1068: $in_frame_js = <<ENDJS;
1069: <script type="text/javascript">
1070: // <![CDATA[
1071: if ((window.self !== window.top) && (document.server.target != '_self')) {
1072: $sso_onclick
1073: }
1074: // ]]>
1075: </script>
1076: ENDJS
1.196 raeburn 1077: }
1.184 raeburn 1078:
1079: $r->print(<<ENDLOGIN);
1080: <div style="display:$stdauthformstyle;" id="LC_standard_login">
1.160 kruse 1081: <div class="LC_Box" style="background:$loginbox_bg;">
1082: $logintitle
1083: $loginform
1084: $noscript_warning
1085: </div>
1086:
1087: <div class="LC_Box" style="padding-top: 10px;">
1088: $loginhelp
1089: $forgotpw
1090: $contactblock
1091: $newuserlink
1092: $coursecatalog
1093: </div>
1094: </div>
1095:
1.184 raeburn 1096: ENDLOGIN
1097: $r->print('</div><div>'."\n");
1.160 kruse 1098: if ($showmainlogo) {
1.194 raeburn 1099: my $alttext = &Apache::loncommon::designparm('login.alttext_logo',$domain);
1100: $r->print(' <img src="'.$logo.'" alt="'.$alttext.'" class="LC_maxwidth" id="lcloginmainlogo" />'."\n");
1.160 kruse 1101: }
1102: $r->print(<<ENDTOP);
1103: $announcements
1104: </div>
1105: <hr style="clear:both;" />
1106: ENDTOP
1107: my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
1108: $domainrow = <<"END";
1109: <tr>
1110: <td align="left" valign="top">
1111: <small><b>$lt{'dom'}: </b></small>
1112: </td>
1113: <td align="left" valign="top">
1114: <small><tt> $domain</tt></small>
1115: </td>
1116: </tr>
1117: END
1118: $serverrow = <<"END";
1119: <tr>
1120: <td align="left" valign="top">
1121: <small><b>$lt{'serv'}: </b></small>
1122: </td>
1123: <td align="left" valign="top">
1124: <small><tt> $lonhost ($role)</tt></small>
1125: </td>
1126: </tr>
1127: END
1128: if ($loadlim) {
1129: $loadrow = <<"END";
1130: <tr>
1131: <td align="left" valign="top">
1132: <small><b>$lt{'load'}: </b></small>
1133: </td>
1134: <td align="left" valign="top">
1135: <small><tt> $loadpercent $lt{'perc'}</tt></small>
1136: </td>
1137: </tr>
1138: END
1139: }
1140: if ($uloadlim) {
1141: $userloadrow = <<"END";
1142: <tr>
1143: <td align="left" valign="top">
1144: <small><b>$lt{'userload'}: </b></small>
1145: </td>
1146: <td align="left" valign="top">
1147: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
1148: </td>
1149: </tr>
1150: END
1151: }
1152: if (($version ne '') && ($version ne '<!-- VERSION -->')) {
1153: $versionrow = <<"END";
1154: <tr>
1155: <td colspan="2" align="left">
1156: <small>$version</small>
1157: </td>
1158: </tr>
1159: END
1160: }
1161:
1162: $r->print(<<ENDDOCUMENT);
1163: <div style="float: left;">
1164: <table border="0" cellspacing="0" cellpadding="0">
1165: $domainrow
1166: $serverrow
1167: $loadrow
1168: $userloadrow
1169: $versionrow
1170: </table>
1171: </div>
1172: <div style="float: right;">
1173: $domainlogo
1174: </div>
1175: <br style="clear:both;" />
1176: </div>
1177:
1.197 raeburn 1178: $in_frame_js
1.160 kruse 1179: <script type="text/javascript">
1180: // <![CDATA[
1181: // the if prevents the script error if the browser can not handle this
1182: if ( document.client.uname ) { document.client.uname.focus(); }
1183: // ]]>
1184: </script>
1185: $helpdeskscript
1186:
1187: ENDDOCUMENT
1188: my %endargs = ( 'noredirectlink' => 1, );
1189: $r->print(&Apache::loncommon::end_page(\%endargs));
1190: return OK;
1191: }
1192:
1193: sub check_loginvia {
1.193 raeburn 1194: my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
1.176 raeburn 1195: if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
1.160 kruse 1196: return;
1197: }
1198: my %domconfhash = &Apache::loncommon::get_domainconf($domain);
1199: my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
1200: my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
1201: my $output;
1202: if ($loginvia ne '') {
1203: my $noredirect;
1.182 raeburn 1204: my $ip = &Apache::lonnet::get_requestor_ip();
1.160 kruse 1205: if ($ip eq '127.0.0.1') {
1206: $noredirect = 1;
1207: } else {
1208: if ($loginvia_exempt ne '') {
1209: my @exempt = split(',',$loginvia_exempt);
1210: if (grep(/^\Q$ip\E$/,@exempt)) {
1211: $noredirect = 1;
1212: }
1213: }
1214: }
1215: unless ($noredirect) {
1216: my ($newhost,$path);
1217: if ($loginvia =~ /:/) {
1218: ($newhost,$path) = split(':',$loginvia);
1219: } else {
1220: $newhost = $loginvia;
1221: }
1222: if ($newhost ne $lonhost) {
1223: if (&Apache::lonnet::hostname($newhost) ne '') {
1.176 raeburn 1224: if ($balcookie) {
1225: my ($balancer,$cookie) = split(/:/,$balcookie);
1226: if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
1227: my ($udom,$uname,$cookieid) = ($1,$2,$3);
1228: unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
1229: if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
1230: while (my $filename=readdir($dh)) {
1231: if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
1232: my $handle = $1;
1233: my %hash =
1234: &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
1235: ['request.balancercookie',
1236: 'user.linkedenv']);
1237: if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
1238: if (unlink("$lonidsdir/$filename")) {
1239: if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
1240: (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
1241: (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
1242: unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
1243: }
1244: }
1245: }
1246: last;
1247: }
1248: }
1249: closedir($dh);
1250: }
1251: }
1252: }
1253: }
1.193 raeburn 1254: $output = &redirect_page($newhost,$path);
1.160 kruse 1255: }
1256: }
1257: }
1258: }
1259: return $output;
1260: }
1261:
1262: sub redirect_page {
1.193 raeburn 1263: my ($desthost,$path) = @_;
1.178 raeburn 1264: my $hostname = &Apache::lonnet::hostname($desthost);
1.160 kruse 1265: my $protocol = $Apache::lonnet::protocol{$desthost};
1266: $protocol = 'http' if ($protocol ne 'https');
1267: unless ($path =~ m{^/}) {
1268: $path = '/'.$path;
1269: }
1.178 raeburn 1270: my $url = $protocol.'://'.$hostname.$path;
1.200 raeburn 1271: my $args = {};
1.199 raeburn 1272: if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
1273: $url = $protocol.'://'.$hostname.$env{'form.firsturl'};
1274: if (($env{'form.ltoken'}) || ($env{'form.linkprot'} ne '') ||
1275: ($env{'form.linkkey'} ne '')) {
1276: my %link_info;
1277: if ($env{'form.ltoken'}) {
1278: %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
1279: &Apache::lonnet::tmpdel($env{'form.ltoken'});
1.200 raeburn 1280: $args->{'only_body'} = 1;
1.199 raeburn 1281: } elsif ($env{'form.linkprot'}) {
1282: $link_info{'linkprot'} = $env{'form.linkprot'};
1.206 raeburn 1283: foreach my $item ('linkprotuser','linkprotexit','linkprotpbid','linkprotpburl') {
1.201 raeburn 1284: if ($env{'form.'.$item}) {
1285: $link_info{$item} = $env{'form.'.$item};
1286: }
1.199 raeburn 1287: }
1.200 raeburn 1288: $args->{'only_body'} = 1;
1.199 raeburn 1289: } elsif ($env{'form.linkkey'} ne '') {
1290: $link_info{'linkkey'} = $env{'form.linkkey'};
1291: }
1292: my $token = &Apache::lonnet::tmpput(\%link_info,$desthost,'link');
1293: unless (($token eq 'con_lost') || ($token eq 'refused') ||
1294: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
1295: $url .= '?ltoken='.$token;
1296: }
1297: }
1298: } else {
1.188 raeburn 1299: my $querystring;
1.199 raeburn 1300: if ($env{'form.firsturl'} ne '') {
1301: if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
1302: $querystring = &uri_escape_utf8($env{'form.firsturl'});
1303: } else {
1304: $querystring = &uri_escape($env{'form.firsturl'});
1305: }
1306: $querystring = &HTML::Entities::encode($querystring,"'");
1307: $querystring = '?firsturl='.$querystring;
1.188 raeburn 1308: }
1.193 raeburn 1309: if ($env{'form.ltoken'}) {
1.199 raeburn 1310: my %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
1311: &Apache::lonnet::tmpdel($env{'form.ltoken'});
1312: my $token = &Apache::lonnet::tmpput(\%link_info,$desthost,'link');
1313: unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
1314: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
1315: unless (($path eq '/adm/roles') || ($path eq '/adm/login')) {
1316: $url = $protocol.'://'.$hostname.'/adm/roles';
1317: }
1318: $querystring .= (($querystring =~/^\?/)?'&':'?') . 'ttoken='.$token;
1319: }
1.177 raeburn 1320: }
1.199 raeburn 1321: $url .= $querystring;
1.177 raeburn 1322: }
1.207 raeburn 1323: $args->{'redirect'} = [0,$url,'','',1];
1.200 raeburn 1324: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,$args);
1.160 kruse 1325: my $end_page = &Apache::loncommon::end_page();
1326: return $start_page.$end_page;
1327: }
1328:
1329: sub contactdisplay {
1330: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
1331: $possdoms) = @_;
1332: my $contactblock;
1333: my $origmail;
1334: if (ref($possdoms) eq 'ARRAY') {
1335: if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
1336: $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
1337: }
1338: }
1339: my $requestmail =
1340: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
1341: $authdomain,$origmail);
1342: unless ($showhelpdesk eq '0') {
1343: if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
1344: $showhelpdesk = 1;
1345: } else {
1346: $showhelpdesk = 0;
1347: }
1348: }
1349: if ($servadm && $showadminmail) {
1350: $contactblock .= $$lt{'servadm'}.':<br />'.
1351: '<tt>'.$servadm.'</tt><br />';
1352: }
1353: if ($showhelpdesk) {
1354: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
1355: my $thisurl = &escape('/adm/login');
1356: $$helpdeskscript = <<"ENDSCRIPT";
1357: <script type="text/javascript">
1358: // <![CDATA[
1359: function helpdesk() {
1360: var possdom = document.client.udom.value;
1361: var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
1362: if (codedom == '') {
1363: codedom = "$authdomain";
1364: }
1365: var querystr = "origurl=$thisurl&codedom="+codedom;
1366: document.location.href = "/adm/helpdesk?"+querystr;
1367: return;
1368: }
1369: // ]]>
1370: </script>
1371: ENDSCRIPT
1372: }
1373: return $contactblock;
1374: }
1375:
1376: sub forgotpwdisplay {
1377: my (%lt) = @_;
1378: my $prompt_for_resetpw = 1;
1379: if ($prompt_for_resetpw) {
1380: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
1381: }
1382: return;
1383: }
1384:
1385: sub coursecatalog_link {
1386: my ($linkname) = @_;
1387: return <<"END";
1388: <a href="/adm/coursecatalog">$linkname</a>
1389: END
1390: }
1391:
1392: sub newuser_link {
1393: my ($linkname) = @_;
1394: return '<a href="/adm/createaccount">'.$linkname.'</a>';
1395: }
1396:
1.192 raeburn 1397: sub decode_token {
1398: my ($info) = @_;
1399: my ($firsturl,@rest)=split(/\&/,$info);
1400: my %form;
1401: if ($firsturl ne '') {
1402: $form{'firsturl'} = &unescape($firsturl);
1403: }
1404: foreach my $item (@rest) {
1405: my ($key,$value) = split(/=/,$item);
1406: $form{$key} = &unescape($value);
1407: }
1408: return %form;
1409: }
1410:
1.160 kruse 1411: 1;
1412: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>