line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Armadito::Agent::Antivirus::Kaspersky::Task::State; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
17750319
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
62
|
|
5
|
1
|
|
|
1
|
|
5
|
use base 'Armadito::Agent::Task::State'; |
|
1
|
|
|
|
|
37
|
|
|
1
|
|
|
|
|
427
|
|
6
|
1
|
|
|
1
|
|
5
|
use Armadito::Agent::Tools::File qw(readFile); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
7
|
1
|
|
|
1
|
|
231
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Time::Local; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub run { |
11
|
|
|
|
|
|
|
my ( $self, %params ) = @_; |
12
|
|
|
|
|
|
|
$self = $self->SUPER::run(%params); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$self->{data} = { |
15
|
|
|
|
|
|
|
dbinfo => {}, |
16
|
|
|
|
|
|
|
avdetails => [] |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$self->_parseUpdateIndex(); |
20
|
|
|
|
|
|
|
$self->_parseProfilesFile(); |
21
|
|
|
|
|
|
|
$self->_sendToGLPI( $self->{data} ); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _getUpdateIndexPath { |
25
|
|
|
|
|
|
|
my ($self) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $osclass = $self->{agent}->{antivirus}->getOSClass(); |
28
|
|
|
|
|
|
|
return $osclass->getDataPath() . "u1313g.xml"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _parseUpdateIndex { |
32
|
|
|
|
|
|
|
my ($self) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $update_index = $self->_getUpdateIndexPath(); |
35
|
|
|
|
|
|
|
my $filecontent = readFile( filepath => $update_index ); |
36
|
|
|
|
|
|
|
$filecontent =~ s/(.*);.*$/$1/ms; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $parser = XML::LibXML->new(); |
39
|
|
|
|
|
|
|
my $doc = $parser->parse_string($filecontent); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->{data}->{dbinfo} = $self->_getDatabasesInfo($doc); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _getDatabasesInfo { |
45
|
|
|
|
|
|
|
my ( $self, $doc ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my ($node) = $doc->findnodes('/Update'); |
48
|
|
|
|
|
|
|
my $date = $node->getAttribute('Date'); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $dbinfo = { |
51
|
|
|
|
|
|
|
global_update_timestamp => $self->_toTimestamp($date), |
52
|
|
|
|
|
|
|
modules => $self->_getModulesInfo($node) |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return $dbinfo; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _getModulesInfo { |
59
|
|
|
|
|
|
|
my ( $self, $node ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my @mod_simple = $self->_getModulesSimpleIndexes($node); |
62
|
|
|
|
|
|
|
my @mod_multiple = $self->_getModulesMultipleIndexes($node); |
63
|
|
|
|
|
|
|
my @modules_infos = ( @mod_simple, @mod_multiple ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return \@modules_infos; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _getModulesSimpleIndexes { |
69
|
|
|
|
|
|
|
my ( $self, $node ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my @modules = (); |
72
|
|
|
|
|
|
|
foreach ( $node->findnodes('./Index') ) { |
73
|
|
|
|
|
|
|
my $module_info = { |
74
|
|
|
|
|
|
|
name => $_->getAttribute('Name'), |
75
|
|
|
|
|
|
|
mod_status => "up-to-date", |
76
|
|
|
|
|
|
|
mod_update_timestamp => $self->_toTimestamp( $_->getAttribute('Date') ), |
77
|
|
|
|
|
|
|
bases => [] |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
push( @modules, $module_info ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return @modules; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _getModulesMultipleIndexes { |
87
|
|
|
|
|
|
|
my ( $self, $node ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my @modules = (); |
90
|
|
|
|
|
|
|
foreach ( $node->findnodes('./Indexes') ) { |
91
|
|
|
|
|
|
|
my @itemkeys = split( ';', $_->getAttribute('Item') ); |
92
|
|
|
|
|
|
|
my @list = split( ';', $_->getAttribute('List') ); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
foreach my $module (@list) { |
95
|
|
|
|
|
|
|
my @items = split( '\|', $module ); |
96
|
|
|
|
|
|
|
my $kmodule_info = {}; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
for ( my $i = 0; $i < scalar(@items); $i++ ) { |
99
|
|
|
|
|
|
|
$kmodule_info->{ $itemkeys[$i] } = $items[$i]; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $module_info = { |
103
|
|
|
|
|
|
|
name => $kmodule_info->{Name}, |
104
|
|
|
|
|
|
|
mod_status => "up-to-date", |
105
|
|
|
|
|
|
|
mod_update_timestamp => $self->_toTimestamp( $kmodule_info->{Date} ), |
106
|
|
|
|
|
|
|
bases => [] |
107
|
|
|
|
|
|
|
}; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
push( @modules, $module_info ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
return @modules; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _toTimestamp { |
117
|
|
|
|
|
|
|
my ( $self, $date ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
if ( $date =~ m/^(\d{2})(\d{2})(\d{4}) (\d{2})(\d{2})/ ) { |
120
|
|
|
|
|
|
|
my ( $mday, $mon, $year, $hour, $min, $sec ) = ( $1, $2, $3, $4, $5, "00" ); |
121
|
|
|
|
|
|
|
return timelocal( $sec, $min, $hour, $mday, $mon - 1, $year ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
return 0; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub _getProfilesFilePath { |
128
|
|
|
|
|
|
|
my ($self) = @_; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $osclass = $self->{agent}->{antivirus}->getOSClass(); |
131
|
|
|
|
|
|
|
return $osclass->getDataPath() . "profiles.xml"; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub _parseProfilesFile { |
135
|
|
|
|
|
|
|
my ($self) = @_; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my $config_file = $self->_getProfilesFilePath(); |
138
|
|
|
|
|
|
|
my $parser = XML::LibXML->new(); |
139
|
|
|
|
|
|
|
my $doc = $parser->parse_file($config_file); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my ($profiles) = $doc->findnodes('/propertiesmap/key'); |
142
|
|
|
|
|
|
|
$self->_parseKeyNode( $profiles, "" ); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub _parseKeyNode { |
146
|
|
|
|
|
|
|
my ( $self, $node, $path ) = @_; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
foreach ( $node->findnodes('./key') ) { |
149
|
|
|
|
|
|
|
$self->_parseKeyNode( $_, $path . ":" . $_->getAttribute('name') ); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
foreach ( $node->findnodes('./tDWORD') ) { |
153
|
|
|
|
|
|
|
$self->_addAVDetail( $path . ":" . $_->getAttribute('name'), $_->to_literal ); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
foreach ( $node->findnodes('./tSTRING') ) { |
157
|
|
|
|
|
|
|
$self->_addAVDetail( $path . ":" . $_->getAttribute('name'), $_->to_literal ); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
__END__ |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 NAME |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Armadito::Agent::Antivirus::Kaspersky::Task::State - State Task for Kaspersky Antivirus. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 DESCRIPTION |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This task inherits from L<Armadito::Agent::Task:State>. Get Antivirus state and then send it in a json formatted POST request to Armadito plugin for GLPI. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 FUNCTIONS |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 run ( $self, %params ) |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Run the task. |