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