fixed server query

This commit is contained in:
Frank Harris 2026-06-07 09:06:49 -05:00
parent e6541370b9
commit a1e5331f4a
7 changed files with 221 additions and 13 deletions

View file

@ -124,12 +124,11 @@ function gsp_agent_port_listening($remote, $server_port)
if ($server_port <= 0 || !method_exists($remote, 'exec')) {
return null;
}
$port_arg = escapeshellarg((string)$server_port);
$command = 'p='.$port_arg.'; '
. 'if command -v ss >/dev/null 2>&1; then ss -lntu 2>/dev/null; else netstat -an 2>/dev/null; fi '
$port_pattern = '[:.]' . $server_port . '([[:space:]]|$)';
$command = 'if command -v ss >/dev/null 2>&1; then ss -lntu 2>/dev/null; else netstat -an 2>/dev/null; fi '
. '| tr -d "\r" '
. '| grep -Eai "(LISTEN|LISTENING|UDP|tcp|udp)" '
. '| grep -E "[:.]$p([[:space:]]|$)" >/dev/null '
. '| grep -E ' . escapeshellarg($port_pattern) . ' >/dev/null '
. '&& echo GSP_PORT_LISTENING || echo GSP_PORT_CLOSED';
$output = $remote->exec($command);
if (strpos((string)$output, 'GSP_PORT_LISTENING') !== false) {