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