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