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' },
74 my $option_properties = $PVE::Firewall
::cluster_option_properties
;
76 my $add_option_properties = sub {
77 my ($properties) = @_;
79 foreach my $k (keys %$option_properties) {
80 $properties->{$k} = $option_properties->{$k};
87 __PACKAGE__-
>register_method({
88 name
=> 'get_options',
91 description
=> "Get Firewall options.",
93 check
=> ['perm', '/', [ 'Sys.Audit' ]],
96 additionalProperties
=> 0,
100 #additionalProperties => 1,
101 properties
=> $option_properties,
106 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
108 return PVE
::Firewall
::copy_opject_with_digest
($cluster_conf->{options
});
112 __PACKAGE__-
>register_method({
113 name
=> 'set_options',
116 description
=> "Set Firewall options.",
119 check
=> ['perm', '/', [ 'Sys.Modify' ]],
122 additionalProperties
=> 0,
123 properties
=> &$add_option_properties({
125 type
=> 'string', format
=> 'pve-configid-list',
126 description
=> "A list of settings you want to delete.",
129 digest
=> get_standard_option
('pve-config-digest'),
132 returns
=> { type
=> "null" },
136 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
138 my (undef, $digest) = PVE
::Firewall
::copy_opject_with_digest
($cluster_conf->{options
});
139 PVE
::Tools
::assert_if_modified
($digest, $param->{digest
});
141 if ($param->{delete}) {
142 foreach my $opt (PVE
::Tools
::split_list
($param->{delete})) {
143 raise_param_exc
({ delete => "no such option '$opt'" })
144 if !$option_properties->{$opt};
145 delete $cluster_conf->{options
}->{$opt};
149 if (defined($param->{enable
}) && ($param->{enable
} > 1)) {
150 $param->{enable
} = time();
153 foreach my $k (keys %$option_properties) {
154 next if !defined($param->{$k});
155 $cluster_conf->{options
}->{$k} = $param->{$k};
158 PVE
::Firewall
::save_clusterfw_conf
($cluster_conf);
160 # instant firewall update when using double (anti-lockout) API call
161 # -> not waiting for a firewall update at the first (timestamp enable) set
162 if (defined($param->{enable
}) && ($param->{enable
} > 1)) {
163 PVE
::Firewall
::update
();
169 __PACKAGE__-
>register_method({
170 name
=> 'get_macros',
173 description
=> "List available macros",
174 permissions
=> { user
=> 'all' },
176 additionalProperties
=> 0,
184 description
=> "Macro name.",
188 description
=> "More verbose description (if available).",
199 my ($macros, $descr) = PVE
::Firewall
::get_macros
();
201 foreach my $macro (keys %$macros) {
202 push @$res, { macro => $macro, descr
=> $descr->{$macro} || $macro };
208 __PACKAGE__-
>register_method({
212 description
=> "Lists possible IPSet/Alias reference which are allowed in source/dest properties.",
214 check
=> ['perm', '/', [ 'Sys.Audit' ]],
217 additionalProperties
=> 0,
220 description
=> "Only list references of specified type.",
222 enum
=> ['alias', 'ipset'],
234 enum
=> ['alias', 'ipset'],
252 my $conf = PVE
::Firewall
::load_clusterfw_conf
();
256 if (!$param->{type
} || $param->{type
} eq 'ipset') {
257 foreach my $name (keys %{$conf->{ipset
}}) {
263 if (my $comment = $conf->{ipset_comments
}->{$name}) {
264 $data->{comment
} = $comment;
270 if (!$param->{type
} || $param->{type
} eq 'alias') {
271 foreach my $name (keys %{$conf->{aliases
}}) {
272 my $e = $conf->{aliases
}->{$name};
278 $data->{comment
} = $e->{comment
} if $e->{comment
};