File Coverage

blib/lib/Any/Daemon/HTTP/UserDirs.pm
Criterion Covered Total %
statement 15 34 44.1
branch 0 12 0.0
condition 0 17 0.0
subroutine 5 8 62.5
pod 0 2 0.0
total 20 73 27.4


line stmt bran cond sub pod time code
1             # Copyrights 2013-2019 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 2.02.
5             # This code is part of distribution Any-Daemon-HTTP. Meta-POD processed
6             # with OODoc into POD and HTML manual-pages. See README.md
7             # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8              
9             package Any::Daemon::HTTP::UserDirs;
10 1     1   6 use vars '$VERSION';
  1         1  
  1         63  
11             $VERSION = '0.29';
12              
13 1     1   5 use parent 'Any::Daemon::HTTP::Directory';
  1         2  
  1         17  
14              
15 1     1   57 use warnings;
  1         1  
  1         37  
16 1     1   5 use strict;
  1         2  
  1         29  
17              
18 1     1   5 use Log::Report 'any-daemon-http';
  1         2  
  1         8  
19              
20              
21             sub init($)
22 0     0 0   { my ($self, $args) = @_;
23              
24 0   0       my $subdirs = $args->{user_subdirs} || 'public_html';
25 0 0         my %allow = map +($_ => 1), @{$args->{allow_users} || []};
  0            
26 0 0         my %deny = map +($_ => 1), @{$args->{deny_users} || []};
  0            
27 0   0       $args->{location} ||= $self->userdirRewrite($subdirs, \%allow, \%deny);
28              
29 0           $self->SUPER::init($args);
30 0           $self;
31             }
32              
33             #-----------------
34              
35             sub userdirRewrite($$$)
36 0     0 0   { my ($self, $udsub, $allow, $deny) = @_;
37 0           my %homes; # cache
38 0     0     sub { my $path = shift;
39 0           my ($user, $pathinfo) = $path =~ m!^/\~([^/]*)(.*)!;
40 0 0 0       return if keys %$allow && !$allow->{$user};
41 0 0 0       return if keys %$deny && $deny->{$user};
42 0 0 0       return if exists $homes{$user} && !defined $homes{$user};
43 0   0       my $d = $homes{$user} ||= (getpwnam $user)[7];
44 0 0         $d ? "$d/$udsub$pathinfo" : undef;
45 0           };
46             }
47              
48             1;