Diff for /loncom/auth/lonracc.pm between versions 1.17 and 1.24

version 1.17, 2005/04/07 06:56:21 version 1.24, 2020/12/18 15:23:03
Line 26 Line 26
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
   
   =pod
   
   =head1 NAME
   
   Apache::lonracc - Access Handler for File Transfers
   
   =head1 SYNOPSIS
   
   Invoked by /etc/httpd/conf/loncapa.conf:
   
    <LocationMatch "^/raw.*">
    PerlAccessHandler Apache::lonracc
    </LocationMatch>
   
   =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;  package Apache::lonracc;
   
 use strict;  use strict;
Line 36  use IO::Socket; Line 83  use IO::Socket;
   
 sub subscribed {  sub subscribed {
     my ($filename,$id) = @_;      my ($filename,$id) = @_;
     my $found=0;  
     my $hostname=$Apache::lonnet::hostname{$id};      return 0 if (!-e "$filename.subscription");
   
       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 105  sub subscribed {
   
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
     my $reqhost = $r->get_remote_host(REMOTE_NOLOOKUP);  
     my %iphost=&Apache::lonnet::get_iphost();      my $filename=$r->filename;
     my $hostids=$iphost{$reqhost};      if (!-e $filename) {
     if (!$hostids && $reqhost ne '127.0.0.1' ) {   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->log_reason("Unable to find a host for ".
        $r->get_remote_host(REMOTE_NOLOOKUP));         $r->get_remote_host(REMOTE_NOLOOKUP));
  return FORBIDDEN;   return FORBIDDEN;
Line 64  sub handler { Line 122  sub handler {
  return OK;   return OK;
     }      }
     my $return;      my $return;
     my @ids=();      my @ids;
     my $id;  
   
     foreach $id (@{$hostids}) {      foreach my $id (@hostids) {
  my $filename=$r->filename;  
  my $uri =$r->uri;   my $uri =$r->uri;
  if ((-e "$filename.$id") ||   if (($filename=~/\.meta$/) ||
     &subscribed($filename,$id) ||      ($uri=~m|^/raw/uploaded|) ||
     ($filename=~/\.meta$/) ||      (-e "$filename.$id") ||
     ($uri=~m|^/raw/uploaded|)) {      &subscribed($filename,$id) ) {
     return OK;      return OK;
  } else {   } else {
     $return=FORBIDDEN;      $return=FORBIDDEN;
Line 92  sub handler { Line 148  sub handler {
 1;  1;
 __END__  __END__
   
 =head1 NAME  
   
 Apache::lonracc - Access Handler for File Transfers  
   
 =head1 SYNOPSIS  
   
 Invoked by /etc/httpd/conf/loncapa.conf:  
   
  <LocationMatch "^/raw.*">  
  PerlAccessHandler Apache::lonracc  
  </LocationMatch>  
   
 =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  
   
   
   

Removed from v.1.17  
changed lines
  Added in v.1.24


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>