]>
git.proxmox.com Git - pve-firewall.git/blob - src/PVE/API2/Firewall/VM.pm
1 package PVE
::API2
::Firewall
::VM
;
5 use PVE
::JSONSchema
qw(get_standard_option);
8 use PVE
::API2
::Firewall
::Rules
;
9 use PVE
::API2
::Firewall
::Aliases
;
11 use Data
::Dumper
; # fixme: remove
13 use base
qw(PVE::RESTHandler);
15 __PACKAGE__-
>register_method ({
16 subclass
=> "PVE::API2::Firewall::VMRules",
20 __PACKAGE__-
>register_method ({
21 subclass
=> "PVE::API2::Firewall::VMAliases",
25 __PACKAGE__-
>register_method({
29 permissions
=> { user
=> 'all' },
30 description
=> "Directory index.",
32 additionalProperties
=> 0,
34 node
=> get_standard_option
('pve-node'),
35 vmid
=> get_standard_option
('pve-vmid'),
44 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
51 { name
=> 'options' },
57 my $option_properties = {
59 description
=> "Enable host firewall rules.",
64 description
=> "Enable/disable MAC address filter.",
69 description
=> "Enable DHCP.",
74 description
=> "Input policy.",
77 enum
=> ['ACCEPT', 'REJECT', 'DROP'],
80 description
=> "Output policy.",
83 enum
=> ['ACCEPT', 'REJECT', 'DROP'],
85 log_level_in
=> get_standard_option
('pve-fw-loglevel', {
86 description
=> "Log level for incoming traffic." }),
87 log_level_out
=> get_standard_option
('pve-fw-loglevel', {
88 description
=> "Log level for outgoing traffic." }),
92 my $add_option_properties = sub {
93 my ($properties) = @_;
95 foreach my $k (keys %$option_properties) {
96 $properties->{$k} = $option_properties->{$k};
101 __PACKAGE__-
>register_method({
102 name
=> 'get_options',
105 description
=> "Get VM firewall options.",
108 additionalProperties
=> 0,
110 node
=> get_standard_option
('pve-node'),
111 vmid
=> get_standard_option
('pve-vmid'),
116 #additionalProperties => 1,
117 properties
=> $option_properties,
122 my $vmfw_conf = PVE
::Firewall
::load_vmfw_conf
($param->{vmid
});
124 return PVE
::Firewall
::copy_opject_with_digest
($vmfw_conf->{options
});
127 __PACKAGE__-
>register_method({
128 name
=> 'set_options',
131 description
=> "Set Firewall options.",
135 additionalProperties
=> 0,
136 properties
=> &$add_option_properties({
137 node
=> get_standard_option
('pve-node'),
138 vmid
=> get_standard_option
('pve-vmid'),
140 type
=> 'string', format
=> 'pve-configid-list',
141 description
=> "A list of settings you want to delete.",
144 digest
=> get_standard_option
('pve-config-digest'),
147 returns
=> { type
=> "null" },
151 my $vmfw_conf = PVE
::Firewall
::load_vmfw_conf
($param->{vmid
});
153 my (undef, $digest) = PVE
::Firewall
::copy_opject_with_digest
($vmfw_conf->{options
});
154 PVE
::Tools
::assert_if_modified
($digest, $param->{digest
});
156 if ($param->{delete}) {
157 foreach my $opt (PVE
::Tools
::split_list
($param->{delete})) {
158 raise_param_exc
({ delete => "no such option '$opt'" })
159 if !$option_properties->{$opt};
160 delete $vmfw_conf->{options
}->{$opt};
164 if (defined($param->{enable
})) {
165 $param->{enable
} = $param->{enable
} ?
1 : 0;
168 foreach my $k (keys %$option_properties) {
169 next if !defined($param->{$k});
170 $vmfw_conf->{options
}->{$k} = $param->{$k};
173 PVE
::Firewall
::save_vmfw_conf
($param->{vmid
}, $vmfw_conf);
178 __PACKAGE__-
>register_method({
182 description
=> "Read firewall log",
185 check
=> ['perm', '/vms/{vmid}', [ 'VM.Console' ]],
189 additionalProperties
=> 0,
191 node
=> get_standard_option
('pve-node'),
192 vmid
=> get_standard_option
('pve-vmid'),
211 description
=> "Line number",
215 description
=> "Line text",
224 my $rpcenv = PVE
::RPCEnvironment
::get
();
225 my $user = $rpcenv->get_user();
226 my $vmid = $param->{vmid
};
228 my ($count, $lines) = PVE
::Tools
::dump_logfile
("/var/log/pve-firewall.log",
229 $param->{start
}, $param->{limit
},
232 $rpcenv->set_result_attrib('total', $count);