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