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.
This commit is contained in:
2026-06-11 20:26:37 -04:00
parent cc0a0c0644
commit 4d3a7e4d65
2 changed files with 14 additions and 3 deletions

View File

@@ -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)) {