]>
Commit | Line | Data |
---|---|---|
009ee3ac DM |
1 | package PVE::API2::Firewall::IPSetBase; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
4a11bba5 | 5 | use PVE::Exception qw(raise raise_param_exc); |
009ee3ac DM |
6 | use PVE::JSONSchema qw(get_standard_option); |
7 | ||
8 | use PVE::Firewall; | |
9 | ||
10 | use base qw(PVE::RESTHandler); | |
11 | ||
12 | my $api_properties = { | |
13 | cidr => { | |
14 | description => "Network/IP specification in CIDR format.", | |
15 | type => 'string', format => 'IPv4orCIDR', | |
16 | }, | |
e74a87f5 | 17 | name => get_standard_option('ipset-name'), |
009ee3ac DM |
18 | comment => { |
19 | type => 'string', | |
20 | optional => 1, | |
21 | }, | |
22 | nomatch => { | |
23 | type => 'boolean', | |
24 | optional => 1, | |
25 | }, | |
26 | }; | |
27 | ||
28 | sub load_config { | |
29 | my ($class, $param) = @_; | |
30 | ||
31 | die "implement this in subclass"; | |
1210ae94 DM |
32 | |
33 | #return ($cluster_conf, $fw_conf, $ipset); | |
009ee3ac DM |
34 | } |
35 | ||
1210ae94 DM |
36 | sub save_config { |
37 | my ($class, $param, $fw_conf) = @_; | |
009ee3ac DM |
38 | |
39 | die "implement this in subclass"; | |
40 | } | |
41 | ||
1210ae94 DM |
42 | sub save_ipset { |
43 | my ($class, $param, $fw_conf, $ipset) = @_; | |
44 | ||
45 | if (!defined($ipset)) { | |
46 | delete $fw_conf->{ipset}->{$param->{name}}; | |
47 | } else { | |
48 | $fw_conf->{ipset}->{$param->{name}} = $ipset; | |
49 | } | |
50 | ||
51 | $class->save_config($param, $fw_conf); | |
52 | } | |
53 | ||
009ee3ac DM |
54 | my $additional_param_hash = {}; |
55 | ||
56 | sub additional_parameters { | |
57 | my ($class, $new_value) = @_; | |
58 | ||
59 | if (defined($new_value)) { | |
60 | $additional_param_hash->{$class} = $new_value; | |
61 | } | |
62 | ||
63 | # return a copy | |
64 | my $copy = {}; | |
65 | my $org = $additional_param_hash->{$class} || {}; | |
66 | foreach my $p (keys %$org) { $copy->{$p} = $org->{$p}; } | |
67 | return $copy; | |
68 | } | |
69 | ||
70 | sub register_get_ipset { | |
71 | my ($class) = @_; | |
72 | ||
73 | my $properties = $class->additional_parameters(); | |
74 | ||
75 | $properties->{name} = $api_properties->{name}; | |
76 | ||
77 | $class->register_method({ | |
78 | name => 'get_ipset', | |
79 | path => '', | |
80 | method => 'GET', | |
81 | description => "List IPSet content", | |
82 | parameters => { | |
83 | additionalProperties => 0, | |
84 | properties => $properties, | |
85 | }, | |
86 | returns => { | |
87 | type => 'array', | |
88 | items => { | |
89 | type => "object", | |
90 | properties => { | |
91 | cidr => { | |
92 | type => 'string', | |
93 | }, | |
94 | comment => { | |
95 | type => 'string', | |
96 | optional => 1, | |
97 | }, | |
98 | nomatch => { | |
99 | type => 'boolean', | |
100 | optional => 1, | |
d72c631c DM |
101 | }, |
102 | digest => get_standard_option('pve-config-digest', { optional => 0} ), | |
009ee3ac DM |
103 | }, |
104 | }, | |
105 | links => [ { rel => 'child', href => "{cidr}" } ], | |
106 | }, | |
107 | code => sub { | |
108 | my ($param) = @_; | |
109 | ||
1210ae94 | 110 | my ($cluster_conf, $fw_conf, $ipset) = $class->load_config($param); |
009ee3ac | 111 | |
5d38d64f | 112 | return PVE::Firewall::copy_list_with_digest($ipset); |
009ee3ac DM |
113 | }}); |
114 | } | |
115 | ||
1210ae94 DM |
116 | sub register_delete_ipset { |
117 | my ($class) = @_; | |
118 | ||
119 | my $properties = $class->additional_parameters(); | |
120 | ||
121 | $properties->{name} = get_standard_option('ipset-name'); | |
122 | ||
123 | $class->register_method({ | |
124 | name => 'delete_ipset', | |
125 | path => '', | |
126 | method => 'DELETE', | |
127 | description => "Delete IPSet", | |
128 | protected => 1, | |
129 | parameters => { | |
130 | additionalProperties => 0, | |
131 | properties => $properties, | |
132 | }, | |
133 | returns => { type => 'null' }, | |
134 | code => sub { | |
135 | my ($param) = @_; | |
136 | ||
137 | my ($cluster_conf, $fw_conf, $ipset) = $class->load_config($param); | |
138 | ||
139 | die "IPSet '$param->{name}' is not empty\n" | |
140 | if scalar(@$ipset); | |
141 | ||
142 | $class->save_ipset($param, $fw_conf, undef); | |
143 | ||
144 | return undef; | |
145 | }}); | |
146 | } | |
147 | ||
a33c74f6 | 148 | sub register_create_ip { |
009ee3ac DM |
149 | my ($class) = @_; |
150 | ||
151 | my $properties = $class->additional_parameters(); | |
152 | ||
153 | $properties->{name} = $api_properties->{name}; | |
154 | $properties->{cidr} = $api_properties->{cidr}; | |
155 | $properties->{nomatch} = $api_properties->{nomatch}; | |
156 | $properties->{comment} = $api_properties->{comment}; | |
d72c631c | 157 | |
009ee3ac | 158 | $class->register_method({ |
a33c74f6 | 159 | name => 'create_ip', |
009ee3ac DM |
160 | path => '', |
161 | method => 'POST', | |
162 | description => "Add IP or Network to IPSet.", | |
163 | protected => 1, | |
164 | parameters => { | |
165 | additionalProperties => 0, | |
166 | properties => $properties, | |
167 | }, | |
168 | returns => { type => "null" }, | |
169 | code => sub { | |
170 | my ($param) = @_; | |
171 | ||
1210ae94 | 172 | my ($cluster_conf, $fw_conf, $ipset) = $class->load_config($param); |
009ee3ac | 173 | |
4a11bba5 DM |
174 | my $cidr = $param->{cidr}; |
175 | ||
176 | foreach my $entry (@$ipset) { | |
177 | raise_param_exc({ cidr => "address '$cidr' already exists" }) | |
178 | if $entry->{cidr} eq $cidr; | |
179 | } | |
180 | ||
181 | my $data = { cidr => $cidr }; | |
009ee3ac DM |
182 | $data->{nomatch} = 1 if $param->{nomatch}; |
183 | $data->{comment} = $param->{comment} if $param->{comment}; | |
184 | ||
009ee3ac DM |
185 | unshift @$ipset, $data; |
186 | ||
187 | $class->save_ipset($param, $fw_conf, $ipset); | |
188 | ||
189 | return undef; | |
190 | }}); | |
191 | } | |
192 | ||
a33c74f6 DM |
193 | sub register_read_ip { |
194 | my ($class) = @_; | |
195 | ||
196 | my $properties = $class->additional_parameters(); | |
197 | ||
198 | $properties->{name} = $api_properties->{name}; | |
199 | $properties->{cidr} = $api_properties->{cidr}; | |
200 | ||
201 | $class->register_method({ | |
202 | name => 'read_ip', | |
203 | path => '{cidr}', | |
204 | method => 'GET', | |
205 | description => "Read IP or Network settings from IPSet.", | |
206 | protected => 1, | |
207 | parameters => { | |
208 | additionalProperties => 0, | |
209 | properties => $properties, | |
210 | }, | |
211 | returns => { type => "object" }, | |
212 | code => sub { | |
213 | my ($param) = @_; | |
214 | ||
1210ae94 | 215 | my ($cluster_conf, $fw_conf, $ipset) = $class->load_config($param); |
a33c74f6 | 216 | |
5d38d64f DM |
217 | my $list = PVE::Firewall::copy_list_with_digest($ipset); |
218 | ||
219 | foreach my $entry (@$list) { | |
d72c631c | 220 | if ($entry->{cidr} eq $param->{cidr}) { |
d72c631c DM |
221 | return $entry; |
222 | } | |
a33c74f6 DM |
223 | } |
224 | ||
225 | raise_param_exc({ cidr => "no such IP/Network" }); | |
226 | }}); | |
227 | } | |
228 | ||
229 | sub register_update_ip { | |
230 | my ($class) = @_; | |
231 | ||
232 | my $properties = $class->additional_parameters(); | |
233 | ||
234 | $properties->{name} = $api_properties->{name}; | |
235 | $properties->{cidr} = $api_properties->{cidr}; | |
236 | $properties->{nomatch} = $api_properties->{nomatch}; | |
237 | $properties->{comment} = $api_properties->{comment}; | |
d72c631c DM |
238 | $properties->{digest} = get_standard_option('pve-config-digest'); |
239 | ||
a33c74f6 DM |
240 | $class->register_method({ |
241 | name => 'update_ip', | |
242 | path => '{cidr}', | |
243 | method => 'PUT', | |
244 | description => "Update IP or Network settings", | |
245 | protected => 1, | |
246 | parameters => { | |
247 | additionalProperties => 0, | |
248 | properties => $properties, | |
249 | }, | |
250 | returns => { type => "null" }, | |
251 | code => sub { | |
252 | my ($param) = @_; | |
253 | ||
1210ae94 | 254 | my ($cluster_conf, $fw_conf, $ipset) = $class->load_config($param); |
a33c74f6 | 255 | |
5d38d64f DM |
256 | my (undef, $digest) = PVE::Firewall::copy_list_with_digest($ipset); |
257 | PVE::Tools::assert_if_modified($digest, $param->{digest}); | |
d72c631c | 258 | |
a33c74f6 DM |
259 | foreach my $entry (@$ipset) { |
260 | if($entry->{cidr} eq $param->{cidr}) { | |
261 | $entry->{nomatch} = $param->{nomatch}; | |
262 | $entry->{comment} = $param->{comment}; | |
263 | $class->save_ipset($param, $fw_conf, $ipset); | |
264 | return; | |
265 | } | |
266 | } | |
267 | ||
268 | raise_param_exc({ cidr => "no such IP/Network" }); | |
269 | }}); | |
270 | } | |
271 | ||
272 | sub register_delete_ip { | |
009ee3ac DM |
273 | my ($class) = @_; |
274 | ||
275 | my $properties = $class->additional_parameters(); | |
276 | ||
277 | $properties->{name} = $api_properties->{name}; | |
278 | $properties->{cidr} = $api_properties->{cidr}; | |
d72c631c DM |
279 | $properties->{digest} = get_standard_option('pve-config-digest'); |
280 | ||
009ee3ac DM |
281 | $class->register_method({ |
282 | name => 'remove_ip', | |
283 | path => '{cidr}', | |
284 | method => 'DELETE', | |
285 | description => "Remove IP or Network from IPSet.", | |
286 | protected => 1, | |
287 | parameters => { | |
288 | additionalProperties => 0, | |
289 | properties => $properties, | |
290 | }, | |
291 | returns => { type => "null" }, | |
292 | code => sub { | |
293 | my ($param) = @_; | |
294 | ||
1210ae94 | 295 | my ($cluster_conf, $fw_conf, $ipset) = $class->load_config($param); |
009ee3ac | 296 | |
5d38d64f DM |
297 | my (undef, $digest) = PVE::Firewall::copy_list_with_digest($ipset); |
298 | PVE::Tools::assert_if_modified($digest, $param->{digest}); | |
d72c631c | 299 | |
4a11bba5 DM |
300 | my $new = []; |
301 | ||
302 | foreach my $entry (@$ipset) { | |
303 | push @$new, $entry if $entry->{cidr} ne $param->{cidr}; | |
304 | } | |
009ee3ac | 305 | |
4a11bba5 DM |
306 | $class->save_ipset($param, $fw_conf, $new); |
307 | ||
009ee3ac DM |
308 | return undef; |
309 | }}); | |
310 | } | |
311 | ||
312 | sub register_handlers { | |
313 | my ($class) = @_; | |
314 | ||
1210ae94 | 315 | $class->register_delete_ipset(); |
009ee3ac | 316 | $class->register_get_ipset(); |
a33c74f6 DM |
317 | $class->register_create_ip(); |
318 | $class->register_read_ip(); | |
319 | $class->register_update_ip(); | |
320 | $class->register_delete_ip(); | |
009ee3ac DM |
321 | } |
322 | ||
323 | package PVE::API2::Firewall::ClusterIPset; | |
324 | ||
325 | use strict; | |
326 | use warnings; | |
327 | ||
328 | use base qw(PVE::API2::Firewall::IPSetBase); | |
329 | ||
330 | sub load_config { | |
331 | my ($class, $param) = @_; | |
332 | ||
333 | my $fw_conf = PVE::Firewall::load_clusterfw_conf(); | |
334 | my $ipset = $fw_conf->{ipset}->{$param->{name}}; | |
335 | die "no such IPSet '$param->{name}'\n" if !defined($ipset); | |
336 | ||
1210ae94 | 337 | return (undef, $fw_conf, $ipset); |
009ee3ac DM |
338 | } |
339 | ||
1210ae94 DM |
340 | sub save_config { |
341 | my ($class, $param, $fw_conf) = @_; | |
009ee3ac | 342 | |
009ee3ac DM |
343 | PVE::Firewall::save_clusterfw_conf($fw_conf); |
344 | } | |
345 | ||
346 | __PACKAGE__->register_handlers(); | |
347 | ||
1210ae94 DM |
348 | package PVE::API2::Firewall::VMIPset; |
349 | ||
350 | use strict; | |
351 | use warnings; | |
352 | use PVE::JSONSchema qw(get_standard_option); | |
353 | ||
354 | use base qw(PVE::API2::Firewall::IPSetBase); | |
355 | ||
356 | __PACKAGE__->additional_parameters({ | |
357 | node => get_standard_option('pve-node'), | |
358 | vmid => get_standard_option('pve-vmid'), | |
359 | }); | |
360 | ||
361 | sub load_config { | |
362 | my ($class, $param) = @_; | |
363 | ||
364 | my $cluster_conf = PVE::Firewall::load_clusterfw_conf(); | |
365 | my $fw_conf = PVE::Firewall::load_vmfw_conf($cluster_conf, 'vm', $param->{vmid}); | |
366 | my $ipset = $fw_conf->{ipset}->{$param->{name}}; | |
367 | die "no such IPSet '$param->{name}'\n" if !defined($ipset); | |
368 | ||
369 | return ($cluster_conf, $fw_conf, $ipset); | |
370 | } | |
371 | ||
372 | sub save_config { | |
373 | my ($class, $param, $fw_conf) = @_; | |
374 | ||
375 | PVE::Firewall::save_vmfw_conf($param->{vmid}, $fw_conf); | |
376 | } | |
377 | ||
378 | __PACKAGE__->register_handlers(); | |
379 | ||
380 | package PVE::API2::Firewall::CTIPset; | |
381 | ||
382 | use strict; | |
383 | use warnings; | |
384 | use PVE::JSONSchema qw(get_standard_option); | |
385 | ||
386 | use base qw(PVE::API2::Firewall::IPSetBase); | |
387 | ||
388 | __PACKAGE__->additional_parameters({ | |
389 | node => get_standard_option('pve-node'), | |
390 | vmid => get_standard_option('pve-vmid'), | |
391 | }); | |
392 | ||
393 | sub load_config { | |
394 | my ($class, $param) = @_; | |
395 | ||
396 | my $cluster_conf = PVE::Firewall::load_clusterfw_conf(); | |
397 | my $fw_conf = PVE::Firewall::load_vmfw_conf($cluster_conf, 'ct', $param->{vmid}); | |
398 | my $ipset = $fw_conf->{ipset}->{$param->{name}}; | |
399 | die "no such IPSet '$param->{name}'\n" if !defined($ipset); | |
400 | ||
401 | return ($cluster_conf, $fw_conf, $ipset); | |
402 | } | |
403 | ||
404 | sub save_config { | |
405 | my ($class, $param, $fw_conf) = @_; | |
406 | ||
407 | PVE::Firewall::save_vmfw_conf($param->{vmid}, $fw_conf); | |
408 | } | |
409 | ||
410 | __PACKAGE__->register_handlers(); | |
411 | ||
c85c87f9 DM |
412 | package PVE::API2::Firewall::BaseIPSetList; |
413 | ||
414 | use strict; | |
415 | use warnings; | |
e74a87f5 | 416 | use PVE::JSONSchema qw(get_standard_option); |
c85c87f9 | 417 | use PVE::Exception qw(raise_param_exc); |
e74a87f5 | 418 | use PVE::Firewall; |
c85c87f9 DM |
419 | |
420 | use base qw(PVE::RESTHandler); | |
421 | ||
1210ae94 DM |
422 | sub load_config { |
423 | my ($class, $param) = @_; | |
424 | ||
425 | die "implement this in subclass"; | |
426 | ||
427 | #return ($cluster_conf, $fw_conf); | |
428 | } | |
429 | ||
430 | sub save_config { | |
431 | my ($class, $param, $fw_conf) = @_; | |
432 | ||
433 | die "implement this in subclass"; | |
434 | } | |
435 | ||
436 | my $additional_param_hash_list = {}; | |
437 | ||
438 | sub additional_parameters { | |
439 | my ($class, $new_value) = @_; | |
440 | ||
441 | if (defined($new_value)) { | |
442 | $additional_param_hash_list->{$class} = $new_value; | |
443 | } | |
444 | ||
445 | # return a copy | |
446 | my $copy = {}; | |
447 | my $org = $additional_param_hash_list->{$class} || {}; | |
448 | foreach my $p (keys %$org) { $copy->{$p} = $org->{$p}; } | |
449 | return $copy; | |
450 | } | |
451 | ||
5d38d64f DM |
452 | my $get_ipset_list = sub { |
453 | my ($fw_conf) = @_; | |
454 | ||
455 | my $res = []; | |
456 | foreach my $name (keys %{$fw_conf->{ipset}}) { | |
457 | my $data = { | |
458 | name => $name, | |
459 | }; | |
460 | if (my $comment = $fw_conf->{ipset_comments}->{$name}) { | |
461 | $data->{comment} = $comment; | |
462 | } | |
463 | push @$res, $data; | |
464 | } | |
465 | ||
466 | my ($list, $digest) = PVE::Firewall::copy_list_with_digest($res); | |
467 | ||
468 | return wantarray ? ($list, $digest) : $list; | |
469 | }; | |
470 | ||
c85c87f9 DM |
471 | sub register_index { |
472 | my ($class) = @_; | |
473 | ||
1210ae94 DM |
474 | my $properties = $class->additional_parameters(); |
475 | ||
c85c87f9 DM |
476 | $class->register_method({ |
477 | name => 'ipset_index', | |
478 | path => '', | |
479 | method => 'GET', | |
480 | description => "List IPSets", | |
481 | parameters => { | |
482 | additionalProperties => 0, | |
1210ae94 | 483 | properties => $properties, |
c85c87f9 DM |
484 | }, |
485 | returns => { | |
486 | type => 'array', | |
487 | items => { | |
488 | type => "object", | |
489 | properties => { | |
e74a87f5 | 490 | name => get_standard_option('ipset-name'), |
d72c631c DM |
491 | digest => get_standard_option('pve-config-digest', { optional => 0} ), |
492 | comment => { | |
493 | type => 'string', | |
494 | optional => 1, | |
495 | } | |
c85c87f9 DM |
496 | }, |
497 | }, | |
498 | links => [ { rel => 'child', href => "{name}" } ], | |
499 | }, | |
500 | code => sub { | |
501 | my ($param) = @_; | |
502 | ||
1210ae94 | 503 | my ($cluster_conf, $fw_conf) = $class->load_config($param); |
c85c87f9 | 504 | |
5d38d64f | 505 | return &$get_ipset_list($fw_conf); |
c85c87f9 DM |
506 | }}); |
507 | } | |
508 | ||
509 | sub register_create { | |
510 | my ($class) = @_; | |
511 | ||
1210ae94 DM |
512 | my $properties = $class->additional_parameters(); |
513 | ||
514 | $properties->{name} = get_standard_option('ipset-name'); | |
515 | ||
516 | $properties->{comment} = { type => 'string', optional => 1 }; | |
517 | ||
518 | $properties->{digest} = get_standard_option('pve-config-digest'); | |
519 | ||
520 | $properties->{rename} = get_standard_option('ipset-name', { | |
521 | description => "Rename an existing IPSet. You can set 'rename' to the same value as 'name' to update the 'comment' of an existing IPSet.", | |
522 | optional => 1 }); | |
523 | ||
c85c87f9 DM |
524 | $class->register_method({ |
525 | name => 'create_ipset', | |
526 | path => '', | |
527 | method => 'POST', | |
528 | description => "Create new IPSet", | |
529 | protected => 1, | |
530 | parameters => { | |
531 | additionalProperties => 0, | |
1210ae94 | 532 | properties => $properties, |
c85c87f9 DM |
533 | }, |
534 | returns => { type => 'null' }, | |
535 | code => sub { | |
536 | my ($param) = @_; | |
537 | ||
1210ae94 | 538 | my ($cluster_conf, $fw_conf) = $class->load_config($param); |
c85c87f9 | 539 | |
bc374ca7 | 540 | if ($param->{rename}) { |
5d38d64f DM |
541 | my (undef, $digest) = &$get_ipset_list($fw_conf); |
542 | PVE::Tools::assert_if_modified($digest, $param->{digest}); | |
543 | ||
bc374ca7 DM |
544 | raise_param_exc({ name => "IPSet '$param->{rename}' does not exists" }) |
545 | if !$fw_conf->{ipset}->{$param->{rename}}; | |
5d38d64f | 546 | |
bc374ca7 DM |
547 | my $data = delete $fw_conf->{ipset}->{$param->{rename}}; |
548 | $fw_conf->{ipset}->{$param->{name}} = $data; | |
d72c631c DM |
549 | if (my $comment = delete $fw_conf->{ipset_comments}->{$param->{rename}}) { |
550 | $fw_conf->{ipset_comments}->{$param->{name}} = $comment; | |
551 | } | |
552 | $fw_conf->{ipset_comments}->{$param->{name}} = $param->{comment} if defined($param->{comment}); | |
5d38d64f DM |
553 | } else { |
554 | foreach my $name (keys %{$fw_conf->{ipset}}) { | |
555 | raise_param_exc({ name => "IPSet '$name' already exists" }) | |
556 | if $name eq $param->{name}; | |
557 | } | |
558 | ||
bc374ca7 | 559 | $fw_conf->{ipset}->{$param->{name}} = []; |
d72c631c | 560 | $fw_conf->{ipset_comments}->{$param->{name}} = $param->{comment} if defined($param->{comment}); |
bc374ca7 DM |
561 | } |
562 | ||
1210ae94 | 563 | $class->save_config($param, $fw_conf); |
c85c87f9 DM |
564 | |
565 | return undef; | |
566 | }}); | |
567 | } | |
568 | ||
1210ae94 | 569 | sub register_handlers { |
c85c87f9 DM |
570 | my ($class) = @_; |
571 | ||
1210ae94 DM |
572 | $class->register_index(); |
573 | $class->register_create(); | |
574 | } | |
c85c87f9 | 575 | |
1210ae94 | 576 | package PVE::API2::Firewall::ClusterIPSetList; |
c85c87f9 | 577 | |
1210ae94 DM |
578 | use strict; |
579 | use warnings; | |
580 | use PVE::Firewall; | |
5d38d64f | 581 | |
1210ae94 DM |
582 | use base qw(PVE::API2::Firewall::BaseIPSetList); |
583 | ||
584 | sub load_config { | |
585 | my ($class, $param) = @_; | |
586 | ||
587 | my $cluster_conf = PVE::Firewall::load_clusterfw_conf(); | |
588 | return (undef, $cluster_conf); | |
589 | } | |
c85c87f9 | 590 | |
1210ae94 DM |
591 | sub save_config { |
592 | my ($class, $param, $fw_conf) = @_; | |
c85c87f9 | 593 | |
1210ae94 DM |
594 | PVE::Firewall::save_clusterfw_conf($fw_conf); |
595 | } | |
c85c87f9 | 596 | |
1210ae94 DM |
597 | __PACKAGE__->register_handlers(); |
598 | ||
599 | __PACKAGE__->register_method ({ | |
600 | subclass => "PVE::API2::Firewall::ClusterIPset", | |
601 | path => '{name}', | |
602 | # set fragment delimiter (no subdirs) - we need that, because CIDR address contain a slash '/' | |
603 | fragmentDelimiter => '', | |
604 | }); | |
605 | ||
606 | package PVE::API2::Firewall::VMIPSetList; | |
607 | ||
608 | use strict; | |
609 | use warnings; | |
610 | use PVE::JSONSchema qw(get_standard_option); | |
611 | use PVE::Firewall; | |
612 | ||
613 | use base qw(PVE::API2::Firewall::BaseIPSetList); | |
614 | ||
615 | __PACKAGE__->additional_parameters({ | |
616 | node => get_standard_option('pve-node'), | |
617 | vmid => get_standard_option('pve-vmid'), | |
618 | }); | |
619 | ||
620 | sub load_config { | |
621 | my ($class, $param) = @_; | |
622 | ||
623 | my $cluster_conf = PVE::Firewall::load_clusterfw_conf(); | |
624 | my $fw_conf = PVE::Firewall::load_vmfw_conf($cluster_conf, 'vm', $param->{vmid}); | |
625 | return ($cluster_conf, $fw_conf); | |
c85c87f9 DM |
626 | } |
627 | ||
1210ae94 DM |
628 | sub save_config { |
629 | my ($class, $param, $fw_conf) = @_; | |
c85c87f9 | 630 | |
1210ae94 | 631 | PVE::Firewall::save_vmfw_conf($param->{vmid}, $fw_conf); |
c85c87f9 DM |
632 | } |
633 | ||
1210ae94 DM |
634 | __PACKAGE__->register_handlers(); |
635 | ||
636 | __PACKAGE__->register_method ({ | |
637 | subclass => "PVE::API2::Firewall::VMIPset", | |
638 | path => '{name}', | |
639 | # set fragment delimiter (no subdirs) - we need that, because CIDR address contain a slash '/' | |
640 | fragmentDelimiter => '', | |
641 | }); | |
642 | ||
643 | package PVE::API2::Firewall::CTIPSetList; | |
c85c87f9 DM |
644 | |
645 | use strict; | |
646 | use warnings; | |
1210ae94 | 647 | use PVE::JSONSchema qw(get_standard_option); |
c85c87f9 DM |
648 | use PVE::Firewall; |
649 | ||
650 | use base qw(PVE::API2::Firewall::BaseIPSetList); | |
651 | ||
1210ae94 DM |
652 | __PACKAGE__->additional_parameters({ |
653 | node => get_standard_option('pve-node'), | |
654 | vmid => get_standard_option('pve-vmid'), | |
655 | }); | |
656 | ||
c85c87f9 | 657 | sub load_config { |
1210ae94 | 658 | my ($class, $param) = @_; |
c85c87f9 | 659 | |
1210ae94 DM |
660 | my $cluster_conf = PVE::Firewall::load_clusterfw_conf(); |
661 | my $fw_conf = PVE::Firewall::load_vmfw_conf($cluster_conf, 'ct', $param->{vmid}); | |
662 | return ($cluster_conf, $fw_conf); | |
c85c87f9 DM |
663 | } |
664 | ||
665 | sub save_config { | |
1210ae94 | 666 | my ($class, $param, $fw_conf) = @_; |
c85c87f9 | 667 | |
1210ae94 | 668 | PVE::Firewall::save_vmfw_conf($param->{vmid}, $fw_conf); |
c85c87f9 DM |
669 | } |
670 | ||
671 | __PACKAGE__->register_handlers(); | |
672 | ||
673 | __PACKAGE__->register_method ({ | |
1210ae94 | 674 | subclass => "PVE::API2::Firewall::CTIPset", |
c85c87f9 DM |
675 | path => '{name}', |
676 | # set fragment delimiter (no subdirs) - we need that, because CIDR address contain a slash '/' | |
677 | fragmentDelimiter => '', | |
678 | }); | |
679 | ||
009ee3ac | 680 | 1; |