]>
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
;
14 use base
qw(PVE::RESTHandler);
16 __PACKAGE__-
>register_method ({
17 subclass
=> "PVE::API2::Firewall::HostRules",
21 __PACKAGE__-
>register_method({
25 permissions
=> { user
=> 'all' },
26 description
=> "Directory index.",
28 additionalProperties
=> 0,
30 node
=> get_standard_option
('pve-node'),
39 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
46 { name
=> 'options' },
53 my $option_properties = $PVE::Firewall
::host_option_properties
;
55 my $add_option_properties = sub {
56 my ($properties) = @_;
58 foreach my $k (keys %$option_properties) {
59 $properties->{$k} = $option_properties->{$k};
66 __PACKAGE__-
>register_method({
67 name
=> 'get_options',
70 description
=> "Get host firewall options.",
73 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
76 additionalProperties
=> 0,
78 node
=> get_standard_option
('pve-node'),
83 #additionalProperties => 1,
84 properties
=> $option_properties,
89 my $hostfw_conf = PVE
::Firewall
::load_hostfw_conf
();
91 return PVE
::Firewall
::copy_opject_with_digest
($hostfw_conf->{options
});
94 __PACKAGE__-
>register_method({
95 name
=> 'set_options',
98 description
=> "Set Firewall options.",
102 check
=> ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
105 additionalProperties
=> 0,
106 properties
=> &$add_option_properties({
107 node
=> get_standard_option
('pve-node'),
109 type
=> 'string', format
=> 'pve-configid-list',
110 description
=> "A list of settings you want to delete.",
113 digest
=> get_standard_option
('pve-config-digest'),
116 returns
=> { type
=> "null" },
120 my $hostfw_conf = PVE
::Firewall
::load_hostfw_conf
();
122 my (undef, $digest) = PVE
::Firewall
::copy_opject_with_digest
($hostfw_conf->{options
});
123 PVE
::Tools
::assert_if_modified
($digest, $param->{digest
});
125 if ($param->{delete}) {
126 foreach my $opt (PVE
::Tools
::split_list
($param->{delete})) {
127 raise_param_exc
({ delete => "no such option '$opt'" })
128 if !$option_properties->{$opt};
129 delete $hostfw_conf->{options
}->{$opt};
133 if (defined($param->{enable
})) {
134 $param->{enable
} = $param->{enable
} ?
1 : 0;
137 foreach my $k (keys %$option_properties) {
138 next if !defined($param->{$k});
139 $hostfw_conf->{options
}->{$k} = $param->{$k};
142 PVE
::Firewall
::save_hostfw_conf
($hostfw_conf);
147 __PACKAGE__-
>register_method({
151 description
=> "Read firewall log",
154 check
=> ['perm', '/nodes/{node}', [ 'Sys.Syslog' ]],
158 additionalProperties
=> 0,
160 node
=> get_standard_option
('pve-node'),
179 description
=> "Line number",
183 description
=> "Line text",
192 my $rpcenv = PVE
::RPCEnvironment
::get
();
193 my $user = $rpcenv->get_user();
194 my $node = $param->{node
};
196 my ($count, $lines) = PVE
::Tools
::dump_logfile
("/var/log/pve-firewall.log", $param->{start
}, $param->{limit
});
198 $rpcenv->set_result_attrib('total', $count);