File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.148: download - view: text, annotated - select for diffs
Sat Jun 11 18:21:07 2011 UTC (12 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_10_X, version_2_10_1, HEAD
- Check for "no_such_host" response when storing logtoken.
- Only display advice to log-in into another server, if they
  other servers are available.

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>