fix(ucp): v2.6.2 regle stricte host/port GroundWire (NAT > VIP HA > IP locale + port local)

This commit is contained in:
sorcier committed 2026-11-12 02:35:46 +01:00
1 parent 789ea79cf2
commit 745e9307d7
2 files changed
+51 -23

No files matched your search

+49 -22
View File
@@ -888,29 +888,57 @@ class UcpManager
}
} catch (\Throwable) {}
$sipHost = trim((string)($settings['external_ip'] ?? ''));
if ($sipHost === '') {
$sipHost = trim((string)($settings['letsencrypt_domain'] ?? ''));
}
if ($sipHost === '' && $haVip !== '') {
$sipHost = $haVip;
}
if ($sipHost === '') {
$rawHttpHost = trim(explode(',', (string)($_SERVER['HTTP_X_FORWARDED_HOST'] ?? $_SERVER['HTTP_HOST'] ?? ''))[0] ?? '');
if ($rawHttpHost !== '') {
$parsedHost = parse_url("http://{$rawHttpHost}", PHP_URL_HOST);
$sipHost = is_string($parsedHost) && $parsedHost !== '' ? $parsedHost : $rawHttpHost;
}
}
if ($sipHost === '') {
$sipHost = trim((string)($settings['domain'] ?? '')) ?: '127.0.0.1';
}
$isTls = (($extRow['transport'] ?? 'udp') === 'tls');
$transport = $isTls ? 'tls' : 'udp';
$sipPort = $isTls
? (((int)($settings['external_tls_port'] ?? 0) > 0) ? (int)$settings['external_tls_port'] : ((int)($settings['tls_port'] ?? 5061) ?: 5061))
: (((int)($settings['external_udp_port'] ?? 0) > 0) ? (int)$settings['external_udp_port'] : ((int)($settings['udp_port'] ?? 5060) ?: 5060));
$localPort = $isTls ? ((int)($settings['tls_port'] ?? 5061) ?: 5061) : ((int)($settings['udp_port'] ?? 5060) ?: 5060);
$natHost = trim((string)($settings['external_ip'] ?? ''));
$natHost = preg_replace('#^(?:https?|sips?)://#i', '', $natHost);
$natHost = trim((string)$natHost, "/ \t\n\r\0\x0B");
if ($natHost !== '') {
// Mode NAT renseigné : adresse NAT + port externe NAT (ou port interne par défaut)
$sipHost = $natHost;
$sipPort = $isTls
? (((int)($settings['external_tls_port'] ?? 0) > 0) ? (int)$settings['external_tls_port'] : $localPort)
: (((int)($settings['external_udp_port'] ?? 0) > 0) ? (int)$settings['external_udp_port'] : $localPort);
$hostPort = str_contains($sipHost, ':') ? $sipHost : "{$sipHost}:{$sipPort}";
} else {
// Mode local : VIP HA si cluster actif, sinon IP locale du PBX + port d'écoute local
$sipHost = '';
if ($haVip !== '') {
$sipHost = $haVip;
}
if ($sipHost === '') {
$rawHttpHost = trim(explode(',', (string)($_SERVER['HTTP_X_FORWARDED_HOST'] ?? $_SERVER['HTTP_HOST'] ?? ''))[0] ?? '');
if ($rawHttpHost !== '') {
$parsedHost = parse_url("http://{$rawHttpHost}", PHP_URL_HOST);
if (is_string($parsedHost) && $parsedHost !== '' && !in_array($parsedHost, ['127.0.0.1', '::1', 'localhost'], true)) {
$sipHost = $parsedHost;
}
}
}
if ($sipHost === '') {
$serverAddr = trim((string)($_SERVER['SERVER_ADDR'] ?? ''));
if ($serverAddr !== '' && !in_array($serverAddr, ['127.0.0.1', '::1'], true)) {
$sipHost = $serverAddr;
}
}
if ($sipHost === '') {
$ips = preg_split('/\s+/', trim((string)@shell_exec('hostname -I 2>/dev/null'))) ?: [];
foreach ($ips as $ip) {
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && !str_starts_with($ip, '127.')) {
$sipHost = $ip;
break;
}
}
}
if ($sipHost === '') {
$sipHost = trim((string)($settings['domain'] ?? '')) ?: '127.0.0.1';
}
$hostPort = "{$sipHost}:{$localPort}";
}
$encMode = (int)($extRow['encryption'] ?? 0);
$sdes = ($isTls || $encMode > 0) ? 'enabled' : 'disabled';
@@ -928,7 +956,6 @@ class UcpManager
$extNum = (string)$extRow['extension'];
$lineName = trim((string)($extRow['name'] ?? '')) ?: $extNum;
$password = (string)($extRow['secret'] ?? '');
$hostPort = "{$sipHost}:{$sipPort}";
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
. "<account>\n"