File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.158.2.2: download - view: text, annotated - select for diffs
Fri Mar 6 22:36:56 2015 UTC (9 years, 2 months ago) by raeburn
Branches: version_2_11_X
Diff to branchpoint 1.158: preferred, unified
- For 2.11
  - Backport 1.159

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

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