line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::AddressList; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
18512
|
use Moose; |
|
3
|
|
|
|
|
300221
|
|
|
3
|
|
|
|
|
15
|
|
4
|
3
|
|
|
3
|
|
13058
|
use namespace::autoclean; |
|
3
|
|
|
|
|
5171
|
|
|
3
|
|
|
|
|
17
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.01'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: a class for IP address lists |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1681
|
use NetAddr::IP; |
|
3
|
|
|
|
|
57375
|
|
|
3
|
|
|
|
|
13
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has '_localhost_addr' => ( is => 'ro', isa => 'ArrayRef[NetAddr::IP]', |
12
|
|
|
|
|
|
|
lazy => 1, |
13
|
|
|
|
|
|
|
default => sub { |
14
|
|
|
|
|
|
|
return [ map { NetAddr::IP->new( $_ ) } |
15
|
|
|
|
|
|
|
( '127.0.0.0/8', '::ffff:127.0.0.0/104', '::1' ) ]; |
16
|
|
|
|
|
|
|
}, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'list' => ( |
21
|
|
|
|
|
|
|
is => 'ro', isa => 'ArrayRef[NetAddr::IP]', lazy => 1, |
22
|
|
|
|
|
|
|
default => sub { [] }, |
23
|
|
|
|
|
|
|
traits => [ 'Array' ], |
24
|
|
|
|
|
|
|
handles => { |
25
|
|
|
|
|
|
|
'add' => 'push', |
26
|
|
|
|
|
|
|
'is_empty' => 'is_empty', |
27
|
|
|
|
|
|
|
'count' => 'count', |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub add_localhost { |
33
|
2
|
|
|
2
|
1
|
3
|
my $self = shift; |
34
|
2
|
|
|
|
|
3
|
$self->add( @{$self->_localhost_addr} ); |
|
2
|
|
|
|
|
61
|
|
35
|
2
|
|
|
|
|
3
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub add_string { |
40
|
3
|
|
|
3
|
1
|
5
|
my ( $self, @strings ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my @addr_strings = map { |
43
|
3
|
|
|
|
|
6
|
split( /\s*[, ]\s*/, $_ ) |
|
3
|
|
|
|
|
13
|
|
44
|
|
|
|
|
|
|
} @strings; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my @addr = map { |
47
|
3
|
|
|
|
|
4
|
NetAddr::IP->new( $_ ); |
|
4
|
|
|
|
|
281
|
|
48
|
|
|
|
|
|
|
} @addr_strings; |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
223
|
$self->add( @addr ); |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
6
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub match { |
57
|
8
|
|
|
8
|
1
|
11
|
my ( $self, $addr ) = @_; |
58
|
8
|
100
|
|
|
|
5
|
if( grep { $_->contains( $addr ) } @{$self->list} ) { |
|
32
|
|
|
|
|
326
|
|
|
8
|
|
|
|
|
252
|
|
59
|
4
|
|
|
|
|
45
|
return 1; |
60
|
|
|
|
|
|
|
} |
61
|
4
|
|
|
|
|
48
|
return 0; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub match_string { |
66
|
8
|
|
|
8
|
1
|
361
|
my ( $self, $string ) = @_; |
67
|
8
|
|
|
|
|
24
|
my $addr = NetAddr::IP->new( $string ); |
68
|
8
|
|
|
|
|
728
|
return( $self->match( $addr ) ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub as_string { |
73
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
74
|
1
|
|
|
|
|
2
|
return join(',', map { $_->cidr } @{$self->list}); |
|
3
|
|
|
|
|
381
|
|
|
1
|
|
|
|
|
30
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=encoding UTF-8 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Mail::MtPolicyd::AddressList - a class for IP address lists |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 VERSION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
version 2.01 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 Attributes |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 list |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Contains an ArrayRef of NetAddr::IP which holds the all entries of this object. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 Methods |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 add |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Add a list of NetAddr::IP objects to the list. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 is_empty |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Returns a true value when empty. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 count |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Returns the number of entries. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 add_localhost |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Add localhost addresses to list. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 add_string |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Takes a list of IP address strings. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The strings itself can contain a list of comma/space separated addresses. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Then a list of NetAddr::IP objects is created and pushed to the list. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 match |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Returns true if the give NetAddr::IP object matches an entry of the list. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 match_string |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Same as match(), but takes an string instead of NetAddr::IP object. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 as_string |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Returns a comma separated string with all addresses. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 AUTHOR |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This is free software, licensed under: |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |