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