]>
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' },
74 my $option_properties = {
80 description
=> "Input policy.",
83 enum
=> ['ACCEPT', 'REJECT', 'DROP'],
86 description
=> "Output policy.",
89 enum
=> ['ACCEPT', 'REJECT', 'DROP'],
93 my $add_option_properties = sub {
94 my ($properties) = @_;
96 foreach my $k (keys %$option_properties) {
97 $properties->{$k} = $option_properties->{$k};
104 __PACKAGE__-
>register_method({
105 name
=> 'get_options',
108 description
=> "Get Firewall options.",
110 additionalProperties
=> 0,
114 #additionalProperties => 1,
115 properties
=> $option_properties,
120 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
122 return PVE
::Firewall
::copy_opject_with_digest
($cluster_conf->{options
});
126 __PACKAGE__-
>register_method({
127 name
=> 'set_options',
130 description
=> "Set Firewall options.",
133 additionalProperties
=> 0,
134 properties
=> &$add_option_properties({
136 type
=> 'string', format
=> 'pve-configid-list',
137 description
=> "A list of settings you want to delete.",
140 digest
=> get_standard_option
('pve-config-digest'),
143 returns
=> { type
=> "null" },
147 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
149 my (undef, $digest) = PVE
::Firewall
::copy_opject_with_digest
($cluster_conf->{options
});
150 PVE
::Tools
::assert_if_modified
($digest, $param->{digest
});
152 if ($param->{delete}) {
153 foreach my $opt (PVE
::Tools
::split_list
($param->{delete})) {
154 raise_param_exc
({ delete => "no such option '$opt'" })
155 if !$option_properties->{$opt};
156 delete $cluster_conf->{options
}->{$opt};
160 if (defined($param->{enable
})) {
161 $param->{enable
} = $param->{enable
} ?
1 : 0;
164 foreach my $k (keys %$option_properties) {
165 next if !defined($param->{$k});
166 $cluster_conf->{options
}->{$k} = $param->{$k};
169 PVE
::Firewall
::save_clusterfw_conf
($cluster_conf);
174 __PACKAGE__-
>register_method({
175 name
=> 'get_macros',
178 description
=> "List available macros",
180 additionalProperties
=> 0,
188 description
=> "Macro name.",
192 description
=> "More verbose description (if available).",
203 my ($macros, $descr) = PVE
::Firewall
::get_macros
();
205 foreach my $macro (keys %$macros) {
206 push @$res, { macro => $macro, descr
=> $descr->{$macro} || $macro };
212 __PACKAGE__-
>register_method({
216 description
=> "Lists possible IPSet/Alias reference which are allowed in source/dest properties.",
218 additionalProperties
=> 0,
228 enum
=> ['alias', 'ipset'],
246 my $conf = PVE
::Firewall
::load_clusterfw_conf
();
250 foreach my $name (keys %{$conf->{ipset
}}) {
256 if (my $comment = $conf->{ipset_comments
}->{$name}) {
257 $data->{comment
} = $comment;
262 foreach my $name (keys %{$conf->{aliases
}}) {
263 my $e = $conf->{aliases
}->{$name};
269 $data->{comment
} = $e->{comment
} if $e->{comment
};