line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::MacOS::Softwares; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
63491655
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
66
|
|
5
|
2
|
|
|
2
|
|
917
|
use Time::Piece; |
|
2
|
|
|
|
|
14892
|
|
|
2
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
514
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
244
|
|
8
|
2
|
|
|
2
|
|
698
|
use FusionInventory::Agent::Tools::MacOS; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
816
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub isEnabled { |
11
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
return |
14
|
|
|
|
|
|
|
!$params{no_category}->{software} && |
15
|
0
|
|
0
|
|
|
0
|
canRun('/usr/sbin/system_profiler'); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub doInventory { |
19
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
0
|
my $softwares = _getSoftwaresList(logger => $params{logger}); |
24
|
0
|
0
|
|
|
|
0
|
return unless $softwares; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
foreach my $software (@$softwares) { |
27
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
28
|
|
|
|
|
|
|
section => 'SOFTWARES', |
29
|
|
|
|
|
|
|
entry => $software |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _getSoftwaresList { |
35
|
1
|
|
|
1
|
|
9
|
my (%params) = @_; |
36
|
1
|
|
|
|
|
1
|
my $logger = $params{logger}; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
24
|
my $infos = getSystemProfilerInfos( |
39
|
|
|
|
|
|
|
type => 'SPApplicationsDataType', |
40
|
|
|
|
|
|
|
@_ |
41
|
|
|
|
|
|
|
); |
42
|
1
|
|
|
|
|
14
|
my $info = $infos->{Applications}; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
2
|
my @softwares; |
45
|
1
|
|
|
|
|
82
|
foreach my $name (keys %$info) { |
46
|
491
|
|
|
|
|
511
|
my $app = $info->{$name}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Windows application found by Parallels (issue #716) |
49
|
|
|
|
|
|
|
next if |
50
|
|
|
|
|
|
|
$app->{'Get Info String'} && |
51
|
491
|
100
|
100
|
|
|
1738
|
$app->{'Get Info String'} =~ /^\S+, [A-Z]:\\/; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
push @softwares, { |
54
|
|
|
|
|
|
|
NAME => $name, |
55
|
|
|
|
|
|
|
VERSION => $app->{'Version'}, |
56
|
|
|
|
|
|
|
COMMENTS => $app->{'Kind'} ? '[' . $app->{'Kind'} . ']' : undef, |
57
|
|
|
|
|
|
|
PUBLISHER => $app->{'Get Info String'}, |
58
|
|
|
|
|
|
|
# extract date's data and format these data |
59
|
407
|
100
|
|
|
|
1089
|
INSTALLDATE => _formatDate($app->{'Last Modified'}, $logger) |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
25
|
return \@softwares; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _formatDate { |
67
|
412
|
|
|
412
|
|
2495
|
my ($dateStr, $logger) = @_; |
68
|
|
|
|
|
|
|
|
69
|
412
|
|
|
|
|
298
|
my $formattedDate = ''; |
70
|
|
|
|
|
|
|
|
71
|
412
|
|
|
|
|
250
|
my $extractionPatternWithAmOrPm = "%m/%d/%y %l:%M %p"; |
72
|
412
|
|
|
|
|
253
|
my $extractionPattern = "%m/%d/%y %H:%M"; |
73
|
412
|
|
|
|
|
238
|
my $extractionPatternUsed = ''; |
74
|
|
|
|
|
|
|
|
75
|
412
|
|
|
|
|
233
|
my $outputFormat = "%Y-%m-%d %H:%M"; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# trim |
78
|
412
|
|
|
|
|
1216
|
$dateStr =~ s/^\s+|\s+$//g; |
79
|
|
|
|
|
|
|
# AM or PM detection in end of string |
80
|
412
|
100
|
|
|
|
686
|
if ($dateStr =~ /(?:AM|PM)$/) { |
81
|
410
|
|
|
|
|
343
|
$extractionPatternUsed = $extractionPatternWithAmOrPm; |
82
|
|
|
|
|
|
|
} else { |
83
|
2
|
|
|
|
|
3
|
$extractionPatternUsed = $extractionPattern; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $func = sub { |
87
|
1
|
50
|
|
1
|
|
5
|
if (defined $logger) { |
88
|
0
|
|
|
|
|
0
|
$logger->error("FusionInventory::Agent::Task::Inventory::MacOS::Softwares::_formatDate() : can't parse string '$dateStr', returns empty string.\n"); |
89
|
|
|
|
|
|
|
} |
90
|
412
|
|
|
|
|
918
|
}; |
91
|
412
|
|
|
|
|
362
|
eval { |
92
|
412
|
|
|
|
|
699
|
my $extracted = Time::Piece->strptime( |
93
|
|
|
|
|
|
|
$dateStr, |
94
|
|
|
|
|
|
|
$extractionPatternUsed |
95
|
|
|
|
|
|
|
); |
96
|
411
|
|
|
|
|
5356
|
$formattedDate = $extracted->strftime( |
97
|
|
|
|
|
|
|
$outputFormat |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
}; |
100
|
412
|
100
|
|
|
|
6072
|
&$func if $@; |
101
|
|
|
|
|
|
|
|
102
|
412
|
|
|
|
|
1776
|
return $formattedDate; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |