| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Armadito::Agent; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
12886
|
use 5.008000; |
|
|
1
|
|
|
|
|
2
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
18
|
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
21
|
|
|
6
|
1
|
|
|
1
|
|
396
|
use English qw(-no_match_vars) ; |
|
|
1
|
|
|
|
|
2527
|
|
|
|
1
|
|
|
|
|
4
|
|
|
7
|
1
|
|
|
1
|
|
635
|
use UNIVERSAL::require; |
|
|
1
|
|
|
|
|
973
|
|
|
|
1
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
402
|
use Armadito::Agent::Config; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Armadito::Agent::Storage; |
|
13
|
|
|
|
|
|
|
use Armadito::Agent::Tools::Fingerprint; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = "0.1.0_01"; |
|
16
|
|
|
|
|
|
|
my @supported_antiviruses = ("Armadito"); |
|
17
|
|
|
|
|
|
|
my @supported_tasks = ("State","Enrollment","Getjobs","Runjobs","Alerts", "Scan"); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
|
|
|
|
|
|
my ($class, %params) = @_; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $self = { |
|
23
|
|
|
|
|
|
|
status => 'unknown', |
|
24
|
|
|
|
|
|
|
confdir => $params{confdir}, |
|
25
|
|
|
|
|
|
|
datadir => $params{datadir}, |
|
26
|
|
|
|
|
|
|
libdir => $params{libdir}, |
|
27
|
|
|
|
|
|
|
vardir => $params{vardir}, |
|
28
|
|
|
|
|
|
|
sigterm => $params{sigterm}, |
|
29
|
|
|
|
|
|
|
targets => [], |
|
30
|
|
|
|
|
|
|
tasks => [] |
|
31
|
|
|
|
|
|
|
}; |
|
32
|
|
|
|
|
|
|
bless $self, $class; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return $self; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub init { |
|
38
|
|
|
|
|
|
|
my ($self, %params) = @_; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Get FusionInventory setup directories |
|
41
|
|
|
|
|
|
|
$self->_getFusionSetup(); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Load configuration |
|
44
|
|
|
|
|
|
|
$self->{config} = Armadito::Agent::Config->new( |
|
45
|
|
|
|
|
|
|
armadito_confdir => $self->{confdir}, |
|
46
|
|
|
|
|
|
|
fusion_confdir => $self->{fusion_confdir}, |
|
47
|
|
|
|
|
|
|
options => $params{options} |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Create logger |
|
51
|
|
|
|
|
|
|
$self->{logger} = FusionInventory::Agent::Logger->new(backends => ['Stderr']); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Init storages |
|
54
|
|
|
|
|
|
|
$self->{fusion_storage} = Armadito::Agent::Storage->new( |
|
55
|
|
|
|
|
|
|
logger => $self->{logger}, |
|
56
|
|
|
|
|
|
|
directory => $self->{fusion_vardir} |
|
57
|
|
|
|
|
|
|
); |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->{armadito_storage} = Armadito::Agent::Storage->new( |
|
60
|
|
|
|
|
|
|
logger => $self->{logger}, |
|
61
|
|
|
|
|
|
|
directory => $self->{vardir} |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Read persistent data from storages |
|
65
|
|
|
|
|
|
|
$self->{agent_id} = 0; |
|
66
|
|
|
|
|
|
|
$self->_getFusionId(); |
|
67
|
|
|
|
|
|
|
$self->_getArmaditoId(); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$self->{fingerprint} = getFingerprint(); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _getLinuxFusionSetupDir { |
|
73
|
|
|
|
|
|
|
my ($res, $dirlabel) = @_; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if($res =~ /$dirlabel: (\S+)/ms){ |
|
76
|
|
|
|
|
|
|
return $1; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
die "$dirlabel not found when parsing fusioninventory-agent --setup."; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _getWindowsFusionSetupDir { |
|
82
|
|
|
|
|
|
|
my $Registry; |
|
83
|
|
|
|
|
|
|
Win32::TieRegistry->require(); |
|
84
|
|
|
|
|
|
|
Win32::TieRegistry->import( |
|
85
|
|
|
|
|
|
|
Delimiter => '/', |
|
86
|
|
|
|
|
|
|
ArrayValues => 0, |
|
87
|
|
|
|
|
|
|
TiedRef => \$Registry |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $machKey = $Registry->Open('LMachine', { |
|
91
|
|
|
|
|
|
|
Access => Win32::TieRegistry::KEY_READ() |
|
92
|
|
|
|
|
|
|
}) or die "Can't open HKEY_LOCAL_MACHINE key: $EXTENDED_OS_ERROR"; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $uninstallValues = |
|
95
|
|
|
|
|
|
|
$machKey->{'SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/FusionInventory-Agent'}; |
|
96
|
|
|
|
|
|
|
die "FusionInventory-Agent InstallLocation registry key not found. Please install FusionInventory-Agent (2.3.17+)" unless $uninstallValues; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $installLocation = $uninstallValues->{'/InstallLocation'}; |
|
99
|
|
|
|
|
|
|
die "FusionInventory-Agent InstallLocation registry key not found. Please install FusionInventory-Agent (2.3.17+)" unless $installLocation; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return $installLocation; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _getFusionSetup { |
|
105
|
|
|
|
|
|
|
my ($self) = @_; |
|
106
|
|
|
|
|
|
|
if($OSNAME ne "MSWin32") { |
|
107
|
|
|
|
|
|
|
my $res = `fusioninventory-agent --setup 2>&1`; |
|
108
|
|
|
|
|
|
|
my $exitvalue = `echo -n $?`; |
|
109
|
|
|
|
|
|
|
die "Unable to get fusioninventory-agent setup. Please, be sure you have correctly installed fusioninventory agent.\n" if($exitvalue != 0); |
|
110
|
|
|
|
|
|
|
$self->{fusion_datadir} = _getLinuxFusionSetupDir($res, "datadir"); |
|
111
|
|
|
|
|
|
|
$self->{fusion_vardir} = _getLinuxFusionSetupDir($res, "vardir"); |
|
112
|
|
|
|
|
|
|
$self->{fusion_confdir} = _getLinuxFusionSetupDir($res, "confdir"); |
|
113
|
|
|
|
|
|
|
$self->{fusion_libdir} = _getLinuxFusionSetupDir($res, "libdir"); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
else{ |
|
116
|
|
|
|
|
|
|
my $fusion_setupdir = _getWindowsFusionSetupDir(); |
|
117
|
|
|
|
|
|
|
$self->{fusion_datadir} = $fusion_setupdir."\\share"; |
|
118
|
|
|
|
|
|
|
$self->{fusion_vardir} = $fusion_setupdir."\\var"; |
|
119
|
|
|
|
|
|
|
$self->{fusion_libdir} = $fusion_setupdir."\\perl\\agent"; |
|
120
|
|
|
|
|
|
|
$self->{fusion_confdir} = $fusion_setupdir."\\etc"; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _getFusionId { |
|
125
|
|
|
|
|
|
|
my ($self) = @_; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $data = $self->{fusion_storage}->restore(name => 'FusionInventory-Agent'); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$self->{fusionid} = $data->{deviceid} if $data->{deviceid}; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _getArmaditoId { |
|
133
|
|
|
|
|
|
|
my ($self) = @_; |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my $data = $self->{armadito_storage}->restore(name => 'Armadito-Agent'); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$self->{agent_id} = $data->{agent_id} if $data->{agent_id}; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub _storeArmaditoId { |
|
141
|
|
|
|
|
|
|
my ($self) = @_; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$self->{armadito_storage}->save( |
|
144
|
|
|
|
|
|
|
name => 'Armadito-Agent', |
|
145
|
|
|
|
|
|
|
data => { |
|
146
|
|
|
|
|
|
|
agent_id => $self->{agent_id}, |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
); |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub isAVSupported { |
|
152
|
|
|
|
|
|
|
my ($self, $antivirus) = @_; |
|
153
|
|
|
|
|
|
|
foreach (@supported_antiviruses) { |
|
154
|
|
|
|
|
|
|
if( $antivirus eq $_ ) { |
|
155
|
|
|
|
|
|
|
return 1; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
return 0; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub isTaskSupported { |
|
162
|
|
|
|
|
|
|
my ($self, $task) = @_; |
|
163
|
|
|
|
|
|
|
foreach (@supported_tasks) { |
|
164
|
|
|
|
|
|
|
if( $task eq $_ ) { |
|
165
|
|
|
|
|
|
|
return 1; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
return 0; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub displaySupportedTasks { |
|
172
|
|
|
|
|
|
|
my ($self) = @_; |
|
173
|
|
|
|
|
|
|
print "List of supported tasks :\n"; |
|
174
|
|
|
|
|
|
|
foreach(@supported_tasks) { |
|
175
|
|
|
|
|
|
|
print $_."\n"; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub displaySupportedAVs { |
|
180
|
|
|
|
|
|
|
my ($self) = @_; |
|
181
|
|
|
|
|
|
|
print "List of supported antiviruses :\n"; |
|
182
|
|
|
|
|
|
|
foreach(@supported_antiviruses) { |
|
183
|
|
|
|
|
|
|
print $_."\n"; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
1; |
|
187
|
|
|
|
|
|
|
__END__ |