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