--- loncom/auth/lonracc.pm 2007/02/01 06:20:34 1.18
+++ loncom/auth/lonracc.pm 2020/12/18 15:23:03 1.24
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Access Handler for File Transfers
#
-# $Id: lonracc.pm,v 1.18 2007/02/01 06:20:34 albertel Exp $
+# $Id: lonracc.pm,v 1.24 2020/12/18 15:23:03 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,6 +26,53 @@
# http://www.lon-capa.org/
#
+=pod
+
+=head1 NAME
+
+Apache::lonracc - Access Handler for File Transfers
+
+=head1 SYNOPSIS
+
+Invoked by /etc/httpd/conf/loncapa.conf:
+
+
+ PerlAccessHandler Apache::lonracc
+
+
+=head1 INTRODUCTION
+
+This module enables authentication for file transfers and works
+against the /res tree.
+
+Only lond invokes the /raw namespace through its subscribe function.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 HANDLER SUBROUTINE
+
+This routine is called by Apache and mod_perl.
+
+=over 4
+
+=item *
+
+Determine requesting host
+
+=item *
+
+See whether or not the requesting host is subscribed.
+
+=item *
+
+Respond with status of request and make log entry in case of unallowed
+access.
+
+=back
+
+=cut
+
package Apache::lonracc;
use strict;
@@ -37,9 +84,9 @@ use IO::Socket;
sub subscribed {
my ($filename,$id) = @_;
- return 0 if (-e "$filename.subscription");
+ 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);
return 0 if (length($ip) != 4);
@@ -58,10 +105,15 @@ sub subscribed {
sub handler {
my $r = shift;
- my $reqhost = $r->get_remote_host(REMOTE_NOLOOKUP);
- my %iphost=&Apache::lonnet::get_iphost();
- my $hostids=$iphost{$reqhost};
- if (!$hostids && $reqhost ne '127.0.0.1' ) {
+
+ my $filename=$r->filename;
+ if (!-e $filename) {
+ return NOT_FOUND;
+ }
+
+ my $reqhost = &Apache::lonnet::get_requestor_ip($r,REMOTE_NOLOOKUP,1);
+ my @hostids= &Apache::lonnet::get_hosts_from_ip($reqhost);
+ if (!@hostids && $reqhost ne '127.0.0.1' ) {
$r->log_reason("Unable to find a host for ".
$r->get_remote_host(REMOTE_NOLOOKUP));
return FORBIDDEN;
@@ -72,8 +124,7 @@ sub handler {
my $return;
my @ids;
- foreach my $id (@{$hostids}) {
- my $filename=$r->filename;
+ foreach my $id (@hostids) {
my $uri =$r->uri;
if (($filename=~/\.meta$/) ||
($uri=~m|^/raw/uploaded|) ||
@@ -97,50 +148,7 @@ sub handler {
1;
__END__
-=head1 NAME
-
-Apache::lonracc - Access Handler for File Transfers
-
-=head1 SYNOPSIS
-
-Invoked by /etc/httpd/conf/loncapa.conf:
-
-
- PerlAccessHandler Apache::lonracc
-
-
-=head1 INTRODUCTION
-
-This module enables authentication for file transfers and works
-against the /res tree.
-
-Only lond invokes the /raw namespace through its subscribe function.
-
-This is part of the LearningOnline Network with CAPA project
-described at http://www.lon-capa.org.
-
-=head1 HANDLER SUBROUTINE
-
-This routine is called by Apache and mod_perl.
-
-=over 4
-
-=item *
-Determine requesting host
-
-=item *
-
-See whether or not the requesting host is subscribed.
-
-=item *
-
-Respond with status of request and make log entry in case of unallowed
-access.
-
-=back
-
-=cut