1: # The LearningOnline Network
2: # Login Screen
3: #
4: # $Id: lonlogin.pm,v 1.158.2.12 2021/01/04 03:49:10 raeburn Exp $
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/';
40: use LONCAPA qw(:DEFAULT :match);
41: use CGI::Cookie();
42:
43: sub handler {
44: my $r = shift;
45:
46: &Apache::loncommon::get_unprocessed_cgi
47: (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
48: $ENV{'REDIRECT_QUERY_STRING'}),
49: ['interface','username','domain','firsturl','localpath','localres',
50: 'token','role','symb','iptoken','btoken']);
51: if (!defined($env{'form.firsturl'})) {
52: &Apache::lonacc::get_posted_cgi($r,['firsturl']);
53: }
54:
55: # -- check if they are a migrating user
56: if (defined($env{'form.token'})) {
57: return &Apache::migrateuser::handler($r);
58: }
59:
60: # For "public user" - remove any exising "public" cookie, as user really wants to log-in
61: my ($handle,$lonidsdir,$expirepub,$userdom);
62: $lonidsdir=$r->dir_config('lonIDsDir');
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:
75: &Apache::loncommon::no_cache($r);
76: &Apache::lonlocal::get_language_handle($r);
77: &Apache::loncommon::content_type($r,'text/html');
78: if ($expirepub) {
79: my $c = new CGI::Cookie(-name => 'lonPubID',
80: -value => '',
81: -expires => '-10y',);
82: $r->header_out('Set-cookie' => $c);
83: } elsif (($handle eq '') && ($userdom ne '')) {
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: }
92: }
93: $r->send_http_header;
94: return OK if $r->header_only;
95:
96:
97: # Are we re-routing?
98: my $londocroot = $r->dir_config('lonDocRoot');
99: if (-e "$londocroot/lon-status/reroute.txt") {
100: &Apache::lonauth::reroute($r);
101: return OK;
102: }
103:
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:
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:
166: $env{'form.firsturl'} =~ s/(`)/'/g;
167:
168: # -------------------------------- Prevent users from attempting to login twice
169: if ($handle ne '') {
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;
187: }
188:
189: # ---------------------------------------------------- No valid token, continue
190:
191: # ---------------------------- Not possible to really login to domain "public"
192: if ($env{'form.domain'} eq 'public') {
193: $env{'form.domain'}='';
194: $env{'form.username'}='';
195: }
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'});
201: unless ($sessiondata{'sessionserver'}) {
202: my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
203: delete($env{'form.iptoken'});
204: }
205: }
206: # ----------------------------------------------------------- Process Interface
207: $env{'form.interface'}=~s/\W//g;
208:
209: (undef,undef,undef,undef,undef,undef,my $clientmobile) =
210: &Apache::loncommon::decode_user_agent();
211:
212: my $iconpath=
213: &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
214:
215: my $domain = &Apache::lonnet::default_login_domain();
216: my $defdom = $domain;
217: if ($lonhost ne '') {
218: unless ($sessiondata{'sessionserver'}) {
219: my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);
220: if ($redirect) {
221: $r->print($redirect);
222: return OK;
223: }
224: }
225: }
226:
227: if (($sessiondata{'domain'}) &&
228: (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
229: $domain=$sessiondata{'domain'};
230: } elsif (($env{'form.domain'}) &&
231: (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
232: $domain=$env{'form.domain'};
233: }
234:
235: my $role = $r->dir_config('lonRole');
236: my $loadlim = $r->dir_config('lonLoadLim');
237: my $uloadlim= $r->dir_config('lonUserLoadLim');
238: my $servadm = $r->dir_config('lonAdmEMail');
239: my $tabdir = $r->dir_config('lonTabDir');
240: my $include = $r->dir_config('lonIncludes');
241: my $expire = $r->dir_config('lonExpire');
242: my $version = $r->dir_config('lonVersion');
243: my $host_name = &Apache::lonnet::hostname($lonhost);
244:
245: # --------------------------------------------- Default values for login fields
246:
247: my ($authusername,$authdomain);
248: if ($sessiondata{'username'}) {
249: $authusername=$sessiondata{'username'};
250: } else {
251: $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
252: $authusername=($env{'form.username'}?$env{'form.username'}:'');
253: }
254: if ($sessiondata{'domain'}) {
255: $authdomain=$sessiondata{'domain'};
256: } else {
257: $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
258: $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
259: }
260:
261: # ---------------------------------------------------------- Determine own load
262: my $loadavg;
263: {
264: my $loadfile=Apache::File->new('/proc/loadavg');
265: $loadavg=<$loadfile>;
266: }
267: $loadavg =~ s/\s.*//g;
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: }
276:
277: my $firsturl=
278: ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
279:
280: # ----------------------------------------------------------- Get announcements
281: my $announcements=&Apache::lonnet::getannounce();
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);
297: if ($lextkey>2147483647) { $lextkey-=4294967296; }
298:
299: my $uextkey=hex($ukey);
300: if ($uextkey>2147483647) { $uextkey-=4294967296; }
301:
302: # -------------------------------------------------------- Store away log token
303: my $tokenextras;
304: if ($env{'form.role'}) {
305: $tokenextras = '&role='.&escape($env{'form.role'});
306: }
307: if ($env{'form.symb'}) {
308: if (!$tokenextras) {
309: $tokenextras = '&';
310: }
311: $tokenextras .= '&symb='.&escape($env{'form.symb'});
312: }
313: if ($env{'form.iptoken'}) {
314: if (!$tokenextras) {
315: $tokenextras = '&&';
316: }
317: $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
318: }
319: my $logtoken=Apache::lonnet::reply(
320: 'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
321: $lonhost);
322:
323: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
324: # we are in serious trouble
325:
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: }
330: my $spares='';
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) {
350: next if ($hostid eq $lonhost);
351: my $hostname = &Apache::lonnet::hostname($hostid);
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.'://'.
357: $hostname.
358: '/adm/login?domain='.$authdomain.'">'.
359: $hostname.'</a>'.
360: ' '.&mt('(preferred)').'</span>'.$/;
361: }
362: if ($spares) {
363: $spares.= '<br />';
364: }
365: my %all_hostnames = &Apache::lonnet::all_hostnames();
366: foreach my $hostid (sort
367: {
368: &Apache::lonnet::hostname($a) cmp
369: &Apache::lonnet::hostname($b);
370: }
371: keys(%all_hostnames)) {
372: next if ($hostid eq $lonhost);
373: my $hostname = &Apache::lonnet::hostname($hostid);
374: next if (($hostname eq '') || ($spareservers{$hostname}));
375: $spareservers{$hostname} = 1;
376: my $protocol = $Apache::lonnet::protocol{$hostid};
377: $protocol = 'http' if ($protocol ne 'https');
378: $spares.='<br /><a href="'.$protocol.'://'.
379: $hostname.
380: '/adm/login?domain='.$authdomain.'">'.
381: $hostname.'</a>';
382: }
383: $r->print(
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>'
387: .&mt('The LearningOnline Network with CAPA')
388: .'</title></head>'
389: .'<body bgcolor="#FFFFFF">'
390: .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
391: .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
392: .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
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: }
403:
404: # ----------------------------------------------- Apparently we are in business
405: $servadm=~s/\,/\<br \/\>/g;
406:
407: # ----------------------------------------------------------- Front page design
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: }
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: }
433: my $showcoursecat =
434: &Apache::loncommon::designparm('login.coursecatalog',$domain);
435: my $shownewuserlink =
436: &Apache::loncommon::designparm('login.newuser',$domain);
437: my $showhelpdesk =
438: &Apache::loncommon::designparm('login.helpdesk',$domain);
439: my $now=time;
440: my $js = (<<ENDSCRIPT);
441:
442: <script type="text/javascript" language="JavaScript">
443: // <![CDATA[
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
457: =getCrypted(this.document.client.elements.upass$now.value);
458:
459: this.document.client.elements.uname.value='';
460: this.document.client.elements.upass$now.value='';
461:
462: this.document.server.submit();
463: return false;
464: }
465:
466: function enableInput() {
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");
470: return;
471: }
472:
473: // ]]>
474: </script>
475:
476: ENDSCRIPT
477:
478: # --------------------------------------------------- Print login screen header
479:
480: my %add_entries = (
481: bgcolor => "$mainbg",
482: text => "$font",
483: link => "$link",
484: vlink => "$vlink",
485: alink => "$alink",
486: onload => 'javascript:enableInput();',);
487:
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};
502: if ($headextra) {
503: my $omitextra;
504: if ($headextra_exempt ne '') {
505: my @exempt = split(',',$headextra_exempt);
506: my $ip = &Apache::lonnet::get_requestor_ip();
507: if (grep(/^\Q$ip\E$/,@exempt)) {
508: $omitextra = 1;
509: }
510: }
511: unless ($omitextra) {
512: my $confname = $defdom.'-domainconfig';
513: if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
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:
522: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
523: { 'redirect' => [$expire,'/adm/roles'],
524: 'add_entries' => \%add_entries,
525: 'only_body' => 1,}));
526:
527: # ----------------------------------------------------------------------- Texts
528:
529: my %lt=&Apache::lonlocal::texthash(
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: );
545: # -------------------------------------------------- Change password field name
546:
547: my $forgotpw = &forgotpwdisplay(%lt);
548: $forgotpw .= '<br />' if $forgotpw;
549: my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
550: if ($loginhelp) {
551: $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
552: }
553:
554: # ---------------------------------------------------- Serve out DES JavaScript
555: {
556: my $jsh=Apache::File->new($include."/londes.js");
557: $r->print(<$jsh>);
558: }
559: # ---------------------------------------------------------- Serve rest of page
560:
561: $r->print(
562: '<div class="LC_Box"'
563: .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
564: );
565:
566: $r->print(<<ENDSERVERFORM);
567: <form name="server" action="/adm/authenticate" method="post" target="_top">
568: <input type="hidden" name="logtoken" value="$logtoken" />
569: <input type="hidden" name="serverid" value="$lonhost" />
570: <input type="hidden" name="uname" value="" />
571: <input type="hidden" name="upass0" value="" />
572: <input type="hidden" name="udom" value="" />
573: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
574: <input type="hidden" name="localres" value="$env{'form.localres'}" />
575: </form>
576: ENDSERVERFORM
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,
597: $authdomain,\$helpdeskscript,
598: $showhelpdesk,\@possdoms);
599:
600: my $mobileargs;
601: if ($clientmobile) {
602: $mobileargs = 'autocapitalize="off" autocorrect="off"';
603: }
604: my $loginform=(<<LFORM);
605: <form name="client" action="" onsubmit="return(send())">
606: <input type="hidden" name="lextkey" value="$lextkey" />
607: <input type="hidden" name="uextkey" value="$uextkey" />
608: <b><label for="uname">$lt{'un'}</label>:</b><br />
609: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
610: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
611: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
612: <b><label for="udom">$lt{'dom'}</label>:</b><br />
613: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
614: <input type="submit" value="$lt{'log'}" />
615: </form>
616: LFORM
617:
618: if ($showbanner) {
619: $r->print(<<HEADER);
620: <!-- The LON-CAPA Header -->
621: <div style="background:$pgbg;margin:0;width:100%;">
622: <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
623: </div>
624: HEADER
625: }
626: $r->print(<<ENDTOP);
627: <div style="float:left;margin-top:0;">
628: <div class="LC_Box" style="background:$loginbox_bg;">
629: $logintitle
630: $loginform
631: $noscript_warning
632: </div>
633:
634: <div class="LC_Box" style="padding-top: 10px;">
635: $loginhelp
636: $forgotpw
637: $contactblock
638: $newuserlink
639: $coursecatalog
640: </div>
641: </div>
642:
643: <div>
644: ENDTOP
645: if ($showmainlogo) {
646: $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
647: }
648: $r->print(<<ENDTOP);
649: $announcements
650: </div>
651: <hr style="clear:both;" />
652: ENDTOP
653: my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
654: $domainrow = <<"END";
655: <tr>
656: <td align="left" valign="top">
657: <small><b>$lt{'dom'}: </b></small>
658: </td>
659: <td align="left" valign="top">
660: <small><tt> $domain</tt></small>
661: </td>
662: </tr>
663: END
664: $serverrow = <<"END";
665: <tr>
666: <td align="left" valign="top">
667: <small><b>$lt{'serv'}: </b></small>
668: </td>
669: <td align="left" valign="top">
670: <small><tt> $lonhost ($role)</tt></small>
671: </td>
672: </tr>
673: END
674: if ($loadlim) {
675: $loadrow = <<"END";
676: <tr>
677: <td align="left" valign="top">
678: <small><b>$lt{'load'}: </b></small>
679: </td>
680: <td align="left" valign="top">
681: <small><tt> $loadpercent $lt{'perc'}</tt></small>
682: </td>
683: </tr>
684: END
685: }
686: if ($uloadlim) {
687: $userloadrow = <<"END";
688: <tr>
689: <td align="left" valign="top">
690: <small><b>$lt{'userload'}: </b></small>
691: </td>
692: <td align="left" valign="top">
693: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
694: </td>
695: </tr>
696: END
697: }
698: if (($version ne '') && ($version ne '<!-- VERSION -->')) {
699: $versionrow = <<"END";
700: <tr>
701: <td colspan="2" align="left">
702: <small>$version</small>
703: </td>
704: </tr>
705: END
706: }
707:
708: $r->print(<<ENDDOCUMENT);
709: <div style="float: left;">
710: <table border="0" cellspacing="0" cellpadding="0">
711: $domainrow
712: $serverrow
713: $loadrow
714: $userloadrow
715: $versionrow
716: </table>
717: </div>
718: <div style="float: right;">
719: $domainlogo
720: </div>
721: <br style="clear:both;" />
722: </div>
723:
724: <script type="text/javascript">
725: // <![CDATA[
726: // the if prevents the script error if the browser can not handle this
727: if ( document.client.uname ) { document.client.uname.focus(); }
728: // ]]>
729: </script>
730: $helpdeskscript
731:
732: ENDDOCUMENT
733: my %endargs = ( 'noredirectlink' => 1, );
734: $r->print(&Apache::loncommon::end_page(\%endargs));
735: return OK;
736: }
737:
738: sub check_loginvia {
739: my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
740: if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
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 = &Apache::lonnet::get_requestor_ip();
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 '') {
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: }
799: $output = &redirect_page($newhost,$path);
800: }
801: }
802: }
803: }
804: return $output;
805: }
806:
807: sub redirect_page {
808: my ($desthost,$path) = @_;
809: my $hostname = &Apache::lonnet::hostname($desthost);
810: my $protocol = $Apache::lonnet::protocol{$desthost};
811: $protocol = 'http' if ($protocol ne 'https');
812: unless ($path =~ m{^/}) {
813: $path = '/'.$path;
814: }
815: my $url = $protocol.'://'.$hostname.$path;
816: if ($env{'form.firsturl'} ne '') {
817: $url .='?firsturl='.$env{'form.firsturl'};
818: }
819: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
820: {'redirect' => [0,$url],});
821: my $end_page = &Apache::loncommon::end_page();
822: return $start_page.$end_page;
823: }
824:
825: sub contactdisplay {
826: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
827: $possdoms) = @_;
828: my $contactblock;
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);
838: unless ($showhelpdesk eq '0') {
839: if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
840: $showhelpdesk = 1;
841: } else {
842: $showhelpdesk = 0;
843: }
844: }
845: if ($servadm && $showadminmail) {
846: $contactblock .= $$lt{'servadm'}.':<br />'.
847: '<tt>'.$servadm.'</tt><br />';
848: }
849: if ($showhelpdesk) {
850: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
851: my $thisurl = &escape('/adm/login');
852: $$helpdeskscript = <<"ENDSCRIPT";
853: <script type="text/javascript">
854: // <![CDATA[
855: function helpdesk() {
856: var possdom = document.client.udom.value;
857: var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
858: if (codedom == '') {
859: codedom = "$authdomain";
860: }
861: var querystr = "origurl=$thisurl&codedom="+codedom;
862: document.location.href = "/adm/helpdesk?"+querystr;
863: return;
864: }
865: // ]]>
866: </script>
867: ENDSCRIPT
868: }
869: return $contactblock;
870: }
871:
872: sub forgotpwdisplay {
873: my (%lt) = @_;
874: my $prompt_for_resetpw = 1;
875: if ($prompt_for_resetpw) {
876: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
877: }
878: return;
879: }
880:
881: sub coursecatalog_link {
882: my ($linkname) = @_;
883: return <<"END";
884: <a href="/adm/coursecatalog">$linkname</a>
885: END
886: }
887:
888: sub newuser_link {
889: my ($linkname) = @_;
890: return '<a href="/adm/createaccount">'.$linkname.'</a>';
891: }
892:
893: 1;
894: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>