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