File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.170: download - view: text, annotated - select for diffs
Sat Feb 25 19:56:09 2017 UTC (7 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Name of cookie for public user set to lonPubID.

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

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