mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
fix(domains): resolve server hostname to IP for sslip.io domains
Closes #12009
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'],
|
||||
]);
|
||||
Reference in New Issue
Block a user