]>
git.proxmox.com Git - pve-firewall.git/blob - src/PVE/API2/Firewall/Cluster.pm
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
::Aliases
;
10 use PVE
::API2
::Firewall
::Rules
;
11 use PVE
::API2
::Firewall
::Groups
;
12 use PVE
::API2
::Firewall
::IPSet
;
16 use Data
::Dumper
; # fixme: remove
18 use base
qw(PVE::RESTHandler);
20 __PACKAGE__-
>register_method ({
21 subclass
=> "PVE::API2::Firewall::Groups",
25 __PACKAGE__-
>register_method ({
26 subclass
=> "PVE::API2::Firewall::ClusterRules",
30 __PACKAGE__-
>register_method ({
31 subclass
=> "PVE::API2::Firewall::ClusterIPSetList",
35 __PACKAGE__-
>register_method ({
36 subclass
=> "PVE::API2::Firewall::ClusterAliases",
41 __PACKAGE__-
>register_method({
45 permissions
=> { user
=> 'all' },
46 description
=> "Directory index.",
48 additionalProperties
=> 0,
56 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
62 { name
=> 'aliases' },
64 { name
=> 'options' },
73 my $option_properties = {
79 description
=> "Input policy.",
82 enum
=> ['ACCEPT', 'REJECT', 'DROP'],
85 description
=> "Output policy.",
88 enum
=> ['ACCEPT', 'REJECT', 'DROP'],
92 my $add_option_properties = sub {
93 my ($properties) = @_;
95 foreach my $k (keys %$option_properties) {
96 $properties->{$k} = $option_properties->{$k};
103 __PACKAGE__-
>register_method({
104 name
=> 'get_options',
107 description
=> "Get Firewall options.",
109 additionalProperties
=> 0,
113 #additionalProperties => 1,
114 properties
=> $option_properties,
119 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
121 return PVE
::Firewall
::copy_opject_with_digest
($cluster_conf->{options
});
125 __PACKAGE__-
>register_method({
126 name
=> 'set_options',
129 description
=> "Set Firewall options.",
132 additionalProperties
=> 0,
133 properties
=> &$add_option_properties({
135 type
=> 'string', format
=> 'pve-configid-list',
136 description
=> "A list of settings you want to delete.",
139 digest
=> get_standard_option
('pve-config-digest'),
142 returns
=> { type
=> "null" },
146 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
148 my (undef, $digest) = PVE
::Firewall
::copy_opject_with_digest
($cluster_conf->{options
});
149 PVE
::Tools
::assert_if_modified
($digest, $param->{digest
});
151 if ($param->{delete}) {
152 foreach my $opt (PVE
::Tools
::split_list
($param->{delete})) {
153 raise_param_exc
({ delete => "no such option '$opt'" })
154 if !$option_properties->{$opt};
155 delete $cluster_conf->{options
}->{$opt};
159 if (defined($param->{enable
})) {
160 $param->{enable
} = $param->{enable
} ?
1 : 0;
163 foreach my $k (keys %$option_properties) {
164 next if !defined($param->{$k});
165 $cluster_conf->{options
}->{$k} = $param->{$k};
168 PVE
::Firewall
::save_clusterfw_conf
($cluster_conf);
173 __PACKAGE__-
>register_method({
174 name
=> 'get_macros',
177 description
=> "List available macros",
179 additionalProperties
=> 0,
187 description
=> "Macro name.",
191 description
=> "More verbose description (if available).",
202 my ($macros, $descr) = PVE
::Firewall
::get_macros
();
204 foreach my $macro (keys %$macros) {
205 push @$res, { macro => $macro, descr
=> $descr->{$macro} || $macro };