version 1.15, 2005/02/06 07:23:40
|
version 1.20, 2007/02/01 07:13:04
|
Line 30 package Apache::lonracc;
|
Line 30 package Apache::lonracc;
|
|
|
use strict; |
use strict; |
use Apache::Constants qw(:common :remotehost); |
use Apache::Constants qw(:common :remotehost); |
use Apache::lonnet(); |
use Apache::lonnet; |
use Apache::File(); |
use Apache::File(); |
use IO::Socket; |
use IO::Socket; |
|
|
sub subscribed { |
sub subscribed { |
my ($filename,$id) = @_; |
my ($filename,$id) = @_; |
my $found=0; |
|
|
return 0 if (!-e "$filename.subscription"); |
|
|
my $hostname=$Apache::lonnet::hostname{$id}; |
my $hostname=$Apache::lonnet::hostname{$id}; |
my (undef,undef,undef,undef,$ip) = gethostbyname($hostname); |
my (undef,undef,undef,undef,$ip) = gethostbyname($hostname); |
|
|
|
return 0 if (length($ip) != 4); |
|
|
$ip=inet_ntoa($ip); |
$ip=inet_ntoa($ip); |
my $expr='^'.$id.':'.$ip.':'; |
|
$expr =~ s/\./\\\./g; |
my $expr='^'.quotemeta($id).':'.quotemeta($ip).':'; |
my $sh; |
|
if ($sh=Apache::File->new("$filename.subscription")) { |
my $found=0; |
|
if (my $sh=Apache::File->new("$filename.subscription")) { |
while (my $subline=<$sh>) { if ($subline =~ /$expr/) { $found=1; } } |
while (my $subline=<$sh>) { if ($subline =~ /$expr/) { $found=1; } } |
$sh->close(); |
$sh->close(); |
} |
} |
Line 52 sub subscribed {
|
Line 58 sub subscribed {
|
|
|
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
|
|
|
my $filename=$r->filename; |
|
if (!-e $filename) { |
|
return NOT_FOUND; |
|
} |
|
|
my $reqhost = $r->get_remote_host(REMOTE_NOLOOKUP); |
my $reqhost = $r->get_remote_host(REMOTE_NOLOOKUP); |
my $netaddr=inet_aton($reqhost); |
my %iphost=&Apache::lonnet::get_iphost(); |
($reqhost) = gethostbyaddr($netaddr,AF_INET); |
my $hostids=$iphost{$reqhost}; |
if (!$reqhost) { |
if (!$hostids && $reqhost ne '127.0.0.1' ) { |
$r->log_reason("Unable to do hostname $reqhost lookup for ".$r->get_remote_host(REMOTE_NOLOOKUP)); |
$r->log_reason("Unable to find a host for ". |
|
$r->get_remote_host(REMOTE_NOLOOKUP)); |
return FORBIDDEN; |
return FORBIDDEN; |
} |
} |
if ($reqhost eq 'localhost.localdomain') { |
if ($reqhost eq '127.0.0.1') { |
return OK; |
return OK; |
} |
} |
my $return; |
my $return; |
my @ids=(); |
my @ids; |
my $id; |
|
foreach $id (keys %Apache::lonnet::hostname) { |
foreach my $id (@{$hostids}) { |
if ($Apache::lonnet::hostname{$id} =~ /^\Q$reqhost\E$/i) { |
my $uri =$r->uri; |
my $filename=$r->filename; |
if (($filename=~/\.meta$/) || |
my $uri =$r->uri; |
($uri=~m|^/raw/uploaded|) || |
if ((-e "$filename.$id") || |
(-e "$filename.$id") || |
&subscribed($filename,$id) || |
&subscribed($filename,$id) ) { |
($filename=~/\.meta$/) || |
return OK; |
($uri=~m|^/raw/uploaded|)) { |
} else { |
return OK; |
$return=FORBIDDEN; |
} else { |
push(@ids,$id); |
$return=FORBIDDEN; |
|
push(@ids,$id); |
|
} |
|
} |
} |
} |
} |
if ($return == FORBIDDEN) { |
if ($return == FORBIDDEN) { |