]> git.proxmox.com Git - pmg-api.git/blame - src/PMG/RuleDB/IPNet.pm
typo fixes all over the place
[pmg-api.git] / src / PMG / RuleDB / IPNet.pm
CommitLineData
f4fe6fc4
DM
1package PMG::RuleDB::IPNet;
2
3use strict;
4use warnings;
f4fe6fc4
DM
5use DBI;
6use Net::CIDR::Lite;
7
8use PMG::Utils;
9use PMG::RuleDB::WhoRegex;
10
11use base qw(PMG::RuleDB::WhoRegex);
12
13sub otype {
14 return 1004;
15}
16
17sub otype_text {
18 return 'IP Network';
19}
20
f4fe6fc4
DM
21sub 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
33sub 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
44sub 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
55sub get {
56 my ($self) = @_;
57
58 return { cidr => $self->{address} };
59}
60
1ad24a43
DM
61sub update {
62 my ($self, $param) = @_;
f4fe6fc4 63
1ad24a43 64 $self->{address} = $param->{cidr};
f4fe6fc4
DM
65}
66
671;
68
69__END__
70
71=head1 PMG::RuleDB::IPNet
72
73A WHO object to check sender IP addresses.
74
1359baef 75=head2 Attributes
f4fe6fc4
DM
76
77=head3 address
78
79An IP address/network (CIDR representation).
80
81=head2 Examples
82
83 $obj = PMG::RuleDB::IPNet->new ('192.168.2.0/20');
84