45 |
|
$filter_manager_port = $ARGV[1]; |
46 |
|
|
47 |
|
$seq_no = 1; |
48 |
< |
$retry_wait = 600; |
48 |
> |
$retry_wait = 6; |
49 |
|
|
50 |
|
# write our PID to a file |
51 |
|
$pidfile = "/var/tmp/ihost.pid"; |
102 |
|
#----------------------------------------------------------------------- |
103 |
|
sub tcp_configure() { |
104 |
|
|
105 |
< |
while (1 == 1) { |
105 |
> |
while (1) { |
106 |
|
my($sock) = new IO::Socket::INET( |
107 |
|
PeerAddr => $filter_manager_addr, |
108 |
|
PeerPort => $filter_manager_port, |
120 |
|
|
121 |
|
print $sock "STARTCONFIG\n"; |
122 |
|
$response = <$sock>; |
123 |
< |
if (!chop $response eq "OK") { |
124 |
< |
print "The i-scream server rejected the STARTCONFIG command. Terminated."; |
123 |
> |
if ($response && !($response eq "OK\n")) { |
124 |
> |
print "The i-scream server rejected the STARTCONFIG command.\n"; |
125 |
|
close($sock); |
126 |
|
wait_then_retry(); |
127 |
|
next; |
131 |
|
|
132 |
|
print $sock "LASTMODIFIED\n"; |
133 |
|
$response = <$sock>; |
134 |
+ |
if (!$response) { |
135 |
+ |
print "The i-scream server did not return anything for the LASTMODIFIED command.\n"; |
136 |
+ |
close($sock); |
137 |
+ |
wait_then_retry(); |
138 |
+ |
next; |
139 |
+ |
} |
140 |
|
chop $response; |
141 |
|
$last_modified = $response; |
142 |
|
|
144 |
|
|
145 |
|
print $sock "FILELIST\n"; |
146 |
|
$response = <$sock>; |
147 |
+ |
if (!$response) { |
148 |
+ |
print "The i-scream server did not provide a configuration file list.\n"; |
149 |
+ |
close($sock); |
150 |
+ |
wait_then_retry(); |
151 |
+ |
next; |
152 |
+ |
} |
153 |
|
chop $response; |
154 |
|
$file_list = $response; |
155 |
|
|
157 |
|
|
158 |
|
print $sock "FQDN\n"; |
159 |
|
$response = <$sock>; |
160 |
+ |
if (!$response) { |
161 |
+ |
print "The i-scream server did not tell us our FQDN.\n"; |
162 |
+ |
close($sock); |
163 |
+ |
wait_then_retry(); |
164 |
+ |
next; |
165 |
+ |
} |
166 |
|
chop $response; |
167 |
|
$fqdn = $response; |
168 |
|
|
170 |
|
|
171 |
|
print $sock "UDPUpdateTime\n"; |
172 |
|
$response = <$sock>; |
173 |
+ |
if (!$response) { |
174 |
+ |
print "The i-scream server did not give us a UDPUpdateTime.\n"; |
175 |
+ |
close($sock); |
176 |
+ |
wait_then_retry(); |
177 |
+ |
next; |
178 |
+ |
} |
179 |
|
chop $response; |
180 |
|
$udp_update_time = $response; |
181 |
|
|
182 |
|
print $sock "TCPUpdateTime\n"; |
183 |
|
$response = <$sock>; |
184 |
+ |
if (!$response) { |
185 |
+ |
print "The i-scream server did not give us a TCPUpdateTime.\n"; |
186 |
+ |
close($sock); |
187 |
+ |
wait_then_retry(); |
188 |
+ |
next; |
189 |
+ |
} |
190 |
|
chop $response; |
191 |
|
$tcp_update_time = $response; |
192 |
|
|
194 |
|
|
195 |
|
print $sock "ENDCONFIG\n"; |
196 |
|
$response = <$sock>; |
197 |
< |
chomp $response; |
168 |
< |
if (!$response eq "OK") { |
197 |
> |
if ($response && !($response eq "OK\n")) { |
198 |
|
print "ENDCONFIG command to server failed. Terminated.\n"; |
199 |
|
close($sock); |
200 |
|
wait_then_retry(); |
205 |
|
|
206 |
|
print $sock "FILTER\n"; |
207 |
|
$response = <$sock>; |
208 |
< |
unless (defined($response)) { |
208 |
> |
if (!$response) { |
209 |
|
print "Failed: Could not get a filter address from the filter manager.\n"; |
210 |
|
close($sock); |
211 |
|
wait_then_retry(); |
212 |
|
next; |
213 |
|
} |
214 |
|
chop $response; |
215 |
< |
$response =~ /(.*);(.*);(.*)/; |
215 |
> |
$response =~ /^(.*);(.*);(.*)/; |
216 |
|
if ($response eq "ERROR") { |
217 |
|
print "There are no active configured filters for your host.\n"; |
218 |
|
close($sock); |
231 |
|
|
232 |
|
print $sock "END\n"; |
233 |
|
$response = <$sock>; |
234 |
< |
chop $response; |
206 |
< |
if ($response eq "OK") { |
234 |
> |
if ($response && ($response eq "OK\n")) { |
235 |
|
print "Host successfully configured via TCP.\n" |
236 |
|
} |
237 |
|
else { |
238 |
< |
print "The server failed the host configuration on the END command."; |
238 |
> |
print "The server failed the host configuration on the END command.\n"; |
239 |
|
close($sock); |
240 |
|
wait_then_retry(); |
241 |
|
next; |
379 |
|
|
380 |
|
print $sock "HEARTBEAT\n"; |
381 |
|
$response = <$sock>; |
382 |
< |
return if (!defined $response); |
355 |
< |
chop $response; |
356 |
< |
if (!$response eq "OK") { |
382 |
> |
if (!$response eq "OK\n") { |
383 |
|
close($sock); |
384 |
|
print "Server gave wrong response to HEARTBEAT: $response\n"; |
385 |
|
&tcp_configure(); |
388 |
|
|
389 |
|
print $sock "CONFIG\n"; |
390 |
|
$response = <$sock>; |
391 |
< |
return if (!defined $response); |
366 |
< |
chop $response; |
367 |
< |
if (!$response eq "OK") { |
391 |
> |
if (!$response eq "OK\n") { |
392 |
|
close($sock); |
393 |
|
print "Server gave wrong response to CONFIG: $response\n"; |
394 |
|
&tcp_configure(); |
397 |
|
|
398 |
|
print $sock "$file_list\n"; |
399 |
|
$response = <$sock>; |
400 |
< |
return if (!defined $response); |
377 |
< |
chop $response; |
378 |
< |
if (!$response eq "OK") { |
400 |
> |
if (!$response eq "OK\n") { |
401 |
|
close($sock); |
402 |
|
print "Server gave wrong response to file list: $response\n"; |
403 |
|
&tcp_configure(); |
406 |
|
|
407 |
|
print $sock "$last_modified\n"; |
408 |
|
$response = <$sock>; |
409 |
< |
return if (!defined $response); |
388 |
< |
chop $response; |
389 |
< |
if ($response eq "ERROR") { |
409 |
> |
if ($response eq "ERROR\n") { |
410 |
|
close($sock); |
411 |
|
print "Server configuration changed. Reconfiguring with filter manager.\n"; |
412 |
|
&tcp_configure(); |
413 |
|
return; |
414 |
|
} |
415 |
< |
if (!$response eq "OK") { |
415 |
> |
if (!$response eq "OK\n") { |
416 |
|
close($sock); |
417 |
|
print "Server gave wrong response to HEARTBEAT: $response\n"; |
418 |
|
&tcp_configure(); |
421 |
|
|
422 |
|
print $sock "ENDHEARTBEAT\n"; |
423 |
|
$response = <$sock>; |
424 |
< |
return if (!defined $response); |
405 |
< |
chop $response; |
406 |
< |
if (!$response eq "OK") { |
424 |
> |
if (!$response eq "OK\n") { |
425 |
|
close($sock); |
426 |
|
print "Server gave wrong response to ENDHEARTBEAT: $response\n"; |
427 |
|
&tcp_configure(); |