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