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