Annotation of loncom/auth/lonracc.pm, revision 1.12

1.1       albertel    1: # The LearningOnline Network
                      2: # Access Handler for File Transfers
1.3       www         3: #
1.12    ! www         4: # $Id: lonracc.pm,v 1.11 2004/03/31 17:42:21 raeburn Exp $
1.3       www         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: #
1.1       albertel   28: 
                     29: package Apache::lonracc;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common :remotehost);
1.5       albertel   33: use Apache::lonnet();
1.1       albertel   34: use Apache::File();
                     35: 
1.5       albertel   36: sub subscribed {
                     37:     my ($filename,$id) = @_;
                     38:     my $found=0;
                     39:     my $expr='^'.$id.':'.$Apache::lonnet::hostip{$id}.':';
                     40:     $expr =~ s/\./\\\./g;
                     41:     my $sh;
                     42:     if ($sh=Apache::File->new("$filename.subscription")) {
                     43: 	while (my $subline=<$sh>) { if ($subline =~ /$expr/) { $found=1; } }
                     44: 	$sh->close();
                     45:     }
                     46:     return $found;
                     47: }
                     48: 
1.1       albertel   49: sub handler {
                     50:     my $r = shift;
1.6       bowersj2   51:     my $reqhost = $r->get_remote_host(REMOTE_DOUBLE_REV);
                     52:     if (!$reqhost && $r->get_remote_host(REMOTE_NOLOOKUP) eq $r->get_server_name()) { 
                     53:         $reqhost = $r->get_server_name();
                     54:     } 
1.7       matthew    55:     unless ($reqhost) {
1.6       bowersj2   56:        $r->log_reason("Spoof request from ".$ENV{'REMOTE_ADDR'});
1.1       albertel   57:        return FORBIDDEN;
1.12    ! www        58:     }
        !            59:     if ($reqhost eq 'localhost.localdomain') {
        !            60:        return OK;
1.1       albertel   61:     }
                     62:     my $readline;
                     63:     my $lontabdir=$r->dir_config('lonTabDir');
                     64:     {
                     65:        my $fh;
                     66:        unless ($fh=Apache::File->new("$lontabdir/hosts.tab")) {
                     67:           $r->log_reason("Could not find host tab file");
                     68:           return FORBIDDEN;
                     69:        }
1.9       albertel   70:        my $return;
                     71:        my @ids=();
1.1       albertel   72:        while ($readline=<$fh>) {
                     73:           my ($id,$domain,$role,$name,$ip)=split(/:/,$readline);
                     74:           if ($name =~ /$reqhost/i) {
                     75:               my $filename=$r->filename;
1.11      raeburn    76:               my $uri =$r->uri;
1.5       albertel   77:               if ((-e "$filename.$id") ||
                     78: 		  &subscribed($filename,$id) ||
1.11      raeburn    79: 		  ($filename=~/\.meta$/) ||
                     80:                   ($uri=~m|^/raw/uploaded|)) {
1.1       albertel   81: 	         return OK;
                     82:               } else {
1.8       albertel   83:                  $return=FORBIDDEN;
1.9       albertel   84: 		 push(@ids,$id);
1.1       albertel   85:               }
                     86:           }
                     87:        }
1.8       albertel   88:        if ($return == FORBIDDEN) {
1.9       albertel   89: 	   $r->log_reason(join(':',@ids)." not subscribed", $r->filename);
1.10      albertel   90: 	   return FORBIDDEN;
1.8       albertel   91:        }
1.1       albertel   92:     }
                     93:     $r->log_reason("Invalid request for file transfer from $reqhost", 
                     94:                    $r->filename); 
                     95:     return FORBIDDEN;
                     96: }
                     97: 
                     98: 1;
                     99: __END__
                    100: 
1.4       harris41  101: =head1 NAME
                    102: 
                    103: Apache::lonracc - Access Handler for File Transfers
                    104: 
                    105: =head1 SYNOPSIS
                    106: 
                    107: Invoked by /etc/httpd/conf/loncapa.conf:
                    108: 
                    109:  <LocationMatch "^/raw.*">
                    110:  PerlAccessHandler Apache::lonracc
                    111:  </LocationMatch>
                    112: 
                    113: =head1 INTRODUCTION
                    114: 
                    115: This module enables authentication for file transfers and works
                    116: against the /res tree.
                    117: 
                    118: Only lond invokes the /raw namespace through its subscribe function.
                    119: 
                    120: This is part of the LearningOnline Network with CAPA project
                    121: described at http://www.lon-capa.org.
                    122: 
                    123: =head1 HANDLER SUBROUTINE
                    124: 
                    125: This routine is called by Apache and mod_perl.
                    126: 
                    127: =over 4
                    128: 
                    129: =item *
                    130: 
                    131: Determine requesting host
                    132: 
                    133: =item *
                    134: 
                    135: See whether or not the requesting host is subscribed.
                    136: 
                    137: =item *
                    138: 
                    139: Respond with status of request and make log entry in case of unallowed
                    140: access.
                    141: 
                    142: =back
                    143: 
                    144: =cut
1.1       albertel  145: 
                    146: 
                    147: 
                    148: 
                    149: 
                    150: 
                    151: 

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