]> git.proxmox.com Git - pmg-api.git/blob - PMG/API2/SMTPWhitelist.pm
fix bux #1776: set http_proxy for sa-update
[pmg-api.git] / PMG / API2 / SMTPWhitelist.pm
1 package PMG::API2::SMTPWhitelist;
2
3 use strict;
4 use warnings;
5 use Data::Dumper;
6
7 use PVE::SafeSyslog;
8 use PVE::Tools qw(extract_param);
9 use HTTP::Status qw(:constants);
10 use PVE::JSONSchema qw(get_standard_option);
11 use PVE::RESTHandler;
12 use PVE::INotify;
13
14 use PMG::Config;
15
16 use PMG::RuleDB::WhoRegex;
17 use PMG::RuleDB::ReceiverRegex;
18 use PMG::RuleDB::EMail;
19 use PMG::RuleDB::Receiver;
20 use PMG::RuleDB::IPAddress;
21 use PMG::RuleDB::IPNet;
22 use PMG::RuleDB::Domain;
23 use PMG::RuleDB::ReceiverDomain;
24 use PMG::RuleDB;
25
26 use base qw(PVE::RESTHandler);
27
28 __PACKAGE__->register_method ({
29 name => 'index',
30 path => '',
31 method => 'GET',
32 description => "Directory index.",
33 permissions => { check => [ 'admin', 'audit' ] },
34 parameters => {
35 additionalProperties => 0,
36 properties => {},
37 },
38 returns => {
39 type => 'array',
40 items => {
41 type => "object",
42 properties => {
43 subdir => { type => 'string'},
44 },
45 },
46 links => [ { rel => 'child', href => "{subdir}" } ],
47 },
48 code => sub {
49 my ($param) = @_;
50
51 return [
52 { subdir => 'objects' },
53 { subdir => 'email' },
54 { subdir => 'receiver' },
55 { subdir => 'domain' },
56 { subdir => 'receiver_domain' },
57 { subdir => 'regex' },
58 { subdir => 'receiver_regex' },
59 { subdir => 'ip' },
60 { subdir => 'network' },
61 ];
62
63 }});
64
65 __PACKAGE__->register_method ({
66 name => 'objects',
67 path => 'objects',
68 method => 'GET',
69 description => "Get list of all SMTP whitelist entries.",
70 proxyto => 'master',
71 permissions => { check => [ 'admin', 'audit' ] },
72 parameters => {
73 additionalProperties => 0,
74 properties => {},
75 },
76 returns => {
77 type => 'array',
78 items => {
79 type => "object",
80 properties => {
81 id => { type => 'integer'},
82 },
83 },
84 links => [ { rel => 'child', href => "{id}" } ],
85 },
86 code => sub {
87 my ($param) = @_;
88
89 my $rdb = PMG::RuleDB->new();
90
91 my $gid = $rdb->greylistexclusion_groupid();
92
93 my $og = $rdb->load_group_objects($gid);
94
95 my $res = [];
96
97 foreach my $obj (@$og) {
98 push @$res, $obj->get_data();
99 }
100
101 return $res;
102 }});
103
104 __PACKAGE__->register_method ({
105 name => 'delete_object',
106 path => 'objects/{id}',
107 method => 'DELETE',
108 description => "Remove an object from the SMTP whitelist.",
109 proxyto => 'master',
110 permissions => { check => [ 'admin' ] },
111 protected => 1,
112 parameters => {
113 additionalProperties => 0,
114 properties => {
115 id => {
116 description => "Object ID.",
117 type => 'integer',
118 },
119 },
120 },
121 returns => { type => 'null' },
122 code => sub {
123 my ($param) = @_;
124
125 my $rdb = PMG::RuleDB->new();
126
127 my $obj = $rdb->load_object($param->{id});
128
129 die "object '$param->{id}' does not exists\n" if !defined($obj);
130
131 $rdb->delete_object($obj);
132
133 PMG::DBTools::reload_ruledb($rdb);
134
135 return undef;
136 }});
137
138
139 PMG::RuleDB::EMail->register_api(__PACKAGE__, 'email', undef, 1);
140 PMG::RuleDB::Receiver->register_api(__PACKAGE__, 'receiver', undef, 1);
141
142 PMG::RuleDB::Domain->register_api(__PACKAGE__, 'domain', undef, 1);
143 PMG::RuleDB::ReceiverDomain->register_api(__PACKAGE__, 'receiver_domain', undef, 1);
144
145 PMG::RuleDB::WhoRegex->register_api(__PACKAGE__, 'regex', undef, 1);
146 PMG::RuleDB::ReceiverRegex->register_api(__PACKAGE__, 'receiver_regex', undef, 1);
147
148 PMG::RuleDB::IPAddress->register_api(__PACKAGE__, 'ip', undef, 1);
149 PMG::RuleDB::IPNet->register_api(__PACKAGE__, 'network', undef, 1);
150
151 1;