]> git.proxmox.com Git - pmg-api.git/commitdiff
implement whitelist/blacklist add/delete API
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 17 Aug 2017 12:37:11 +0000 (14:37 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 17 Aug 2017 12:37:11 +0000 (14:37 +0200)
PMG/API2/Quarantine.pm

index bf70836d7324145de8fbfa0de65fa5c5d978b543..7530e134e6dfbc3082ec357a2b20b175adcadc56 100644 (file)
@@ -173,8 +173,8 @@ __PACKAGE__->register_method ({
     }});
 
 
-my $read_user_bw_list = sub {
-    my ($listname, $param) = @_;
+my $read_or_modify_user_bw_list = sub {
+    my ($listname, $param, $addrs, $delete) = @_;
 
     my $rpcenv = PMG::RESTEnvironment->get();
     my $authuser = $rpcenv->get_user();
@@ -184,13 +184,16 @@ my $read_user_bw_list = sub {
 
     my $dbh = PMG::DBTools::open_ruledb();
 
-    my $list = PMG::Quarantine::add_to_blackwhite($dbh, $pmail, $listname);
+    my $list = PMG::Quarantine::add_to_blackwhite(
+       $dbh, $pmail, $listname, $addrs, $delete);
 
     my $res = [];
     foreach my $a (@$list) { push @$res, { address => $a }; }
     return $res;
 };
 
+my $address_pattern = '[a-zA-Z0-9\+\-\_\*\.\@]+';
+
 __PACKAGE__->register_method ({
     name => 'whitelist',
     path => 'whitelist',
@@ -217,7 +220,63 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       return $read_user_bw_list->('WL', $param);
+       return $read_or_modify_user_bw_list->('WL', $param);
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'whitelist_add',
+    path => 'whitelist',
+    method => 'POST',
+    description => "Add user whitelist entries.",
+    permissions => { check => [ 'admin', 'qmanager', 'audit', 'quser'] },
+    protected => 1,
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           pmail => $pmail_param_type,
+           address => {
+               description => "The address you want to add.",
+               type => "string",
+               pattern => $address_pattern,
+               maxLength => 512,
+           },
+       },
+    },
+    returns => { type => 'null' },
+    code => sub {
+       my ($param) = @_;
+
+       $read_or_modify_user_bw_list->('WL', $param, [ $param->{address} ]);
+
+       return undef;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'whitelist_delete',
+    path => 'whitelist/{address}',
+    method => 'DELETE',
+    description => "Delete user whitelist entries.",
+    permissions => { check => [ 'admin', 'qmanager', 'audit', 'quser'] },
+    protected => 1,
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           pmail => $pmail_param_type,
+           address => {
+               description => "The address you want to remove.",
+               type => "string",
+               pattern => $address_pattern,
+               maxLength => 512,
+           },
+       },
+    },
+    returns => { type => 'null' },
+    code => sub {
+       my ($param) = @_;
+
+       $read_or_modify_user_bw_list->('WL', $param, [ $param->{address} ], 1);
+
+       return undef;
     }});
 
 __PACKAGE__->register_method ({
@@ -246,7 +305,63 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       return $read_user_bw_list->('BL', $param);
+       return $read_or_modify_user_bw_list->('BL', $param);
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'blacklist_add',
+    path => 'blacklist',
+    method => 'POST',
+    description => "Add user blacklist entries.",
+    permissions => { check => [ 'admin', 'qmanager', 'audit', 'quser'] },
+    protected => 1,
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           pmail => $pmail_param_type,
+           address => {
+               description => "The address you want to add.",
+               type => "string",
+               pattern => $address_pattern,
+               maxLength => 512,
+           },
+       },
+    },
+    returns => { type => 'null' },
+    code => sub {
+       my ($param) = @_;
+
+       $read_or_modify_user_bw_list->('BL', $param, [ $param->{address} ]);
+
+       return undef;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'blacklist_delete',
+    path => 'blacklist/{address}',
+    method => 'DELETE',
+    description => "Delete user blacklist entries.",
+    permissions => { check => [ 'admin', 'qmanager', 'audit', 'quser'] },
+    protected => 1,
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           pmail => $pmail_param_type,
+           address => {
+               description => "The address you want to remove.",
+               type => "string",
+               pattern => $address_pattern,
+               maxLength => 512,
+           },
+       },
+    },
+    returns => { type => 'null' },
+    code => sub {
+       my ($param) = @_;
+
+       $read_or_modify_user_bw_list->('BL', $param, [ $param->{address} ], 1);
+
+       return undef;
     }});
 
 __PACKAGE__->register_method ({