Annotation of loncom/auth/lonlogin.pm, revision 1.158.2.10
1.1 albertel 1: # The LearningOnline Network
2: # Login Screen
1.11 www 3: #
1.158.2.10! raeburn 4: # $Id: lonlogin.pm,v 1.158.2.9 2019/08/04 12:18:44 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}));
! 375: my $protocol = $Apache::lonnet::protocol{$hostid};
! 376: $protocol = 'http' if ($protocol ne 'https');
! 377: $spares.='<br /><a href="'.$protocol.'://'.
1.151 raeburn 378: $hostname.
379: '/adm/login?domain='.$authdomain.'">'.
380: $hostname.'</a>';
381: }
382: $r->print(
1.158.2.10! raeburn 383: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
! 384: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
! 385: .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'
1.107 tempelho 386: .&mt('The LearningOnline Network with CAPA')
387: .'</title></head>'
388: .'<body bgcolor="#FFFFFF">'
389: .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
1.158.2.10! raeburn 390: .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
1.148 raeburn 391: .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
1.151 raeburn 392: if ($spares) {
393: $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
394: .'</p>'
395: .$spares);
396: }
397: $r->print('</body>'
398: .'</html>'
399: );
400: return OK;
401: }
1.31 www 402:
403: # ----------------------------------------------- Apparently we are in business
1.151 raeburn 404: $servadm=~s/\,/\<br \/\>/g;
1.38 www 405:
1.21 www 406: # ----------------------------------------------------------- Front page design
1.151 raeburn 407: my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
408: my $font=&Apache::loncommon::designparm('login.font',$domain);
409: my $link=&Apache::loncommon::designparm('login.link',$domain);
410: my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
411: my $alink=&Apache::loncommon::designparm('login.alink',$domain);
412: my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
413: my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
414: my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
415: my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
416: my $logo=&Apache::loncommon::designparm('login.logo',$domain);
417: my $img=&Apache::loncommon::designparm('login.img',$domain);
418: my $domainlogo=&Apache::loncommon::domainlogo($domain);
419: my $showbanner = 1;
420: my $showmainlogo = 1;
421: if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
422: $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
423: }
424: if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
425: $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
426: }
1.153 raeburn 427: my $showadminmail;
428: my @possdoms = &Apache::lonnet::current_machine_domains();
429: if (grep(/^\Q$domain\E$/,@possdoms)) {
430: $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
431: }
1.151 raeburn 432: my $showcoursecat =
433: &Apache::loncommon::designparm('login.coursecatalog',$domain);
434: my $shownewuserlink =
435: &Apache::loncommon::designparm('login.newuser',$domain);
1.153 raeburn 436: my $showhelpdesk =
437: &Apache::loncommon::designparm('login.helpdesk',$domain);
1.151 raeburn 438: my $now=time;
439: my $js = (<<ENDSCRIPT);
1.107 tempelho 440:
1.116 bisitz 441: <script type="text/javascript" language="JavaScript">
1.122 bisitz 442: // <![CDATA[
1.107 tempelho 443: function send()
444: {
445: this.document.server.elements.uname.value
446: =this.document.client.elements.uname.value;
447:
448: this.document.server.elements.udom.value
449: =this.document.client.elements.udom.value;
450:
451: uextkey=this.document.client.elements.uextkey.value;
452: lextkey=this.document.client.elements.lextkey.value;
453: initkeys();
454:
455: this.document.server.elements.upass0.value
1.158.2.5 raeburn 456: =getCrypted(this.document.client.elements.upass$now.value);
1.6 www 457:
1.107 tempelho 458: this.document.client.elements.uname.value='';
459: this.document.client.elements.upass$now.value='';
1.6 www 460:
1.107 tempelho 461: this.document.server.submit();
462: return false;
463: }
1.139 raeburn 464:
465: function enableInput() {
1.144 bisitz 466: this.document.client.elements.upass$now.removeAttribute("readOnly");
467: this.document.client.elements.uname.removeAttribute("readOnly");
468: this.document.client.elements.udom.removeAttribute("readOnly");
1.139 raeburn 469: return;
470: }
471:
1.122 bisitz 472: // ]]>
1.107 tempelho 473: </script>
1.98 raeburn 474:
1.16 www 475: ENDSCRIPT
1.6 www 476:
1.98 raeburn 477: # --------------------------------------------------- Print login screen header
478:
1.151 raeburn 479: my %add_entries = (
1.108 tempelho 480: bgcolor => "$mainbg",
1.107 tempelho 481: text => "$font",
482: link => "$link",
483: vlink => "$vlink",
1.139 raeburn 484: alink => "$alink",
485: onload => 'javascript:enableInput();',);
1.107 tempelho 486:
1.158.2.4 raeburn 487: my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
488: @hosts = &Apache::lonnet::current_machine_ids();
489: $lonhost_in_use = $lonhost;
490: if (@hosts > 1) {
491: foreach my $hostid (@hosts) {
492: if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
493: $lonhost_in_use = $hostid;
494: last;
495: }
496: }
497: }
498: %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
499: $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
500: $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
1.158.2.1 raeburn 501: if ($headextra) {
502: my $omitextra;
503: if ($headextra_exempt ne '') {
504: my @exempt = split(',',$headextra_exempt);
505: my $ip = $ENV{'REMOTE_ADDR'};
506: if (grep(/^\Q$ip\E$/,@exempt)) {
507: $omitextra = 1;
508: }
509: }
510: unless ($omitextra) {
511: my $confname = $defdom.'-domainconfig';
1.158.2.4 raeburn 512: if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
1.158.2.1 raeburn 513: my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
514: unless ($extra eq '-1') {
515: $js .= "\n".$extra."\n";
516: }
517: }
518: }
519: }
520:
1.151 raeburn 521: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
1.107 tempelho 522: { 'redirect' => [$expire,'/adm/roles'],
523: 'add_entries' => \%add_entries,
524: 'only_body' => 1,}));
1.98 raeburn 525:
526: # ----------------------------------------------------------------------- Texts
527:
1.151 raeburn 528: my %lt=&Apache::lonlocal::texthash(
1.129 bisitz 529: 'un' => 'Username',
530: 'pw' => 'Password',
531: 'dom' => 'Domain',
532: 'perc' => 'percent',
533: 'load' => 'Server Load',
534: 'userload' => 'User Load',
535: 'catalog' => 'Course/Community Catalog',
536: 'log' => 'Log in',
537: 'help' => 'Log-in Help',
538: 'serv' => 'Server',
539: 'servadm' => 'Server Administration',
540: 'helpdesk' => 'Contact Helpdesk',
541: 'forgotpw' => 'Forgot password?',
542: 'newuser' => 'New User?',
543: );
1.98 raeburn 544: # -------------------------------------------------- Change password field name
1.131 jms 545:
1.151 raeburn 546: my $forgotpw = &forgotpwdisplay(%lt);
547: $forgotpw .= '<br />' if $forgotpw;
1.152 raeburn 548: my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
549: if ($loginhelp) {
550: $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
551: }
1.98 raeburn 552:
553: # ---------------------------------------------------- Serve out DES JavaScript
1.151 raeburn 554: {
555: my $jsh=Apache::File->new($include."/londes.js");
556: $r->print(<$jsh>);
557: }
1.98 raeburn 558: # ---------------------------------------------------------- Serve rest of page
559:
1.151 raeburn 560: $r->print(
1.137 bisitz 561: '<div class="LC_Box"'
562: .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
563: );
1.6 www 564:
1.151 raeburn 565: $r->print(<<ENDSERVERFORM);
1.140 raeburn 566: <form name="server" action="/adm/authenticate" method="post" target="_top">
1.33 www 567: <input type="hidden" name="logtoken" value="$logtoken" />
568: <input type="hidden" name="serverid" value="$lonhost" />
569: <input type="hidden" name="uname" value="" />
1.65 www 570: <input type="hidden" name="upass0" value="" />
1.33 www 571: <input type="hidden" name="udom" value="" />
1.63 albertel 572: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
573: <input type="hidden" name="localres" value="$env{'form.localres'}" />
1.14 albertel 574: </form>
1.16 www 575: ENDSERVERFORM
1.151 raeburn 576: my $coursecatalog;
577: if (($showcoursecat eq '') || ($showcoursecat)) {
578: $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
579: }
580: my $newuserlink;
581: if ($shownewuserlink) {
582: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
583: }
584: my $logintitle =
585: '<h2 class="LC_hcell"'
586: .' style="background:'.$loginbox_header_bgcol.';'
587: .' color:'.$loginbox_header_textcol.'">'
588: .$lt{'log'}
589: .'</h2>';
590:
591: my $noscript_warning='<noscript><span class="LC_warning"><b>'
592: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
593: .'</b></span></noscript>';
594: my $helpdeskscript;
595: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
1.153 raeburn 596: $authdomain,\$helpdeskscript,
597: $showhelpdesk,\@possdoms);
1.107 tempelho 598:
1.156 raeburn 599: my $mobileargs;
600: if ($clientmobile) {
601: $mobileargs = 'autocapitalize="off" autocorrect="off"';
602: }
1.151 raeburn 603: my $loginform=(<<LFORM);
1.122 bisitz 604: <form name="client" action="" onsubmit="return(send())">
1.115 bisitz 605: <input type="hidden" name="lextkey" value="$lextkey" />
606: <input type="hidden" name="uextkey" value="$uextkey" />
1.108 tempelho 607: <b><label for="uname">$lt{'un'}</label>:</b><br />
1.156 raeburn 608: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
1.108 tempelho 609: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
1.139 raeburn 610: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
1.108 tempelho 611: <b><label for="udom">$lt{'dom'}</label>:</b><br />
1.156 raeburn 612: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
1.108 tempelho 613: <input type="submit" value="$lt{'log'}" />
614: </form>
615: LFORM
616:
1.109 raeburn 617: if ($showbanner) {
618: $r->print(<<HEADER);
619: <!-- The LON-CAPA Header -->
1.132 bisitz 620: <div style="background:$pgbg;margin:0;width:100%;">
1.158.2.6 raeburn 621: <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
1.132 bisitz 622: </div>
1.109 raeburn 623: HEADER
624: }
625: $r->print(<<ENDTOP);
1.146 bisitz 626: <div style="float:left;margin-top:0;">
1.137 bisitz 627: <div class="LC_Box" style="background:$loginbox_bg;">
1.112 muellerd 628: $logintitle
1.137 bisitz 629: $loginform
630: $noscript_warning
1.108 tempelho 631: </div>
1.107 tempelho 632:
1.137 bisitz 633: <div class="LC_Box" style="padding-top: 10px;">
1.132 bisitz 634: $loginhelp
635: $forgotpw
636: $contactblock
637: $newuserlink
1.130 bisitz 638: $coursecatalog
1.107 tempelho 639: </div>
1.118 tempelho 640: </div>
1.137 bisitz 641:
642: <div>
1.118 tempelho 643: ENDTOP
644: if ($showmainlogo) {
1.158.2.6 raeburn 645: $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
1.118 tempelho 646: }
647: $r->print(<<ENDTOP);
648: $announcements
1.137 bisitz 649: </div>
650: <hr style="clear:both;" />
1.108 tempelho 651: ENDTOP
1.147 raeburn 652: my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
653: $domainrow = <<"END";
1.14 albertel 654: <tr>
1.110 muellerd 655: <td align="left" valign="top">
1.132 bisitz 656: <small><b>$lt{'dom'}: </b></small>
1.14 albertel 657: </td>
1.110 muellerd 658: <td align="left" valign="top">
1.14 albertel 659: <small><tt> $domain</tt></small>
660: </td>
661: </tr>
1.147 raeburn 662: END
663: $serverrow = <<"END";
1.14 albertel 664: <tr>
1.110 muellerd 665: <td align="left" valign="top">
1.132 bisitz 666: <small><b>$lt{'serv'}: </b></small>
1.14 albertel 667: </td>
1.110 muellerd 668: <td align="left" valign="top">
1.14 albertel 669: <small><tt> $lonhost ($role)</tt></small>
670: </td>
671: </tr>
1.147 raeburn 672: END
673: if ($loadlim) {
674: $loadrow = <<"END";
1.14 albertel 675: <tr>
1.110 muellerd 676: <td align="left" valign="top">
1.132 bisitz 677: <small><b>$lt{'load'}: </b></small>
1.14 albertel 678: </td>
1.110 muellerd 679: <td align="left" valign="top">
1.51 www 680: <small><tt> $loadpercent $lt{'perc'}</tt></small>
1.42 albertel 681: </td>
682: </tr>
1.147 raeburn 683: END
684: }
685: if ($uloadlim) {
686: $userloadrow = <<"END";
1.42 albertel 687: <tr>
1.110 muellerd 688: <td align="left" valign="top">
1.132 bisitz 689: <small><b>$lt{'userload'}: </b></small>
1.42 albertel 690: </td>
1.110 muellerd 691: <td align="left" valign="top">
1.51 www 692: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
1.14 albertel 693: </td>
694: </tr>
1.147 raeburn 695: END
696: }
697: if (($version ne '') && ($version ne '<!-- VERSION -->')) {
698: $versionrow = <<"END";
1.132 bisitz 699: <tr>
700: <td colspan="2" align="left">
701: <small>$version</small>
702: </td>
703: </tr>
1.147 raeburn 704: END
705: }
706:
1.151 raeburn 707: $r->print(<<ENDDOCUMENT);
1.147 raeburn 708: <div style="float: left;">
709: <table border="0" cellspacing="0" cellpadding="0">
710: $domainrow
711: $serverrow
712: $loadrow
713: $userloadrow
714: $versionrow
1.14 albertel 715: </table>
1.141 raeburn 716: </div>
717: <div style="float: right;">
718: $domainlogo
719: </div>
720: <br style="clear:both;" />
1.107 tempelho 721: </div>
1.25 bowersj2 722:
1.59 albertel 723: <script type="text/javascript">
1.122 bisitz 724: // <![CDATA[
1.59 albertel 725: // the if prevents the script error if the browser can not handle this
1.25 bowersj2 726: if ( document.client.uname ) { document.client.uname.focus(); }
1.122 bisitz 727: // ]]>
1.25 bowersj2 728: </script>
1.62 raeburn 729: $helpdeskscript
1.14 albertel 730:
1.1 albertel 731: ENDDOCUMENT
1.98 raeburn 732: my %endargs = ( 'noredirectlink' => 1, );
733: $r->print(&Apache::loncommon::end_page(\%endargs));
1.1 albertel 734: return OK;
1.60 raeburn 735: }
736:
1.133 raeburn 737: sub check_loginvia {
1.158.2.8 raeburn 738: my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
739: if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
1.133 raeburn 740: return;
741: }
742: my %domconfhash = &Apache::loncommon::get_domainconf($domain);
743: my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
744: my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
745: my $output;
746: if ($loginvia ne '') {
747: my $noredirect;
748: my $ip = $ENV{'REMOTE_ADDR'};
749: if ($ip eq '127.0.0.1') {
750: $noredirect = 1;
751: } else {
752: if ($loginvia_exempt ne '') {
753: my @exempt = split(',',$loginvia_exempt);
754: if (grep(/^\Q$ip\E$/,@exempt)) {
755: $noredirect = 1;
756: }
757: }
758: }
759: unless ($noredirect) {
760: my ($newhost,$path);
761: if ($loginvia =~ /:/) {
762: ($newhost,$path) = split(':',$loginvia);
763: } else {
764: $newhost = $loginvia;
765: }
766: if ($newhost ne $lonhost) {
767: if (&Apache::lonnet::hostname($newhost) ne '') {
1.158.2.8 raeburn 768: if ($balcookie) {
769: my ($balancer,$cookie) = split(/:/,$balcookie);
770: if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
771: my ($udom,$uname,$cookieid) = ($1,$2,$3);
772: unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
773: if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
774: while (my $filename=readdir($dh)) {
775: if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
776: my $handle = $1;
777: my %hash =
778: &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
779: ['request.balancercookie',
780: 'user.linkedenv']);
781: if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
782: if (unlink("$lonidsdir/$filename")) {
783: if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
784: (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
785: (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
786: unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
787: }
788: }
789: }
790: last;
791: }
792: }
793: closedir($dh);
794: }
795: }
796: }
797: }
1.133 raeburn 798: $output = &redirect_page($newhost,$path);
799: }
800: }
801: }
802: }
803: return $output;
804: }
805:
1.126 raeburn 806: sub redirect_page {
1.133 raeburn 807: my ($desthost,$path) = @_;
1.158.2.8 raeburn 808: my $hostname = &Apache::lonnet::hostname($desthost);
1.126 raeburn 809: my $protocol = $Apache::lonnet::protocol{$desthost};
810: $protocol = 'http' if ($protocol ne 'https');
1.133 raeburn 811: unless ($path =~ m{^/}) {
812: $path = '/'.$path;
813: }
1.158.2.8 raeburn 814: my $url = $protocol.'://'.$hostname.$path;
1.126 raeburn 815: if ($env{'form.firsturl'} ne '') {
816: $url .='?firsturl='.$env{'form.firsturl'};
817: }
1.136 raeburn 818: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
1.126 raeburn 819: {'redirect' => [0,$url],});
820: my $end_page = &Apache::loncommon::end_page();
821: return $start_page.$end_page;
822: }
823:
1.60 raeburn 824: sub contactdisplay {
1.153 raeburn 825: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
826: $possdoms) = @_;
1.60 raeburn 827: my $contactblock;
1.153 raeburn 828: my $origmail;
829: if (ref($possdoms) eq 'ARRAY') {
830: if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
831: $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
832: }
833: }
834: my $requestmail =
835: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
836: $authdomain,$origmail);
1.154 raeburn 837: unless ($showhelpdesk eq '0') {
838: if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
839: $showhelpdesk = 1;
840: } else {
1.153 raeburn 841: $showhelpdesk = 0;
842: }
1.62 raeburn 843: }
1.90 raeburn 844: if ($servadm && $showadminmail) {
1.130 bisitz 845: $contactblock .= $$lt{'servadm'}.':<br />'.
846: '<tt>'.$servadm.'</tt><br />';
1.90 raeburn 847: }
1.60 raeburn 848: if ($showhelpdesk) {
1.114 tempelho 849: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
1.75 www 850: my $thisurl = &escape('/adm/login');
1.62 raeburn 851: $$helpdeskscript = <<"ENDSCRIPT";
852: <script type="text/javascript">
1.122 bisitz 853: // <![CDATA[
1.62 raeburn 854: function helpdesk() {
1.155 raeburn 855: var possdom = document.client.udom.value;
856: var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
1.62 raeburn 857: if (codedom == '') {
858: codedom = "$authdomain";
859: }
860: var querystr = "origurl=$thisurl&codedom="+codedom;
861: document.location.href = "/adm/helpdesk?"+querystr;
862: return;
863: }
1.122 bisitz 864: // ]]>
1.62 raeburn 865: </script>
866: ENDSCRIPT
1.60 raeburn 867: }
868: return $contactblock;
869: }
1.83 raeburn 870:
871: sub forgotpwdisplay {
1.84 raeburn 872: my (%lt) = @_;
1.83 raeburn 873: my $prompt_for_resetpw = 1;
874: if ($prompt_for_resetpw) {
1.107 tempelho 875: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
1.84 raeburn 876: }
877: return;
878: }
879:
1.90 raeburn 880: sub coursecatalog_link {
881: my ($linkname) = @_;
882: return <<"END";
1.137 bisitz 883: <a href="/adm/coursecatalog">$linkname</a>
1.90 raeburn 884: END
885: }
886:
1.101 raeburn 887: sub newuser_link {
888: my ($linkname) = @_;
1.130 bisitz 889: return '<a href="/adm/createaccount">'.$linkname.'</a>';
1.101 raeburn 890: }
891:
1.1 albertel 892: 1;
893: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>