--- loncom/lond 2011/05/13 02:58:02 1.472
+++ loncom/lond 2011/10/24 20:43:51 1.482
@@ -2,7 +2,7 @@
# The LearningOnline Network
# lond "LON Daemon" Server (port "LOND" 5663)
#
-# $Id: lond,v 1.472 2011/05/13 02:58:02 raeburn Exp $
+# $Id: lond,v 1.482 2011/10/24 20:43:51 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -60,7 +60,7 @@ my $DEBUG = 0; # Non zero to ena
my $status='';
my $lastlog='';
-my $VERSION='$Revision: 1.472 $'; #' stupid emacs
+my $VERSION='$Revision: 1.482 $'; #' stupid emacs
my $remoteVERSION;
my $currenthostid="default";
my $currentdomainid;
@@ -92,6 +92,8 @@ my %managers; # Ip -> manager names
my %perlvar; # Will have the apache conf defined perl vars.
+my $dist;
+
#
# The hash below is used for command dispatching, and is therefore keyed on the request keyword.
# Each element of the hash contains a reference to an array that contains:
@@ -421,7 +423,8 @@ sub ReadManagerTable {
my $tablename = $perlvar{'lonTabDir'}."/managers.tab";
if (!open (MANAGERS, $tablename)) {
- if (&loncapa_dns_server()) {
+ my $hostname = &Apache::lonnet::hostname($perlvar{'lonHostID'});
+ if (&Apache::lonnet::is_LC_dns($hostname)) {
&logthis('No manager table. Nobody can manage!!');
}
return;
@@ -677,7 +680,7 @@ sub PushFile {
return "error:$!";
} else {
&logthis(' Installed new '.$tablefile
- ."");
+ ." - transaction by: $clientname ($clientip)");
my $adminmail = $perlvar{'lonAdmEMail'};
my $admindom = &Apache::lonnet::host_domain($perlvar{'lonHostID'});
if ($admindom ne '') {
@@ -691,16 +694,12 @@ sub PushFile {
}
if ($adminmail =~ /^[^\@]+\@[^\@]+$/) {
my $msg = new Mail::Send;
- my $senderaddress = $perlvar{'lonSysEMail'};
$msg->to($adminmail);
$msg->subject('LON-CAPA DNS update on '.$perlvar{'lonHostID'});
- if ($senderaddress) {
- $msg->add('From',$senderaddress);
- }
$msg->add('Content-type','text/plain; charset=UTF-8');
if (my $fh = $msg->open()) {
print $fh 'Update to '.$tablefile.' from Cluster Manager '.
- $client."\n";
+ "$clientname ($clientip)\n";
$fh->close;
}
}
@@ -712,25 +711,6 @@ sub PushFile {
}
-sub loncapa_dns_server {
- my $lonhost = &Apache::lonnet::get_host_ip($perlvar{'lonHostID'});
- my $hoststable = "$perlvar{'lonTabDir'}/hosts.tab";
- my $is_dns_server;
- if (!open(HOSTS,"<$hoststable")) {
- &logthis('Could not open hosts.tab to check for LON-CAPA DNS servers.');
- while (my $host = ) {
- chomp($host);
- $host =~ s/(^\s+|\s+$)//g;
- if ($host =~ /^\Q^$lonhost\E/) {
- $is_dns_server = 1;
- last;
- }
- }
- close(HOSTS);
- }
- return $is_dns_server;
-}
-
#
# Called to re-init either lonc or lond.
#
@@ -1663,6 +1643,74 @@ sub ls3_handler {
}
®ister_handler("ls3", \&ls3_handler, 0, 1, 0);
+sub read_lonnet_global {
+ my ($cmd,$tail,$client) = @_;
+ my $userinput = "$cmd:$tail";
+ my $requested = &Apache::lonnet::thaw_unescape($tail);
+ my $result;
+ my %packagevars = (
+ spareid => \%Apache::lonnet::spareid,
+ perlvar => \%Apache::lonnet::perlvar,
+ );
+ my %limit_to = (
+ perlvar => {
+ lonOtherAuthen => 1,
+ lonBalancer => 1,
+ lonVersion => 1,
+ lonSysEMail => 1,
+ lonHostID => 1,
+ lonRole => 1,
+ lonDefDomain => 1,
+ lonLoadLim => 1,
+ lonUserLoadLim => 1,
+ }
+ );
+ if (ref($requested) eq 'HASH') {
+ foreach my $what (keys(%{$requested})) {
+ my $response;
+ my $items = {};
+ if (exists($packagevars{$what})) {
+ if (ref($limit_to{$what}) eq 'HASH') {
+ foreach my $varname (keys(%{$packagevars{$what}})) {
+ if ($limit_to{$what}{$varname}) {
+ $items->{$varname} = $packagevars{$what}{$varname};
+ }
+ }
+ } else {
+ $items = $packagevars{$what};
+ }
+ if ($what eq 'perlvar') {
+ if (!exists($packagevars{$what}{'lonBalancer'})) {
+ if ($dist =~ /^(centos|rhes|fedora|scientific)/) {
+ my $othervarref=LONCAPA::Configuration::read_conf('httpd.conf');
+ if (ref($othervarref) eq 'HASH') {
+ $items->{'lonBalancer'} = $othervarref->{'lonBalancer'};
+ }
+ }
+ }
+ }
+ $response = &Apache::lonnet::freeze_escape($items);
+ }
+ $result .= &escape($what).'='.$response.'&';
+ }
+ }
+ $result =~ s/\&$//;
+ &Reply($client,\$result,$userinput);
+ return 1;
+}
+®ister_handler("readlonnetglobal", \&read_lonnet_global, 0, 1, 0);
+
+sub server_devalidatecache_handler {
+ my ($cmd,$tail,$client) = @_;
+ my $userinput = "$cmd:$tail";
+ my ($name,$id) = map { &unescape($_); } split(/:/,$tail);
+ &Apache::lonnet::devalidate_cache_new($name,$id);
+ my $result = 'ok';
+ &Reply($client,\$result,$userinput);
+ return 1;
+}
+®ister_handler("devalidatecache", \&server_devalidatecache_handler, 0, 1, 0);
+
sub server_timezone_handler {
my ($cmd,$tail,$client) = @_;
my $userinput = "$cmd:$tail";
@@ -2300,7 +2348,9 @@ sub fetch_user_file_handler {
my $destname=$udir.'/'.$ufile;
my $transname=$udir.'/'.$ufile.'.in.transit';
- my $remoteurl='http://'.$clientip.'/userfiles/'.$fname;
+ my $clientprotocol=$Apache::lonnet::protocol{$clientname};
+ $clientprotocol = 'http' if ($clientprotocol ne 'https');
+ my $remoteurl=$clientprotocol.'://'.$clientip.'/userfiles/'.$fname;
my $response;
Debug("Remote URL : $remoteurl Transfername $transname Destname: $destname");
alarm(120);
@@ -6114,9 +6164,13 @@ sub HUPSMAN { # sig
# a setuid perl script that can be root for us to do this job.
#
sub ReloadApache {
- my $execdir = $perlvar{'lonDaemons'};
- my $script = $execdir."/apachereload";
- system($script);
+# --------------------------- Handle case of another apachereload process (locking)
+ if (&LONCAPA::try_to_lock('/tmp/lock_apachereload')) {
+ my $execdir = $perlvar{'lonDaemons'};
+ my $script = $execdir."/apachereload";
+ system($script);
+ unlink('/tmp/lock_apachereload'); # Remove the lock file.
+ }
}
#
@@ -6380,11 +6434,13 @@ $SIG{USR2} = \&UpdateHosts;
&Apache::lonnet::load_hosts_tab();
my %iphost = &Apache::lonnet::get_iphost(1);
-my $dist=`$perlvar{'lonDaemons'}/distprobe`;
+$dist=`$perlvar{'lonDaemons'}/distprobe`;
my $arch = `uname -i`;
+chomp($arch);
if ($arch eq 'unknown') {
$arch = `uname -m`;
+ chomp($arch);
}
# --------------------------------------------------------------
@@ -6674,8 +6730,7 @@ sub is_author {
}
#
# Checks to see if the input roleput request was to set
-# an author role. If so, invokes the lchtmldir script to set
-# up a correct public_html
+# an author role. If so, creates construction space
# Parameters:
# request - The request sent to the rolesput subchunk.
# We're looking for /domain/_au
@@ -6685,16 +6740,15 @@ sub is_author {
#
sub manage_permissions {
my ($request, $domain, $user, $authtype) = @_;
-
- &Debug("manage_permissions: $request $domain $user $authtype");
-
# See if the request is of the form /$domain/_au
if($request =~ /^(\/\Q$domain\E\/_au)$/) { # It's an author rolesput...
- my $execdir = $perlvar{'lonDaemons'};
- my $userhome= "/home/$user" ;
- &logthis("system $execdir/lchtmldir $userhome $user $authtype");
- &Debug("Setting homedir permissions for $userhome");
- system("$execdir/lchtmldir $userhome $user $authtype");
+ my $path="/home/httpd/html/priv/".$domain;
+ unless (-e $path) {
+ mkdir($path);
+ }
+ unless (-e $path.'/'.$user) {
+ mkdir($path.'/'.$user);
+ }
}
}
@@ -7183,7 +7237,9 @@ sub subscribe {
# the metadata
unless ($fname=~/\.meta$/) { &unsub("$fname.meta",$clientip); }
$fname=~s/\/home\/httpd\/html\/res/raw/;
- $fname="http://".&Apache::lonnet::hostname($perlvar{'lonHostID'})."/".$fname;
+ my $protocol = $Apache::lonnet::protocol{$perlvar{'lonHostID'}};
+ $protocol = 'http' if ($protocol ne 'https');
+ $fname=$protocol.'://'.&Apache::lonnet::hostname($perlvar{'lonHostID'})."/".$fname;
$result="$fname\n";
}
} else {