]> git.proxmox.com Git - pve-firewall.git/blob - src/PVE/API2/Firewall/Host.pm
remove unused options
[pve-firewall.git] / src / PVE / API2 / Firewall / Host.pm
1 package PVE::API2::Firewall::Host;
2
3 use strict;
4 use warnings;
5 use PVE::JSONSchema qw(get_standard_option);
6 use PVE::RPCEnvironment;
7
8 use PVE::Firewall;
9 use PVE::API2::Firewall::Rules;
10
11 use Data::Dumper; # fixme: remove
12
13 use base qw(PVE::RESTHandler);
14
15 __PACKAGE__->register_method ({
16 subclass => "PVE::API2::Firewall::HostRules",
17 path => 'rules',
18 });
19
20 __PACKAGE__->register_method({
21 name => 'index',
22 path => '',
23 method => 'GET',
24 permissions => { user => 'all' },
25 description => "Directory index.",
26 parameters => {
27 additionalProperties => 0,
28 properties => {
29 node => get_standard_option('pve-node'),
30 },
31 },
32 returns => {
33 type => 'array',
34 items => {
35 type => "object",
36 properties => {},
37 },
38 links => [ { rel => 'child', href => "{name}" } ],
39 },
40 code => sub {
41 my ($param) = @_;
42
43 my $result = [
44 { name => 'rules' },
45 { name => 'options' },
46 { name => 'log' },
47 ];
48
49 return $result;
50 }});
51
52 my $option_properties = {
53 enable => {
54 description => "Enable host firewall rules.",
55 type => 'boolean',
56 optional => 1,
57 },
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." }),
66 nosmurfs => {
67 description => "Enable SMURFS filter.",
68 type => 'boolean',
69 optional => 1,
70 },
71 tcpflags => {
72 description => "Filter illegal combinations of TCP flags.",
73 type => 'boolean',
74 optional => 1,
75 },
76 nf_conntrack_max => {
77 description => "Maximum number of tracked connections.",
78 type => 'integer',
79 optional => 1,
80 minimum => 32768,
81 },
82 nf_conntrack_tcp_timeout_established => {
83 description => "Conntrack established timeout.",
84 type => 'integer',
85 optional => 1,
86 minimum => 7875,
87 }
88 };
89
90 my $add_option_properties = sub {
91 my ($properties) = @_;
92
93 foreach my $k (keys %$option_properties) {
94 $properties->{$k} = $option_properties->{$k};
95 }
96
97 return $properties;
98 };
99
100
101 __PACKAGE__->register_method({
102 name => 'get_options',
103 path => 'options',
104 method => 'GET',
105 description => "Get host firewall options.",
106 proxyto => 'node',
107 parameters => {
108 additionalProperties => 0,
109 properties => {
110 node => get_standard_option('pve-node'),
111 },
112 },
113 returns => {
114 type => "object",
115 #additionalProperties => 1,
116 properties => $option_properties,
117 },
118 code => sub {
119 my ($param) = @_;
120
121 my $hostfw_conf = PVE::Firewall::load_hostfw_conf();
122
123 return PVE::Firewall::copy_opject_with_digest($hostfw_conf->{options});
124 }});
125
126 __PACKAGE__->register_method({
127 name => 'set_options',
128 path => 'options',
129 method => 'PUT',
130 description => "Set Firewall options.",
131 protected => 1,
132 proxyto => 'node',
133 parameters => {
134 additionalProperties => 0,
135 properties => &$add_option_properties({
136 node => get_standard_option('pve-node'),
137 delete => {
138 type => 'string', format => 'pve-configid-list',
139 description => "A list of settings you want to delete.",
140 optional => 1,
141 },
142 digest => get_standard_option('pve-config-digest'),
143 }),
144 },
145 returns => { type => "null" },
146 code => sub {
147 my ($param) = @_;
148
149 my $hostfw_conf = PVE::Firewall::load_hostfw_conf();
150
151 my (undef, $digest) = PVE::Firewall::copy_opject_with_digest($hostfw_conf->{options});
152 PVE::Tools::assert_if_modified($digest, $param->{digest});
153
154 if ($param->{delete}) {
155 foreach my $opt (PVE::Tools::split_list($param->{delete})) {
156 raise_param_exc({ delete => "no such option '$opt'" })
157 if !$option_properties->{$opt};
158 delete $hostfw_conf->{options}->{$opt};
159 }
160 }
161
162 if (defined($param->{enable})) {
163 $param->{enable} = $param->{enable} ? 1 : 0;
164 }
165
166 foreach my $k (keys %$option_properties) {
167 next if !defined($param->{$k});
168 $hostfw_conf->{options}->{$k} = $param->{$k};
169 }
170
171 PVE::Firewall::save_hostfw_conf($hostfw_conf);
172
173 return undef;
174 }});
175
176 __PACKAGE__->register_method({
177 name => 'log',
178 path => 'log',
179 method => 'GET',
180 description => "Read firewall log",
181 proxyto => 'node',
182 permissions => {
183 check => ['perm', '/nodes/{node}', [ 'Sys.Syslog' ]],
184 },
185 protected => 1,
186 parameters => {
187 additionalProperties => 0,
188 properties => {
189 node => get_standard_option('pve-node'),
190 start => {
191 type => 'integer',
192 minimum => 0,
193 optional => 1,
194 },
195 limit => {
196 type => 'integer',
197 minimum => 0,
198 optional => 1,
199 },
200 },
201 },
202 returns => {
203 type => 'array',
204 items => {
205 type => "object",
206 properties => {
207 n => {
208 description=> "Line number",
209 type=> 'integer',
210 },
211 t => {
212 description=> "Line text",
213 type => 'string',
214 }
215 }
216 }
217 },
218 code => sub {
219 my ($param) = @_;
220
221 my $rpcenv = PVE::RPCEnvironment::get();
222 my $user = $rpcenv->get_user();
223 my $node = $param->{node};
224
225 my ($count, $lines) = PVE::Tools::dump_logfile("/var/log/pve-firewall.log", $param->{start}, $param->{limit});
226
227 $rpcenv->set_result_attrib('total', $count);
228
229 return $lines;
230 }});
231
232 1;