]>
Commit | Line | Data |
---|---|---|
5bdc31fb AD |
1 | package PVE::Firewall::Helpers; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::Tools qw(file_get_contents file_set_contents); | |
7 | ||
8 | use base 'Exporter'; | |
9 | our @EXPORT_OK = qw( | |
10 | remove_vmfw_conf | |
11 | clone_vmfw_conf | |
12 | ); | |
13 | ||
14 | my $pvefw_conf_dir = "/etc/pve/firewall"; | |
15 | ||
16 | sub remove_vmfw_conf { | |
17 | my ($vmid) = @_; | |
18 | ||
19 | my $vmfw_conffile = "$pvefw_conf_dir/$vmid.fw"; | |
20 | ||
21 | unlink $vmfw_conffile; | |
22 | } | |
23 | ||
24 | sub clone_vmfw_conf { | |
25 | my ($vmid, $newid) = @_; | |
26 | ||
27 | my $sourcevm_conffile = "$pvefw_conf_dir/$vmid.fw"; | |
28 | my $clonevm_conffile = "$pvefw_conf_dir/$newid.fw"; | |
29 | ||
30 | lock_vmfw_conf($newid, 10, sub { | |
31 | if (-f $clonevm_conffile) { | |
32 | unlink $clonevm_conffile; | |
33 | } | |
34 | if (-f $sourcevm_conffile) { | |
35 | my $data = file_get_contents($sourcevm_conffile); | |
36 | file_set_contents($clonevm_conffile, $data); | |
37 | } | |
38 | }); | |
39 | } | |
40 | ||
41 | 1; |