| 48 |
|
$last_udp_time = time; |
| 49 |
|
$last_tcp_time = time; |
| 50 |
|
while (1) { |
| 51 |
< |
if (time >= $last_udp_time + $udp_update_time) { |
| 51 |
> |
my($time) = time; |
| 52 |
> |
if ($time >= $last_udp_time + $udp_update_time) { |
| 53 |
|
&send_udp_packet(); |
| 54 |
< |
$last_udp_time = time; |
| 54 |
> |
$last_udp_time = $time; |
| 55 |
|
} |
| 56 |
< |
if (time >= $last_tcp_time + $tcp_update_time) { |
| 56 |
> |
if ($time >= $last_tcp_time + $tcp_update_time) { |
| 57 |
|
&send_tcp_heartbeat(); |
| 58 |
< |
$last_tcp_time = time; |
| 58 |
> |
$last_tcp_time = $time; |
| 59 |
|
} |
| 60 |
< |
`sleep 1`; |
| 60 |
> |
my($next_udp) = $udp_update_time - $time + $last_udp_time; |
| 61 |
> |
my($next_tcp) = $tcp_update_time - $time + $last_tcp_time; |
| 62 |
> |
my($delay); |
| 63 |
> |
if ($next_udp < $next_tcp) { |
| 64 |
> |
$delay = $next_udp |
| 65 |
> |
} |
| 66 |
> |
else { |
| 67 |
> |
$delay = $next_tcp; |
| 68 |
> |
} |
| 69 |
> |
`sleep $delay`; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
exit(0); |
| 77 |
|
PeerAddr => $filter_manager_addr, |
| 78 |
|
PeerPort => $filter_manager_port, |
| 79 |
|
Proto => 'tcp' |
| 80 |
< |
) or die "Could not perform configuration via TCP: $!\n"; |
| 80 |
> |
); |
| 81 |
> |
if (!defined $sock) { |
| 82 |
> |
print "IHOST ERROR: Could not connect to $filter_manager_addr:$filter_manager_port.\n"; |
| 83 |
> |
print "Please check that there is an i-scream server at this address.\n"; |
| 84 |
> |
print "Program ended.\n"; |
| 85 |
> |
exit(1); |
| 86 |
> |
} |
| 87 |
|
|
| 72 |
– |
die "Could not connect to the i-scream filter manager: $!\n" unless $sock; |
| 73 |
– |
|
| 88 |
|
# Now run through the configuration process. |
| 89 |
|
my($response); |
| 90 |
|
|
| 102 |
|
chop $response; |
| 103 |
|
$last_modified = $response; |
| 104 |
|
|
| 105 |
< |
print "Config last modified: ". scalar localtime $last_modified . "\n"; |
| 105 |
> |
print "Config last modified: ". (scalar localtime $last_modified/1000) . "\n"; |
| 106 |
|
|
| 107 |
|
print $sock "FILELIST\n"; |
| 108 |
|
$response = <$sock>; |
| 121 |
|
chop $response; |
| 122 |
|
$tcp_update_time = $response; |
| 123 |
|
|
| 124 |
< |
print "UDP packet period: $udp_update_time seconds.\nTCP heartbeat period: $tcp_update_time.\n"; |
| 124 |
> |
print "UDP packet period: $udp_update_time seconds.\nTCP heartbeat period: $tcp_update_time seconds.\n"; |
| 125 |
|
|
| 126 |
|
print $sock "ENDCONFIG\n"; |
| 127 |
|
$response = <$sock>; |
| 184 |
|
|
| 185 |
|
my($hostname) = hostname(); |
| 186 |
|
$hostname =~ s/\..*$//g; |
| 187 |
< |
my($domainname) = `cat /etc/resolv.conf`; |
| 188 |
< |
$domainname =~ s/domain\s*([^\s]*?)/$1/; |
| 187 |
> |
`cat /etc/resolv.conf` =~ /domain\s+([^\s]+)/; |
| 188 |
> |
my($domainname) = $1; |
| 189 |
|
my($machine_name) = "$hostname.$domainname"; |
| 190 |
|
my($ip) = inet_ntoa(scalar(gethostbyname($hostname)) || 'localhost'); |
| 191 |
|
|
| 205 |
|
<platform>$packet{"packet.os.platform"}</platform> |
| 206 |
|
<sysname>$packet{"packet.os.sysname"}</sysname> |
| 207 |
|
<version>$packet{"packet.os.version"}</version> |
| 208 |
+ |
<uptime>$packet{"packet.os.uptime"}</uptime> |
| 209 |
|
</os> |
| 210 |
|
<users> |
| 211 |
|
<count>$packet{"packet.users.count"}</count> |
| 258 |
|
PeerAddr => $filter_addr, |
| 259 |
|
PeerPort => $tcp_port, |
| 260 |
|
Proto => 'tcp' |
| 261 |
< |
) or die "Could not perform heartbeat via TCP: $!\n"; |
| 262 |
< |
|
| 263 |
< |
die "Could not connect to the i-scream filter: $!\n" unless $sock; |
| 261 |
> |
); |
| 262 |
> |
if (!defined $sock) { |
| 263 |
> |
print "IHOST WARNING: Failed to deliver a heartbeat to the i-scream filter.\n"; |
| 264 |
> |
return; |
| 265 |
> |
} |
| 266 |
|
|
| 267 |
|
# Now run through the configuration process. |
| 268 |
|
my($response); |