]> git.proxmox.com Git - pmg-api.git/blob - PMG/API2/ClamAV.pm
delete/deliver_quarantined_mail: use receiver instead of pmail
[pmg-api.git] / PMG / API2 / ClamAV.pm
1 package PMG::API2::ClamAV;
2
3 use strict;
4 use warnings;
5
6 use PVE::Tools;
7 use PVE::SafeSyslog;
8 use PVE::INotify;
9 use PVE::Exception qw(raise_param_exc);
10 use PVE::RESTHandler;
11 use PMG::RESTEnvironment;
12 use PVE::JSONSchema qw(get_standard_option);
13
14 use PMG::Utils;
15
16 use base qw(PVE::RESTHandler);
17
18
19 __PACKAGE__->register_method ({
20 name => 'index',
21 path => '',
22 method => 'GET',
23 description => "Directory index.",
24 permissions => { check => [ 'admin', 'audit' ] },
25 parameters => {
26 additionalProperties => 0,
27 properties => {
28 node => get_standard_option('pve-node'),
29 },
30 },
31 returns => {
32 type => 'array',
33 items => {
34 type => "object",
35 properties => {},
36 },
37 links => [ { rel => 'child', href => "{subdir}" } ],
38 },
39 code => sub {
40 my ($param) = @_;
41
42 my $res = [];
43
44 push @$res, { subdir => "database" };
45
46 return $res;
47 }});
48
49 __PACKAGE__->register_method({
50 name => 'database_status',
51 path => 'database',
52 method => 'GET',
53 description => "ClamAV virus database status.",
54 parameters => {
55 additionalProperties => 0,
56 properties => {
57 node => get_standard_option('pve-node'),
58 },
59 },
60 permissions => { check => [ 'admin', 'audit' ] },
61 proxyto => 'node',
62 returns => {
63 type => 'array',
64 items => {
65 type => "object",
66 properties => {
67 type => { type => 'string' },
68 build_time => { type => 'string' },
69 version => { type => 'string', optional => 1 },
70 nsigs => { type => 'integer' },
71 },
72 },
73 },
74 code => sub {
75 my ($param) = @_;
76
77 return PMG::Utils::clamav_dbstat();
78 }});
79
80 __PACKAGE__->register_method({
81 name => 'update_database',
82 path => 'database',
83 method => 'POST',
84 description => "Update ClamAV virus databases.",
85 permissions => { check => [ 'admin' ] },
86 proxyto => 'node',
87 protected => 1,
88 parameters => {
89 additionalProperties => 0,
90 properties => {
91 node => get_standard_option('pve-node'),
92 },
93 },
94 returns => { type => 'string' },
95 code => sub {
96 my ($param) = @_;
97
98 my $rpcenv = PMG::RESTEnvironment->get();
99 my $authuser = $rpcenv->get_user();
100
101 my $realcmd = sub {
102 my $upid = shift;
103
104 # remove mirrors.dat so freshclam checks all servers again
105 # fixes bug #303
106 unlink "/var/lib/clamav/mirrors.dat";
107
108 my $cmd = ['/usr/bin/freshclam', '--stdout'];
109
110 PVE::Tools::run_command($cmd);
111 };
112
113 return $rpcenv->fork_worker('avupdate', undef, $authuser, $realcmd);
114 }});
115
116 1;