fix(domains): resolve server hostname to IP for sslip.io domains

Closes #12009
This commit is contained in:
Andras Bacsai
2026-10-15 23:15:30 +02:00
parent bc3ff14567
commit bcf4663f0c
2 changed files with 34 additions and 1 deletions
+19 -1
View File
@@ -1497,7 +1497,25 @@ function sslip(Server $server)
}
$ip = $server->ip === 'host.docker.internal' ? base_ip() : $server->ip;
return 'http://'.sslipHostLabel($ip).'.sslip.io';
return 'http://'.sslipHostLabel(resolveHostToIp($ip)).'.sslip.io';
}
/**
* Resolve a hostname to its IPv4 (or else IPv6) address. sslip.io only answers for names that
* contain an IP address. Returns the input unchanged if it is already an IP or does not resolve.
*/
function resolveHostToIp(string $host): string
{
if (filter_var(normalizeIpAddress($host), FILTER_VALIDATE_IP) !== false) {
return $host;
}
$ipv4 = gethostbyname($host);
if (filter_var($ipv4, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) {
return $ipv4;
}
$ipv6 = data_get(@dns_get_record($host, DNS_AAAA), '0.ipv6');
return is_string($ipv6) && $ipv6 !== '' ? $ipv6 : $host;
}
function service_templates_cache_key(): string
+15
View File
@@ -0,0 +1,15 @@
<?php
use App\Models\Server;
it('builds the sslip.io domain from the IP address of the server', function (string $address, string $expected) {
$server = new Server(['ip' => $address]);
$server->id = 1;
expect(sslip($server))->toBe($expected);
})->with([
'IPv4' => ['188.245.12.182', 'http://188.245.12.182.sslip.io'],
'IPv6' => ['2a01:4f8:c016:bd23::1', 'http://2a01-4f8-c016-bd23--1.sslip.io'],
'resolvable hostname' => ['localhost', 'http://127.0.0.1.sslip.io'],
'unresolvable hostname' => ['coolify-test.invalid', 'http://coolify-test.invalid.sslip.io'],
]);