]>
Commit | Line | Data |
---|---|---|
f4fe6fc4 DM |
1 | package PMG::RuleDB::IPNet; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
f4fe6fc4 DM |
5 | use DBI; |
6 | use Net::CIDR::Lite; | |
7 | ||
8 | use PMG::Utils; | |
9 | use PMG::RuleDB::WhoRegex; | |
10 | ||
11 | use base qw(PMG::RuleDB::WhoRegex); | |
12 | ||
13 | sub otype { | |
14 | return 1004; | |
15 | } | |
16 | ||
17 | sub otype_text { | |
18 | return 'IP Network'; | |
19 | } | |
20 | ||
f4fe6fc4 DM |
21 | sub new { |
22 | my ($type, $address, $ogroup) = @_; | |
23 | ||
24 | my $class = ref($type) || $type; | |
25 | ||
26 | $address //= '127.0.0.1/32'; | |
27 | ||
28 | my $self = $class->SUPER::new($address, $ogroup); | |
29 | ||
30 | return $self; | |
31 | } | |
32 | ||
33 | sub who_match { | |
34 | my ($self, $addr, $ip) = @_; | |
35 | ||
f4fe6fc4 DM |
36 | return 0 if !$ip; |
37 | ||
38 | my $cidr = Net::CIDR::Lite->new; | |
39 | $cidr->add($self->{address}); | |
40 | ||
41 | return $cidr->find($ip); | |
42 | } | |
43 | ||
1ad24a43 DM |
44 | sub properties { |
45 | my ($class) = @_; | |
46 | ||
47 | return { | |
48 | cidr => { | |
49 | description => "Network address in CIDR notation.", | |
50 | type => 'string', format => 'CIDR', | |
51 | }, | |
52 | }; | |
53 | } | |
f4fe6fc4 | 54 | |
718d48a7 DM |
55 | sub get { |
56 | my ($self) = @_; | |
57 | ||
58 | return { cidr => $self->{address} }; | |
59 | } | |
60 | ||
1ad24a43 DM |
61 | sub update { |
62 | my ($self, $param) = @_; | |
f4fe6fc4 | 63 | |
1ad24a43 | 64 | $self->{address} = $param->{cidr}; |
f4fe6fc4 DM |
65 | } |
66 | ||
67 | 1; | |
68 | ||
69 | __END__ | |
70 | ||
71 | =head1 PMG::RuleDB::IPNet | |
72 | ||
73 | A WHO object to check sender IP addresses. | |
74 | ||
1359baef | 75 | =head2 Attributes |
f4fe6fc4 DM |
76 | |
77 | =head3 address | |
78 | ||
79 | An IP address/network (CIDR representation). | |
80 | ||
81 | =head2 Examples | |
82 | ||
83 | $obj = PMG::RuleDB::IPNet->new ('192.168.2.0/20'); | |
84 |