Annotation of loncom/auth/lonlogin.pm, revision 1.161
1.160 kruse 1: # The LearningOnline Network
2: # Login Screen
3: #
1.161 ! raeburn 4: # $Id: lonlogin.pm,v 1.160 2014/12/05 12:03:20 kruse Exp $
1.160 kruse 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::lonlogin;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::File ();
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonauth();
37: use Apache::lonlocal;
38: use Apache::migrateuser();
39: use lib '/home/httpd/lib/perl/';
40: use LONCAPA;
41:
42: sub handler {
43: my $r = shift;
44:
45: &Apache::loncommon::get_unprocessed_cgi
46: (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
47: $ENV{'REDIRECT_QUERY_STRING'}),
48: ['interface','username','domain','firsturl','localpath','localres',
49: 'token','role','symb','iptoken']);
50: if (!defined($env{'form.firsturl'})) {
51: &Apache::lonacc::get_posted_cgi($r,['firsturl']);
52: }
53:
54: # -- check if they are a migrating user
55: if (defined($env{'form.token'})) {
56: return &Apache::migrateuser::handler($r);
57: }
58:
59: &Apache::loncommon::no_cache($r);
60: &Apache::lonlocal::get_language_handle($r);
61: &Apache::loncommon::content_type($r,'text/html');
62: $r->send_http_header;
63: return OK if $r->header_only;
64:
65:
66: # Are we re-routing?
67: my $londocroot = $r->dir_config('lonDocRoot');
68: if (-e "$londocroot/lon-status/reroute.txt") {
69: &Apache::lonauth::reroute($r);
70: return OK;
71: }
72:
73: $env{'form.firsturl'} =~ s/(`)/'/g;
74:
75: # -------------------------------- Prevent users from attempting to login twice
76: my $handle = &Apache::lonnet::check_for_valid_session($r);
77: if ($handle ne '') {
78: my $lonidsdir=$r->dir_config('lonIDsDir');
79: if ($handle=~/^publicuser\_/) {
80: # For "public user" - remove it, we apparently really want to login
81: unlink($r->dir_config('lonIDsDir')."/$handle.id");
82: } else {
83: # Indeed, a valid token is found
84: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
85: my $start_page =
86: &Apache::loncommon::start_page('Already logged in');
87: my $end_page =
88: &Apache::loncommon::end_page();
89: my $dest = '/adm/roles';
90: if ($env{'form.firsturl'} ne '') {
91: $dest = $env{'form.firsturl'};
92: }
93: $r->print(
94: $start_page
95: .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
96: .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
97: '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
98: .$end_page
99: );
100: return OK;
101: }
102: }
103:
104: # ---------------------------------------------------- No valid token, continue
105:
106: # ---------------------------- Not possible to really login to domain "public"
107: if ($env{'form.domain'} eq 'public') {
108: $env{'form.domain'}='';
109: $env{'form.username'}='';
110: }
111:
112: # ------ Is this page requested because /adm/migrateuser detected an IP change?
113: my %sessiondata;
114: if ($env{'form.iptoken'}) {
115: %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
116: my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
117: }
118: # ----------------------------------------------------------- Process Interface
119: $env{'form.interface'}=~s/\W//g;
120:
121: (undef,undef,undef,undef,undef,undef,my $clientmobile) =
122: &Apache::loncommon::decode_user_agent();
123:
124: my $iconpath=
125: &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
126:
127: my $lonhost = $r->dir_config('lonHostID');
128: my $domain = &Apache::lonnet::default_login_domain();
1.161 ! raeburn 129: my $defdom = $domain;
1.160 kruse 130: if ($lonhost ne '') {
131: unless ($sessiondata{'sessionserver'}) {
132: my $redirect = &check_loginvia($domain,$lonhost);
133: if ($redirect) {
134: $r->print($redirect);
135: return OK;
136: }
137: }
138: }
139:
140: if (($sessiondata{'domain'}) &&
141: (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
142: $domain=$sessiondata{'domain'};
143: } elsif (($env{'form.domain'}) &&
144: (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
145: $domain=$env{'form.domain'};
146: }
147:
148: my $role = $r->dir_config('lonRole');
149: my $loadlim = $r->dir_config('lonLoadLim');
150: my $uloadlim= $r->dir_config('lonUserLoadLim');
151: my $servadm = $r->dir_config('lonAdmEMail');
152: my $tabdir = $r->dir_config('lonTabDir');
153: my $include = $r->dir_config('lonIncludes');
154: my $expire = $r->dir_config('lonExpire');
155: my $version = $r->dir_config('lonVersion');
156: my $host_name = &Apache::lonnet::hostname($lonhost);
157:
158: # --------------------------------------------- Default values for login fields
159:
160: my ($authusername,$authdomain);
161: if ($sessiondata{'username'}) {
162: $authusername=$sessiondata{'username'};
163: } else {
164: $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
165: $authusername=($env{'form.username'}?$env{'form.username'}:'');
166: }
167: if ($sessiondata{'domain'}) {
168: $authdomain=$sessiondata{'domain'};
169: } else {
170: $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
171: $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
172: }
173:
174: # ---------------------------------------------------------- Determine own load
175: my $loadavg;
176: {
177: my $loadfile=Apache::File->new('/proc/loadavg');
178: $loadavg=<$loadfile>;
179: }
180: $loadavg =~ s/\s.*//g;
181:
182: my ($loadpercent,$userloadpercent);
183: if ($loadlim) {
184: $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
185: }
186: if ($uloadlim) {
187: $userloadpercent=&Apache::lonnet::userload();
188: }
189:
190: my $firsturl=
191: ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
192:
193: # ----------------------------------------------------------- Get announcements
194: my $announcements=&Apache::lonnet::getannounce();
195: # -------------------------------------------------------- Set login parameters
196:
197: my @hexstr=('0','1','2','3','4','5','6','7',
198: '8','9','a','b','c','d','e','f');
199: my $lkey='';
200: for (0..7) {
201: $lkey.=$hexstr[rand(15)];
202: }
203:
204: my $ukey='';
205: for (0..7) {
206: $ukey.=$hexstr[rand(15)];
207: }
208:
209: my $lextkey=hex($lkey);
210: if ($lextkey>2147483647) { $lextkey-=4294967296; }
211:
212: my $uextkey=hex($ukey);
213: if ($uextkey>2147483647) { $uextkey-=4294967296; }
214:
215: # -------------------------------------------------------- Store away log token
216: my $tokenextras;
217: if ($env{'form.role'}) {
218: $tokenextras = '&role='.&escape($env{'form.role'});
219: }
220: if ($env{'form.symb'}) {
221: if (!$tokenextras) {
222: $tokenextras = '&';
223: }
224: $tokenextras .= '&symb='.&escape($env{'form.symb'});
225: }
226: my $logtoken=Apache::lonnet::reply(
227: 'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
228: $lonhost);
229:
230: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
231: # we are in serious trouble
232:
233: if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
234: if ($logtoken eq 'no_such_host') {
235: &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
236: }
237: my $spares='';
238: my $last;
239: foreach my $hostid (sort
240: {
241: &Apache::lonnet::hostname($a) cmp
242: &Apache::lonnet::hostname($b);
243: }
244: keys(%Apache::lonnet::spareid)) {
245: next if ($hostid eq $lonhost);
246: my $hostname = &Apache::lonnet::hostname($hostid);
247: next if (($last eq $hostname) || ($hostname eq ''));
248: $spares.='<br /><font size="+1"><a href="http://'.
249: $hostname.
250: '/adm/login?domain='.$authdomain.'">'.
251: $hostname.'</a>'.
252: ' '.&mt('(preferred)').'</font>'.$/;
253: $last=$hostname;
254: }
255: if ($spares) {
256: $spares.= '<br />';
257: }
258: my %all_hostnames = &Apache::lonnet::all_hostnames();
259: foreach my $hostid (sort
260: {
261: &Apache::lonnet::hostname($a) cmp
262: &Apache::lonnet::hostname($b);
263: }
264: keys(%all_hostnames)) {
265: next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
266: my $hostname = &Apache::lonnet::hostname($hostid);
267: next if (($last eq $hostname) || ($hostname eq ''));
268: $spares.='<br /><a href="http://'.
269: $hostname.
270: '/adm/login?domain='.$authdomain.'">'.
271: $hostname.'</a>';
272: $last=$hostname;
273: }
274: $r->print(
275: '<html>'
276: .'<head><title>'
277: .&mt('The LearningOnline Network with CAPA')
278: .'</title></head>'
279: .'<body bgcolor="#FFFFFF">'
280: .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
281: .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
282: .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
283: if ($spares) {
284: $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
285: .'</p>'
286: .$spares);
287: }
288: $r->print('</body>'
289: .'</html>'
290: );
291: return OK;
292: }
293:
294: # ----------------------------------------------- Apparently we are in business
295: $servadm=~s/\,/\<br \/\>/g;
296:
297: # ----------------------------------------------------------- Front page design
298: my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
299: my $font=&Apache::loncommon::designparm('login.font',$domain);
300: my $link=&Apache::loncommon::designparm('login.link',$domain);
301: my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
302: my $alink=&Apache::loncommon::designparm('login.alink',$domain);
303: my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
304: my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
305: my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
306: my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
307: my $logo=&Apache::loncommon::designparm('login.logo',$domain);
308: my $img=&Apache::loncommon::designparm('login.img',$domain);
309: my $domainlogo=&Apache::loncommon::domainlogo($domain);
310: my $showbanner = 1;
311: my $showmainlogo = 1;
312: if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
313: $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
314: }
315: if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
316: $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
317: }
318: my $showadminmail;
319: my @possdoms = &Apache::lonnet::current_machine_domains();
320: if (grep(/^\Q$domain\E$/,@possdoms)) {
321: $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
322: }
323: my $showcoursecat =
324: &Apache::loncommon::designparm('login.coursecatalog',$domain);
325: my $shownewuserlink =
326: &Apache::loncommon::designparm('login.newuser',$domain);
327: my $showhelpdesk =
328: &Apache::loncommon::designparm('login.helpdesk',$domain);
329: my $now=time;
330: my $js = (<<ENDSCRIPT);
331:
332: <script type="text/javascript" language="JavaScript">
333: // <![CDATA[
334: function send()
335: {
336: this.document.server.elements.uname.value
337: =this.document.client.elements.uname.value;
338:
339: this.document.server.elements.udom.value
340: =this.document.client.elements.udom.value;
341:
342: uextkey=this.document.client.elements.uextkey.value;
343: lextkey=this.document.client.elements.lextkey.value;
344: initkeys();
345:
346: this.document.server.elements.upass0.value
347: =this.document.client.elements.upass$now.value.substr(0,15);
348: this.document.server.elements.upass1.value
349: =this.document.client.elements.upass$now.value.substr(15,15);
350: this.document.server.elements.upass2.value
351: =this.document.client.elements.upass$now.value.substr(30,15);
352:
353: if(this.document.server.action.substr(0,5) === 'http:'){
354: for (var idx in [1,2,3]){
355: this.document.server.elements['upass' + idx].value =
356: crypted(this.document.server.elements['upass' + idx].value);
357: }
358: }
359:
360: this.document.client.elements.uname.value='';
361: this.document.client.elements.upass$now.value='';
362:
363: this.document.server.submit();
364: return false;
365: }
366:
367: function enableInput() {
368: this.document.client.elements.upass$now.removeAttribute("readOnly");
369: this.document.client.elements.uname.removeAttribute("readOnly");
370: this.document.client.elements.udom.removeAttribute("readOnly");
371: return;
372: }
373:
374: // ]]>
375: </script>
376:
377: ENDSCRIPT
378:
379: # --------------------------------------------------- Print login screen header
380:
381: my %add_entries = (
382: bgcolor => "$mainbg",
383: text => "$font",
384: link => "$link",
385: vlink => "$vlink",
386: alink => "$alink",
387: onload => 'javascript:enableInput();',);
388:
1.161 ! raeburn 389: my %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
! 390: my $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost};
! 391: my $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost};
! 392: if ($headextra) {
! 393: my $omitextra;
! 394: if ($headextra_exempt ne '') {
! 395: my @exempt = split(',',$headextra_exempt);
! 396: my $ip = $ENV{'REMOTE_ADDR'};
! 397: if (grep(/^\Q$ip\E$/,@exempt)) {
! 398: $omitextra = 1;
! 399: }
! 400: }
! 401: unless ($omitextra) {
! 402: my $confname = $defdom.'-domainconfig';
! 403: if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost/\E}) {
! 404: my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
! 405: unless ($extra eq '-1') {
! 406: $js .= "\n".$extra."\n";
! 407: }
! 408: }
! 409: }
! 410: }
! 411:
1.160 kruse 412: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
413: { 'redirect' => [$expire,'/adm/roles'],
414: 'add_entries' => \%add_entries,
415: 'only_body' => 1,}));
416:
417: # ----------------------------------------------------------------------- Texts
418:
419: my %lt=&Apache::lonlocal::texthash(
420: 'un' => 'Username',
421: 'pw' => 'Password',
422: 'dom' => 'Domain',
423: 'perc' => 'percent',
424: 'load' => 'Server Load',
425: 'userload' => 'User Load',
426: 'catalog' => 'Course/Community Catalog',
427: 'log' => 'Log in',
428: 'help' => 'Log-in Help',
429: 'serv' => 'Server',
430: 'servadm' => 'Server Administration',
431: 'helpdesk' => 'Contact Helpdesk',
432: 'forgotpw' => 'Forgot password?',
433: 'newuser' => 'New User?',
434: );
435: # -------------------------------------------------- Change password field name
436:
437: my $forgotpw = &forgotpwdisplay(%lt);
438: $forgotpw .= '<br />' if $forgotpw;
439: my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
440: if ($loginhelp) {
441: $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
442: }
443:
444: # ---------------------------------------------------- Serve out DES JavaScript
445: {
446: my $jsh=Apache::File->new($include."/londes.js");
447: $r->print(<$jsh>);
448: }
449: # ---------------------------------------------------------- Serve rest of page
450:
451: $r->print(
452: '<div class="LC_Box"'
453: .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
454: );
455:
456: $r->print(<<ENDSERVERFORM);
457: <form name="server" action="/adm/authenticate" method="post" target="_top">
458: <input type="hidden" name="logtoken" value="$logtoken" />
459: <input type="hidden" name="serverid" value="$lonhost" />
460: <input type="hidden" name="uname" value="" />
461: <input type="hidden" name="upass0" value="" />
462: <input type="hidden" name="upass1" value="" />
463: <input type="hidden" name="upass2" value="" />
464: <input type="hidden" name="udom" value="" />
465: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
466: <input type="hidden" name="localres" value="$env{'form.localres'}" />
467: </form>
468: ENDSERVERFORM
469: my $coursecatalog;
470: if (($showcoursecat eq '') || ($showcoursecat)) {
471: $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
472: }
473: my $newuserlink;
474: if ($shownewuserlink) {
475: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
476: }
477: my $logintitle =
478: '<h2 class="LC_hcell"'
479: .' style="background:'.$loginbox_header_bgcol.';'
480: .' color:'.$loginbox_header_textcol.'">'
481: .$lt{'log'}
482: .'</h2>';
483:
484: my $noscript_warning='<noscript><span class="LC_warning"><b>'
485: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
486: .'</b></span></noscript>';
487: my $helpdeskscript;
488: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
489: $authdomain,\$helpdeskscript,
490: $showhelpdesk,\@possdoms);
491:
492: my $mobileargs;
493: if ($clientmobile) {
494: $mobileargs = 'autocapitalize="off" autocorrect="off"';
495: }
496: my $loginform=(<<LFORM);
497: <form name="client" action="" onsubmit="return(send())">
498: <input type="hidden" name="lextkey" value="$lextkey" />
499: <input type="hidden" name="uextkey" value="$uextkey" />
500: <b><label for="uname">$lt{'un'}</label>:</b><br />
501: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
502: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
503: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
504: <b><label for="udom">$lt{'dom'}</label>:</b><br />
505: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
506: <input type="submit" value="$lt{'log'}" />
507: </form>
508: LFORM
509:
510: if ($showbanner) {
511: $r->print(<<HEADER);
512: <!-- The LON-CAPA Header -->
513: <div style="background:$pgbg;margin:0;width:100%;">
514: <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
515: </div>
516: HEADER
517: }
518: $r->print(<<ENDTOP);
519: <div style="float:left;margin-top:0;">
520: <div class="LC_Box" style="background:$loginbox_bg;">
521: $logintitle
522: $loginform
523: $noscript_warning
524: </div>
525:
526: <div class="LC_Box" style="padding-top: 10px;">
527: $loginhelp
528: $forgotpw
529: $contactblock
530: $newuserlink
531: $coursecatalog
532: </div>
533: </div>
534:
535: <div>
536: ENDTOP
537: if ($showmainlogo) {
538: $r->print(' <img src="'.$logo.'" alt="" />'."\n");
539: }
540: $r->print(<<ENDTOP);
541: $announcements
542: </div>
543: <hr style="clear:both;" />
544: ENDTOP
545: my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
546: $domainrow = <<"END";
547: <tr>
548: <td align="left" valign="top">
549: <small><b>$lt{'dom'}: </b></small>
550: </td>
551: <td align="left" valign="top">
552: <small><tt> $domain</tt></small>
553: </td>
554: </tr>
555: END
556: $serverrow = <<"END";
557: <tr>
558: <td align="left" valign="top">
559: <small><b>$lt{'serv'}: </b></small>
560: </td>
561: <td align="left" valign="top">
562: <small><tt> $lonhost ($role)</tt></small>
563: </td>
564: </tr>
565: END
566: if ($loadlim) {
567: $loadrow = <<"END";
568: <tr>
569: <td align="left" valign="top">
570: <small><b>$lt{'load'}: </b></small>
571: </td>
572: <td align="left" valign="top">
573: <small><tt> $loadpercent $lt{'perc'}</tt></small>
574: </td>
575: </tr>
576: END
577: }
578: if ($uloadlim) {
579: $userloadrow = <<"END";
580: <tr>
581: <td align="left" valign="top">
582: <small><b>$lt{'userload'}: </b></small>
583: </td>
584: <td align="left" valign="top">
585: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
586: </td>
587: </tr>
588: END
589: }
590: if (($version ne '') && ($version ne '<!-- VERSION -->')) {
591: $versionrow = <<"END";
592: <tr>
593: <td colspan="2" align="left">
594: <small>$version</small>
595: </td>
596: </tr>
597: END
598: }
599:
600: $r->print(<<ENDDOCUMENT);
601: <div style="float: left;">
602: <table border="0" cellspacing="0" cellpadding="0">
603: $domainrow
604: $serverrow
605: $loadrow
606: $userloadrow
607: $versionrow
608: </table>
609: </div>
610: <div style="float: right;">
611: $domainlogo
612: </div>
613: <br style="clear:both;" />
614: </div>
615:
616: <script type="text/javascript">
617: // <![CDATA[
618: // the if prevents the script error if the browser can not handle this
619: if ( document.client.uname ) { document.client.uname.focus(); }
620: // ]]>
621: </script>
622: $helpdeskscript
623:
624: ENDDOCUMENT
625: my %endargs = ( 'noredirectlink' => 1, );
626: $r->print(&Apache::loncommon::end_page(\%endargs));
627: return OK;
628: }
629:
630: sub check_loginvia {
631: my ($domain,$lonhost) = @_;
632: if ($domain eq '' || $lonhost eq '') {
633: return;
634: }
635: my %domconfhash = &Apache::loncommon::get_domainconf($domain);
636: my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
637: my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
638: my $output;
639: if ($loginvia ne '') {
640: my $noredirect;
641: my $ip = $ENV{'REMOTE_ADDR'};
642: if ($ip eq '127.0.0.1') {
643: $noredirect = 1;
644: } else {
645: if ($loginvia_exempt ne '') {
646: my @exempt = split(',',$loginvia_exempt);
647: if (grep(/^\Q$ip\E$/,@exempt)) {
648: $noredirect = 1;
649: }
650: }
651: }
652: unless ($noredirect) {
653: my ($newhost,$path);
654: if ($loginvia =~ /:/) {
655: ($newhost,$path) = split(':',$loginvia);
656: } else {
657: $newhost = $loginvia;
658: }
659: if ($newhost ne $lonhost) {
660: if (&Apache::lonnet::hostname($newhost) ne '') {
661: $output = &redirect_page($newhost,$path);
662: }
663: }
664: }
665: }
666: return $output;
667: }
668:
669: sub redirect_page {
670: my ($desthost,$path) = @_;
671: my $protocol = $Apache::lonnet::protocol{$desthost};
672: $protocol = 'http' if ($protocol ne 'https');
673: unless ($path =~ m{^/}) {
674: $path = '/'.$path;
675: }
676: my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
677: if ($env{'form.firsturl'} ne '') {
678: $url .='?firsturl='.$env{'form.firsturl'};
679: }
680: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
681: {'redirect' => [0,$url],});
682: my $end_page = &Apache::loncommon::end_page();
683: return $start_page.$end_page;
684: }
685:
686: sub contactdisplay {
687: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
688: $possdoms) = @_;
689: my $contactblock;
690: my $origmail;
691: if (ref($possdoms) eq 'ARRAY') {
692: if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
693: $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
694: }
695: }
696: my $requestmail =
697: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
698: $authdomain,$origmail);
699: unless ($showhelpdesk eq '0') {
700: if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
701: $showhelpdesk = 1;
702: } else {
703: $showhelpdesk = 0;
704: }
705: }
706: if ($servadm && $showadminmail) {
707: $contactblock .= $$lt{'servadm'}.':<br />'.
708: '<tt>'.$servadm.'</tt><br />';
709: }
710: if ($showhelpdesk) {
711: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
712: my $thisurl = &escape('/adm/login');
713: $$helpdeskscript = <<"ENDSCRIPT";
714: <script type="text/javascript">
715: // <![CDATA[
716: function helpdesk() {
717: var possdom = document.client.udom.value;
718: var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
719: if (codedom == '') {
720: codedom = "$authdomain";
721: }
722: var querystr = "origurl=$thisurl&codedom="+codedom;
723: document.location.href = "/adm/helpdesk?"+querystr;
724: return;
725: }
726: // ]]>
727: </script>
728: ENDSCRIPT
729: }
730: return $contactblock;
731: }
732:
733: sub forgotpwdisplay {
734: my (%lt) = @_;
735: my $prompt_for_resetpw = 1;
736: if ($prompt_for_resetpw) {
737: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
738: }
739: return;
740: }
741:
742: sub coursecatalog_link {
743: my ($linkname) = @_;
744: return <<"END";
745: <a href="/adm/coursecatalog">$linkname</a>
746: END
747: }
748:
749: sub newuser_link {
750: my ($linkname) = @_;
751: return '<a href="/adm/createaccount">'.$linkname.'</a>';
752: }
753:
754: 1;
755: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>