]>
git.proxmox.com Git - pve-firewall.git/blob - src/PVE/API2/Firewall/Host.pm
bbc34c5a97063cccb0c792165a23483015b65cd8
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 = $PVE::Firewall
::host_option_properties
;
54 my $add_option_properties = sub {
55 my ($properties) = @_;
57 foreach my $k (keys %$option_properties) {
58 $properties->{$k} = $option_properties->{$k};
65 __PACKAGE__-
>register_method({
66 name
=> 'get_options',
69 description
=> "Get host firewall options.",
72 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
75 additionalProperties
=> 0,
77 node
=> get_standard_option
('pve-node'),
82 #additionalProperties => 1,
83 properties
=> $option_properties,
88 my $hostfw_conf = PVE
::Firewall
::load_hostfw_conf
();
90 return PVE
::Firewall
::copy_opject_with_digest
($hostfw_conf->{options
});
93 __PACKAGE__-
>register_method({
94 name
=> 'set_options',
97 description
=> "Set Firewall options.",
101 check
=> ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
104 additionalProperties
=> 0,
105 properties
=> &$add_option_properties({
106 node
=> get_standard_option
('pve-node'),
108 type
=> 'string', format
=> 'pve-configid-list',
109 description
=> "A list of settings you want to delete.",
112 digest
=> get_standard_option
('pve-config-digest'),
115 returns
=> { type
=> "null" },
119 my $hostfw_conf = PVE
::Firewall
::load_hostfw_conf
();
121 my (undef, $digest) = PVE
::Firewall
::copy_opject_with_digest
($hostfw_conf->{options
});
122 PVE
::Tools
::assert_if_modified
($digest, $param->{digest
});
124 if ($param->{delete}) {
125 foreach my $opt (PVE
::Tools
::split_list
($param->{delete})) {
126 raise_param_exc
({ delete => "no such option '$opt'" })
127 if !$option_properties->{$opt};
128 delete $hostfw_conf->{options
}->{$opt};
132 if (defined($param->{enable
})) {
133 $param->{enable
} = $param->{enable
} ?
1 : 0;
136 foreach my $k (keys %$option_properties) {
137 next if !defined($param->{$k});
138 $hostfw_conf->{options
}->{$k} = $param->{$k};
141 PVE
::Firewall
::save_hostfw_conf
($hostfw_conf);
146 __PACKAGE__-
>register_method({
150 description
=> "Read firewall log",
153 check
=> ['perm', '/nodes/{node}', [ 'Sys.Syslog' ]],
157 additionalProperties
=> 0,
159 node
=> get_standard_option
('pve-node'),
178 description
=> "Line number",
182 description
=> "Line text",
191 my $rpcenv = PVE
::RPCEnvironment
::get
();
192 my $user = $rpcenv->get_user();
193 my $node = $param->{node
};
195 my ($count, $lines) = PVE
::Tools
::dump_logfile
("/var/log/pve-firewall.log", $param->{start
}, $param->{limit
});
197 $rpcenv->set_result_attrib('total', $count);