File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.133: download - view: text, annotated - select for diffs
Wed Mar 3 17:00:01 2010 UTC (14 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- More flexibilty in redirection from log-in page for a server in a domain to
  domain's load balancer or SSO server.
  - Append specified path from domain config to destination hostname.
  - No redirection if client IP is listed as exempt in domain config.

    1: # The LearningOnline Network
    2: # Login Screen
    3: #
    4: # $Id: lonlogin.pm,v 1.133 2010/03/03 17:00:01 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: 
   73: # -------------------------------- Prevent users from attempting to login twice
   74:     my $handle = &Apache::lonnet::check_for_valid_session($r);
   75:     if ($handle=~/^publicuser\_/) {
   76: # For "public user" - remove it, we apparently really want to login
   77: 	unlink($r->dir_config('lonIDsDir')."/$handle.id");
   78:     } elsif ($handle ne '') {
   79: # Indeed, a valid token is found
   80: 	my $start_page = 
   81: 	    &Apache::loncommon::start_page('Already logged in');
   82: 	my $end_page = 
   83: 	    &Apache::loncommon::end_page();
   84:         my $dest = '/adm/roles';
   85:         if ($env{'form.firsturl'} ne '') {
   86:             $dest = $env{'form.firsturl'}; 
   87:         }
   88:         
   89:     my $dom = &Apache::lonnet::default_login_domain();
   90:     my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);
   91:     
   92:     my $loginhelp_page = $helpconfig{'helpsettings'}{'loginhelpurl'};
   93:     if ($loginhelp_page eq '') {
   94: 		$loginhelp_page = '/adm/loginproblems.html';
   95:     }
   96: 	$r->print(
   97:                   $start_page
   98:                  .'<h1>'.&mt('You are already logged in!').'</h1>'
   99:                  .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
  100:                   '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
  101:                  .'<p><a href="'.$loginhelp_page.'">'.&mt('Login problems?').'</a></p>'
  102:                  .$dom.' '.$end_page
  103:                  );
  104:         return OK;
  105:     }
  106: 
  107: # ---------------------------------------------------- No valid token, continue
  108: 
  109:  # ---------------------------- Not possible to really login to domain "public"
  110:     if ($env{'form.domain'} eq 'public') {
  111: 	$env{'form.domain'}='';
  112: 	$env{'form.username'}='';
  113:     }
  114: # ----------------------------------------------------------- Process Interface
  115:     $env{'form.interface'}=~s/\W//g;
  116: 
  117:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
  118: 
  119:     my $iconpath= 
  120: 	&Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
  121: 
  122:     my $lonhost = $r->dir_config('lonHostID');
  123:     my $domain = &Apache::lonnet::default_login_domain();
  124:     if ($lonhost ne '') {
  125:         my $redirect = &check_loginvia($domain,$lonhost);
  126:         if ($redirect) {
  127:             $r->print($redirect);
  128:             return OK;
  129:         } 
  130:     }
  131: 
  132:     if (($env{'form.domain'}) && 
  133: 	(&Apache::lonnet::domain($env{'form.domain'},'description'))) {
  134: 	$domain=$env{'form.domain'};
  135:     }
  136:     my $role    = $r->dir_config('lonRole');
  137:     my $loadlim = $r->dir_config('lonLoadLim');
  138:     my $servadm = $r->dir_config('lonAdmEMail');
  139:     my $tabdir  = $r->dir_config('lonTabDir');
  140:     my $include = $r->dir_config('lonIncludes');
  141:     my $expire  = $r->dir_config('lonExpire');
  142:     my $version = $r->dir_config('lonVersion');
  143:     my $host_name = &Apache::lonnet::hostname($lonhost);
  144: 
  145: # --------------------------------------------- Default values for login fields
  146: 
  147:     my $authusername=($env{'form.username'}?$env{'form.username'}:'');
  148:     my $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
  149: 
  150: # ---------------------------------------------------------- Determine own load
  151:     my $loadavg;
  152:     {
  153: 	my $loadfile=Apache::File->new('/proc/loadavg');
  154: 	$loadavg=<$loadfile>;
  155:     }
  156:     $loadavg =~ s/\s.*//g;
  157:     my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
  158:     my $userloadpercent=&Apache::lonnet::userload();
  159: 
  160: # ------------------------------------------------------- Do the load balancing
  161:     my $otherserver= &Apache::lonnet::absolute_url($host_name);
  162:     my $firsturl=
  163:     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
  164: # ---------------------------------------------------------- Are we overloaded?
  165:     if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
  166:         my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent);
  167: 	if ($unloaded) { $otherserver=$unloaded; }
  168:     }
  169: 
  170: # ----------------------------------------------------------- Get announcements
  171:     my $announcements=&Apache::lonnet::getannounce();
  172: # -------------------------------------------------------- Set login parameters
  173: 
  174:     my @hexstr=('0','1','2','3','4','5','6','7',
  175:                 '8','9','a','b','c','d','e','f');
  176:     my $lkey='';
  177:     for (0..7) {
  178:         $lkey.=$hexstr[rand(15)];
  179:     }
  180: 
  181:     my $ukey='';
  182:     for (0..7) {
  183:         $ukey.=$hexstr[rand(15)];
  184:     }
  185: 
  186:     my $lextkey=hex($lkey);
  187:     if ($lextkey>2147483647) { $lextkey-=4294967296; }
  188: 
  189:     my $uextkey=hex($ukey);
  190:     if ($uextkey>2147483647) { $uextkey-=4294967296; }
  191: 
  192: # -------------------------------------------------------- Store away log token
  193:     my $tokenextras;
  194:     if ($env{'form.role'}) {
  195:         $tokenextras = '&role='.&escape($env{'form.role'});
  196:     }
  197:     if ($env{'form.symb'}) {
  198:         if (!$tokenextras) {
  199:             $tokenextras = '&';
  200:         }
  201:         $tokenextras .= '&symb='.&escape($env{'form.symb'});
  202:     }
  203:     my $logtoken=Apache::lonnet::reply(
  204:        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
  205:        $lonhost);
  206: 
  207: # ------------------- If we cannot talk to ourselves, we are in serious trouble
  208: 
  209:     if ($logtoken eq 'con_lost') {
  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);
  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: $spares.= '<br />';
  229: my %all_hostnames = &Apache::lonnet::all_hostnames();
  230: foreach my $hostid (sort
  231: 		    {
  232: 			&Apache::lonnet::hostname($a) cmp
  233: 			    &Apache::lonnet::hostname($b);
  234: 		    }
  235: 		    keys(%all_hostnames)) {
  236:     next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
  237:     my $hostname = &Apache::lonnet::hostname($hostid);
  238:     next if ($last eq $hostname);
  239:     $spares.='<br /><a href="http://'.
  240: 	$hostname.
  241: 	'/adm/login?domain='.$authdomain.'">'.
  242: 	$hostname.'</a>';
  243:     $last=$hostname;
  244: }
  245: $r->print(
  246:    '<html>'
  247:   .'<head><title>'
  248:   .&mt('The LearningOnline Network with CAPA')
  249:   .'</title></head>'
  250:   .'<body bgcolor="#FFFFFF">'
  251:   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
  252:   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
  253:   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>'
  254:   .'<p>'.&mt('Please attempt to login to one of the following servers:').'</p>'
  255:   .$spares
  256:   .'</body>'
  257:   .'</html>'
  258: );
  259: return OK;
  260: }
  261: 
  262: # ----------------------------------------------- Apparently we are in business
  263: $servadm=~s/\,/\<br \/\>/g;
  264: 
  265: # ----------------------------------------------------------- Front page design
  266: my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
  267: my $font=&Apache::loncommon::designparm('login.font',$domain);
  268: my $link=&Apache::loncommon::designparm('login.link',$domain);
  269: my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
  270: my $alink=&Apache::loncommon::designparm('login.alink',$domain);
  271: my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
  272: my $logo=&Apache::loncommon::designparm('login.logo',$domain);
  273: my $img=&Apache::loncommon::designparm('login.img',$domain);
  274: my $domainlogo='<div>'.&Apache::loncommon::domainlogo($domain).'</div>';
  275: my $login=&Apache::loncommon::designparm('login.login',$domain);
  276: if ($login eq '') {
  277: $login = $iconpath.'/'.&mt('userauthentication.gif');
  278: }
  279: my $showbanner = 1;
  280: my $showmainlogo = 1;
  281: if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
  282:     $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
  283: }
  284: if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
  285:     $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
  286: }
  287: my $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
  288: my $showcoursecat =
  289: &Apache::loncommon::designparm('login.coursecatalog',$domain);
  290: my $loginheader =&Apache::loncommon::designparm('login.loginheader',$domain);
  291: my $shownewuserlink = 
  292: &Apache::loncommon::designparm('login.newuser',$domain);
  293: my $now=time;
  294: my $js = (<<ENDSCRIPT);
  295: 
  296: <script type="text/javascript" language="JavaScript">
  297: // <![CDATA[
  298: function send()
  299: {
  300: this.document.server.elements.uname.value
  301: =this.document.client.elements.uname.value;
  302: 
  303: this.document.server.elements.udom.value
  304: =this.document.client.elements.udom.value;
  305: 
  306: uextkey=this.document.client.elements.uextkey.value;
  307: lextkey=this.document.client.elements.lextkey.value;
  308: initkeys();
  309: 
  310: this.document.server.elements.upass0.value
  311:     =crypted(this.document.client.elements.upass$now.value.substr(0,15));
  312: this.document.server.elements.upass1.value
  313:     =crypted(this.document.client.elements.upass$now.value.substr(15,15));
  314: this.document.server.elements.upass2.value
  315:     =crypted(this.document.client.elements.upass$now.value.substr(30,15));
  316: 
  317: this.document.client.elements.uname.value='';
  318: this.document.client.elements.upass$now.value='';
  319: 
  320: this.document.server.submit();
  321: return false;
  322: }
  323: // ]]>
  324: </script>
  325: 
  326: ENDSCRIPT
  327: 
  328: # --------------------------------------------------- Print login screen header
  329: 
  330: my %add_entries = (
  331: 	       bgcolor      => "$mainbg",
  332: 	       text         => "$font",
  333: 	       link         => "$link",
  334: 	       vlink        => "$vlink",
  335: 	       alink        => "$alink",);
  336: 
  337: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
  338: 			       { 'redirect'       => [$expire,'/adm/roles'], 
  339: 				 'add_entries' => \%add_entries,
  340: 				 'only_body'   => 1,}));
  341: 
  342: # ----------------------------------------------------------------------- Texts
  343: 
  344: my %lt=&Apache::lonlocal::texthash(
  345:           'un'       => 'Username',
  346:           'pw'       => 'Password',
  347:           'dom'      => 'Domain',
  348:           'perc'     => 'percent',
  349:           'load'     => 'Server Load',
  350:           'userload' => 'User Load',
  351:           'catalog'  => 'Course/Community Catalog',
  352:           'log'      => 'Log in',
  353:           'help'     => 'Log-in Help',
  354:           'serv'     => 'Server',
  355:           'servadm'  => 'Server Administration',
  356:           'helpdesk' => 'Contact Helpdesk',
  357:           'forgotpw' => 'Forgot password?',
  358:           'newuser'  => 'New User?',
  359:        );
  360: # -------------------------------------------------- Change password field name
  361: 
  362: my $forgotpw = &forgotpwdisplay(%lt);
  363: $forgotpw .= '<br />' if $forgotpw;
  364: my $loginhelp = &loginhelpdisplay(%lt);
  365: $loginhelp .= '<br />' if $loginhelp;
  366: 
  367: # ---------------------------------------------------- Serve out DES JavaScript
  368: {
  369: my $jsh=Apache::File->new($include."/londes.js");
  370: $r->print(<$jsh>);
  371: }
  372: # ---------------------------------------------------------- Serve rest of page
  373: 
  374: $r->print(
  375: 	  '<div class="LC_loginpage_container">');
  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: if ($loginheader eq 'text') {
  405:     $logintitle ='<h2>'.$lt{'log'}.'</h2>';
  406: } else {
  407:     $logintitle = '<img src="'.$login.'" alt="'.
  408:                   &mt('User Authentication').'" />';
  409: }
  410: 
  411: my $noscript_warning='<noscript><span class="LC_warning"><b>'
  412:                      .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
  413:                     .'</b></span></noscript>';
  414: my $helpdeskscript;
  415: my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
  416:                                    $authdomain,\$helpdeskscript);
  417: 
  418: my $loginform=(<<LFORM);
  419: <form name="client" action="" onsubmit="return(send())">
  420:   <input type="hidden" name="lextkey" value="$lextkey" />
  421:   <input type="hidden" name="uextkey" value="$uextkey" />
  422:   <b><label for="uname">$lt{'un'}</label>:</b><br />
  423:   <input type="text" name="uname" id="uname" size="15" value="$authusername" /><br />
  424:   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
  425:   <input type="password" name="upass$now" id="upass$now" size="15" /><br />
  426:   <b><label for="udom">$lt{'dom'}</label>:</b><br />
  427:   <input type="text" name="udom" id="udom" size="15" value="$authdomain" /><br />
  428:   <input type="submit" value="$lt{'log'}" />
  429: </form>
  430: LFORM
  431: 
  432:     if ($showbanner) {
  433:         $r->print(<<HEADER);
  434: <!-- The LON-CAPA Header -->
  435: <div style="background:$pgbg;margin:0;width:100%;">
  436:   <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
  437: </div>
  438: HEADER
  439:     }
  440:     $r->print(<<ENDTOP);
  441: <div class="LC_loginpage_space">&nbsp;</div>
  442: <div class="LC_loginpage_floatLeft">
  443: <div class="LC_loginpage_loginContainer">
  444:   $logintitle
  445:    <table border="0" align="left" cellspacing="1" cellpadding="2" width="100%">
  446:       <tr>
  447: 	   <td>
  448: 		$loginform
  449:            </td>
  450:       </tr>
  451:    </table>   	
  452:    $noscript_warning
  453: </div>
  454:   
  455: <div class="LC_loginpage_loginInfo">
  456:   $loginhelp
  457:   $forgotpw
  458:   $contactblock
  459:   $newuserlink
  460:   $coursecatalog
  461: </div>
  462: </div>
  463: ENDTOP
  464:     if ($showmainlogo) {
  465:         $r->print(' <img src="'.$logo.'" alt="" />'."\n");
  466:     }
  467: $r->print(<<ENDTOP);
  468: $announcements
  469: $domainlogo
  470: <div class="LC_loginpage_space">&nbsp;</div>
  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 (%lt) = @_;
  630:     my $login_help = 1;
  631:     if ($login_help) {
  632:     	my $dom = &Apache::lonnet::default_login_domain();
  633: 		my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);
  634: 		my $loginhelp_url = $helpconfig{'helpsettings'}{'loginhelpurl'};
  635: 		if ($loginhelp_url ne '') {
  636:         	return '<a href="'.$loginhelp_url.'">'.$lt{'help'}.'</a>';
  637:         } else {
  638:         	return '<a href="/adm/loginproblems.html">'.$lt{'help'}.'</a>';
  639:        	}
  640:     }
  641:     return;
  642: }
  643: 
  644: sub coursecatalog_link {
  645:     my ($linkname) = @_;
  646:     return <<"END";
  647:       <a href="/adm/coursecatalog">$linkname</a>
  648: END
  649: }
  650: 
  651: sub newuser_link {
  652:     my ($linkname) = @_;
  653:     return '<a href="/adm/createaccount">'.$linkname.'</a>';
  654: }
  655: 
  656: 1;
  657: __END__

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