line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Generic::Domains; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
121662099
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
86
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
837
|
use Sys::Hostname; |
|
1
|
|
|
|
|
1904
|
|
|
1
|
|
|
|
|
70
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
633
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
476
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub isEnabled { |
11
|
0
|
|
|
0
|
0
|
|
return -f "/etc/resolv.conf"; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub doInventory { |
15
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
18
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# first, parse /etc/resolv.conf for the DNS servers, |
21
|
|
|
|
|
|
|
# and the domain search list |
22
|
0
|
|
|
|
|
|
my %dns_list; |
23
|
|
|
|
|
|
|
my %search_list; |
24
|
0
|
|
|
|
|
|
my $handle = getFileHandle( |
25
|
|
|
|
|
|
|
file => '/etc/resolv.conf', |
26
|
|
|
|
|
|
|
logger => $logger |
27
|
|
|
|
|
|
|
); |
28
|
0
|
0
|
|
|
|
|
if ($handle) { |
29
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
30
|
0
|
0
|
|
|
|
|
if ($line =~ /^nameserver\s+(\S+)/) { |
|
|
0
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$dns_list{$1} = 1; |
32
|
|
|
|
|
|
|
} elsif ($line =~ /^(domain|search)\s+(\S+)/) { |
33
|
0
|
|
|
|
|
|
$search_list{$2} = 1; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
|
close $handle; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $dns = join('/', keys %dns_list); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# attempt to deduce the actual domain from the host name |
42
|
|
|
|
|
|
|
# and fallback on the domain search list |
43
|
0
|
|
|
|
|
|
my $domain; |
44
|
0
|
|
|
|
|
|
my $hostname = hostname(); |
45
|
0
|
|
|
|
|
|
my $pos = index $hostname, '.'; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if ($pos >= 0) { |
48
|
0
|
|
|
|
|
|
$domain = substr($hostname, $pos + 1); |
49
|
|
|
|
|
|
|
} else { |
50
|
0
|
|
|
|
|
|
$domain = join('/', keys %search_list); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$inventory->setHardware({ |
54
|
|
|
|
|
|
|
WORKGROUP => $domain, |
55
|
|
|
|
|
|
|
DNS => $dns |
56
|
|
|
|
|
|
|
}); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |