1 package PVE
::API2
::Firewall
::Host
;
5 use PVE
::JSONSchema
qw(get_standard_option);
6 use PVE
::RPCEnvironment
;
9 use PVE
::API2
::Firewall
::Rules
;
11 use Data
::Dumper
; # fixme: remove
13 use base
qw(PVE::RESTHandler);
15 __PACKAGE__-
>register_method ({
16 subclass
=> "PVE::API2::Firewall::HostRules",
20 __PACKAGE__-
>register_method({
24 permissions
=> { user
=> 'all' },
25 description
=> "Directory index.",
27 additionalProperties
=> 0,
29 node
=> get_standard_option
('pve-node'),
38 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
45 { name
=> 'options' },
52 my $option_properties = {
54 description
=> "Enable host firewall rules.",
58 log_level_in
=> get_standard_option
('pve-fw-loglevel', {
59 description
=> "Log level for incoming traffic." }),
60 log_level_out
=> get_standard_option
('pve-fw-loglevel', {
61 description
=> "Log level for outgoing traffic." }),
62 tcp_flags_log_level
=> get_standard_option
('pve-fw-loglevel', {
63 description
=> "Log level for illegal tcp flags filter." }),
64 smurf_log_level
=> get_standard_option
('pve-fw-loglevel', {
65 description
=> "Log level for SMURFS filter." }),
67 description
=> "Enable SMURFS filter.",
72 description
=> "Filter illegal combinations of TCP flags.",
76 allow_bridge_route
=> {
77 description
=> "Enable firewall when bridges contains IP address. The firewall is not fully functional in that case, so you need to enable that explicitly",
82 description
=> "Allow rules processing speed optimizations.",
87 description
=> "Maximum number of tracked connections.",
92 nf_conntrack_tcp_timeout_established
=> {
93 description
=> "Conntrack established timeout.",
100 my $add_option_properties = sub {
101 my ($properties) = @_;
103 foreach my $k (keys %$option_properties) {
104 $properties->{$k} = $option_properties->{$k};
111 __PACKAGE__-
>register_method({
112 name
=> 'get_options',
115 description
=> "Get host firewall options.",
118 additionalProperties
=> 0,
120 node
=> get_standard_option
('pve-node'),
125 #additionalProperties => 1,
126 properties
=> $option_properties,
131 my $hostfw_conf = PVE
::Firewall
::load_hostfw_conf
();
133 return PVE
::Firewall
::copy_opject_with_digest
($hostfw_conf->{options
});
136 __PACKAGE__-
>register_method({
137 name
=> 'set_options',
140 description
=> "Set Firewall options.",
144 additionalProperties
=> 0,
145 properties
=> &$add_option_properties({
146 node
=> get_standard_option
('pve-node'),
148 type
=> 'string', format
=> 'pve-configid-list',
149 description
=> "A list of settings you want to delete.",
152 digest
=> get_standard_option
('pve-config-digest'),
155 returns
=> { type
=> "null" },
159 my $hostfw_conf = PVE
::Firewall
::load_hostfw_conf
();
161 my (undef, $digest) = PVE
::Firewall
::copy_opject_with_digest
($hostfw_conf->{options
});
162 PVE
::Tools
::assert_if_modified
($digest, $param->{digest
});
164 if ($param->{delete}) {
165 foreach my $opt (PVE
::Tools
::split_list
($param->{delete})) {
166 raise_param_exc
({ delete => "no such option '$opt'" })
167 if !$option_properties->{$opt};
168 delete $hostfw_conf->{options
}->{$opt};
172 if (defined($param->{enable
})) {
173 $param->{enable
} = $param->{enable
} ?
1 : 0;
176 foreach my $k (keys %$option_properties) {
177 next if !defined($param->{$k});
178 $hostfw_conf->{options
}->{$k} = $param->{$k};
181 PVE
::Firewall
::save_hostfw_conf
($hostfw_conf);
186 __PACKAGE__-
>register_method({
190 description
=> "Read firewall log",
193 check
=> ['perm', '/nodes/{node}', [ 'Sys.Syslog' ]],
197 additionalProperties
=> 0,
199 node
=> get_standard_option
('pve-node'),
218 description
=> "Line number",
222 description
=> "Line text",
231 my $rpcenv = PVE
::RPCEnvironment
::get
();
232 my $user = $rpcenv->get_user();
233 my $node = $param->{node
};
235 my ($count, $lines) = PVE
::Tools
::dump_logfile
("/var/log/pve-firewall.log", $param->{start
}, $param->{limit
});
237 $rpcenv->set_result_attrib('total', $count);