version 1.297, 2005/09/08 17:14:41
|
version 1.309, 2006/01/31 04:26:41
|
Line 87 my $ConnectionType;
|
Line 87 my $ConnectionType;
|
|
|
my %hostid; # ID's for hosts in cluster by ip. |
my %hostid; # ID's for hosts in cluster by ip. |
my %hostdom; # LonCAPA domain for hosts in cluster. |
my %hostdom; # LonCAPA domain for hosts in cluster. |
|
my %hostname; # DNSname -> ID's mapping. |
my %hostip; # IPs for hosts in cluster. |
my %hostip; # IPs for hosts in cluster. |
my %hostdns; # ID's of hosts looked up by DNS name. |
my %hostdns; # ID's of hosts looked up by DNS name. |
|
|
Line 1422 sub ls_handler {
|
Line 1423 sub ls_handler {
|
open(FILE, $ulsdir.'/'.$ulsfn.".meta"); |
open(FILE, $ulsdir.'/'.$ulsfn.".meta"); |
my @obsolete=<FILE>; |
my @obsolete=<FILE>; |
foreach my $obsolete (@obsolete) { |
foreach my $obsolete (@obsolete) { |
if($obsolete =~ m|(<obsolete>)(on)|) { $obs = 1; } |
if($obsolete =~ m/(<obsolete>)(on|1)/) { $obs = 1; } |
if($obsolete =~ m|(<copyright>)(default)|) { $rights = 1; } |
if($obsolete =~ m|(<copyright>)(default)|) { $rights = 1; } |
} |
} |
} |
} |
Line 1490 sub ls2_handler {
|
Line 1491 sub ls2_handler {
|
open(FILE, $ulsdir.'/'.$ulsfn.".meta"); |
open(FILE, $ulsdir.'/'.$ulsfn.".meta"); |
my @obsolete=<FILE>; |
my @obsolete=<FILE>; |
foreach my $obsolete (@obsolete) { |
foreach my $obsolete (@obsolete) { |
if($obsolete =~ m|(<obsolete>)(on)|) { $obs = 1; } |
if($obsolete =~ m/(<obsolete>)(on|1)/) { $obs = 1; } |
if($obsolete =~ m|(<copyright>)(default)|) { |
if($obsolete =~ m|(<copyright>)(default)|) { |
$rights = 1; |
$rights = 1; |
} |
} |
Line 1943 sub update_resource_handler {
|
Line 1944 sub update_resource_handler {
|
my $since=$now-$atime; |
my $since=$now-$atime; |
if ($since>$perlvar{'lonExpire'}) { |
if ($since>$perlvar{'lonExpire'}) { |
my $reply=&reply("unsub:$fname","$clientname"); |
my $reply=&reply("unsub:$fname","$clientname"); |
|
&devalidate_meta_cache($fname); |
unlink("$fname"); |
unlink("$fname"); |
} else { |
} else { |
my $transname="$fname.in.transfer"; |
my $transname="$fname.in.transfer"; |
Line 1973 sub update_resource_handler {
|
Line 1975 sub update_resource_handler {
|
alarm(0); |
alarm(0); |
} |
} |
rename($transname,$fname); |
rename($transname,$fname); |
|
&devalidate_meta_cache($fname); |
} |
} |
} |
} |
&Reply( $client, "ok\n", $userinput); |
&Reply( $client, "ok\n", $userinput); |
Line 1986 sub update_resource_handler {
|
Line 1989 sub update_resource_handler {
|
} |
} |
®ister_handler("update", \&update_resource_handler, 0 ,1, 0); |
®ister_handler("update", \&update_resource_handler, 0 ,1, 0); |
|
|
|
sub devalidate_meta_cache { |
|
my ($url) = @_; |
|
use Cache::Memcached; |
|
my $memcache = new Cache::Memcached({'servers'=>['127.0.0.1:11211']}); |
|
$url = &declutter($url); |
|
$url =~ s-\.meta$--; |
|
my $id = &escape('meta:'.$url); |
|
$memcache->delete($id); |
|
} |
|
|
|
sub declutter { |
|
my $thisfn=shift; |
|
$thisfn=~s/^\Q$perlvar{'lonDocRoot'}\E//; |
|
$thisfn=~s/^\///; |
|
$thisfn=~s|^adm/wrapper/||; |
|
$thisfn=~s|^adm/coursedocs/showdoc/||; |
|
$thisfn=~s/^res\///; |
|
$thisfn=~s/\?.+$//; |
|
return $thisfn; |
|
} |
# |
# |
# Fetch a user file from a remote server to the user's home directory |
# Fetch a user file from a remote server to the user's home directory |
# userfiles subdir. |
# userfiles subdir. |
Line 2887 sub dump_with_regexp {
|
Line 2910 sub dump_with_regexp {
|
|
|
my $userinput = "$cmd:$tail"; |
my $userinput = "$cmd:$tail"; |
|
|
my ($udom,$uname,$namespace,$regexp)=split(/:/,$tail); |
my ($udom,$uname,$namespace,$regexp,$range)=split(/:/,$tail); |
if (defined($regexp)) { |
if (defined($regexp)) { |
$regexp=&unescape($regexp); |
$regexp=&unescape($regexp); |
} else { |
} else { |
$regexp='.'; |
$regexp='.'; |
} |
} |
|
my ($start,$end); |
|
if (defined($range)) { |
|
if ($range =~/^(\d+)\-(\d+)$/) { |
|
($start,$end) = ($1,$2); |
|
} elsif ($range =~/^(\d+)$/) { |
|
($start,$end) = (0,$1); |
|
} else { |
|
undef($range); |
|
} |
|
} |
my $hashref = &tie_user_hash($udom, $uname, $namespace, |
my $hashref = &tie_user_hash($udom, $uname, $namespace, |
&GDBM_READER()); |
&GDBM_READER()); |
if ($hashref) { |
if ($hashref) { |
my $qresult=''; |
my $qresult=''; |
|
my $count=0; |
while (my ($key,$value) = each(%$hashref)) { |
while (my ($key,$value) = each(%$hashref)) { |
if ($regexp eq '.') { |
if ($regexp eq '.') { |
|
$count++; |
|
if (defined($range) && $count >= $end) { last; } |
|
if (defined($range) && $count < $start) { next; } |
$qresult.=$key.'='.$value.'&'; |
$qresult.=$key.'='.$value.'&'; |
} else { |
} else { |
my $unescapeKey = &unescape($key); |
my $unescapeKey = &unescape($key); |
if (eval('$unescapeKey=~/$regexp/')) { |
if (eval('$unescapeKey=~/$regexp/')) { |
|
$count++; |
|
if (defined($range) && $count >= $end) { last; } |
|
if (defined($range) && $count < $start) { next; } |
$qresult.="$key=$value&"; |
$qresult.="$key=$value&"; |
} |
} |
} |
} |
Line 3021 sub restore_handler {
|
Line 3061 sub restore_handler {
|
$namespace=~s/\//\_/g; |
$namespace=~s/\//\_/g; |
$namespace=~s/\W//g; |
$namespace=~s/\W//g; |
chomp($rid); |
chomp($rid); |
my $proname=&propath($udom,$uname); |
|
my $qresult=''; |
my $qresult=''; |
my %hash; |
my $hashref = &tie_user_hash($udom, $uname, $namespace, &GDBM_READER()); |
if (tie(%hash,'GDBM_File',"$proname/$namespace.db", |
if ($hashref) { |
&GDBM_READER(),0640)) { |
my $version=$hashref->{"version:$rid"}; |
my $version=$hash{"version:$rid"}; |
|
$qresult.="version=$version&"; |
$qresult.="version=$version&"; |
my $scope; |
my $scope; |
for ($scope=1;$scope<=$version;$scope++) { |
for ($scope=1;$scope<=$version;$scope++) { |
my $vkeys=$hash{"$scope:keys:$rid"}; |
my $vkeys=$hashref->{"$scope:keys:$rid"}; |
my @keys=split(/:/,$vkeys); |
my @keys=split(/:/,$vkeys); |
my $key; |
my $key; |
$qresult.="$scope:keys=$vkeys&"; |
$qresult.="$scope:keys=$vkeys&"; |
foreach $key (@keys) { |
foreach $key (@keys) { |
$qresult.="$scope:$key=".$hash{"$scope:$rid:$key"}."&"; |
$qresult.="$scope:$key=".$hashref->{"$scope:$rid:$key"}."&"; |
} |
} |
} |
} |
if (untie(%hash)) { |
if (untie(%$hashref)) { |
$qresult=~s/\&$//; |
$qresult=~s/\&$//; |
&Reply( $client, "$qresult\n", $userinput); |
&Reply( $client, "$qresult\n", $userinput); |
} else { |
} else { |
Line 3502 sub get_id_handler {
|
Line 3540 sub get_id_handler {
|
®ister_handler("idget", \&get_id_handler, 0, 1, 0); |
®ister_handler("idget", \&get_id_handler, 0, 1, 0); |
|
|
# |
# |
|
# Puts broadcast e-mail sent by Domain Coordinator in nohist_dcmail database |
|
# |
|
# Parameters |
|
# $cmd - Command keyword that caused us to be dispatched. |
|
# $tail - Tail of the command. Consists of a colon separated: |
|
# domain - the domain whose dcmail we are recording |
|
# email Consists of key=value pair |
|
# where key is unique msgid |
|
# and value is message (in XML) |
|
# $client - Socket open on the client. |
|
# |
|
# Returns: |
|
# 1 - indicating processing should continue. |
|
# Side effects |
|
# reply is written to $client. |
|
# |
|
sub put_dcmail_handler { |
|
my ($cmd,$tail,$client) = @_; |
|
my $userinput = "$cmd:$tail"; |
|
|
|
my ($udom,$what)=split(/:/,$tail); |
|
chomp($what); |
|
my $hashref = &tie_domain_hash($udom, "nohist_dcmail", &GDBM_WRCREAT()); |
|
if ($hashref) { |
|
my ($key,$value)=split(/=/,$what); |
|
$hashref->{$key}=$value; |
|
} |
|
if (untie(%$hashref)) { |
|
&Reply($client, "ok\n", $userinput); |
|
} else { |
|
&Failure($client, "error: ".($!+0)." untie(GDBM) Failed ". |
|
"while attempting dcmailput\n", $userinput); |
|
} |
|
return 1; |
|
} |
|
®ister_handler("dcmailput", \&put_dcmail_handler, 0, 1, 0); |
|
|
|
# |
|
# Retrieves broadcast e-mail from nohist_dcmail database |
|
# Returns to client an & separated list of key=value pairs, |
|
# where key is msgid and value is message information. |
|
# |
|
# Parameters |
|
# $cmd - Command keyword that caused us to be dispatched. |
|
# $tail - Tail of the command. Consists of a colon separated: |
|
# domain - the domain whose dcmail table we dump |
|
# startfilter - beginning of time window |
|
# endfilter - end of time window |
|
# sendersfilter - & separated list of username:domain |
|
# for senders to search for. |
|
# $client - Socket open on the client. |
|
# |
|
# Returns: |
|
# 1 - indicating processing should continue. |
|
# Side effects |
|
# reply (& separated list of msgid=messageinfo pairs) is |
|
# written to $client. |
|
# |
|
sub dump_dcmail_handler { |
|
my ($cmd, $tail, $client) = @_; |
|
|
|
my $userinput = "$cmd:$tail"; |
|
my ($udom,$startfilter,$endfilter,$sendersfilter) = split(/:/,$tail); |
|
chomp($sendersfilter); |
|
my @senders = (); |
|
if (defined($startfilter)) { |
|
$startfilter=&unescape($startfilter); |
|
} else { |
|
$startfilter='.'; |
|
} |
|
if (defined($endfilter)) { |
|
$endfilter=&unescape($endfilter); |
|
} else { |
|
$endfilter='.'; |
|
} |
|
if (defined($sendersfilter)) { |
|
$sendersfilter=&unescape($sendersfilter); |
|
@senders = map { &unescape($_) } split(/\&/,$sendersfilter); |
|
} |
|
|
|
my $qresult=''; |
|
my $hashref = &tie_domain_hash($udom, "nohist_dcmail", &GDBM_WRCREAT()); |
|
if ($hashref) { |
|
while (my ($key,$value) = each(%$hashref)) { |
|
my $match = 1; |
|
my ($timestamp,$subj,$uname,$udom) = |
|
split(/:/,&unescape(&unescape($key)),5); # yes, twice really |
|
$subj = &unescape($subj); |
|
unless ($startfilter eq '.' || !defined($startfilter)) { |
|
if ($timestamp < $startfilter) { |
|
$match = 0; |
|
} |
|
} |
|
unless ($endfilter eq '.' || !defined($endfilter)) { |
|
if ($timestamp > $endfilter) { |
|
$match = 0; |
|
} |
|
} |
|
unless (@senders < 1) { |
|
unless (grep/^$uname:$udom$/,@senders) { |
|
$match = 0; |
|
} |
|
} |
|
if ($match == 1) { |
|
$qresult.=$key.'='.$value.'&'; |
|
} |
|
} |
|
if (untie(%$hashref)) { |
|
chop($qresult); |
|
&Reply($client, "$qresult\n", $userinput); |
|
} else { |
|
&Failure($client, "error: ".($!+0)." untie(GDBM) Failed ". |
|
"while attempting dcmaildump\n", $userinput); |
|
} |
|
} else { |
|
&Failure($client, "error: ".($!+0)." tie(GDBM) Failed ". |
|
"while attempting dcmaildump\n", $userinput); |
|
} |
|
return 1; |
|
} |
|
|
|
®ister_handler("dcmaildump", \&dump_dcmail_handler, 0, 1, 0); |
|
|
|
# |
|
# Puts domain roles in nohist_domainroles database |
|
# |
|
# Parameters |
|
# $cmd - Command keyword that caused us to be dispatched. |
|
# $tail - Tail of the command. Consists of a colon separated: |
|
# domain - the domain whose roles we are recording |
|
# role - Consists of key=value pair |
|
# where key is unique role |
|
# and value is start/end date information |
|
# $client - Socket open on the client. |
|
# |
|
# Returns: |
|
# 1 - indicating processing should continue. |
|
# Side effects |
|
# reply is written to $client. |
|
# |
|
|
|
sub put_domainroles_handler { |
|
my ($cmd,$tail,$client) = @_; |
|
|
|
my $userinput = "$cmd:$tail"; |
|
my ($udom,$what)=split(/:/,$tail); |
|
chomp($what); |
|
my @pairs=split(/\&/,$what); |
|
my $hashref = &tie_domain_hash($udom, "nohist_domainroles", &GDBM_WRCREAT()); |
|
if ($hashref) { |
|
foreach my $pair (@pairs) { |
|
my ($key,$value)=split(/=/,$pair); |
|
$hashref->{$key}=$value; |
|
} |
|
if (untie(%$hashref)) { |
|
&Reply($client, "ok\n", $userinput); |
|
} else { |
|
&Failure($client, "error: ".($!+0)." untie(GDBM) Failed ". |
|
"while attempting domroleput\n", $userinput); |
|
} |
|
} else { |
|
&Failure( $client, "error: ".($!+0)." tie(GDBM) Failed ". |
|
"while attempting domroleput\n", $userinput); |
|
} |
|
|
|
return 1; |
|
} |
|
|
|
®ister_handler("domroleput", \&put_domainroles_handler, 0, 1, 0); |
|
|
|
# |
|
# Retrieves domain roles from nohist_domainroles database |
|
# Returns to client an & separated list of key=value pairs, |
|
# where key is role and value is start and end date information. |
|
# |
|
# Parameters |
|
# $cmd - Command keyword that caused us to be dispatched. |
|
# $tail - Tail of the command. Consists of a colon separated: |
|
# domain - the domain whose domain roles table we dump |
|
# $client - Socket open on the client. |
|
# |
|
# Returns: |
|
# 1 - indicating processing should continue. |
|
# Side effects |
|
# reply (& separated list of role=start/end info pairs) is |
|
# written to $client. |
|
# |
|
sub dump_domainroles_handler { |
|
my ($cmd, $tail, $client) = @_; |
|
|
|
my $userinput = "$cmd:$tail"; |
|
my ($udom,$startfilter,$endfilter,$rolesfilter) = split(/:/,$tail); |
|
chomp($rolesfilter); |
|
my @roles = (); |
|
if (defined($startfilter)) { |
|
$startfilter=&unescape($startfilter); |
|
} else { |
|
$startfilter='.'; |
|
} |
|
if (defined($endfilter)) { |
|
$endfilter=&unescape($endfilter); |
|
} else { |
|
$endfilter='.'; |
|
} |
|
if (defined($rolesfilter)) { |
|
$rolesfilter=&unescape($rolesfilter); |
|
@roles = split(/\&/,$rolesfilter); |
|
} |
|
|
|
my $hashref = &tie_domain_hash($udom, "nohist_domainroles", &GDBM_WRCREAT()); |
|
if ($hashref) { |
|
my $qresult = ''; |
|
while (my ($key,$value) = each(%$hashref)) { |
|
my $match = 1; |
|
my ($start,$end) = split(/:/,&unescape($value)); |
|
my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,&unescape($key)); |
|
unless ($startfilter eq '.' || !defined($startfilter)) { |
|
if ($start >= $startfilter) { |
|
$match = 0; |
|
} |
|
} |
|
unless ($endfilter eq '.' || !defined($endfilter)) { |
|
if ($end <= $endfilter) { |
|
$match = 0; |
|
} |
|
} |
|
unless (@roles < 1) { |
|
unless (grep/^$trole$/,@roles) { |
|
$match = 0; |
|
} |
|
} |
|
if ($match == 1) { |
|
$qresult.=$key.'='.$value.'&'; |
|
} |
|
} |
|
if (untie(%$hashref)) { |
|
chop($qresult); |
|
&Reply($client, "$qresult\n", $userinput); |
|
} else { |
|
&Failure($client, "error: ".($!+0)." untie(GDBM) Failed ". |
|
"while attempting domrolesdump\n", $userinput); |
|
} |
|
} else { |
|
&Failure($client, "error: ".($!+0)." tie(GDBM) Failed ". |
|
"while attempting domrolesdump\n", $userinput); |
|
} |
|
return 1; |
|
} |
|
|
|
®ister_handler("domrolesdump", \&dump_domainroles_handler, 0, 1, 0); |
|
|
|
|
# Process the tmpput command I'm not sure what this does.. Seems to |
# Process the tmpput command I'm not sure what this does.. Seems to |
# create a file in the lonDaemons/tmp directory of the form $id.tmp |
# create a file in the lonDaemons/tmp directory of the form $id.tmp |
# where Id is the client's ip concatenated with a sequence number. |
# where Id is the client's ip concatenated with a sequence number. |
Line 4424 sub ReadHostTable {
|
Line 4714 sub ReadHostTable {
|
} |
} |
$hostid{$ip}=$id; # LonCAPA name of host by IP. |
$hostid{$ip}=$id; # LonCAPA name of host by IP. |
$hostdom{$id}=$domain; # LonCAPA domain name of host. |
$hostdom{$id}=$domain; # LonCAPA domain name of host. |
|
$hostname{$id}=$name; # LonCAPA name -> DNS name |
$hostip{$id}=$ip; # IP address of host. |
$hostip{$id}=$ip; # IP address of host. |
$hostdns{$name} = $id; # LonCAPA name of host by DNS. |
$hostdns{$name} = $id; # LonCAPA name of host by DNS. |
|
|
Line 4674 sub reconlonc {
|
Line 4965 sub reconlonc {
|
|
|
sub subreply { |
sub subreply { |
my ($cmd,$server)=@_; |
my ($cmd,$server)=@_; |
my $peerfile="$perlvar{'lonSockDir'}/$server"; |
my $peerfile="$perlvar{'lonSockDir'}/".$hostname{$server}; |
my $sclient=IO::Socket::UNIX->new(Peer =>"$peerfile", |
my $sclient=IO::Socket::UNIX->new(Peer =>"$peerfile", |
Type => SOCK_STREAM, |
Type => SOCK_STREAM, |
Timeout => 10) |
Timeout => 10) |
or return "con_lost"; |
or return "con_lost"; |
print $sclient "$cmd\n"; |
print $sclient "sethost:$server:$cmd\n"; |
my $answer=<$sclient>; |
my $answer=<$sclient>; |
chomp($answer); |
chomp($answer); |
if (!$answer) { $answer="con_lost"; } |
if (!$answer) { $answer="con_lost"; } |
Line 4695 sub reply {
|
Line 4986 sub reply {
|
$answer=subreply("ping",$server); |
$answer=subreply("ping",$server); |
if ($answer ne $server) { |
if ($answer ne $server) { |
&logthis("sub reply: answer != server answer is $answer, server is $server"); |
&logthis("sub reply: answer != server answer is $answer, server is $server"); |
&reconlonc("$perlvar{'lonSockDir'}/$server"); |
&reconlonc("$perlvar{'lonSockDir'}/".$hostname{$server}); |
} |
} |
$answer=subreply($cmd,$server); |
$answer=subreply($cmd,$server); |
} |
} |
Line 5001 sub make_new_child {
|
Line 5292 sub make_new_child {
|
# no need to try to do recon's to myself |
# no need to try to do recon's to myself |
next; |
next; |
} |
} |
&reconlonc("$perlvar{'lonSockDir'}/$id"); |
&reconlonc("$perlvar{'lonSockDir'}/".$hostname{$id}); |
} |
} |
&logthis("<font color='green'>Established connection: $clientname</font>"); |
&logthis("<font color='green'>Established connection: $clientname</font>"); |
&status('Will listen to '.$clientname); |
&status('Will listen to '.$clientname); |