File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.137: download - view: text, annotated - select for diffs
Thu May 6 16:15:59 2010 UTC (14 years, 1 month ago) by bisitz
Branches: MAIN
CVS tags: PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD
Bug 6271 - Simplyfied/consistent login page styles
- Replaced some special styles by standard styles and added special CSS directly to corresponding tags where needed.
- Removed unnecessary HTML table in login box.
- Removed upper separator line (seems unnecessary) and use simple <hr> at bottom.
- Consistent and simplified floating of block elements.
- Removed nobreak for catalog link and removed box width limit. Now more flexible with enhanced floating.
  "nobreak" not needed since box width (both, upper and lower box) is now controlled by the longest element (independent from used language, wording, browser font and other browser rendering differences). line break on (very) small screens should be ok though.
- Moved retrival of login box colors from loncommon.pm to lonlogin.pm - the only place where this and the corresponding styles are needed.

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

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