| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # Copyrights 2013-2020 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 | 2 |  |  | 2 |  | 12 | use vars '$VERSION'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 123 |  | 
| 11 |  |  |  |  |  |  | $VERSION = '0.30'; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 2 |  |  | 2 |  | 10 | use parent 'Any::Daemon::HTTP::Directory'; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 13 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 2 |  |  | 2 |  | 114 | use warnings; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 63 |  | 
| 16 | 2 |  |  | 2 |  | 10 | use strict; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 58 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 2 |  |  | 2 |  | 11 | use Log::Report    'any-daemon-http'; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 14 |  | 
| 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; |