]> git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/IPNet.pm
delete/deliver_quarantined_mail: use receiver instead of pmail
[pmg-api.git] / PMG / RuleDB / IPNet.pm
1 package PMG::RuleDB::IPNet;
2
3 use strict;
4 use warnings;
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
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
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
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 }
54
55 sub get {
56 my ($self) = @_;
57
58 return { cidr => $self->{address} };
59 }
60
61 sub update {
62 my ($self, $param) = @_;
63
64 $self->{address} = $param->{cidr};
65 }
66
67 1;
68
69 __END__
70
71 =head1 PMG::RuleDB::IPNet
72
73 A WHO object to check sender IP addresses.
74
75 =head2 Attribues
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