]>
git.proxmox.com Git - pve-firewall.git/blob - src/PVE/API2/Firewall/Cluster.pm
8d575da5e85985d2b75cca6d86629dd91c520752
1 package PVE
::API2
::Firewall
::Cluster
;
5 use PVE
::Exception
qw(raise raise_param_exc raise_perm_exc);
6 use PVE
::JSONSchema
qw(get_standard_option);
9 use PVE
::API2
::Firewall
::Rules
;
10 use PVE
::API2
::Firewall
::Groups
;
11 use PVE
::API2
::Firewall
::IPSet
;
15 use Data
::Dumper
; # fixme: remove
17 use base
qw(PVE::RESTHandler);
19 __PACKAGE__-
>register_method ({
20 subclass
=> "PVE::API2::Firewall::Groups",
24 __PACKAGE__-
>register_method ({
25 subclass
=> "PVE::API2::Firewall::ClusterRules",
29 __PACKAGE__-
>register_method ({
30 subclass
=> "PVE::API2::Firewall::ClusterIPSetList",
34 __PACKAGE__-
>register_method({
38 permissions
=> { user
=> 'all' },
39 description
=> "Directory index.",
41 additionalProperties
=> 0,
49 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
56 { name
=> 'options' },
65 __PACKAGE__-
>register_method({
66 name
=> 'get_options',
69 description
=> "Get Firewall options.",
71 additionalProperties
=> 0,
75 #additionalProperties => 1,
86 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
88 return PVE
::Firewall
::copy_opject_with_digest
($cluster_conf->{options
});
91 my $option_properties = {
98 my $add_option_properties = sub {
99 my ($properties) = @_;
101 foreach my $k (keys %$option_properties) {
102 $properties->{$k} = $option_properties->{$k};
108 __PACKAGE__-
>register_method({
109 name
=> 'set_options',
112 description
=> "Set Firewall options.",
115 additionalProperties
=> 0,
116 properties
=> &$add_option_properties({
118 type
=> 'string', format
=> 'pve-configid-list',
119 description
=> "A list of settings you want to delete.",
122 digest
=> get_standard_option
('pve-config-digest'),
125 returns
=> { type
=> "null" },
129 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
131 my (undef, $digest) = PVE
::Firewall
::copy_opject_with_digest
($cluster_conf->{options
});
132 PVE
::Tools
::assert_if_modified
($digest, $param->{digest
});
134 if ($param->{delete}) {
135 foreach my $opt (PVE
::Tools
::split_list
($param->{delete})) {
136 raise_param_exc
({ delete => "no such option '$opt'" })
137 if !$option_properties->{$opt};
138 delete $cluster_conf->{options
}->{$opt};
142 if (defined($param->{enable
})) {
143 $cluster_conf->{options
}->{enable
} = $param->{enable
} ?
1 : 0;
146 PVE
::Firewall
::save_clusterfw_conf
($cluster_conf);
151 __PACKAGE__-
>register_method({
152 name
=> 'get_macros',
155 description
=> "List available macros",
157 additionalProperties
=> 0,
165 description
=> "Macro name.",
169 description
=> "More verbose description (if available).",
180 my ($macros, $descr) = PVE
::Firewall
::get_macros
();
182 foreach my $macro (keys %$macros) {
183 push @$res, { macro => $macro, descr
=> $descr->{$macro} || $macro };