Skip to content

Commit

Permalink
Fixing #5796 - New Ping Method
Browse files Browse the repository at this point in the history
Due to Conflicting Interpretations of TCP Ping, Introduce new Ping Method
  • Loading branch information
TheWitness committed Aug 8, 2024
1 parent b4bf96f commit 5faade8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Cacti CHANGELOG
-issue#5790: Cactid - Cron out of sync with poller Message
-issue#5791: Unable to filter users by user group, or the last time they logged into Cacti
-feature#5784: Provide a means by which a user can track Cacti connections and disconnects from the php error_log
-feature#5796: Due to Conflicting Interpretations of TCP Ping, Introduce new Ping Method

1.2.27
-security#GHSA-37x7-mfjv-mm7m: Authentication Bypass when using using older password hashes
Expand Down
7 changes: 4 additions & 3 deletions include/global_arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,10 @@
);

$ping_methods = array(
PING_ICMP => __('ICMP Ping'),
PING_TCP => __('TCP Ping'),
PING_UDP => __('UDP Ping')
PING_ICMP => __('ICMP Ping'),
PING_TCP => __('TCP Ping'),
PING_TCP_CLOSED => __('TCP Ping Closed'),
PING_UDP => __('UDP Ping')
);

$logfile_verbosity = array(
Expand Down
1 change: 1 addition & 0 deletions include/global_constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
define('PING_ICMP', 1);
define('PING_UDP', 2);
define('PING_TCP', 3);
define('PING_TCP_CLOSED', 5);
define('PING_SNMP', 4);

define('HOST_UNKNOWN', 0);
Expand Down
22 changes: 17 additions & 5 deletions lib/ping.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,26 @@ function ping_tcp() {
$errno = socket_last_error($this->socket);

if ($errno > 0) {
$this->ping_response = __('TCP ping: socket_connect(), reason: %s', socket_strerror($errno));
$this->ping_status = 'down';
if ($errno == 111 && $this->ping_type == PING_TCP_CLOSED) {
$this->time = $this->get_time($this->precision);
$this->ping_status = 'up';
$this->ping_response = __('TCP Ping Success Connection Refused (%s ms)', $this->time*1000);
$this->ping_status = $this->time*1000;
} else {
$this->ping_response = __('TCP Ping Failed: socket_connect(), reason: %s', socket_strerror($errno));
$this->ping_status = 'down';
}

socket_clear_error($this->socket);

$this->close_socket();
$this->restore_cacti_error_handler();

return false;
if ($this->ping_status == 'down') {
return false;
} else {
return true;
}
}

$r = array($this->socket);
Expand All @@ -567,7 +578,7 @@ function ping_tcp() {
$num_changed_sockets = socket_select($r, $w, $f, $to_sec, $to_usec);

if ($num_changed_sockets === false) {
$this->ping_response = __('TCP ping: socket_select() failed, reason: %s', socket_strerror(socket_last_error()));
$this->ping_response = __('TCP Ping Failed: socket_select() failed, reason: %s', socket_strerror(socket_last_error()));
$this->ping_status = 'down';

$this->close_socket();
Expand Down Expand Up @@ -620,6 +631,7 @@ function ping($avail_method = AVAIL_SNMP_AND_PING, $ping_type = PING_ICMP, $time

$this->ping_status = 'down';
$this->ping_response = __('Ping not performed due to setting.');
$this->ping_type = $ping_type;
$this->snmp_status = 'down';
$this->snmp_response = 'SNMP not performed due to setting or ping result.';
$this->avail_method = $avail_method;
Expand Down Expand Up @@ -664,7 +676,7 @@ function ping($avail_method = AVAIL_SNMP_AND_PING, $ping_type = PING_ICMP, $time
$ping_result = $this->ping_icmp();
} elseif ($ping_type == PING_UDP) {
$ping_result = $this->ping_udp();
} elseif ($ping_type == PING_TCP) {
} elseif ($ping_type == PING_TCP || $ping_type == PING_TCP_CLOSED) {
$ping_result = $this->ping_tcp();
}
}
Expand Down

0 comments on commit 5faade8

Please sign in to comment.