File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.164: download - view: text, annotated - select for diffs
Sat Jun 6 14:39:42 2015 UTC (8 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Eliminate duplicate definitions.

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

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