line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::HTDocs; |
2
|
99
|
|
|
99
|
|
598
|
use strict; |
|
99
|
|
|
|
|
217
|
|
|
99
|
|
|
|
|
2508
|
|
3
|
99
|
|
|
99
|
|
423
|
use warnings; |
|
99
|
|
|
|
|
240
|
|
|
99
|
|
|
|
|
43588
|
|
4
|
|
|
|
|
|
|
our $VERSION = '20191206'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
0
|
|
|
0
|
1
|
|
my ( $class ) = @_; |
10
|
0
|
|
|
|
|
|
my $self = {}; |
11
|
0
|
|
|
|
|
|
bless $self, $class; |
12
|
0
|
|
|
|
|
|
return $self; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub get_whitelist { |
17
|
0
|
|
|
0
|
1
|
|
my ( $self, $path ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my @whitelist; |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
if ( opendir( my $dh, join( '/', $self->get_basedir(), $path ) ) ) { |
22
|
0
|
|
|
|
|
|
while ( my $file = readdir( $dh ) ) { |
23
|
0
|
0
|
|
|
|
|
next if $file =~ /^\./; |
24
|
0
|
|
|
|
|
|
my $full_path = join( '/', $self->get_basedir(), $path, $file ); |
25
|
0
|
0
|
|
|
|
|
if ( -f $full_path ) { |
26
|
0
|
|
|
|
|
|
push @whitelist, join( '/', $path, $file ); |
27
|
|
|
|
|
|
|
} |
28
|
0
|
0
|
|
|
|
|
if ( -d $full_path ) { |
29
|
0
|
|
|
|
|
|
@whitelist = ( @whitelist, @{ $self->get_whitelist( join ( '/', $path, $file ) ) } ); |
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return \@whitelist; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_basedir { |
39
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
40
|
0
|
|
|
|
|
|
my $basedir = __FILE__; |
41
|
0
|
|
|
|
|
|
$basedir =~ s/HTDocs\.pm$/htdocs/; |
42
|
0
|
|
|
|
|
|
return $basedir; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_file { |
47
|
0
|
|
|
0
|
1
|
|
my ( $self, $file ) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $whitelisted = grep { $_ eq $file } @{ $self->get_whitelist( '' ) }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
return if ! $whitelisted; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $basefile = $self->get_basedir(); |
53
|
0
|
|
|
|
|
|
$basefile .= $file; |
54
|
0
|
0
|
|
|
|
|
if ( ! -e $basefile ) { |
55
|
0
|
|
|
|
|
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
open my $InF, '<', $basefile; |
58
|
0
|
|
|
|
|
|
my @Content = <$InF>; |
59
|
0
|
|
|
|
|
|
close $InF; |
60
|
0
|
|
|
|
|
|
return join( q{}, @Content ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=pod |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=encoding UTF-8 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Mail::Milter::Authentication::HTDocs |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 VERSION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
version 20191206 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Load and serve static files via the in-build http server. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 I<new()> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Return a new instance of this class |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 METHODS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 I<get_whitelist()> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Return an arrayref of valid URLs/Filenames whih are allowed to be served. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 I<get_basedir()> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Return the base directory for htdocs files |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 I<get_file( $file )> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Return a full HTTP response for the given filename, or null if it does not exist. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 AUTHOR |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Marc Bradshaw <marc@marcbradshaw.net> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Marc Bradshaw. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
112
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |