| 1 | # Copyrights 2008 by Mark Overmeer. | ||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 1.05. | ||||||||||||||||||||||
| 5 | package HTTP::Server::Directory; | ||||||||||||||||||||||
| 6 | 1 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 1 | $VERSION = '0.11'; | |||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | 1 | ▶ | use Log::Report 'httpd-multiplex', syntax => 'SHORT'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | 1 | ▶ | use Net::CIDR qw/cidrlookup/; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | 1 | ▶ | use File::Spec (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | sub _allow_cleanup($); | ||||||||||||||||||||||
| 18 | sub _allow_match($$$$); | ||||||||||||||||||||||
| 19 | sub _filename_trans($$); | ||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | sub new(@) | ||||||||||||||||||||||
| 23 | 0 | ▶ | { my $class = shift; | ||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 24 | 0 | ▶ | my $args = @_==1 ? shift : {@_}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 25 | 0 | (bless {}, $class)->init($args); | |||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | sub init($) | ||||||||||||||||||||||
| 29 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||
|
Subroutine
init: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | 0 | ▶ | my $path = $self->{HSD_path} = $args->{path} || '/'; | ||||||||||||||||||||
|
Condition0%0/2
$args->{'path'} || '/'
MC/DC0%0/1
$args->{'path'} || '/'
$args->{'path'}
Truth table0%0/2
A
A= $args->{'path'}
| |||||||||||||||||||||||
| 32 | my $loc = $args->{location} | ||||||||||||||||||||||
| 33 | 0 | ▶ | or error __x"directory definition requires location"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | 0 | ▶ | if(ref $loc eq 'CODE') {;} | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 36 | else | ||||||||||||||||||||||
| 37 | 0 | ▶ | { File::Spec->file_name_is_absolute($loc) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 38 | or error __x"directory location {loc} for path {path} not absolute" | ||||||||||||||||||||||
| 39 | , loc => $loc, path => $path; | ||||||||||||||||||||||
| 40 | 0 | ▶ | -d $loc | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 41 | or error __x"directory location {loc} for path {path} does not exist" | ||||||||||||||||||||||
| 42 | , loc => $loc, path => $path; | ||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | 0 | ▶ | substr($loc,-1) eq '/' or $loc .= '/'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||
| 46 | 0 | $self->{HSD_loc} = $loc; | |||||||||||||||||||||
| 47 | 0 | $self->{HSD_fn} = _filename_trans $path, $loc; | |||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | 0 | $self->{HSD_allow} = _allow_cleanup $args->{allow}; | |||||||||||||||||||||
| 50 | 0 | $self->{HSD_deny} = _allow_cleanup $args->{deny}; | |||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | 0 | $self; | |||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | #----------------- | ||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | 0 | ▶ | sub path() {shift->{HSD_path}} | ||||||||||||||||||||
|
Subroutine
path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 58 | 0 | ▶ | sub location() {shift->{HSD_location}} | ||||||||||||||||||||
|
Subroutine
location: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | #----------------- | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | sub allow($$$$) | ||||||||||||||||||||||
| 63 | 0 | ▶ | { my ($self, $client, $session, $req, $uri) = @_; | ||||||||||||||||||||
|
Subroutine
allow: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||
| 64 | 0 | ▶ | if(my $allow = $self->{HSD_allow}) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 65 | 0 | ▶ | { $self->_allow_match($client, $session, $uri, $allow) or return 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | 0 | ▶ | if(my $deny = $self->{HSD_deny}) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 68 | 0 | ▶ | { $self->_allow_match($client, $session, $uri, $deny) and return 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | 0 | 1; | |||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | sub _allow_match($$$$) | ||||||||||||||||||||||
| 74 | 0 | ▶ | { my ($self, $client, $session, $uri, $rules) = @_; | ||||||||||||||||||||
|
Subroutine
_allow_match: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 75 | 0 | my ($ip, $host) = @$client{'ip', 'host'}; | |||||||||||||||||||||
| 76 | 0 | ▶ | first { $_->($ip, $host, $session, $uri) } @$rules ? 1 : 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | sub _allow_cleanup($) | ||||||||||||||||||||||
| 80 | 0 | ▶ | { my $p = shift or return; | ||||||||||||||||||||
|
Subroutine
_allow_cleanup: not called CC=9 SCAR=45.0
Branch: 1 branch
| |||||||||||||||||||||||
| 81 | 0 | my @p; | |||||||||||||||||||||
| 82 | 0 | ▶ | foreach my $r (ref $p eq 'ARRAY' ? @$p : $p) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 83 | { push @p | ||||||||||||||||||||||
| 84 | , ref $r eq 'CODE' ? $r | ||||||||||||||||||||||
| 85 | 0 | ▶ | : index($r, ':') >= 0 ? sub {cidrlookup $_[0], $r} # IPv6 | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 86 | 0 | ▶ | : $r !~ m/[a-zA-Z]/ ? sub {cidrlookup $_[0], $r} # IPv4 | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 87 | 0 | ▶ | : $r =~ s/^\.// ? sub {$_[1] =~ qr/(^|\.)\Q$r\E$/i} # Domain | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 88 | 0 | ▶ | : sub {lc($_[1]) eq lc($r)} # hostname | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 89 | 0 | ▶ | } | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 90 | 0 | ▶ | @p ? \@p : undef; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||
| 92 | |||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | 0 | ▶ | sub filename($) { $_[0]->{HSD_fn}->($_[1]) } | ||||||||||||||||||||
|
Subroutine
filename: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | sub _filename_trans($$) | ||||||||||||||||||||||
| 97 | 0 | ▶ | { my ($path, $loc) = @_; | ||||||||||||||||||||
|
Subroutine
_filename_trans: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 98 | 0 | ▶ | return $loc if ref $loc eq 'CODE'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 99 | sub | ||||||||||||||||||||||
| 100 | 0 | ▶ | { my $x = shift; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 101 | 0 | ▶ | $x =~ s!^\Q$path!$loc! or panic "path $x not within $path"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 102 | 0 | $x; | |||||||||||||||||||||
| 103 | 0 | }; | |||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | 1 | 1; | |||||||||||||||||||||