version 1.13, 2004/05/03 19:52:19
|
version 1.18, 2007/02/01 06:20:34
|
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; |
|
|
sub subscribed { |
sub subscribed { |
my ($filename,$id) = @_; |
my ($filename,$id) = @_; |
|
|
|
return 0 if (-e "$filename.subscription"); |
|
|
|
my $hostname=$Apache::lonnet::hostname{$id}; |
|
my (undef,undef,undef,undef,$ip) = gethostbyname($hostname); |
|
|
|
return 0 if (length($ip) != 4); |
|
|
|
$ip=inet_ntoa($ip); |
|
|
|
my $expr='^'.quotemeta($id).':'.quotemeta($ip).':'; |
|
|
my $found=0; |
my $found=0; |
my $expr='^'.$id.':'.$Apache::lonnet::hostip{$id}.':'; |
if (my $sh=Apache::File->new("$filename.subscription")) { |
$expr =~ s/\./\\\./g; |
|
my $sh; |
|
if ($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 48 sub subscribed {
|
Line 58 sub subscribed {
|
|
|
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
my $reqhost = $r->get_remote_host(REMOTE_DOUBLE_REV); |
my $reqhost = $r->get_remote_host(REMOTE_NOLOOKUP); |
if (!$reqhost && $r->get_remote_host(REMOTE_NOLOOKUP) eq $r->get_server_name()) { |
my %iphost=&Apache::lonnet::get_iphost(); |
$reqhost = $r->get_server_name(); |
my $hostids=$iphost{$reqhost}; |
} |
if (!$hostids && $reqhost ne '127.0.0.1' ) { |
unless ($reqhost) { |
$r->log_reason("Unable to find a host for ". |
$r->log_reason("Spoof request from ".$ENV{'REMOTE_ADDR'}); |
$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} =~ /$reqhost/i) { |
my $filename=$r->filename; |
my $filename=$r->filename; |
my $uri =$r->uri; |
my $uri =$r->uri; |
if (($filename=~/\.meta$/) || |
if ((-e "$filename.$id") || |
($uri=~m|^/raw/uploaded|) || |
&subscribed($filename,$id) || |
(-e "$filename.$id") || |
($filename=~/\.meta$/) || |
&subscribed($filename,$id) ) { |
($uri=~m|^/raw/uploaded|)) { |
return OK; |
return OK; |
} else { |
} else { |
$return=FORBIDDEN; |
$return=FORBIDDEN; |
push(@ids,$id); |
push(@ids,$id); |
|
} |
|
} |
} |
} |
} |
if ($return == FORBIDDEN) { |
if ($return == FORBIDDEN) { |