File:  [LON-CAPA] / loncom / auth / lonracc.pm
Revision 1.17: download - view: text, annotated - select for diffs
Thu Apr 7 06:56:21 2005 UTC (19 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: version_2_3_X, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_X, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, HEAD
- ENV -> env

    1: # The LearningOnline Network
    2: # Access Handler for File Transfers
    3: #
    4: # $Id: lonracc.pm,v 1.17 2005/04/07 06:56:21 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::lonracc;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common :remotehost);
   33: use Apache::lonnet;
   34: use Apache::File();
   35: use IO::Socket;
   36: 
   37: sub subscribed {
   38:     my ($filename,$id) = @_;
   39:     my $found=0;
   40:     my $hostname=$Apache::lonnet::hostname{$id};
   41:     my (undef,undef,undef,undef,$ip) = gethostbyname($hostname);
   42:     $ip=inet_ntoa($ip);
   43:     my $expr='^'.$id.':'.$ip.':';
   44:     $expr =~ s/\./\\\./g;
   45:     my $sh;
   46:     if ($sh=Apache::File->new("$filename.subscription")) {
   47: 	while (my $subline=<$sh>) { if ($subline =~ /$expr/) { $found=1; } }
   48: 	$sh->close();
   49:     }
   50:     return $found;
   51: }
   52: 
   53: sub handler {
   54:     my $r = shift;
   55:     my $reqhost = $r->get_remote_host(REMOTE_NOLOOKUP);
   56:     my %iphost=&Apache::lonnet::get_iphost();
   57:     my $hostids=$iphost{$reqhost};
   58:     if (!$hostids && $reqhost ne '127.0.0.1' ) {
   59: 	$r->log_reason("Unable to find a host for ".
   60: 		       $r->get_remote_host(REMOTE_NOLOOKUP));
   61: 	return FORBIDDEN;
   62:     }
   63:     if ($reqhost eq '127.0.0.1') {
   64: 	return OK;
   65:     }
   66:     my $return;
   67:     my @ids=();
   68:     my $id;
   69: 
   70:     foreach $id (@{$hostids}) {
   71: 	my $filename=$r->filename;
   72: 	my $uri =$r->uri;
   73: 	if ((-e "$filename.$id") ||
   74: 	    &subscribed($filename,$id) ||
   75: 	    ($filename=~/\.meta$/) ||
   76: 	    ($uri=~m|^/raw/uploaded|)) {
   77: 	    return OK;
   78: 	} else {
   79: 	    $return=FORBIDDEN;
   80: 	    push(@ids,$id);
   81: 	}
   82:     }
   83:     if ($return == FORBIDDEN) {
   84: 	$r->log_reason(join(':',@ids)." not subscribed", $r->filename);
   85: 	return FORBIDDEN;
   86:     }
   87:     $r->log_reason("Invalid request for file transfer from $reqhost", 
   88:                    $r->filename); 
   89:     return FORBIDDEN;
   90: }
   91: 
   92: 1;
   93: __END__
   94: 
   95: =head1 NAME
   96: 
   97: Apache::lonracc - Access Handler for File Transfers
   98: 
   99: =head1 SYNOPSIS
  100: 
  101: Invoked by /etc/httpd/conf/loncapa.conf:
  102: 
  103:  <LocationMatch "^/raw.*">
  104:  PerlAccessHandler Apache::lonracc
  105:  </LocationMatch>
  106: 
  107: =head1 INTRODUCTION
  108: 
  109: This module enables authentication for file transfers and works
  110: against the /res tree.
  111: 
  112: Only lond invokes the /raw namespace through its subscribe function.
  113: 
  114: This is part of the LearningOnline Network with CAPA project
  115: described at http://www.lon-capa.org.
  116: 
  117: =head1 HANDLER SUBROUTINE
  118: 
  119: This routine is called by Apache and mod_perl.
  120: 
  121: =over 4
  122: 
  123: =item *
  124: 
  125: Determine requesting host
  126: 
  127: =item *
  128: 
  129: See whether or not the requesting host is subscribed.
  130: 
  131: =item *
  132: 
  133: Respond with status of request and make log entry in case of unallowed
  134: access.
  135: 
  136: =back
  137: 
  138: =cut
  139: 
  140: 
  141: 
  142: 
  143: 
  144: 
  145: 

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