fix: use ['HTTP_HOST'] dynamically for agent URL

This commit is contained in:
2026-06-11 20:28:35 -04:00
parent 8abeb9a2d8
commit 25caf2b596

View File

@@ -37,13 +37,12 @@ class AgentService
$agentKey = $server['agent_key']; $agentKey = $server['agent_key'];
$serverUrl = rtrim((App::getConfig()['app']['url'] ?? ''), '/'); $serverUrl = rtrim((App::getConfig()['app']['url'] ?? ''), '/');
if (empty($serverUrl) || str_contains($serverUrl, 'localhost')) { if (empty($serverUrl)) {
$serverUrl = ($_SERVER['HTTPS'] ?? '' === 'on' ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? 'sysadmin.lan'); $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'; $scriptPath = $this->basePath . '/install/agent-install.sh';
if (!file_exists($scriptPath)) { if (!file_exists($scriptPath)) {