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