mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-05-21 02:40:09 +00:00
refactor: deduplicate resolveHostname into DataConst
Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/42427bd4-05e6-4197-bdb7-db3761815113 Co-authored-by: szaimen <42591237+szaimen@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
3abbbfbc2b
commit
ec5d23fd58
@@ -1111,9 +1111,9 @@ class ConfigurationManager
|
||||
'INSTALL_LATEST_MAJOR' => $this->installLatestMajor ? 'yes' : '',
|
||||
'REMOVE_DISABLED_APPS' => $this->nextcloudKeepDisabledApps ? '' : 'yes',
|
||||
// Allow to get local ip-address of database container which allows to talk to it even in host mode (the container that requires this needs to be started first then)
|
||||
'AIO_DATABASE_HOST' => $this->resolveHostname('nextcloud-aio-database'),
|
||||
'AIO_DATABASE_HOST' => DataConst::resolveHostname('nextcloud-aio-database'),
|
||||
// Allow to get local ip-address of caddy container and add it to trusted proxies automatically
|
||||
'CADDY_IP_ADDRESS' => in_array('caddy', $this->aioCommunityContainers, true) ? $this->resolveHostname('nextcloud-aio-caddy') : '',
|
||||
'CADDY_IP_ADDRESS' => in_array('caddy', $this->aioCommunityContainers, true) ? DataConst::resolveHostname('nextcloud-aio-caddy') : '',
|
||||
'WHITEBOARD_ENABLED' => $this->isWhiteboardEnabled ? 'yes' : '',
|
||||
'AIO_VERSION' => $this->getAioVersion(),
|
||||
default => $this->getRegisteredSecret($placeholder),
|
||||
@@ -1123,21 +1123,4 @@ class ConfigurationManager
|
||||
private function booleanize(mixed $value) : bool {
|
||||
return in_array($value, [true, 'true'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a hostname to its IP address, trying IPv4 first and falling back
|
||||
* to IPv6 (AAAA record) when no A record is found. Returns the hostname
|
||||
* unchanged when neither record resolves successfully.
|
||||
*/
|
||||
private function resolveHostname(string $hostname): string {
|
||||
$ipv4 = gethostbyname($hostname);
|
||||
if ($ipv4 !== $hostname) {
|
||||
return $ipv4;
|
||||
}
|
||||
$records = dns_get_record($hostname, DNS_AAAA);
|
||||
if (is_array($records) && isset($records[0]['ipv6']) && $records[0]['ipv6'] !== '') {
|
||||
return $records[0]['ipv6'];
|
||||
}
|
||||
return $hostname;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,4 +71,21 @@ class DataConst {
|
||||
public static function GetAioVersionFile() : string {
|
||||
return (string)realpath(__DIR__ . '/../../templates/includes/aio-version.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a hostname to its IP address, trying IPv4 first and falling back
|
||||
* to IPv6 (AAAA record) when no A record is found. Returns the hostname
|
||||
* unchanged when neither record resolves successfully.
|
||||
*/
|
||||
public static function resolveHostname(string $hostname): string {
|
||||
$ipv4 = gethostbyname($hostname);
|
||||
if ($ipv4 !== $hostname) {
|
||||
return $ipv4;
|
||||
}
|
||||
$records = dns_get_record($hostname, DNS_AAAA);
|
||||
if (is_array($records) && isset($records[0]['ipv6']) && $records[0]['ipv6'] !== '') {
|
||||
return $records[0]['ipv6'];
|
||||
}
|
||||
return $hostname;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ readonly class DockerActionManager {
|
||||
|
||||
// Special things for the jellyfin community container
|
||||
} elseif ($container->identifier === 'nextcloud-aio-jellyfin') {
|
||||
$lldapIp = $this->resolveHostname('nextcloud-aio-lldap');
|
||||
$lldapIp = DataConst::resolveHostname('nextcloud-aio-lldap');
|
||||
if ($lldapIp !== 'nextcloud-aio-lldap') {
|
||||
$requestBody['HostConfig']['ExtraHosts'] = ['nextcloud-aio-lldap:' . $lldapIp];
|
||||
}
|
||||
@@ -1093,21 +1093,4 @@ readonly class DockerActionManager {
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a hostname to its IP address, trying IPv4 first and falling back
|
||||
* to IPv6 (AAAA record) when no A record is found. Returns the hostname
|
||||
* unchanged when neither record resolves successfully.
|
||||
*/
|
||||
private function resolveHostname(string $hostname): string {
|
||||
$ipv4 = gethostbyname($hostname);
|
||||
if ($ipv4 !== $hostname) {
|
||||
return $ipv4;
|
||||
}
|
||||
$records = dns_get_record($hostname, DNS_AAAA);
|
||||
if (is_array($records) && isset($records[0]['ipv6']) && $records[0]['ipv6'] !== '') {
|
||||
return $records[0]['ipv6'];
|
||||
}
|
||||
return $hostname;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user