From 4d3a7e4d6506d44fd014a9749e0f6e90f80f27a4 Mon Sep 17 00:00:00 2001 From: Agent Date: Thu, 11 Jun 2026 20:26:37 -0400 Subject: [PATCH 1/2] fix: use correct server URL instead of localhost AgentService now replaces 'localhost' in the server URL with sysadmin.lan before sending to the remote agent. Also added URL/hostname debug output to the agent startup log. --- install/agent-install.sh | 10 +++++++++- src/Services/AgentService.php | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/install/agent-install.sh b/install/agent-install.sh index 2c8c023..5a59c55 100644 --- a/install/agent-install.sh +++ b/install/agent-install.sh @@ -82,12 +82,20 @@ EOF echo "$code" } -echo "ServerManager Agent started (interval: ${INTERVAL}s)" +echo "ServerManager Agent started" +echo " Server: $SERVER_URL/api/metrics/push" +echo " Interval: ${INTERVAL}s" +echo " Host: $(hostname)" sleep 2 while true; do collect_metrics http_code=$(push_metrics) echo "[$(date)] HTTP $http_code" + if [ "$http_code" = "200" ]; then + true + elif [ "$http_code" = "0" ]; then + echo " curl failed — check SERVER_URL=$SERVER_URL" + fi sleep "$INTERVAL" done AGENTSCRIPT diff --git a/src/Services/AgentService.php b/src/Services/AgentService.php index ea44e9c..933efb0 100644 --- a/src/Services/AgentService.php +++ b/src/Services/AgentService.php @@ -37,10 +37,13 @@ class AgentService $agentKey = $server['agent_key']; $serverUrl = rtrim((App::getConfig()['app']['url'] ?? ''), '/'); - if (empty($serverUrl)) { - $serverUrl = ($_SERVER['HTTPS'] ?? '' === 'on' ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? 'localhost'); + if (empty($serverUrl) || str_contains($serverUrl, 'localhost')) { + $serverUrl = ($_SERVER['HTTPS'] ?? '' === 'on' ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? 'sysadmin.lan'); } + // Replace localhost with actual hostname if still localhost + $serverUrl = preg_replace('/https?:\/\/localhost(:\d+)?/', 'http://sysadmin.lan$1', $serverUrl); + $scriptPath = $this->basePath . '/install/agent-install.sh'; if (!file_exists($scriptPath)) { -- 2.43.0 From 26e35c6bc7a84618cca46b6ad113be1d0f91132e Mon Sep 17 00:00:00 2001 From: Agent Date: Thu, 11 Jun 2026 20:28:35 -0400 Subject: [PATCH 2/2] fix: use ['HTTP_HOST'] dynamically for agent URL --- src/Services/AgentService.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Services/AgentService.php b/src/Services/AgentService.php index 933efb0..ea05604 100644 --- a/src/Services/AgentService.php +++ b/src/Services/AgentService.php @@ -37,13 +37,12 @@ class AgentService $agentKey = $server['agent_key']; $serverUrl = rtrim((App::getConfig()['app']['url'] ?? ''), '/'); - if (empty($serverUrl) || str_contains($serverUrl, 'localhost')) { - $serverUrl = ($_SERVER['HTTPS'] ?? '' === 'on' ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? 'sysadmin.lan'); + if (empty($serverUrl)) { + $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://'; + $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; + $serverUrl = $scheme . $host; } - // Replace localhost with actual hostname if still localhost - $serverUrl = preg_replace('/https?:\/\/localhost(:\d+)?/', 'http://sysadmin.lan$1', $serverUrl); - $scriptPath = $this->basePath . '/install/agent-install.sh'; if (!file_exists($scriptPath)) { -- 2.43.0