]>
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; | |
9d82c6bc | 11 | use PMG::RESTEnvironment; |
d17c5265 DM |
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.", | |
46607089 | 24 | permissions => { check => [ 'admin', 'audit' ] }, |
d17c5265 DM |
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 | ||
7e032f86 | 44 | push @$res, { subdir => "database" }; |
d17c5265 DM |
45 | |
46 | return $res; | |
47 | }}); | |
48 | ||
49 | __PACKAGE__->register_method({ | |
719df39b DM |
50 | name => 'database_status', |
51 | path => 'database', | |
d17c5265 DM |
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 | }, | |
46607089 DM |
60 | permissions => { check => [ 'admin', 'audit' ] }, |
61 | proxyto => 'node', | |
d17c5265 DM |
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 | ||
8f03cf56 DM |
80 | __PACKAGE__->register_method({ |
81 | name => 'update_database', | |
719df39b | 82 | path => 'database', |
8f03cf56 DM |
83 | method => 'POST', |
84 | description => "Update ClamAV virus databases.", | |
46607089 DM |
85 | permissions => { check => [ 'admin' ] }, |
86 | proxyto => 'node', | |
8f03cf56 DM |
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 | ||
f1c29260 | 98 | my $rpcenv = PMG::RESTEnvironment->get(); |
8f03cf56 DM |
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 | ||
e309b754 | 108 | my $cmd = ['/usr/bin/freshclam', '--stdout']; |
8f03cf56 DM |
109 | |
110 | PVE::Tools::run_command($cmd); | |
111 | }; | |
112 | ||
113 | return $rpcenv->fork_worker('avupdate', undef, $authuser, $realcmd); | |
114 | }}); | |
115 | ||
d17c5265 | 116 | 1; |