]>
Commit | Line | Data |
---|---|---|
d17c5265 DM |
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 PVE::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 | 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 | ||
95 | my $rpcenv = PVE::RESTEnvironment::get(); | |
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 | 113 | 1; |