Annotation of loncom/auth/lonlogin.pm, revision 1.140
1.1 albertel 1: # The LearningOnline Network
2: # Login Screen
1.11 www 3: #
1.140 ! raeburn 4: # $Id: lonlogin.pm,v 1.139 2010/08/22 21:51:11 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/';
40: use LONCAPA;
41:
1.1 albertel 42: sub handler {
43: my $r = shift;
1.71 albertel 44:
45: &Apache::loncommon::get_unprocessed_cgi
1.79 albertel 46: (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
47: $ENV{'REDIRECT_QUERY_STRING'}),
1.71 albertel 48: ['interface','username','domain','firsturl','localpath','localres',
1.123 raeburn 49: 'token','role','symb']);
1.102 raeburn 50: if (!defined($env{'form.firsturl'})) {
51: &Apache::lonacc::get_posted_cgi($r,['firsturl']);
52: }
1.71 albertel 53:
54: # -- check if they are a migrating user
55: if (defined($env{'form.token'})) {
56: return &Apache::migrateuser::handler($r);
57: }
58:
1.53 www 59: &Apache::loncommon::no_cache($r);
60: &Apache::lonlocal::get_language_handle($r);
1.54 www 61: &Apache::loncommon::content_type($r,'text/html');
1.1 albertel 62: $r->send_http_header;
63: return OK if $r->header_only;
64:
1.49 www 65:
66: # Are we re-routing?
67: if (-e '/home/httpd/html/lon-status/reroute.txt') {
68: &Apache::lonauth::reroute($r);
69: return OK;
70: }
1.55 www 71:
1.71 albertel 72:
1.55 www 73: # -------------------------------- Prevent users from attempting to login twice
1.95 albertel 74: my $handle = &Apache::lonnet::check_for_valid_session($r);
1.135 raeburn 75: if ($handle ne '') {
76: my $lonidsdir=$r->dir_config('lonIDsDir');
77: if ($handle=~/^publicuser\_/) {
1.70 www 78: # For "public user" - remove it, we apparently really want to login
1.135 raeburn 79: unlink($r->dir_config('lonIDsDir')."/$handle.id");
80: } else {
1.55 www 81: # Indeed, a valid token is found
1.135 raeburn 82: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
83: my $start_page =
84: &Apache::loncommon::start_page('Already logged in');
85: my $end_page =
86: &Apache::loncommon::end_page();
87: my $dest = '/adm/roles';
88: if ($env{'form.firsturl'} ne '') {
89: $dest = $env{'form.firsturl'};
90: }
91: $r->print(
1.100 bisitz 92: $start_page
1.103 bisitz 93: .'<h1>'.&mt('You are already logged in!').'</h1>'
1.117 hauer 94: .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
1.125 raeburn 95: '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
1.135 raeburn 96: .$end_page
1.100 bisitz 97: );
1.135 raeburn 98: return OK;
99: }
1.55 www 100: }
101:
102: # ---------------------------------------------------- No valid token, continue
1.16 www 103:
1.70 www 104: # ---------------------------- Not possible to really login to domain "public"
105: if ($env{'form.domain'} eq 'public') {
106: $env{'form.domain'}='';
107: $env{'form.username'}='';
108: }
1.32 www 109: # ----------------------------------------------------------- Process Interface
1.63 albertel 110: $env{'form.interface'}=~s/\W//g;
1.16 www 111:
1.32 www 112: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.94 albertel 113:
114: my $iconpath=
115: &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
116:
1.126 raeburn 117: my $lonhost = $r->dir_config('lonHostID');
1.87 raeburn 118: my $domain = &Apache::lonnet::default_login_domain();
1.126 raeburn 119: if ($lonhost ne '') {
1.133 raeburn 120: my $redirect = &check_loginvia($domain,$lonhost);
121: if ($redirect) {
122: $r->print($redirect);
123: return OK;
124: }
1.126 raeburn 125: }
126:
1.63 albertel 127: if (($env{'form.domain'}) &&
1.89 albertel 128: (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
1.63 albertel 129: $domain=$env{'form.domain'};
1.46 www 130: }
1.1 albertel 131: my $role = $r->dir_config('lonRole');
132: my $loadlim = $r->dir_config('lonLoadLim');
1.90 raeburn 133: my $servadm = $r->dir_config('lonAdmEMail');
1.1 albertel 134: my $tabdir = $r->dir_config('lonTabDir');
1.6 www 135: my $include = $r->dir_config('lonIncludes');
1.37 www 136: my $expire = $r->dir_config('lonExpire');
1.44 www 137: my $version = $r->dir_config('lonVersion');
1.88 albertel 138: my $host_name = &Apache::lonnet::hostname($lonhost);
1.1 albertel 139:
1.30 www 140: # --------------------------------------------- Default values for login fields
141:
1.63 albertel 142: my $authusername=($env{'form.username'}?$env{'form.username'}:'');
143: my $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
1.30 www 144:
145: # ---------------------------------------------------------- Determine own load
1.1 albertel 146: my $loadavg;
1.41 albertel 147: {
148: my $loadfile=Apache::File->new('/proc/loadavg');
149: $loadavg=<$loadfile>;
150: }
1.1 albertel 151: $loadavg =~ s/\s.*//g;
1.57 matthew 152: my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
1.41 albertel 153: my $userloadpercent=&Apache::lonnet::userload();
1.1 albertel 154:
1.31 www 155: my $firsturl=
1.63 albertel 156: ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
1.45 www 157: # ----------------------------------------------------------- Get announcements
158: my $announcements=&Apache::lonnet::getannounce();
1.6 www 159: # -------------------------------------------------------- Set login parameters
160:
161: my @hexstr=('0','1','2','3','4','5','6','7',
162: '8','9','a','b','c','d','e','f');
163: my $lkey='';
164: for (0..7) {
165: $lkey.=$hexstr[rand(15)];
166: }
167:
168: my $ukey='';
169: for (0..7) {
170: $ukey.=$hexstr[rand(15)];
171: }
172:
173: my $lextkey=hex($lkey);
1.15 www 174: if ($lextkey>2147483647) { $lextkey-=4294967296; }
175:
1.6 www 176: my $uextkey=hex($ukey);
1.15 www 177: if ($uextkey>2147483647) { $uextkey-=4294967296; }
178:
1.31 www 179: # -------------------------------------------------------- Store away log token
1.123 raeburn 180: my $tokenextras;
181: if ($env{'form.role'}) {
182: $tokenextras = '&role='.&escape($env{'form.role'});
183: }
184: if ($env{'form.symb'}) {
1.124 raeburn 185: if (!$tokenextras) {
186: $tokenextras = '&';
187: }
1.123 raeburn 188: $tokenextras .= '&symb='.&escape($env{'form.symb'});
189: }
1.6 www 190: my $logtoken=Apache::lonnet::reply(
1.123 raeburn 191: 'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
1.6 www 192: $lonhost);
1.31 www 193:
194: # ------------------- If we cannot talk to ourselves, we are in serious trouble
195:
196: if ($logtoken eq 'con_lost') {
197: my $spares='';
1.64 albertel 198: my $last;
199: foreach my $hostid (sort
200: {
1.88 albertel 201: &Apache::lonnet::hostname($a) cmp
202: &Apache::lonnet::hostname($b);
1.64 albertel 203: }
204: keys(%Apache::lonnet::spareid)) {
1.58 matthew 205: next if ($hostid eq $lonhost);
1.88 albertel 206: my $hostname = &Apache::lonnet::hostname($hostid);
207: next if ($last eq $hostname);
1.58 matthew 208: $spares.='<br /><font size="+1"><a href="http://'.
1.88 albertel 209: $hostname.
1.58 matthew 210: '/adm/login?domain='.$authdomain.'">'.
1.88 albertel 211: $hostname.'</a>'.
1.106 bisitz 212: ' '.&mt('(preferred)').'</font>'.$/;
1.88 albertel 213: $last=$hostname;
1.58 matthew 214: }
1.107 tempelho 215: $spares.= '<br />';
216: my %all_hostnames = &Apache::lonnet::all_hostnames();
217: foreach my $hostid (sort
218: {
219: &Apache::lonnet::hostname($a) cmp
220: &Apache::lonnet::hostname($b);
221: }
222: keys(%all_hostnames)) {
223: next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
224: my $hostname = &Apache::lonnet::hostname($hostid);
225: next if ($last eq $hostname);
226: $spares.='<br /><a href="http://'.
227: $hostname.
228: '/adm/login?domain='.$authdomain.'">'.
229: $hostname.'</a>';
230: $last=$hostname;
231: }
232: $r->print(
233: '<html>'
234: .'<head><title>'
235: .&mt('The LearningOnline Network with CAPA')
236: .'</title></head>'
237: .'<body bgcolor="#FFFFFF">'
238: .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
239: .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
240: .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>'
241: .'<p>'.&mt('Please attempt to login to one of the following servers:').'</p>'
242: .$spares
243: .'</body>'
244: .'</html>'
245: );
246: return OK;
247: }
1.31 www 248:
249: # ----------------------------------------------- Apparently we are in business
1.107 tempelho 250: $servadm=~s/\,/\<br \/\>/g;
1.38 www 251:
1.21 www 252: # ----------------------------------------------------------- Front page design
1.119 tempelho 253: my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
254: my $font=&Apache::loncommon::designparm('login.font',$domain);
255: my $link=&Apache::loncommon::designparm('login.link',$domain);
256: my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
1.107 tempelho 257: my $alink=&Apache::loncommon::designparm('login.alink',$domain);
1.119 tempelho 258: my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
1.137 bisitz 259: my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
260: my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
261: my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
1.107 tempelho 262: my $logo=&Apache::loncommon::designparm('login.logo',$domain);
263: my $img=&Apache::loncommon::designparm('login.img',$domain);
1.132 bisitz 264: my $domainlogo='<div>'.&Apache::loncommon::domainlogo($domain).'</div>';
1.109 raeburn 265: my $showbanner = 1;
266: my $showmainlogo = 1;
267: if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
268: $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
269: }
270: if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
271: $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
272: }
1.107 tempelho 273: my $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
274: my $showcoursecat =
275: &Apache::loncommon::designparm('login.coursecatalog',$domain);
276: my $shownewuserlink =
277: &Apache::loncommon::designparm('login.newuser',$domain);
278: my $now=time;
279: my $js = (<<ENDSCRIPT);
280:
1.116 bisitz 281: <script type="text/javascript" language="JavaScript">
1.122 bisitz 282: // <![CDATA[
1.107 tempelho 283: function send()
284: {
285: this.document.server.elements.uname.value
286: =this.document.client.elements.uname.value;
287:
288: this.document.server.elements.udom.value
289: =this.document.client.elements.udom.value;
290:
291: uextkey=this.document.client.elements.uextkey.value;
292: lextkey=this.document.client.elements.lextkey.value;
293: initkeys();
294:
295: this.document.server.elements.upass0.value
296: =crypted(this.document.client.elements.upass$now.value.substr(0,15));
297: this.document.server.elements.upass1.value
298: =crypted(this.document.client.elements.upass$now.value.substr(15,15));
299: this.document.server.elements.upass2.value
300: =crypted(this.document.client.elements.upass$now.value.substr(30,15));
1.6 www 301:
1.107 tempelho 302: this.document.client.elements.uname.value='';
303: this.document.client.elements.upass$now.value='';
1.6 www 304:
1.107 tempelho 305: this.document.server.submit();
306: return false;
307: }
1.139 raeburn 308:
309: function enableInput() {
310: this.document.client.elements.upass$now.removeAttribute("readonly");
311: this.document.client.elements.uname.removeAttribute("readonly");
312: this.document.client.elements.udom.removeAttribute("readonly");
313: return;
314: }
315:
1.122 bisitz 316: // ]]>
1.107 tempelho 317: </script>
1.98 raeburn 318:
1.16 www 319: ENDSCRIPT
1.6 www 320:
1.98 raeburn 321: # --------------------------------------------------- Print login screen header
322:
1.118 tempelho 323: my %add_entries = (
1.108 tempelho 324: bgcolor => "$mainbg",
1.107 tempelho 325: text => "$font",
326: link => "$link",
327: vlink => "$vlink",
1.139 raeburn 328: alink => "$alink",
329: onload => 'javascript:enableInput();',);
1.107 tempelho 330:
331: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
332: { 'redirect' => [$expire,'/adm/roles'],
333: 'add_entries' => \%add_entries,
334: 'only_body' => 1,}));
1.98 raeburn 335:
336: # ----------------------------------------------------------------------- Texts
337:
338: my %lt=&Apache::lonlocal::texthash(
1.129 bisitz 339: 'un' => 'Username',
340: 'pw' => 'Password',
341: 'dom' => 'Domain',
342: 'perc' => 'percent',
343: 'load' => 'Server Load',
344: 'userload' => 'User Load',
345: 'catalog' => 'Course/Community Catalog',
346: 'log' => 'Log in',
347: 'help' => 'Log-in Help',
348: 'serv' => 'Server',
349: 'servadm' => 'Server Administration',
350: 'helpdesk' => 'Contact Helpdesk',
351: 'forgotpw' => 'Forgot password?',
352: 'newuser' => 'New User?',
353: );
1.98 raeburn 354: # -------------------------------------------------- Change password field name
1.131 jms 355:
1.107 tempelho 356: my $forgotpw = &forgotpwdisplay(%lt);
1.132 bisitz 357: $forgotpw .= '<br />' if $forgotpw;
1.135 raeburn 358: my $loginhelp = &loginhelpdisplay($authdomain,%lt);
1.132 bisitz 359: $loginhelp .= '<br />' if $loginhelp;
1.98 raeburn 360:
361: # ---------------------------------------------------- Serve out DES JavaScript
1.107 tempelho 362: {
363: my $jsh=Apache::File->new($include."/londes.js");
364: $r->print(<$jsh>);
365: }
1.98 raeburn 366: # ---------------------------------------------------------- Serve rest of page
367:
1.107 tempelho 368: $r->print(
1.137 bisitz 369: '<div class="LC_Box"'
370: .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
371: );
1.6 www 372:
1.120 foxr 373: #
374: # If the loadbalancing yielded just http:// because perhaps there's no loadbalancing?
375: # then just us a relative link to authenticate:
376: #
377:
1.107 tempelho 378: $r->print(<<ENDSERVERFORM);
1.140 ! raeburn 379: <form name="server" action="/adm/authenticate" method="post" target="_top">
1.33 www 380: <input type="hidden" name="logtoken" value="$logtoken" />
381: <input type="hidden" name="serverid" value="$lonhost" />
382: <input type="hidden" name="uname" value="" />
1.65 www 383: <input type="hidden" name="upass0" value="" />
384: <input type="hidden" name="upass1" value="" />
385: <input type="hidden" name="upass2" value="" />
1.33 www 386: <input type="hidden" name="udom" value="" />
1.63 albertel 387: <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
388: <input type="hidden" name="localres" value="$env{'form.localres'}" />
1.14 albertel 389: </form>
1.16 www 390: ENDSERVERFORM
1.108 tempelho 391: my $coursecatalog;
392: if (($showcoursecat eq '') || ($showcoursecat)) {
1.132 bisitz 393: $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
1.108 tempelho 394: }
395: my $newuserlink;
396: if ($shownewuserlink) {
1.132 bisitz 397: $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
1.108 tempelho 398: }
1.137 bisitz 399: my $logintitle =
400: '<h2 class="LC_hcell"'
401: .' style="background:'.$loginbox_header_bgcol.';'
1.138 bisitz 402: .' color:'.$loginbox_header_textcol.'">'
403: .$lt{'log'}
404: .'</h2>';
1.108 tempelho 405:
406: my $noscript_warning='<noscript><span class="LC_warning"><b>'
407: .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
408: .'</b></span></noscript>';
409: my $helpdeskscript;
410: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
1.132 bisitz 411: $authdomain,\$helpdeskscript);
1.107 tempelho 412:
1.108 tempelho 413: my $loginform=(<<LFORM);
1.122 bisitz 414: <form name="client" action="" onsubmit="return(send())">
1.115 bisitz 415: <input type="hidden" name="lextkey" value="$lextkey" />
416: <input type="hidden" name="uextkey" value="$uextkey" />
1.108 tempelho 417: <b><label for="uname">$lt{'un'}</label>:</b><br />
1.139 raeburn 418: <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" /><br />
1.108 tempelho 419: <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
1.139 raeburn 420: <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
1.108 tempelho 421: <b><label for="udom">$lt{'dom'}</label>:</b><br />
1.139 raeburn 422: <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" /><br />
1.108 tempelho 423: <input type="submit" value="$lt{'log'}" />
424: </form>
425: LFORM
426:
1.109 raeburn 427: if ($showbanner) {
428: $r->print(<<HEADER);
429: <!-- The LON-CAPA Header -->
1.132 bisitz 430: <div style="background:$pgbg;margin:0;width:100%;">
431: <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
432: </div>
1.109 raeburn 433: HEADER
434: }
435: $r->print(<<ENDTOP);
1.137 bisitz 436: <div style="float:left;">
437: <div class="LC_Box" style="background:$loginbox_bg;">
1.112 muellerd 438: $logintitle
1.137 bisitz 439: $loginform
440: $noscript_warning
1.108 tempelho 441: </div>
1.107 tempelho 442:
1.137 bisitz 443: <div class="LC_Box" style="padding-top: 10px;">
1.132 bisitz 444: $loginhelp
445: $forgotpw
446: $contactblock
447: $newuserlink
1.130 bisitz 448: $coursecatalog
1.107 tempelho 449: </div>
1.118 tempelho 450: </div>
1.137 bisitz 451:
452: <div>
1.118 tempelho 453: ENDTOP
454: if ($showmainlogo) {
455: $r->print(' <img src="'.$logo.'" alt="" />'."\n");
456: }
457: $r->print(<<ENDTOP);
458: $announcements
459: $domainlogo
1.137 bisitz 460: </div>
461: <hr style="clear:both;" />
1.108 tempelho 462: ENDTOP
463:
464: $r->print(<<ENDDOCUMENT);
1.115 bisitz 465: <table border="0" cellspacing="0" cellpadding="0">
1.14 albertel 466: <tr>
1.110 muellerd 467: <td align="left" valign="top">
1.132 bisitz 468: <small><b>$lt{'dom'}: </b></small>
1.14 albertel 469: </td>
1.110 muellerd 470: <td align="left" valign="top">
1.14 albertel 471: <small><tt> $domain</tt></small>
472: </td>
473: </tr>
474: <tr>
1.110 muellerd 475: <td align="left" valign="top">
1.132 bisitz 476: <small><b>$lt{'serv'}: </b></small>
1.14 albertel 477: </td>
1.110 muellerd 478: <td align="left" valign="top">
1.14 albertel 479: <small><tt> $lonhost ($role)</tt></small>
480: </td>
481: </tr>
482: <tr>
1.110 muellerd 483: <td align="left" valign="top">
1.132 bisitz 484: <small><b>$lt{'load'}: </b></small>
1.14 albertel 485: </td>
1.110 muellerd 486: <td align="left" valign="top">
1.51 www 487: <small><tt> $loadpercent $lt{'perc'}</tt></small>
1.42 albertel 488: </td>
489: </tr>
490: <tr>
1.110 muellerd 491: <td align="left" valign="top">
1.132 bisitz 492: <small><b>$lt{'userload'}: </b></small>
1.42 albertel 493: </td>
1.110 muellerd 494: <td align="left" valign="top">
1.51 www 495: <small><tt> $userloadpercent $lt{'perc'}</tt></small>
1.14 albertel 496: </td>
497: </tr>
1.132 bisitz 498: <tr>
499: <td colspan="2" align="left">
500: <small>$version</small>
501: </td>
502: </tr>
1.14 albertel 503: </table>
1.107 tempelho 504: </div>
1.25 bowersj2 505:
1.59 albertel 506: <script type="text/javascript">
1.122 bisitz 507: // <![CDATA[
1.59 albertel 508: // the if prevents the script error if the browser can not handle this
1.25 bowersj2 509: if ( document.client.uname ) { document.client.uname.focus(); }
1.122 bisitz 510: // ]]>
1.25 bowersj2 511: </script>
1.62 raeburn 512: $helpdeskscript
1.14 albertel 513:
1.1 albertel 514: ENDDOCUMENT
1.98 raeburn 515: my %endargs = ( 'noredirectlink' => 1, );
516: $r->print(&Apache::loncommon::end_page(\%endargs));
1.1 albertel 517: return OK;
1.60 raeburn 518: }
519:
1.133 raeburn 520: sub check_loginvia {
521: my ($domain,$lonhost) = @_;
522: if ($domain eq '' || $lonhost eq '') {
523: return;
524: }
525: my %domconfhash = &Apache::loncommon::get_domainconf($domain);
526: my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
527: my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
528: my $output;
529: if ($loginvia ne '') {
530: my $noredirect;
531: my $ip = $ENV{'REMOTE_ADDR'};
532: if ($ip eq '127.0.0.1') {
533: $noredirect = 1;
534: } else {
535: if ($loginvia_exempt ne '') {
536: my @exempt = split(',',$loginvia_exempt);
537: if (grep(/^\Q$ip\E$/,@exempt)) {
538: $noredirect = 1;
539: }
540: }
541: }
542: unless ($noredirect) {
543: my ($newhost,$path);
544: if ($loginvia =~ /:/) {
545: ($newhost,$path) = split(':',$loginvia);
546: } else {
547: $newhost = $loginvia;
548: }
549: if ($newhost ne $lonhost) {
550: if (&Apache::lonnet::hostname($newhost) ne '') {
551: $output = &redirect_page($newhost,$path);
552: }
553: }
554: }
555: }
556: return $output;
557: }
558:
1.126 raeburn 559: sub redirect_page {
1.133 raeburn 560: my ($desthost,$path) = @_;
1.126 raeburn 561: my $protocol = $Apache::lonnet::protocol{$desthost};
562: $protocol = 'http' if ($protocol ne 'https');
1.133 raeburn 563: unless ($path =~ m{^/}) {
564: $path = '/'.$path;
565: }
566: my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
1.126 raeburn 567: if ($env{'form.firsturl'} ne '') {
568: $url .='?firsturl='.$env{'form.firsturl'};
569: }
1.136 raeburn 570: my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
1.126 raeburn 571: {'redirect' => [0,$url],});
572: my $end_page = &Apache::loncommon::end_page();
573: return $start_page.$end_page;
574: }
575:
1.60 raeburn 576: sub contactdisplay {
1.132 bisitz 577: my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript) = @_;
1.60 raeburn 578: my $contactblock;
1.62 raeburn 579: my $showhelpdesk = 0;
580: my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
581: if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {
582: $showhelpdesk = 1;
583: }
1.90 raeburn 584: if ($servadm && $showadminmail) {
1.130 bisitz 585: $contactblock .= $$lt{'servadm'}.':<br />'.
586: '<tt>'.$servadm.'</tt><br />';
1.90 raeburn 587: }
1.60 raeburn 588: if ($showhelpdesk) {
1.114 tempelho 589: $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
1.75 www 590: my $thisurl = &escape('/adm/login');
1.62 raeburn 591: $$helpdeskscript = <<"ENDSCRIPT";
592: <script type="text/javascript">
1.122 bisitz 593: // <![CDATA[
1.62 raeburn 594: function helpdesk() {
595: var codedom = document.client.udom.value;
596: if (codedom == '') {
597: codedom = "$authdomain";
598: }
599: var querystr = "origurl=$thisurl&codedom="+codedom;
600: document.location.href = "/adm/helpdesk?"+querystr;
601: return;
602: }
1.122 bisitz 603: // ]]>
1.62 raeburn 604: </script>
605: ENDSCRIPT
1.60 raeburn 606: }
607: return $contactblock;
608: }
1.83 raeburn 609:
610: sub forgotpwdisplay {
1.84 raeburn 611: my (%lt) = @_;
1.83 raeburn 612: my $prompt_for_resetpw = 1;
613: if ($prompt_for_resetpw) {
1.107 tempelho 614: return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
1.84 raeburn 615: }
616: return;
617: }
618:
619: sub loginhelpdisplay {
1.135 raeburn 620: my ($authdomain,%lt) = @_;
1.84 raeburn 621: my $login_help = 1;
622: if ($login_help) {
1.135 raeburn 623: my $dom = $authdomain;
624: if ($dom eq '') {
625: $dom = &Apache::lonnet::default_login_domain();
626: }
627: my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);
628: my $loginhelp_url = $helpconfig{'helpsettings'}{'loginhelpurl'};
629: if ($loginhelp_url ne '') {
630: return '<a href="'.$loginhelp_url.'">'.$lt{'help'}.'</a>';
1.131 jms 631: } else {
1.135 raeburn 632: return '<a href="/adm/loginproblems.html">'.$lt{'help'}.'</a>';
633: }
1.83 raeburn 634: }
635: return;
636: }
1.1 albertel 637:
1.90 raeburn 638: sub coursecatalog_link {
639: my ($linkname) = @_;
640: return <<"END";
1.137 bisitz 641: <a href="/adm/coursecatalog">$linkname</a>
1.90 raeburn 642: END
643: }
644:
1.101 raeburn 645: sub newuser_link {
646: my ($linkname) = @_;
1.130 bisitz 647: return '<a href="/adm/createaccount">'.$linkname.'</a>';
1.101 raeburn 648: }
649:
1.1 albertel 650: 1;
651: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>