]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/API2/SMTPWhitelist.pm
1 package PMG
::API2
::SMTPWhitelist
;
8 use PVE
::Tools
qw(extract_param);
9 use HTTP
::Status
qw(:constants);
10 use PVE
::JSONSchema
qw(get_standard_option);
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
;
26 use base
qw(PVE::RESTHandler);
28 __PACKAGE__-
>register_method ({
32 description
=> "Directory index.",
33 permissions
=> { check
=> [ 'admin', 'audit' ] },
35 additionalProperties
=> 0,
43 subdir
=> { type
=> 'string'},
46 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
52 { subdir
=> 'objects' },
53 { subdir
=> 'email' },
54 { subdir
=> 'receiver' },
55 { subdir
=> 'domain' },
56 { subdir
=> 'receiver_domain' },
57 { subdir
=> 'regex' },
58 { subdir
=> 'receiver_regex' },
60 { subdir
=> 'network' },
65 __PACKAGE__-
>register_method ({
69 description
=> "Get list of all SMTP whitelist entries.",
71 permissions
=> { check
=> [ 'admin', 'audit' ] },
73 additionalProperties
=> 0,
81 id
=> { type
=> 'integer'},
84 links
=> [ { rel
=> 'child', href
=> "{id}" } ],
89 my $rdb = PMG
::RuleDB-
>new();
91 my $gid = $rdb->greylistexclusion_groupid();
93 my $og = $rdb->load_group_objects($gid);
97 foreach my $obj (@$og) {
98 push @$res, $obj->get_data();
104 __PACKAGE__-
>register_method ({
105 name
=> 'delete_object',
106 path
=> 'objects/{id}',
108 description
=> "Remove an object from the SMTP whitelist.",
110 permissions
=> { check
=> [ 'admin' ] },
113 additionalProperties
=> 0,
116 description
=> "Object ID.",
121 returns
=> { type
=> 'null' },
125 my $rdb = PMG
::RuleDB-
>new();
127 my $obj = $rdb->load_object($param->{id
});
129 die "object '$param->{id}' does not exists\n" if !defined($obj);
131 $rdb->delete_object($obj);
133 PMG
::DBTools
::reload_ruledb
($rdb);
139 PMG
::RuleDB
::EMail-
>register_api(__PACKAGE__
, 'email', undef, 1);
140 PMG
::RuleDB
::Receiver-
>register_api(__PACKAGE__
, 'receiver', undef, 1);
142 PMG
::RuleDB
::Domain-
>register_api(__PACKAGE__
, 'domain', undef, 1);
143 PMG
::RuleDB
::ReceiverDomain-
>register_api(__PACKAGE__
, 'receiver_domain', undef, 1);
145 PMG
::RuleDB
::WhoRegex-
>register_api(__PACKAGE__
, 'regex', undef, 1);
146 PMG
::RuleDB
::ReceiverRegex-
>register_api(__PACKAGE__
, 'receiver_regex', undef, 1);
148 PMG
::RuleDB
::IPAddress-
>register_api(__PACKAGE__
, 'ip', undef, 1);
149 PMG
::RuleDB
::IPNet-
>register_api(__PACKAGE__
, 'network', undef, 1);