File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.145: download - view: text, annotated - select for diffs
Thu Sep 2 09:24:42 2010 UTC (13 years, 8 months ago) by www
Branches: MAIN
CVS tags: version_2_10_0_RC2, HEAD
Don't show "User Load: 0.00 percent" if there is no maximum load configured. That looks like nobody is using the system.

    1: # The LearningOnline Network
    2: # Login Screen
    3: #
    4: # $Id: lonlogin.pm,v 1.145 2010/09/02 09:24:42 www 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:     my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
  155:     unless ($loadlim) { $loadpercent='---'; }
  156:     my $userloadpercent=&Apache::lonnet::userload();
  157:     unless ($uloadlim) { $userloadpercent='---'; }
  158: 
  159:     my $firsturl=
  160:     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
  161: 
  162: # ----------------------------------------------------------- Get announcements
  163:     my $announcements=&Apache::lonnet::getannounce();
  164: # -------------------------------------------------------- Set login parameters
  165: 
  166:     my @hexstr=('0','1','2','3','4','5','6','7',
  167:                 '8','9','a','b','c','d','e','f');
  168:     my $lkey='';
  169:     for (0..7) {
  170:         $lkey.=$hexstr[rand(15)];
  171:     }
  172: 
  173:     my $ukey='';
  174:     for (0..7) {
  175:         $ukey.=$hexstr[rand(15)];
  176:     }
  177: 
  178:     my $lextkey=hex($lkey);
  179:     if ($lextkey>2147483647) { $lextkey-=4294967296; }
  180: 
  181:     my $uextkey=hex($ukey);
  182:     if ($uextkey>2147483647) { $uextkey-=4294967296; }
  183: 
  184: # -------------------------------------------------------- Store away log token
  185:     my $tokenextras;
  186:     if ($env{'form.role'}) {
  187:         $tokenextras = '&role='.&escape($env{'form.role'});
  188:     }
  189:     if ($env{'form.symb'}) {
  190:         if (!$tokenextras) {
  191:             $tokenextras = '&';
  192:         }
  193:         $tokenextras .= '&symb='.&escape($env{'form.symb'});
  194:     }
  195:     my $logtoken=Apache::lonnet::reply(
  196:        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
  197:        $lonhost);
  198: 
  199: # ------------------- If we cannot talk to ourselves, we are in serious trouble
  200: 
  201:     if ($logtoken eq 'con_lost') {
  202:         my $spares='';
  203: 	my $last;
  204:         foreach my $hostid (sort
  205: 			    {
  206: 				&Apache::lonnet::hostname($a) cmp
  207: 				    &Apache::lonnet::hostname($b);
  208: 			    }
  209: 			    keys(%Apache::lonnet::spareid)) {
  210:             next if ($hostid eq $lonhost);
  211: 	    my $hostname = &Apache::lonnet::hostname($hostid);
  212: 	    next if ($last eq $hostname);
  213:             $spares.='<br /><font size="+1"><a href="http://'.
  214:                 $hostname.
  215:                 '/adm/login?domain='.$authdomain.'">'.
  216:                 $hostname.'</a>'.
  217:                 ' '.&mt('(preferred)').'</font>'.$/;
  218: 	    $last=$hostname;
  219:         }
  220: $spares.= '<br />';
  221: my %all_hostnames = &Apache::lonnet::all_hostnames();
  222: foreach my $hostid (sort
  223: 		    {
  224: 			&Apache::lonnet::hostname($a) cmp
  225: 			    &Apache::lonnet::hostname($b);
  226: 		    }
  227: 		    keys(%all_hostnames)) {
  228:     next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
  229:     my $hostname = &Apache::lonnet::hostname($hostid);
  230:     next if ($last eq $hostname);
  231:     $spares.='<br /><a href="http://'.
  232: 	$hostname.
  233: 	'/adm/login?domain='.$authdomain.'">'.
  234: 	$hostname.'</a>';
  235:     $last=$hostname;
  236: }
  237: $r->print(
  238:    '<html>'
  239:   .'<head><title>'
  240:   .&mt('The LearningOnline Network with CAPA')
  241:   .'</title></head>'
  242:   .'<body bgcolor="#FFFFFF">'
  243:   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
  244:   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
  245:   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>'
  246:   .'<p>'.&mt('Please attempt to login to one of the following servers:').'</p>'
  247:   .$spares
  248:   .'</body>'
  249:   .'</html>'
  250: );
  251: return OK;
  252: }
  253: 
  254: # ----------------------------------------------- Apparently we are in business
  255: $servadm=~s/\,/\<br \/\>/g;
  256: 
  257: # ----------------------------------------------------------- Front page design
  258: my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
  259: my $font=&Apache::loncommon::designparm('login.font',$domain);
  260: my $link=&Apache::loncommon::designparm('login.link',$domain);
  261: my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
  262: my $alink=&Apache::loncommon::designparm('login.alink',$domain);
  263: my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
  264: my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
  265: my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
  266: my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
  267: my $logo=&Apache::loncommon::designparm('login.logo',$domain);
  268: my $img=&Apache::loncommon::designparm('login.img',$domain);
  269: my $domainlogo=&Apache::loncommon::domainlogo($domain);
  270: my $showbanner = 1;
  271: my $showmainlogo = 1;
  272: if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
  273:     $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
  274: }
  275: if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
  276:     $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
  277: }
  278: my $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
  279: my $showcoursecat =
  280: &Apache::loncommon::designparm('login.coursecatalog',$domain);
  281: my $shownewuserlink = 
  282: &Apache::loncommon::designparm('login.newuser',$domain);
  283: my $now=time;
  284: my $js = (<<ENDSCRIPT);
  285: 
  286: <script type="text/javascript" language="JavaScript">
  287: // <![CDATA[
  288: function send()
  289: {
  290: this.document.server.elements.uname.value
  291: =this.document.client.elements.uname.value;
  292: 
  293: this.document.server.elements.udom.value
  294: =this.document.client.elements.udom.value;
  295: 
  296: uextkey=this.document.client.elements.uextkey.value;
  297: lextkey=this.document.client.elements.lextkey.value;
  298: initkeys();
  299: 
  300: this.document.server.elements.upass0.value
  301:     =crypted(this.document.client.elements.upass$now.value.substr(0,15));
  302: this.document.server.elements.upass1.value
  303:     =crypted(this.document.client.elements.upass$now.value.substr(15,15));
  304: this.document.server.elements.upass2.value
  305:     =crypted(this.document.client.elements.upass$now.value.substr(30,15));
  306: 
  307: this.document.client.elements.uname.value='';
  308: this.document.client.elements.upass$now.value='';
  309: 
  310: this.document.server.submit();
  311: return false;
  312: }
  313: 
  314: function enableInput() {
  315:     this.document.client.elements.upass$now.removeAttribute("readOnly");
  316:     this.document.client.elements.uname.removeAttribute("readOnly");
  317:     this.document.client.elements.udom.removeAttribute("readOnly");
  318:     return;
  319: }
  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:                onload       => 'javascript:enableInput();',);
  335: 
  336: $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
  337: 			       { 'redirect'       => [$expire,'/adm/roles'], 
  338: 				 'add_entries' => \%add_entries,
  339: 				 'only_body'   => 1,}));
  340: 
  341: # ----------------------------------------------------------------------- Texts
  342: 
  343: my %lt=&Apache::lonlocal::texthash(
  344:           'un'       => 'Username',
  345:           'pw'       => 'Password',
  346:           'dom'      => 'Domain',
  347:           'perc'     => 'percent',
  348:           'load'     => 'Server Load',
  349:           'userload' => 'User Load',
  350:           'catalog'  => 'Course/Community Catalog',
  351:           'log'      => 'Log in',
  352:           'help'     => 'Log-in Help',
  353:           'serv'     => 'Server',
  354:           'servadm'  => 'Server Administration',
  355:           'helpdesk' => 'Contact Helpdesk',
  356:           'forgotpw' => 'Forgot password?',
  357:           'newuser'  => 'New User?',
  358:        );
  359: # -------------------------------------------------- Change password field name
  360: 
  361: my $forgotpw = &forgotpwdisplay(%lt);
  362: $forgotpw .= '<br />' if $forgotpw;
  363: my $loginhelp = &loginhelpdisplay($authdomain,%lt);
  364: $loginhelp .= '<br />' if $loginhelp;
  365: 
  366: # ---------------------------------------------------- Serve out DES JavaScript
  367: {
  368: my $jsh=Apache::File->new($include."/londes.js");
  369: $r->print(<$jsh>);
  370: }
  371: # ---------------------------------------------------------- Serve rest of page
  372: 
  373: $r->print(
  374:     '<div class="LC_Box"'
  375:    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
  376: );
  377: 
  378: #
  379: #  If the loadbalancing yielded just http:// because perhaps there's no loadbalancing?
  380: #  then just us a relative link to authenticate:
  381: #
  382: 
  383: $r->print(<<ENDSERVERFORM);
  384: <form name="server" action="/adm/authenticate" method="post" target="_top">
  385:    <input type="hidden" name="logtoken" value="$logtoken" />
  386:    <input type="hidden" name="serverid" value="$lonhost" />
  387:    <input type="hidden" name="uname" value="" />
  388:    <input type="hidden" name="upass0" value="" />
  389:    <input type="hidden" name="upass1" value="" />
  390:    <input type="hidden" name="upass2" value="" />
  391:    <input type="hidden" name="udom" value="" />
  392:    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
  393:    <input type="hidden" name="localres" value="$env{'form.localres'}" />
  394:   </form>
  395: ENDSERVERFORM
  396: my $coursecatalog;
  397: if (($showcoursecat eq '') || ($showcoursecat)) {
  398:     $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
  399: }
  400: my $newuserlink;
  401: if ($shownewuserlink) {
  402:     $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
  403: }
  404: my $logintitle =
  405:     '<h2 class="LC_hcell"'
  406:    .' style="background:'.$loginbox_header_bgcol.';'
  407:    .' color:'.$loginbox_header_textcol.'">'
  408:    .$lt{'log'}
  409:    .'</h2>';
  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" readonly="readonly" /><br />
  424:   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
  425:   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
  426:   <b><label for="udom">$lt{'dom'}</label>:</b><br />
  427:   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" /><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 style="float:left;">
  442: <div class="LC_Box" style="background:$loginbox_bg;">
  443:   $logintitle
  444:   $loginform
  445:   $noscript_warning
  446: </div>
  447:   
  448: <div class="LC_Box" style="padding-top: 10px;">
  449:   $loginhelp
  450:   $forgotpw
  451:   $contactblock
  452:   $newuserlink
  453:   $coursecatalog
  454: </div>
  455: </div>
  456: 
  457: <div>
  458: ENDTOP
  459:     if ($showmainlogo) {
  460:         $r->print(' <img src="'.$logo.'" alt="" />'."\n");
  461:     }
  462: $r->print(<<ENDTOP);
  463: $announcements
  464: </div>
  465: <hr style="clear:both;" />
  466: ENDTOP
  467: 
  468: $r->print(<<ENDDOCUMENT);
  469:     <div style="float: left;">
  470:      <table border="0" cellspacing="0" cellpadding="0">
  471:       <tr>
  472:        <td  align="left" valign="top">
  473:         <small><b>$lt{'dom'}:&nbsp;</b></small>
  474:        </td>
  475:        <td  align="left" valign="top">
  476:         <small><tt>&nbsp;$domain</tt></small>
  477:        </td>
  478:       </tr>
  479:       <tr>
  480:        <td  align="left" valign="top">
  481:         <small><b>$lt{'serv'}:&nbsp;</b></small>
  482:        </td>
  483:        <td align="left" valign="top">
  484:         <small><tt>&nbsp;$lonhost ($role)</tt></small>
  485:        </td>
  486:       </tr>
  487:       <tr>
  488:        <td align="left" valign="top">
  489:         <small><b>$lt{'load'}:&nbsp;</b></small>
  490:        </td>
  491:        <td align="left" valign="top">
  492:         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
  493:        </td>
  494:       </tr>
  495:       <tr>
  496:        <td align="left" valign="top">
  497:         <small><b>$lt{'userload'}:&nbsp;</b></small>
  498:        </td>
  499:        <td align="left" valign="top">
  500:         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
  501:        </td>
  502:       </tr>
  503:       <tr>
  504:        <td colspan="2" align="left">
  505:         <small>$version</small>
  506:        </td>
  507:       </tr>
  508:      </table>
  509:     </div>
  510:     <div style="float: right;">
  511:     $domainlogo
  512:     </div>
  513:     <br style="clear:both;" />
  514:  </div>
  515: 
  516: <script type="text/javascript">
  517: // <![CDATA[
  518: // the if prevents the script error if the browser can not handle this
  519: if ( document.client.uname ) { document.client.uname.focus(); }
  520: // ]]>
  521: </script>
  522: $helpdeskscript
  523: 
  524: ENDDOCUMENT
  525:     my %endargs = ( 'noredirectlink' => 1, );
  526:     $r->print(&Apache::loncommon::end_page(\%endargs));
  527:     return OK;
  528: }
  529: 
  530: sub check_loginvia {
  531:     my ($domain,$lonhost) = @_;
  532:     if ($domain eq '' || $lonhost eq '') {
  533:         return;
  534:     }
  535:     my %domconfhash = &Apache::loncommon::get_domainconf($domain);
  536:     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
  537:     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
  538:     my $output;
  539:     if ($loginvia ne '') {
  540:         my $noredirect;
  541:         my $ip = $ENV{'REMOTE_ADDR'};
  542:         if ($ip eq '127.0.0.1') {
  543:             $noredirect = 1;
  544:         } else {
  545:             if ($loginvia_exempt ne '') {
  546:                 my @exempt = split(',',$loginvia_exempt);
  547:                 if (grep(/^\Q$ip\E$/,@exempt)) {
  548:                     $noredirect = 1;
  549:                 }
  550:             }
  551:         }
  552:         unless ($noredirect) {
  553:             my ($newhost,$path);
  554:             if ($loginvia =~ /:/) {
  555:                 ($newhost,$path) = split(':',$loginvia);
  556:             } else {
  557:                 $newhost = $loginvia;
  558:             }
  559:             if ($newhost ne $lonhost) {
  560:                 if (&Apache::lonnet::hostname($newhost) ne '') {
  561:                     $output = &redirect_page($newhost,$path);
  562:                 }
  563:             }
  564:         }
  565:     }
  566:     return $output;
  567: }
  568: 
  569: sub redirect_page {
  570:     my ($desthost,$path) = @_;
  571:     my $protocol = $Apache::lonnet::protocol{$desthost};
  572:     $protocol = 'http' if ($protocol ne 'https');
  573:     unless ($path =~ m{^/}) {
  574:         $path = '/'.$path;
  575:     }
  576:     my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
  577:     if ($env{'form.firsturl'} ne '') {
  578:         $url .='?firsturl='.$env{'form.firsturl'};
  579:     }
  580:     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
  581:                                                     {'redirect' => [0,$url],});
  582:     my $end_page   = &Apache::loncommon::end_page();
  583:     return $start_page.$end_page;
  584: }
  585: 
  586: sub contactdisplay {
  587:     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript) = @_;
  588:     my $contactblock;
  589:     my $showhelpdesk = 0;
  590:     my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  591:     if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {
  592:         $showhelpdesk = 1;
  593:     }
  594:     if ($servadm && $showadminmail) {
  595:         $contactblock .= $$lt{'servadm'}.':<br />'.
  596:                          '<tt>'.$servadm.'</tt><br />';
  597:     }
  598:     if ($showhelpdesk) {
  599:         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
  600:         my $thisurl = &escape('/adm/login');
  601:         $$helpdeskscript = <<"ENDSCRIPT";
  602: <script type="text/javascript">
  603: // <![CDATA[
  604: function helpdesk() {
  605:     var codedom = document.client.udom.value;
  606:     if (codedom == '') {
  607:         codedom = "$authdomain";
  608:     }
  609:     var querystr = "origurl=$thisurl&codedom="+codedom;
  610:     document.location.href = "/adm/helpdesk?"+querystr;
  611:     return;
  612: }
  613: // ]]>
  614: </script>
  615: ENDSCRIPT
  616:     }
  617:     return $contactblock;
  618: }
  619: 
  620: sub forgotpwdisplay {
  621:     my (%lt) = @_;
  622:     my $prompt_for_resetpw = 1; 
  623:     if ($prompt_for_resetpw) {
  624:         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
  625:     }
  626:     return;
  627: }
  628: 
  629: sub loginhelpdisplay {
  630:     my ($authdomain,%lt) = @_;
  631:     my $login_help = 1;
  632:     if ($login_help) {
  633:         my $dom = $authdomain;
  634:         if ($dom eq '') {
  635:             $dom = &Apache::lonnet::default_login_domain();
  636:         }
  637:         my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);
  638:         my $loginhelp_url = $helpconfig{'helpsettings'}{'loginhelpurl'};
  639:         if ($loginhelp_url ne '') {
  640:             return '<a href="'.$loginhelp_url.'">'.$lt{'help'}.'</a>';
  641:         } else {
  642:             return '<a href="/adm/loginproblems.html">'.$lt{'help'}.'</a>';
  643:         }
  644:     }
  645:     return;
  646: }
  647: 
  648: sub coursecatalog_link {
  649:     my ($linkname) = @_;
  650:     return <<"END";
  651:       <a href="/adm/coursecatalog">$linkname</a>
  652: END
  653: }
  654: 
  655: sub newuser_link {
  656:     my ($linkname) = @_;
  657:     return '<a href="/adm/createaccount">'.$linkname.'</a>';
  658: }
  659: 
  660: 1;
  661: __END__

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