| 1 | package Mail::Milter::Authentication::HTDocs; | ||||||||||
| 2 | 143 | ▶ | use 5.20.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 143 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 143 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 143 | ▶ | use Mail::Milter::Authentication::Pragmas; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | # ABSTRACT: Load and serve static files via the in-built http server. | ||||||||||
| 7 | 143 | our $VERSION = '4.20261116'; # VERSION | |||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 12 | 1 | my ( $class ) = @_; | |||||||||
| 13 | 1 | my $self = {}; | |||||||||
| 14 | 1 | bless $self, $class; | |||||||||
| 15 | 1 | return $self; | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | sub get_whitelist { | ||||||||
|
Subroutine
get_whitelist: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||
| 20 | 2 | my ( $self, $path ) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 2 | my @whitelist; | |||||||||
| 23 | |||||||||||
| 24 | 2 | ▶ | if ( opendir( my $dh, join( '/', $self->get_basedir(), $path ) ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 2 | ▶ | while ( my $file = readdir( $dh ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 8 | ▶ | next if $file =~ /^\./; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 4 | my $full_path = join( '/', $self->get_basedir(), $path, $file ); | |||||||||
| 28 | 4 | ▶ | if ( -f $full_path ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 3 | push @whitelist, join( '/', $path, $file ); | |||||||||
| 30 | } | ||||||||||
| 31 | 4 | ▶ | if ( -d $full_path ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 1 | @whitelist = ( @whitelist, @{ $self->get_whitelist( join ( '/', $path, $file ) ) } ); | |||||||||
| 33 | } | ||||||||||
| 34 | } | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 2 | return \@whitelist; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | |||||||||||
| 41 | 6 | ▶ | sub get_basedir { | ||||||||
|
Subroutine
get_basedir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 42 | 6 | my ( $self ) = @_; | |||||||||
| 43 | 6 | my $basedir = __FILE__; | |||||||||
| 44 | 6 | $basedir =~ s/HTDocs\.pm$/htdocs/; | |||||||||
| 45 | 6 | return $basedir; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | 1 | ▶ | sub get_file { | ||||||||
|
Subroutine
get_file: called CC=3 SCAR=16.9
Pod
documented
| |||||||||||
| 50 | 1 | my ( $self, $file ) = @_; | |||||||||
| 51 | |||||||||||
| 52 | 1 | my $whitelisted = grep { $_ eq $file } @{ $self->get_whitelist( '' ) }; | |||||||||
| 53 | 1 | ▶ | return if ! $whitelisted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | |||||||||||
| 55 | 0 | my $basefile = $self->get_basedir(); | |||||||||
| 56 | 0 | $basefile .= $file; | |||||||||
| 57 | 0 | ▶ | if ( ! -e $basefile ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | return; | |||||||||
| 59 | } | ||||||||||
| 60 | 0 | open my $InF, '<', $basefile; | |||||||||
| 61 | 0 | my @Content = <$InF>; | |||||||||
| 62 | 0 | close $InF; | |||||||||
| 63 | 0 | return join( q{}, @Content ); | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 143 | 1; | |||||||||
| 67 | |||||||||||
| 68 | __END__ | ||||||||||