| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Armadito::Agent; |
|
2
|
|
|
|
|
|
|
|
|
3
|
23
|
|
|
23
|
|
171695
|
use 5.008000; |
|
|
23
|
|
|
|
|
70
|
|
|
4
|
23
|
|
|
23
|
|
90
|
use strict; |
|
|
23
|
|
|
|
|
35
|
|
|
|
23
|
|
|
|
|
429
|
|
|
5
|
23
|
|
|
23
|
|
90
|
use warnings; |
|
|
23
|
|
|
|
|
70
|
|
|
|
23
|
|
|
|
|
680
|
|
|
6
|
23
|
|
|
23
|
|
91
|
use English qw(-no_match_vars); |
|
|
23
|
|
|
|
|
31
|
|
|
|
23
|
|
|
|
|
459
|
|
|
7
|
23
|
|
|
23
|
|
14629
|
use UNIVERSAL::require; |
|
|
23
|
|
|
|
|
876
|
|
|
|
23
|
|
|
|
|
272
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
|
10
|
|
|
|
|
|
|
|
|
11
|
23
|
|
|
23
|
|
8802
|
use Armadito::Agent::Config; |
|
|
23
|
|
|
|
|
37
|
|
|
|
23
|
|
|
|
|
216
|
|
|
12
|
23
|
|
|
23
|
|
8333
|
use Armadito::Agent::Storage; |
|
|
23
|
|
|
|
|
53
|
|
|
|
23
|
|
|
|
|
335
|
|
|
13
|
23
|
|
|
23
|
|
8959
|
use Armadito::Agent::Antivirus; |
|
|
23
|
|
|
|
|
42
|
|
|
|
23
|
|
|
|
|
218
|
|
|
14
|
23
|
|
|
23
|
|
593
|
use Armadito::Agent::Logger qw (LOG_DEBUG LOG_INFO LOG_DEBUG2); |
|
|
23
|
|
|
|
|
29
|
|
|
|
23
|
|
|
|
|
20229
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "0.10.1"; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my @supported_antiviruses = ( "Armadito", "Eset", "Kaspersky" ); |
|
19
|
|
|
|
|
|
|
my @supported_tasks = ( "State", "Enrollment", "Getjobs", "Runjobs", "Alerts", "Scan", "AVConfig", "Scheduler" ); |
|
20
|
|
|
|
|
|
|
my @unspecific_tasks = ( "Enrollment", "Getjobs", "Runjobs" ); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
|
23
|
0
|
|
|
0
|
1
|
|
my ( $class, %params ) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $self = { |
|
26
|
|
|
|
|
|
|
status => 'unknown', |
|
27
|
|
|
|
|
|
|
confdir => $params{confdir}, |
|
28
|
|
|
|
|
|
|
datadir => $params{datadir}, |
|
29
|
|
|
|
|
|
|
libdir => $params{libdir}, |
|
30
|
|
|
|
|
|
|
vardir => $params{vardir}, |
|
31
|
|
|
|
|
|
|
sigterm => $params{sigterm}, |
|
32
|
0
|
|
|
|
|
|
targets => [], |
|
33
|
|
|
|
|
|
|
tasks => [] |
|
34
|
|
|
|
|
|
|
}; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
bless $self, $class; |
|
37
|
0
|
|
|
|
|
|
return $self; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub init { |
|
41
|
0
|
|
|
0
|
1
|
|
my ( $self, %params ) = @_; |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->_loadAgentConfiguration(%params); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $verbosity |
|
46
|
|
|
|
|
|
|
= $self->{config}->{debug} && $self->{config}->{debug} == 1 ? LOG_DEBUG |
|
47
|
0
|
0
|
0
|
|
|
|
: $self->{config}->{debug} && $self->{config}->{debug} == 2 ? LOG_DEBUG2 |
|
|
|
0
|
0
|
|
|
|
|
|
48
|
|
|
|
|
|
|
: LOG_INFO; |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self->_validateOptions(%params); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$self->{logger} = Armadito::Agent::Logger->new( |
|
53
|
|
|
|
|
|
|
config => $self->{config}, |
|
54
|
|
|
|
|
|
|
backends => $self->{config}->{logger}, |
|
55
|
0
|
|
|
|
|
|
verbosity => $verbosity |
|
56
|
|
|
|
|
|
|
); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$self->{armadito_storage} = Armadito::Agent::Storage->new( |
|
59
|
|
|
|
|
|
|
logger => $self->{logger}, |
|
60
|
|
|
|
|
|
|
directory => $self->{vardir} |
|
61
|
0
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
$self->{key} = defined( $params{options}->{key} ) ? $params{options}->{key} : ""; |
|
64
|
0
|
|
|
|
|
|
$self->{agent_id} = 0; |
|
65
|
0
|
|
|
|
|
|
$self->{scheduler_id} = 0; |
|
66
|
0
|
|
|
|
|
|
$self->_getArmaditoIds(); |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $class = "Armadito::Agent::Antivirus::$self->{config}->{antivirus}"; |
|
69
|
0
|
|
|
|
|
|
$class->require(); |
|
70
|
0
|
|
|
|
|
|
$self->{antivirus} = $class->new( logger => $self->{logger} ); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _loadAgentConfiguration { |
|
74
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self->{config} = Armadito::Agent::Config->new(); |
|
77
|
0
|
|
|
|
|
|
$self->{config}->loadDefaults( $self->_getDefaultConf() ); |
|
78
|
0
|
|
|
|
|
|
$self->{config}->loadFromFile( $self->{confdir} . "/agent.cfg" ); |
|
79
|
0
|
|
|
|
|
|
$self->{config}->overrideWithArgs(%params); |
|
80
|
0
|
|
|
|
|
|
$self->{config}->checkContent(); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _getDefaultConf { |
|
84
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return { |
|
87
|
0
|
|
|
|
|
|
'ca-cert-dir' => undef, |
|
88
|
|
|
|
|
|
|
'ca-cert-file' => undef, |
|
89
|
|
|
|
|
|
|
'color' => undef, |
|
90
|
|
|
|
|
|
|
'conf-reload-interval' => 0, |
|
91
|
|
|
|
|
|
|
'debug' => undef, |
|
92
|
|
|
|
|
|
|
'force' => undef, |
|
93
|
|
|
|
|
|
|
'html' => undef, |
|
94
|
|
|
|
|
|
|
'local' => undef, |
|
95
|
|
|
|
|
|
|
'logger' => 'Stderr', |
|
96
|
|
|
|
|
|
|
'logfile' => undef, |
|
97
|
|
|
|
|
|
|
'logfacility' => 'LOG_USER', |
|
98
|
|
|
|
|
|
|
'logfile-maxsize' => undef, |
|
99
|
|
|
|
|
|
|
'no-ssl-check' => undef, |
|
100
|
|
|
|
|
|
|
'proxy' => undef, |
|
101
|
|
|
|
|
|
|
'server' => undef, |
|
102
|
|
|
|
|
|
|
'timeout' => 180, |
|
103
|
|
|
|
|
|
|
'user' => undef, |
|
104
|
|
|
|
|
|
|
'password' => undef, |
|
105
|
|
|
|
|
|
|
'stdout' => undef, |
|
106
|
|
|
|
|
|
|
'antivirus' => undef, |
|
107
|
|
|
|
|
|
|
'scheduler' => undef |
|
108
|
|
|
|
|
|
|
}; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _validateOptions { |
|
112
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$self->isAVSupported( $self->{config}->{antivirus} ) |
|
115
|
0
|
0
|
|
|
|
|
or die "Unsupported Antivirus. Use --list-avs to see which antiviruses are supported."; |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if ( $params{options}->{task} ) { |
|
118
|
|
|
|
|
|
|
$self->isTaskSupported( $params{options}->{task} ) |
|
119
|
0
|
0
|
|
|
|
|
or die "Unsupported Task. Use --list-tasks to see which tasks are supported."; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _getArmaditoIds { |
|
124
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $data = $self->{armadito_storage}->restore( name => 'Armadito-Agent' ); |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
$self->{agent_id} = $data->{agent_id} if ( defined( $data->{agent_id} ) ); |
|
129
|
0
|
0
|
|
|
|
|
$self->{scheduler_id} = $data->{scheduler_id} if ( defined( $data->{scheduler_id} ) ); |
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
$self->{logger}->debug( "agent_id = " . $self->{agent_id} ); |
|
132
|
0
|
|
|
|
|
|
$self->{logger}->debug( "scheduler_id = " . $self->{scheduler_id} ); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub _storeArmaditoIds { |
|
136
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$self->{armadito_storage}->save( |
|
139
|
|
|
|
|
|
|
name => 'Armadito-Agent', |
|
140
|
|
|
|
|
|
|
data => { |
|
141
|
|
|
|
|
|
|
agent_id => $self->{agent_id}, |
|
142
|
|
|
|
|
|
|
scheduler_id => $self->{scheduler_id} |
|
143
|
|
|
|
|
|
|
} |
|
144
|
0
|
|
|
|
|
|
); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub isAVSupported { |
|
148
|
0
|
|
|
0
|
1
|
|
my ( $self, $antivirus ) = @_; |
|
149
|
0
|
|
|
|
|
|
foreach (@supported_antiviruses) { |
|
150
|
0
|
0
|
|
|
|
|
if ( $antivirus eq $_ ) { |
|
151
|
0
|
|
|
|
|
|
return 1; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
} |
|
154
|
0
|
|
|
|
|
|
return 0; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub isTaskSupported { |
|
158
|
0
|
|
|
0
|
1
|
|
my ( $self, $task ) = @_; |
|
159
|
0
|
|
|
|
|
|
foreach (@supported_tasks) { |
|
160
|
0
|
0
|
|
|
|
|
if ( $task eq $_ ) { |
|
161
|
0
|
|
|
|
|
|
return 1; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
} |
|
164
|
0
|
|
|
|
|
|
return 0; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub isTaskSpecificToAV { |
|
168
|
0
|
|
|
0
|
1
|
|
my ( $self, $task ) = @_; |
|
169
|
0
|
|
|
|
|
|
foreach (@unspecific_tasks) { |
|
170
|
0
|
0
|
|
|
|
|
if ( $task eq $_ ) { |
|
171
|
0
|
|
|
|
|
|
return 0; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
} |
|
174
|
0
|
|
|
|
|
|
return 1; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub displaySupportedTasks { |
|
178
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
179
|
0
|
|
|
|
|
|
print "List of supported tasks :\n"; |
|
180
|
0
|
|
|
|
|
|
foreach (@supported_tasks) { |
|
181
|
0
|
|
|
|
|
|
print $_. "\n"; |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub displaySupportedAVs { |
|
186
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
187
|
0
|
|
|
|
|
|
print "List of supported antiviruses :\n"; |
|
188
|
0
|
|
|
|
|
|
foreach (@supported_antiviruses) { |
|
189
|
0
|
|
|
|
|
|
print $_. "\n"; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub runTask { |
|
194
|
0
|
|
|
0
|
1
|
|
my ( $self, $task ) = @_; |
|
195
|
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
my $class = "Armadito::Agent::Task::$task"; |
|
197
|
0
|
|
|
|
|
|
my $antivirus = $self->{config}->{antivirus}; |
|
198
|
|
|
|
|
|
|
|
|
199
|
0
|
0
|
|
|
|
|
if ( $self->isTaskSpecificToAV($task) ) { |
|
200
|
0
|
|
|
|
|
|
$class = "Armadito::Agent::Antivirus::" . $antivirus . "::Task::" . $task; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
|
|
203
|
0
|
0
|
|
|
|
|
if ( $task eq "Scheduler" ) { |
|
204
|
0
|
|
|
|
|
|
$class = "Armadito::Agent::Scheduler::" . $self->{config}->{scheduler}; |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
$class->require(); |
|
208
|
0
|
|
|
|
|
|
my $taskclass = $class->new( agent => $self ); |
|
209
|
0
|
|
|
|
|
|
$taskclass->run(); |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
1; |
|
213
|
|
|
|
|
|
|
__END__ |
|
214
|
|
|
|
|
|
|
=head1 NAME |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Armadito::Agent - Armadito Agent |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 VERSION |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
0.10.1 |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Agent interfacing between Armadito Antivirus and Armadito plugin for GLPI for Windows and Linux. |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 METHODS |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 new(%params) |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
The constructor. The following parameters are allowed, as keys of the %params |
|
231
|
|
|
|
|
|
|
hash: |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=over |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item I<confdir> |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
the configuration directory. |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item I<datadir> |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
the read-only data directory. |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item I<vardir> |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
the read-write data directory. |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item I<options> |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
the options to use. |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=back |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head2 init() |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
Initialize the agent. |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head2 isAVSupported($antivirus) |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Returns true if given antivirus is supported by the current version of the agent. |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head2 isTaskSupported($task) |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Returns true if given task is supported by the current version of the agent. |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head2 isTaskSpecificToAV($task) |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Returns true if given task is specific to an Antivirus. |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head2 displaySupportedTasks() |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Display all currently supported tasks to stdout. |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head2 displaySupportedAVs() |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Display all currently supported Antiviruses to stdout. |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head2 runTask($task) |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Run a given task. |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=over 4 |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item * L<http://armadito-glpi.readthedocs.io/en/dev/> |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
Armadito for GLPI online documentation. |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item * L<https://github.com/armadito> |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
Armadito organization on github. |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item * L<http://www.glpi-project.org/> |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
GLPI Project main page. |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=back |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=cut |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head1 AUTHOR |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
vhamon, E<lt>vhamon@teclib.comE<gt> |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head1 COPYRIGHTS |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
Copyright (C) 2006-2010 OCS Inventory contributors |
|
308
|
|
|
|
|
|
|
Copyright (C) 2010-2012 FusionInventory Team |
|
309
|
|
|
|
|
|
|
Copyright (C) 2011-2017 Teclib' |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head1 LICENSE |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
This software is licensed under the terms of GPLv3, see COPYING file for |
|
314
|
|
|
|
|
|
|
details. |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=cut |