]> git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/IPNet.pm
change backup dir to /var/lib/pmg/backup
[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 oicon {
22 return 'ip.gif';
23 }
24
25 sub new {
26 my ($type, $address, $ogroup) = @_;
27
28 my $class = ref($type) || $type;
29
30 $address //= '127.0.0.1/32';
31
32 my $self = $class->SUPER::new($address, $ogroup);
33
34 return $self;
35 }
36
37 sub who_match {
38 my ($self, $addr, $ip) = @_;
39
40 # fixme: implement me
41 # use queue->{xforward}->{addr} for from match
42 # dont know what to do in To match
43
44 return 0 if !$ip;
45
46 my $cidr = Net::CIDR::Lite->new;
47 $cidr->add($self->{address});
48
49 return $cidr->find($ip);
50 }
51
52 sub properties {
53 my ($class) = @_;
54
55 return {
56 cidr => {
57 description => "Network address in CIDR notation.",
58 type => 'string', format => 'CIDR',
59 },
60 };
61 }
62
63 sub get {
64 my ($self) = @_;
65
66 return { cidr => $self->{address} };
67 }
68
69 sub update {
70 my ($self, $param) = @_;
71
72 $self->{address} = $param->{cidr};
73 }
74
75 1;
76
77 __END__
78
79 =head1 PMG::RuleDB::IPNet
80
81 A WHO object to check sender IP addresses.
82
83 =head2 Attribues
84
85 =head3 address
86
87 An IP address/network (CIDR representation).
88
89 =head2 Examples
90
91 $obj = PMG::RuleDB::IPNet->new ('192.168.2.0/20');
92