]>
git.proxmox.com Git - pve-firewall.git/blob - src/PVE/API2/Firewall/Host.pm
1 package PVE
::API2
::Firewall
::Host
;
6 use PVE
::Exception
qw(raise_param_exc);
7 use PVE
::JSONSchema
qw(get_standard_option);
8 use PVE
::RPCEnvironment
;
11 use PVE
::API2
::Firewall
::Rules
;
13 use Data
::Dumper
; # fixme: remove
15 use base
qw(PVE::RESTHandler);
17 __PACKAGE__-
>register_method ({
18 subclass
=> "PVE::API2::Firewall::HostRules",
22 __PACKAGE__-
>register_method({
26 permissions
=> { user
=> 'all' },
27 description
=> "Directory index.",
29 additionalProperties
=> 0,
31 node
=> get_standard_option
('pve-node'),
40 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
47 { name
=> 'options' },
54 my $option_properties = $PVE::Firewall
::host_option_properties
;
56 my $add_option_properties = sub {
57 my ($properties) = @_;
59 foreach my $k (keys %$option_properties) {
60 $properties->{$k} = $option_properties->{$k};
67 __PACKAGE__-
>register_method({
68 name
=> 'get_options',
71 description
=> "Get host firewall options.",
74 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
77 additionalProperties
=> 0,
79 node
=> get_standard_option
('pve-node'),
84 #additionalProperties => 1,
85 properties
=> $option_properties,
90 my $hostfw_conf = PVE
::Firewall
::load_hostfw_conf
();
92 return PVE
::Firewall
::copy_opject_with_digest
($hostfw_conf->{options
});
95 __PACKAGE__-
>register_method({
96 name
=> 'set_options',
99 description
=> "Set Firewall options.",
103 check
=> ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
106 additionalProperties
=> 0,
107 properties
=> &$add_option_properties({
108 node
=> get_standard_option
('pve-node'),
110 type
=> 'string', format
=> 'pve-configid-list',
111 description
=> "A list of settings you want to delete.",
114 digest
=> get_standard_option
('pve-config-digest'),
117 returns
=> { type
=> "null" },
121 my $hostfw_conf = PVE
::Firewall
::load_hostfw_conf
();
123 my (undef, $digest) = PVE
::Firewall
::copy_opject_with_digest
($hostfw_conf->{options
});
124 PVE
::Tools
::assert_if_modified
($digest, $param->{digest
});
126 if ($param->{delete}) {
127 foreach my $opt (PVE
::Tools
::split_list
($param->{delete})) {
128 raise_param_exc
({ delete => "no such option '$opt'" })
129 if !$option_properties->{$opt};
130 delete $hostfw_conf->{options
}->{$opt};
134 if (defined($param->{enable
})) {
135 $param->{enable
} = $param->{enable
} ?
1 : 0;
138 foreach my $k (keys %$option_properties) {
139 next if !defined($param->{$k});
140 $hostfw_conf->{options
}->{$k} = $param->{$k};
143 PVE
::Firewall
::save_hostfw_conf
($hostfw_conf);
148 __PACKAGE__-
>register_method({
152 description
=> "Read firewall log",
155 check
=> ['perm', '/nodes/{node}', [ 'Sys.Syslog' ]],
159 additionalProperties
=> 0,
161 node
=> get_standard_option
('pve-node'),
180 description
=> "Line number",
184 description
=> "Line text",
193 my $rpcenv = PVE
::RPCEnvironment
::get
();
194 my $user = $rpcenv->get_user();
195 my $node = $param->{node
};
197 my ($count, $lines) = PVE
::Tools
::dump_logfile
("/var/log/pve-firewall.log", $param->{start
}, $param->{limit
});
199 $rpcenv->set_result_attrib('total', $count);