Annotation of loncom/auth/lonlogin.pm, revision 1.158.2.11
1.1 albertel 1: # The LearningOnline Network
2: # Login Screen
1.11 www 3: #
1.158.2.11! raeburn 4: # $Id: lonlogin.pm,v 1.158.2.10 2020/10/24 19:49:06 raeburn Exp $
1.11 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.14 albertel 28:
1.1 albertel 29: package Apache::lonlogin;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::File ();
1.63 albertel 34: use Apache::lonnet;
1.12 albertel 35: use Apache::loncommon();
1.49 www 36: use Apache::lonauth();
1.50 www 37: use Apache::lonlocal;
1.71 albertel 38: use Apache::migrateuser();
1.75 www 39: use lib '/home/httpd/lib/perl/';
1.158.2.8 raeburn 40: use LONCAPA qw(:DEFAULT :match);
1.158.2.7 raeburn 41: use CGI::Cookie();
1.75 www 42:
1.1 albertel 43: sub handler {
44: my $r = shift;
1.71 albertel 45:
46: &Apache::loncommon::get_unprocessed_cgi
1.79 albertel 47: (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
48: $ENV{'REDIRECT_QUERY_STRING'}),
1.71 albertel 49: ['interface','username','domain','firsturl','localpath','localres',
1.158.2.8 raeburn 50: 'token','role','symb','iptoken','btoken']);
1.102 raeburn 51: if (!defined($env{'form.firsturl'})) {
52: &Apache::lonacc::get_posted_cgi($r,['firsturl']);
53: }
1.71 albertel 54:
55: # -- check if they are a migrating user
56: if (defined($env{'form.token'})) {
57: return &Apache::migrateuser::handler($r);
58: }
59:
1.158.2.7 raeburn 60: # For "public user" - remove any exising "public" cookie, as user really wants to log-in
61: my ($handle,$lonidsdir,$expirepub,$userdom);
1.158.2.8 raeburn 62: $lonidsdir=$r->dir_config('lonIDsDir');
1.158.2.7 raeburn 63: unless ($r->header_only) {
64: $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
65: if ($handle ne '') {
66: if ($handle=~/^publicuser\_/) {
67: unlink($r->dir_config('lonIDsDir')."/$handle.id");
68: undef($handle);
69: undef($userdom);
70: $expirepub = 1;
71: }
72: }
73: }
74:
1.53 www 75: &Apache::loncommon::no_cache($r);
76: &Apache::lonlocal::get_language_handle($r);
1.54 www 77: &Apache::loncommon::content_type($r,'text/html');
1.158.2.7 raeburn 78: if ($expirepub) {
1.158.2.9 raeburn 79: my $c = new CGI::Cookie(-name => 'lonPubID',
1.158.2.7 raeburn 80: -value => '',
81: -expires => '-10y',);
82: $r->header_out('Set-cookie' => $c);
83: } elsif (($handle eq '') && ($userdom ne '')) {
1.158.2.9 raeburn 84: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
85: foreach my $name (keys(%cookies)) {
86: next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
87: my $c = new CGI::Cookie(-name => $name,
88: -value => '',
89: -expires => '-10y',);
90: $r->headers_out->add('Set-cookie' => $c);
91: }
1.158.2.7 raeburn 92: }
1.1 albertel 93: $r->send_http_header;
94: return OK if $r->header_only;
95:
1.49 www 96:
97: # Are we re-routing?
1.149 raeburn 98: my $londocroot = $r->dir_config('lonDocRoot');
99: if (-e "$londocroot/lon-status/reroute.txt") {
1.49 www 100: &Apache::lonauth::reroute($r);
101: return OK;
102: }
1.55 www 103:
1.158.2.8 raeburn 104: my $lonhost = $r->dir_config('lonHostID');
105: $env{'form.firsturl'} =~ s/(`)/'/g;
106:
107: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
108:
109: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
110: if ($found_server) {
111: my $hostname = &Apache::lonnet::hostname($found_server);
112: if ($hostname ne '') {
113: my $protocol = $Apache::lonnet::protocol{$found_server};
114: $protocol = 'http' if ($protocol ne 'https');
115: my $dest = '/adm/roles';
116: if ($env{'form.firsturl'} ne '') {
117: $dest = $env{'form.firsturl'};
118: }
119: my %info = (
120: balcookie => $lonhost.':'.$balancer_cookie,
121: );
122: my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
123: if ($balancer_token) {
124: $dest .= (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;
125: }
126: my $url = $protocol.'://'.$hostname.$dest;
127: my $start_page =
128: &Apache::loncommon::start_page('Switching Server ...',undef,
129: {'redirect' => [0,$url],});
130: my $end_page = &Apache::loncommon::end_page();
131: $r->print($start_page.$end_page);
132: return OK;
133: }
134: }
135:
136: #
137: # Check if a LON-CAPA load balancer sent user here because user's browser sent
138: # it a balancer cookie for an active session on this server.
139: #
140:
141: my $balcookie;
142: if ($env{'form.btoken'}) {
143: my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
144: $balcookie = $info{'balcookie'};
145: &Apache::lonnet::tmpdel($env{'form.btoken'});
146: delete($env{'form.btoken'});
147: }
148:
1.158.2.7 raeburn 149: #
150: # If browser sent an old cookie for which the session file had been removed
151: # check if configuration for user's domain has a portal URL set. If so
152: # switch user's log-in to the portal.
153: #
154:
155: if (($handle eq '') && ($userdom ne '')) {
156: my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
157: if ($domdefaults{'portal_def'} =~ /^https?\:/) {
158: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
159: {'redirect' => [0,$domdefaults{'portal_def'}],});
160: my $end_page = &Apache::loncommon::end_page();
161: $r->print($start_page.$end_page);
162: return OK;
163: }
164: }
165:
1.143 raeburn 166: $env{'form.firsturl'} =~ s/(`)/'/g;
1.71 albertel 167:
1.55 www 168: # -------------------------------- Prevent users from attempting to login twice
1.135 raeburn 169: if ($handle ne '') {
1.158.2.7 raeburn 170: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
171: my $start_page =
172: &Apache::loncommon::start_page('Already logged in');
173: my $end_page =
174: &Apache::loncommon::end_page();
175: my $dest = '/adm/roles';
176: if ($env{'form.firsturl'} ne '') {
177: $dest = $env{'form.firsturl'};
178: }
179: $r->print(
180: $start_page
181: .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
182: .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
183: '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
184: .$end_page
185: );
186: return OK;
1.55 www 187: }
188:
189: # ---------------------------------------------------- No valid token, continue
1.16 www 190:
1.157 raeburn 191: # ---------------------------- Not possible to really login to domain "public"
1.70 www 192: if ($env{'form.domain'} eq 'public') {
193: $env{'form.domain'}='';
194: $env{'form.username'}='';
195: }
1.157 raeburn 196:
197: # ------ Is this page requested because /adm/migrateuser detected an IP change?
198: my %sessiondata;
199: if ($env{'form.iptoken'}) {
200: %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
1.158.2.2 raeburn 201: unless ($sessiondata{'sessionserver'}) {
202: my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
203: delete($env{'form.iptoken'});
204: }
1.157 raeburn 205: }
1.32 www 206: # ----------------------------------------------------------- Process Interface
1.63 albertel 207: $env{'form.interface'}=~s/\W//g;
1.16 www 208:
1.156 raeburn 209: (undef,undef,undef,undef,undef,undef,my $clientmobile) =
210: &Apache::loncommon::decode_user_agent();
1.94 albertel 211:
212: my $iconpath=
213: &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
214:
1.87 raeburn 215: my $domain = &Apache::lonnet::default_login_domain();
1.158.2.3 raeburn 216: my $defdom = $domain;
1.126 raeburn 217: if ($lonhost ne '') {
1.157 raeburn 218: unless ($sessiondata{'sessionserver'}) {
1.158.2.8 raeburn 219: my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);
1.157 raeburn 220: if ($redirect) {
221: $r->print($redirect);
222: return OK;
223: }
224: }
1.126 raeburn 225: }
226:
1.157 raeburn 227: if (($sessiondata{'domain'}) &&
1.158.2.8 raeburn 228: (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
1.157 raeburn 229: $domain=$sessiondata{'domain'};
230: } elsif (($env{'form.domain'}) &&
1.89 albertel 231: (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
1.63 albertel 232: $domain=$env{'form.domain'};
1.46 www 233: }
1.157 raeburn 234:
1.1 albertel 235: my $role = $r->dir_config('lonRole');
236: my $loadlim = $r->dir_config('lonLoadLim');
1.145 www 237: my $uloadlim= $r->dir_config('lonUserLoadLim');
1.90 raeburn 238: my $servadm = $r->dir_config('lonAdmEMail');
1.1 albertel 239: my $tabdir = $r->dir_config('lonTabDir');
1.6 www 240: my $include = $r->dir_config('lonIncludes');
1.37 www 241: my $expire = $r->dir_config('lonExpire');
1.44 www 242: my $version = $r->dir_config('lonVersion');
1.88 albertel 243: my $host_name = &Apache::lonnet::hostname($lonhost);
1.1 albertel 244:
1.30 www 245: # --------------------------------------------- Default values for login fields
1.157 raeburn 246:
247: my ($authusername,$authdomain);
248: if ($sessiondata{'username'}) {
249: $authusername=$sessiondata{'username'};
250: } else {
1.158 raeburn 251: $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
1.157 raeburn 252: $authusername=($env{'form.username'}?$env{'form.username'}:'');
253: }
254: if ($sessiondata{'domain'}) {
255: $authdomain=$sessiondata{'domain'};
1.158 raeburn 256: } else {
257: $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
1.157 raeburn 258: $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
259: }
1.30 www 260:
261: # ---------------------------------------------------------- Determine own load
1.1 albertel 262: my $loadavg;
1.41 albertel 263: {
264: my $loadfile=Apache::File->new('/proc/loadavg');
265: $loadavg=<$loadfile>;
266: }
1.1 albertel 267: $loadavg =~ s/\s.*//g;
1.147 raeburn 268:
269: my ($loadpercent,$userloadpercent);
270: if ($loadlim) {
271: $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
272: }
273: if ($uloadlim) {
274: $userloadpercent=&Apache::lonnet::userload();
275: }
1.1 albertel 276:
1.31 www 277: my $firsturl=
1.63 albertel 278: ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
1.141 raeburn 279:
1.45 www 280: # ----------------------------------------------------------- Get announcements
281: my $announcements=&Apache::lonnet::getannounce();
1.6 www 282: # -------------------------------------------------------- Set login parameters
283:
284: my @hexstr=('0','1','2','3','4','5','6','7',
285: '8','9','a','b','c','d','e','f');
286: my $lkey='';
287: for (0..7) {
288: $lkey.=$hexstr[rand(15)];
289: }
290:
291: my $ukey='';
292: for (0..7) {
293: $ukey.=$hexstr[rand(15)];
294: }
295:
296: my $lextkey=hex($lkey);
1.15 www 297: if ($lextkey>2147483647) { $lextkey-=4294967296; }
298:
1.6 www 299: my $uextkey=hex($ukey);
1.15 www 300: if ($uextkey>2147483647) { $uextkey-=4294967296; }
301:
1.31 www 302: # -------------------------------------------------------- Store away log token
1.123 raeburn 303: my $tokenextras;
304: if ($env{'form.role'}) {
305: $tokenextras = '&role='.&escape($env{'form.role'});
306: }
307: if ($env{'form.symb'}) {
1.124 raeburn 308: if (!$tokenextras) {
309: $tokenextras = '&';
310: }
1.123 raeburn 311: $tokenextras .= '&symb='.&escape($env{'form.symb'});
312: }
1.158.2.2 raeburn 313: if ($env{'form.iptoken'}) {
314: if (!$tokenextras) {
315: $tokenextras = '&&';
316: }
317: $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
318: }
1.6 www 319: my $logtoken=Apache::lonnet::reply(
1.123 raeburn 320: 'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
1.6 www 321: $lonhost);
1.31 www 322:
1.148 raeburn 323: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
324: # we are in serious trouble
1.31 www 325:
1.148 raeburn 326: if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
327: if ($logtoken eq 'no_such_host') {
328: &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
329: }
1.31 www 330: my $spares='';
1.158.2.10 raeburn 331: my (@sparehosts,%spareservers);
332: my $sparesref = &Apache::lonnet::this_host_spares($defdom);
333: if (ref($sparesref) eq 'HASH') {
334: foreach my $key (keys(%{$sparesref})) {
335: if (ref($sparesref->{$key}) eq 'ARRAY') {
336: my @sorted = sort { &Apache::lonnet::hostname($a) cmp
337: &Apache::lonnet::hostname($b);
338: } @{$sparesref->{$key}};
339: if (@sorted) {
340: if ($key eq 'primary') {
341: unshift(@sparehosts,@sorted);
342: } elsif ($key eq 'default') {
343: push(@sparehosts,@sorted);
344: }
345: }
346: }
347: }
348: }
349: foreach my $hostid (@sparehosts) {
1.58 matthew 350: next if ($hostid eq $lonhost);
1.88 albertel 351: my $hostname = &Apache::lonnet::hostname($hostid);
1.158.2.10 raeburn 352: next if (($hostname eq '') || ($spareservers{$hostname}));
353: $spareservers{$hostname} = 1;
354: my $protocol = $Apache::lonnet::protocol{$hostid};
355: $protocol = 'http' if ($protocol ne 'https');
356: $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.
1.88 albertel 357: $hostname.
1.58 matthew 358: '/adm/login?domain='.$authdomain.'">'.
1.88 albertel 359: $hostname.'</a>'.
1.158.2.10 raeburn 360: ' '.&mt('(preferred)').'</span>'.$/;
1.58 matthew 361: }
1.148 raeburn 362: if ($spares) {
363: $spares.= '<br />';
364: }
1.151 raeburn 365: my %all_hostnames = &Apache::lonnet::all_hostnames();
366: foreach my $hostid (sort
1.107 tempelho 367: {
368: &Apache::lonnet::hostname($a) cmp
369: &Apache::lonnet::hostname($b);
370: }
371: keys(%all_hostnames)) {
1.158.2.10 raeburn 372: next if ($hostid eq $lonhost);
1.151 raeburn 373: my $hostname = &Apache::lonnet::hostname($hostid);
1.158.2.10 raeburn 374: next if (($hostname eq '') || ($spareservers{$hostname}));
1.158.2.11! raeburn 375: $spareservers{$hostname} = 1;
1.158.2.10 raeburn 376: my $protocol = $Apache::lonnet::protocol{$hostid};
377: $protocol = 'http' if ($protocol ne 'https');
378: $spares.='<br /><a href="'.$protocol.'://'.
1.151 raeburn 379: $hostname.
380: '/adm/login?domain='.$authdomain.'">'.
381: $hostname.'</a>';
382: }
383: $r->print(
1.158.2.10 raeburn 384: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
385: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
386: .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'
1.107 tempelho 387: .&mt('The LearningOnline Network with CAPA')
388: .'</title></head>'
389: .'<body bgcolor="#FFFFFF">'
390: .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
1.158.2.10 raeburn 391: .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
1.148 raeburn 392: .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
1.151 raeburn 393: if ($spares) {
394: $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
395: .'</p>'
396: .$spares);
397: }
398: $r->print('</body>'
399: .'</html>'
400: );
401: return OK;
402: }
1.31 www 403:
404: # ----------------------------------------------- Apparently we are in business
1.151 raeburn 405: $servadm=~s/\,/\<br \/\>/g;
1.38 www 406:
1.21 www 407: # ----------------------------------------------------------- Front page design
1.151 raeburn 408: my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
409: my $font=&Apache::loncommon::designparm('login.font',$domain);
410: my $link=&Apache::loncommon::designparm('login.link',$domain);
411: my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
412: my $alink=&Apache::loncommon::designparm('login.alink',$domain);
413: my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
414: my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
415: my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
416: my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
417: my $logo=&Apache::loncommon::designparm('login.logo',$domain);
418: my $img=&Apache::loncommon::designparm('login.img',$domain);
419: my $domainlogo=&Apache::loncommon::domainlogo($domain);
420: my $showbanner = 1;
421: my $showmainlogo = 1;
422: if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
423: $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
424: }
425: if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
426: $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
427: }
1.153 raeburn 428: my $showadminmail;
429: my @possdoms = &Apache::lonnet::current_machine_domains();
430: if (grep(/^\Q$domain\E$/,@possdoms)) {
431: $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
432: }
1.151 raeburn 433: my $showcoursecat =
434: &Apache::loncommon::designparm('login.coursecatalog',$domain);
435: my $shownewuserlink =
436: &Apache::loncommon::designparm('login.newuser',$domain);
1.153 raeburn 437: my $showhelpdesk =
438: &Apache::loncommon::designparm('login.helpdesk',$domain);
1.151 raeburn 439: my $now=time;
440: my $js = (<<ENDSCRIPT);
1.107 tempelho 441:
1.116 bisitz 442: <script type="text/javascript" language="JavaScript">
1.122 bisitz 443: // <![CDATA[
1.107 tempelho 444: function send()
445: {
446: this.document.server.elements.uname.value
447: =this.document.client.elements.uname.value;
448:
449: this.document.server.elements.udom.value
450: =this.document.client.elements.udom.value;
451:
452: uextkey=this.document.client.elements.uextkey.value;
453: lextkey=this.document.client.elements.lextkey.value;
454: initkeys();
455:
456: this.document.server.elements.upass0.value
1.158.2.5 raeburn 457: =getCrypted(this.document.client.elements.upass$now.value);
1.6 www 458:
1.107 tempelho 459: this.document.client.elements.uname.value='';
460: this.document.client.elements.upass$now.value='';
1.6 www 461:
1.107 tempelho 462: this.document.server.submit();
463: return false;
464: }
1.139 raeburn 465:
466: function enableInput() {
1.144 bisitz 467: this.document.client.elements.upass$now.removeAttribute("readOnly");
468: this.document.client.elements.uname.removeAttribute("readOnly");
469: this.document.client.elements.udom.removeAttribute("readOnly");
1.139 raeburn 470: return;
471: }
472:
1.122 bisitz 473: // ]]>
1.107 tempelho 474: </script>
1.98 raeburn 475:
1.16 www 476: ENDSCRIPT
1.6 www 477:
1.98 raeburn 478: # --------------------------------------------------- Print login screen header
479:
1.151 raeburn 480: my %add_entries = (
1.108 tempelho 481: bgcolor => "$mainbg",
1.107 tempelho 482: text => "$font",
483: link => "$link",
484: vlink => "$vlink",
1.139 raeburn 485: alink => "$alink",
486: onload => 'javascript:enableInput();',);
1.107 tempelho 487:
1.158.2.4 raeburn 488: my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
489: @hosts = &Apache::lonnet::current_machine_ids();
490: $lonhost_in_use = $lonhost;
491: if (@hosts > 1) {
492: foreach my $hostid (@hosts) {
493: if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
494: $lonhost_in_use = $hostid;
495: last;
496: }
497: }
498: }
499: %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
500: $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
501: $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
1.158.2.1 raeburn 502: if ($headextra) {
503: my $omitextra;
504: if ($headextra_exempt ne '') {
505: my @exempt = split(',',$headextra_exempt);
506: my $ip = $ENV{'REMOTE_ADDR'};
507: if (grep(/^\Q$ip\E$/,@exempt)) {
508: $omitextra = 1;
509: }
510: }
511: unless ($omitextra) {
512: my $confname = $defdom.'-domainconfig';
1.158.2.4 raeburn 513: if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
1.158.2.1 raeburn 514: my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
515: unless ($extra eq '-1') {
516: $js .= "\n".$extra."\n";
517: }
518: }
519: }
520: }
521:
1.151 raeburn 522: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
1.107 tempelho 523: { 'redirect' => [$expire,'/adm/roles'],
524: 'add_entries' => \%add_entries,
525: 'only_body' => 1,}));
1.98 raeburn 526:
527: # ----------------------------------------------------------------------- Texts
528:
1.151 raeburn 529: my %lt=&Apache::lonlocal::texthash(
1.129 bisitz 530: 'un' => 'Username',
531: 'pw' => 'Password',
532: 'dom' => 'Domain',
533: 'perc' => 'percent',
534: 'load' => 'Server Load',
535: 'userload' => 'User Load',
536: 'catalog' => 'Course/Community Catalog',
537: 'log' => 'Log in',
538: 'help' => 'Log-in Help',
539: 'serv' => 'Server',
540: 'servadm' => 'Server Administration',
541: 'helpdesk' => 'Contact Helpdesk',
542: 'forgotpw' => 'Forgot password?',
543: 'newuser' => 'New User?',
544: );
1.98 raeburn 545: # -------------------------------------------------- Change password field name
1.131 jms 546:
1.151 raeburn 547: my $forgotpw = &forgotpwdisplay(%lt);
548: $forgotpw .= '<br />' if $forgotpw;
1.152 raeburn 549: my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
550: if ($loginhelp) {
551: $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
552: }
1.98 raeburn 553:
554: # ---------------------------------------------------- Serve out DES JavaScript
1.151 raeburn 555: {
556: my $jsh=Apache::File->new($include."/londes.js");
557: $r->print(<$jsh>);
558: }
1.98 raeburn 559: # ---------------------------------------------------------- Serve rest of page
560:
1.151 raeburn 561: $r->print(
1.137 bisitz 562: '<div class="LC_Box"'
563: .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
564: );
1.6 www 565:
1.151 raeburn 566: $r->print(<<ENDSERVERFORM);
1.140 raeburn 567: <form name="server" action="/adm/authenticate" method="post" target="_top">
1.33 www 568: <input type="hidden" name="logtoken" value="$logtoken" />
569: <input type="hidden" name="serverid" value="$lonhost" />
570: <input type="hidden" name="uname" value="" />
1.65 www 571: <input type="hidden" name="upass0" value="" />
1.33 www 572: <input type="hidden" name="udom" value="" />
1.63 albertel 573: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
574: <input type="hidden" name="localres" value="$env{'form.localres'}" />
1.14 albertel 575: </form>
1.16 www 576: ENDSERVERFORM
1.151 raeburn 577: my $coursecatalog;
578: if (($showcoursecat eq '') || ($showcoursecat)) {
579: $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
580: }
581: my $newuserlink;
582: if ($shownewuserlink) {
583: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
584: }
585: my $logintitle =
586: '<h2 class="LC_hcell"'
587: .' style="background:'.$loginbox_header_bgcol.';'
588: .' color:'.$loginbox_header_textcol.'">'
589: .$lt{'log'}
590: .'</h2>';
591:
592: my $noscript_warning='<noscript><span class="LC_warning"><b>'
593: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
594: .'</b></span></noscript>';
595: my $helpdeskscript;
596: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
1.153 raeburn 597: $authdomain,\$helpdeskscript,
598: $showhelpdesk,\@possdoms);
1.107 tempelho 599:
1.156 raeburn 600: my $mobileargs;
601: if ($clientmobile) {
602: $mobileargs = 'autocapitalize="off" autocorrect="off"';
603: }
1.151 raeburn 604: my $loginform=(<<LFORM);
1.122 bisitz 605: <form name="client" action="" onsubmit="return(send())">
1.115 bisitz 606: <input type="hidden" name="lextkey" value="$lextkey" />
607: <input type="hidden" name="uextkey" value="$uextkey" />
1.108 tempelho 608: <b><label for="uname">$lt{'un'}</label>:</b><br />
1.156 raeburn 609: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
1.108 tempelho 610: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
1.139 raeburn 611: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
1.108 tempelho 612: <b><label for="udom">$lt{'dom'}</label>:</b><br />
1.156 raeburn 613: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
1.108 tempelho 614: <input type="submit" value="$lt{'log'}" />
615: </form>
616: LFORM
617:
1.109 raeburn 618: if ($showbanner) {
619: $r->print(<<HEADER);
620: <!-- The LON-CAPA Header -->
1.132 bisitz 621: <div style="background:$pgbg;margin:0;width:100%;">
1.158.2.6 raeburn 622: <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
1.132 bisitz 623: </div>
1.109 raeburn 624: HEADER
625: }
626: $r->print(<<ENDTOP);
1.146 bisitz 627: <div style="float:left;margin-top:0;">
1.137 bisitz 628: <div class="LC_Box" style="background:$loginbox_bg;">
1.112 muellerd 629: $logintitle
1.137 bisitz 630: $loginform
631: $noscript_warning
1.108 tempelho 632: </div>
1.107 tempelho 633:
1.137 bisitz 634: <div class="LC_Box" style="padding-top: 10px;">
1.132 bisitz 635: $loginhelp
636: $forgotpw
637: $contactblock
638: $newuserlink
1.130 bisitz 639: $coursecatalog
1.107 tempelho 640: </div>
1.118 tempelho 641: </div>
1.137 bisitz 642:
643: <div>
1.118 tempelho 644: ENDTOP
645: if ($showmainlogo) {
1.158.2.6 raeburn 646: $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
1.118 tempelho 647: }
648: $r->print(<<ENDTOP);
649: $announcements
1.137 bisitz 650: </div>
651: <hr style="clear:both;" />
1.108 tempelho 652: ENDTOP
1.147 raeburn 653: my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
654: $domainrow = <<"END";
1.14 albertel 655: <tr>
1.110 muellerd 656: <td align="left" valign="top">
1.132 bisitz 657: <small><b>$lt{'dom'}: </b></small>
1.14 albertel 658: </td>
1.110 muellerd 659: <td align="left" valign="top">
1.14 albertel 660: <small><tt> $domain</tt></small>
661: </td>
662: </tr>
1.147 raeburn 663: END
664: $serverrow = <<"END";
1.14 albertel 665: <tr>
1.110 muellerd 666: <td align="left" valign="top">
1.132 bisitz 667: <small><b>$lt{'serv'}: </b></small>
1.14 albertel 668: </td>
1.110 muellerd 669: <td align="left" valign="top">
1.14 albertel 670: <small><tt> $lonhost ($role)</tt></small>
671: </td>
672: </tr>
1.147 raeburn 673: END
674: if ($loadlim) {
675: $loadrow = <<"END";
1.14 albertel 676: <tr>
1.110 muellerd 677: <td align="left" valign="top">
1.132 bisitz 678: <small><b>$lt{'load'}: </b></small>
1.14 albertel 679: </td>
1.110 muellerd 680: <td align="left" valign="top">
1.51 www 681: <small><tt> $loadpercent $lt{'perc'}</tt></small>
1.42 albertel 682: </td>
683: </tr>
1.147 raeburn 684: END
685: }
686: if ($uloadlim) {
687: $userloadrow = <<"END";
1.42 albertel 688: <tr>
1.110 muellerd 689: <td align="left" valign="top">
1.132 bisitz 690: <small><b>$lt{'userload'}: </b></small>
1.42 albertel 691: </td>
1.110 muellerd 692: <td align="left" valign="top">
1.51 www 693: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
1.14 albertel 694: </td>
695: </tr>
1.147 raeburn 696: END
697: }
698: if (($version ne '') && ($version ne '<!-- VERSION -->')) {
699: $versionrow = <<"END";
1.132 bisitz 700: <tr>
701: <td colspan="2" align="left">
702: <small>$version</small>
703: </td>
704: </tr>
1.147 raeburn 705: END
706: }
707:
1.151 raeburn 708: $r->print(<<ENDDOCUMENT);
1.147 raeburn 709: <div style="float: left;">
710: <table border="0" cellspacing="0" cellpadding="0">
711: $domainrow
712: $serverrow
713: $loadrow
714: $userloadrow
715: $versionrow
1.14 albertel 716: </table>
1.141 raeburn 717: </div>
718: <div style="float: right;">
719: $domainlogo
720: </div>
721: <br style="clear:both;" />
1.107 tempelho 722: </div>
1.25 bowersj2 723:
1.59 albertel 724: <script type="text/javascript">
1.122 bisitz 725: // <![CDATA[
1.59 albertel 726: // the if prevents the script error if the browser can not handle this
1.25 bowersj2 727: if ( document.client.uname ) { document.client.uname.focus(); }
1.122 bisitz 728: // ]]>
1.25 bowersj2 729: </script>
1.62 raeburn 730: $helpdeskscript
1.14 albertel 731:
1.1 albertel 732: ENDDOCUMENT
1.98 raeburn 733: my %endargs = ( 'noredirectlink' => 1, );
734: $r->print(&Apache::loncommon::end_page(\%endargs));
1.1 albertel 735: return OK;
1.60 raeburn 736: }
737:
1.133 raeburn 738: sub check_loginvia {
1.158.2.8 raeburn 739: my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
740: if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
1.133 raeburn 741: return;
742: }
743: my %domconfhash = &Apache::loncommon::get_domainconf($domain);
744: my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
745: my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
746: my $output;
747: if ($loginvia ne '') {
748: my $noredirect;
749: my $ip = $ENV{'REMOTE_ADDR'};
750: if ($ip eq '127.0.0.1') {
751: $noredirect = 1;
752: } else {
753: if ($loginvia_exempt ne '') {
754: my @exempt = split(',',$loginvia_exempt);
755: if (grep(/^\Q$ip\E$/,@exempt)) {
756: $noredirect = 1;
757: }
758: }
759: }
760: unless ($noredirect) {
761: my ($newhost,$path);
762: if ($loginvia =~ /:/) {
763: ($newhost,$path) = split(':',$loginvia);
764: } else {
765: $newhost = $loginvia;
766: }
767: if ($newhost ne $lonhost) {
768: if (&Apache::lonnet::hostname($newhost) ne '') {
1.158.2.8 raeburn 769: if ($balcookie) {
770: my ($balancer,$cookie) = split(/:/,$balcookie);
771: if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
772: my ($udom,$uname,$cookieid) = ($1,$2,$3);
773: unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
774: if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
775: while (my $filename=readdir($dh)) {
776: if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
777: my $handle = $1;
778: my %hash =
779: &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
780: ['request.balancercookie',
781: 'user.linkedenv']);
782: if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
783: if (unlink("$lonidsdir/$filename")) {
784: if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
785: (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
786: (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
787: unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
788: }
789: }
790: }
791: last;
792: }
793: }
794: closedir($dh);
795: }
796: }
797: }
798: }
1.133 raeburn 799: $output = &redirect_page($newhost,$path);
800: }
801: }
802: }
803: }
804: return $output;
805: }
806:
1.126 raeburn 807: sub redirect_page {
1.133 raeburn 808: my ($desthost,$path) = @_;
1.158.2.8 raeburn 809: my $hostname = &Apache::lonnet::hostname($desthost);
1.126 raeburn 810: my $protocol = $Apache::lonnet::protocol{$desthost};
811: $protocol = 'http' if ($protocol ne 'https');
1.133 raeburn 812: unless ($path =~ m{^/}) {
813: $path = '/'.$path;
814: }
1.158.2.8 raeburn 815: my $url = $protocol.'://'.$hostname.$path;
1.126 raeburn 816: if ($env{'form.firsturl'} ne '') {
817: $url .='?firsturl='.$env{'form.firsturl'};
818: }
1.136 raeburn 819: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
1.126 raeburn 820: {'redirect' => [0,$url],});
821: my $end_page = &Apache::loncommon::end_page();
822: return $start_page.$end_page;
823: }
824:
1.60 raeburn 825: sub contactdisplay {
1.153 raeburn 826: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
827: $possdoms) = @_;
1.60 raeburn 828: my $contactblock;
1.153 raeburn 829: my $origmail;
830: if (ref($possdoms) eq 'ARRAY') {
831: if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
832: $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
833: }
834: }
835: my $requestmail =
836: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
837: $authdomain,$origmail);
1.154 raeburn 838: unless ($showhelpdesk eq '0') {
839: if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
840: $showhelpdesk = 1;
841: } else {
1.153 raeburn 842: $showhelpdesk = 0;
843: }
1.62 raeburn 844: }
1.90 raeburn 845: if ($servadm && $showadminmail) {
1.130 bisitz 846: $contactblock .= $$lt{'servadm'}.':<br />'.
847: '<tt>'.$servadm.'</tt><br />';
1.90 raeburn 848: }
1.60 raeburn 849: if ($showhelpdesk) {
1.114 tempelho 850: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
1.75 www 851: my $thisurl = &escape('/adm/login');
1.62 raeburn 852: $$helpdeskscript = <<"ENDSCRIPT";
853: <script type="text/javascript">
1.122 bisitz 854: // <![CDATA[
1.62 raeburn 855: function helpdesk() {
1.155 raeburn 856: var possdom = document.client.udom.value;
857: var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
1.62 raeburn 858: if (codedom == '') {
859: codedom = "$authdomain";
860: }
861: var querystr = "origurl=$thisurl&codedom="+codedom;
862: document.location.href = "/adm/helpdesk?"+querystr;
863: return;
864: }
1.122 bisitz 865: // ]]>
1.62 raeburn 866: </script>
867: ENDSCRIPT
1.60 raeburn 868: }
869: return $contactblock;
870: }
1.83 raeburn 871:
872: sub forgotpwdisplay {
1.84 raeburn 873: my (%lt) = @_;
1.83 raeburn 874: my $prompt_for_resetpw = 1;
875: if ($prompt_for_resetpw) {
1.107 tempelho 876: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
1.84 raeburn 877: }
878: return;
879: }
880:
1.90 raeburn 881: sub coursecatalog_link {
882: my ($linkname) = @_;
883: return <<"END";
1.137 bisitz 884: <a href="/adm/coursecatalog">$linkname</a>
1.90 raeburn 885: END
886: }
887:
1.101 raeburn 888: sub newuser_link {
889: my ($linkname) = @_;
1.130 bisitz 890: return '<a href="/adm/createaccount">'.$linkname.'</a>';
1.101 raeburn 891: }
892:
1.1 albertel 893: 1;
894: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>