From: Dietmar Maurer Date: Thu, 3 Apr 2014 09:48:48 +0000 (+0200) Subject: rule type and action are required parameters X-Git-Url: https://git.proxmox.com/?p=pve-firewall.git;a=commitdiff_plain;h=3655b01f381276b96d69f6be303504affcbc7311 rule type and action are required parameters --- diff --git a/src/PVE/API2/Firewall/Rules.pm b/src/PVE/API2/Firewall/Rules.pm index cd3ea7e..9db899d 100644 --- a/src/PVE/API2/Firewall/Rules.pm +++ b/src/PVE/API2/Firewall/Rules.pm @@ -136,7 +136,9 @@ sub register_create_rule { my $properties = $class->additional_parameters(); my $create_rule_properties = PVE::Firewall::add_rule_properties($properties); - + $create_rule_properties->{action}->{optional} = 0; + $create_rule_properties->{type}->{optional} = 0; + $class->register_method({ name => 'create_rule', path => '', @@ -154,11 +156,13 @@ sub register_create_rule { my ($fw_conf, $rules) = $class->load_config($param); my $digest = $fw_conf->{digest}; - - my $rule = { type => 'out', action => 'ACCEPT', enable => 0}; + + my $rule = {}; PVE::Firewall::copy_rule_data($rule, $param); + $rule->{enable} = 0 if !defined($param->{enable}); + unshift @$rules, $rule; $class->save_rules($param, $fw_conf, $rules); @@ -219,6 +223,11 @@ sub register_update_rule { push @$newrules, $rule if $moveto >= scalar(@$rules); $rules = $newrules; } else { + raise_param_exc({ type => "property is missing"}) + if !defined($param->{type}); + raise_param_exc({ action => "property is missing"}) + if !defined($param->{action}); + PVE::Firewall::copy_rule_data($rule, $param); } diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm index 226d1fc..8fd0f48 100644 --- a/src/PVE/Firewall.pm +++ b/src/PVE/Firewall.pm @@ -767,7 +767,9 @@ sub add_rule_properties { my ($properties) = @_; foreach my $k (keys %$rule_properties) { - $properties->{$k} = $rule_properties->{$k}; + my $h = $rule_properties->{$k}; + # copy data, so that we can modify later without side effects + foreach my $opt (keys %$h) { $properties->{$k}->{$opt} = $h->{$opt}; } } return $properties;