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