]> git.proxmox.com Git - pve-firewall.git/blobdiff - src/PVE/API2/Firewall/Host.pm
api: host, vm: explicit import raise_param_exc
[pve-firewall.git] / src / PVE / API2 / Firewall / Host.pm
index 4ae0d0f2176483998f7cc77f83cbd46372e9465e..2500bd07d739e1c9d6341bbf666048385065ef29 100644 (file)
@@ -2,6 +2,8 @@ package PVE::API2::Firewall::Host;
 
 use strict;
 use warnings;
+
+use PVE::Exception qw(raise_param_exc);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RPCEnvironment;
 
@@ -49,12 +51,28 @@ __PACKAGE__->register_method({
        return $result;
     }});
 
+my $option_properties = $PVE::Firewall::host_option_properties;
+
+my $add_option_properties = sub {
+    my ($properties) = @_;
+
+    foreach my $k (keys %$option_properties) {
+       $properties->{$k} = $option_properties->{$k};
+    }
+    
+    return $properties;
+};
+
+
 __PACKAGE__->register_method({
     name => 'get_options',
     path => 'options',
     method => 'GET',
     description => "Get host firewall options.",
     proxyto => 'node',
+    permissions => {
+       check => ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
+    },
     parameters => {
        additionalProperties => 0,
        properties => {
@@ -63,7 +81,8 @@ __PACKAGE__->register_method({
     },
     returns => {
        type => "object",
-       properties => {},
+       #additionalProperties => 1,
+       properties => $option_properties,
     },
     code => sub {
        my ($param) = @_;
@@ -73,6 +92,59 @@ __PACKAGE__->register_method({
        return PVE::Firewall::copy_opject_with_digest($hostfw_conf->{options});
     }});
 
+__PACKAGE__->register_method({
+    name => 'set_options',
+    path => 'options',
+    method => 'PUT',
+    description => "Set Firewall options.",
+    protected => 1,
+    proxyto => 'node',
+    permissions => {
+       check => ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+       additionalProperties => 0,
+       properties => &$add_option_properties({
+           node => get_standard_option('pve-node'),
+           delete => {
+               type => 'string', format => 'pve-configid-list',
+               description => "A list of settings you want to delete.",
+               optional => 1,
+           },
+           digest => get_standard_option('pve-config-digest'),
+       }),
+    },
+    returns => { type => "null" },
+    code => sub {
+       my ($param) = @_;
+
+       my $hostfw_conf = PVE::Firewall::load_hostfw_conf();
+
+       my (undef, $digest) = PVE::Firewall::copy_opject_with_digest($hostfw_conf->{options});
+       PVE::Tools::assert_if_modified($digest, $param->{digest});
+
+       if ($param->{delete}) {
+           foreach my $opt (PVE::Tools::split_list($param->{delete})) {
+               raise_param_exc({ delete => "no such option '$opt'" }) 
+                   if !$option_properties->{$opt};
+               delete $hostfw_conf->{options}->{$opt};
+           }
+       }
+
+       if (defined($param->{enable})) {
+           $param->{enable} = $param->{enable} ? 1 : 0;
+       }
+
+       foreach my $k (keys %$option_properties) {
+           next if !defined($param->{$k});
+           $hostfw_conf->{options}->{$k} = $param->{$k}; 
+       }
+
+       PVE::Firewall::save_hostfw_conf($hostfw_conf);
+
+       return undef;
+    }});
+
 __PACKAGE__->register_method({
     name => 'log', 
     path => 'log',