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