From 5f99a597399667751f043a1bdb0f64f4417cf30b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 May 2026 22:29:14 +0000 Subject: [PATCH] refactor: move resolveHostname from DataConst into new NetworkHelper class Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/73cb1d89-ab85-43b6-adfe-a90c00ad60a1 Co-authored-by: szaimen <42591237+szaimen@users.noreply.github.com> --- php/src/Data/ConfigurationManager.php | 5 +++-- php/src/Data/DataConst.php | 16 ---------------- php/src/Docker/DockerActionManager.php | 3 ++- php/src/Helper/NetworkHelper.php | 23 +++++++++++++++++++++++ 4 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 php/src/Helper/NetworkHelper.php diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index a62fc621..5b290c73 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -5,6 +5,7 @@ namespace AIO\Data; use AIO\Auth\PasswordGenerator; use AIO\Controller\DockerController; +use AIO\Helper\NetworkHelper; use GuzzleHttp\Client; use GuzzleHttp\Exception\TransferException; @@ -1111,9 +1112,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' => DataConst::resolveHostname('nextcloud-aio-database'), + 'AIO_DATABASE_HOST' => NetworkHelper::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) ? DataConst::resolveHostname('nextcloud-aio-caddy') : '', + 'CADDY_IP_ADDRESS' => in_array('caddy', $this->aioCommunityContainers, true) ? NetworkHelper::resolveHostname('nextcloud-aio-caddy') : '', 'WHITEBOARD_ENABLED' => $this->isWhiteboardEnabled ? 'yes' : '', 'AIO_VERSION' => $this->getAioVersion(), default => $this->getRegisteredSecret($placeholder), diff --git a/php/src/Data/DataConst.php b/php/src/Data/DataConst.php index 0d4ff9c2..dfd47241 100644 --- a/php/src/Data/DataConst.php +++ b/php/src/Data/DataConst.php @@ -72,20 +72,4 @@ class DataConst { 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; - } } diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index a98685b7..f963d066 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -9,6 +9,7 @@ use AIO\Container\VersionState; use AIO\ContainerDefinitionFetcher; use AIO\Data\ConfigurationManager; use AIO\Data\DataConst; +use AIO\Helper\NetworkHelper; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use http\Env\Response; @@ -449,7 +450,7 @@ readonly class DockerActionManager { // Special things for the jellyfin community container } elseif ($container->identifier === 'nextcloud-aio-jellyfin') { - $lldapIp = DataConst::resolveHostname('nextcloud-aio-lldap'); + $lldapIp = NetworkHelper::resolveHostname('nextcloud-aio-lldap'); if ($lldapIp !== 'nextcloud-aio-lldap') { $requestBody['HostConfig']['ExtraHosts'] = ['nextcloud-aio-lldap:' . $lldapIp]; } diff --git a/php/src/Helper/NetworkHelper.php b/php/src/Helper/NetworkHelper.php new file mode 100644 index 00000000..8728f967 --- /dev/null +++ b/php/src/Helper/NetworkHelper.php @@ -0,0 +1,23 @@ +