mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-05-21 02:40:09 +00:00
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>
This commit is contained in:
committed by
GitHub
parent
ec5d23fd58
commit
5f99a59739
@@ -5,6 +5,7 @@ namespace AIO\Data;
|
|||||||
|
|
||||||
use AIO\Auth\PasswordGenerator;
|
use AIO\Auth\PasswordGenerator;
|
||||||
use AIO\Controller\DockerController;
|
use AIO\Controller\DockerController;
|
||||||
|
use AIO\Helper\NetworkHelper;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\TransferException;
|
use GuzzleHttp\Exception\TransferException;
|
||||||
|
|
||||||
@@ -1111,9 +1112,9 @@ class ConfigurationManager
|
|||||||
'INSTALL_LATEST_MAJOR' => $this->installLatestMajor ? 'yes' : '',
|
'INSTALL_LATEST_MAJOR' => $this->installLatestMajor ? 'yes' : '',
|
||||||
'REMOVE_DISABLED_APPS' => $this->nextcloudKeepDisabledApps ? '' : '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)
|
// 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
|
// 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' : '',
|
'WHITEBOARD_ENABLED' => $this->isWhiteboardEnabled ? 'yes' : '',
|
||||||
'AIO_VERSION' => $this->getAioVersion(),
|
'AIO_VERSION' => $this->getAioVersion(),
|
||||||
default => $this->getRegisteredSecret($placeholder),
|
default => $this->getRegisteredSecret($placeholder),
|
||||||
|
|||||||
@@ -72,20 +72,4 @@ class DataConst {
|
|||||||
return (string)realpath(__DIR__ . '/../../templates/includes/aio-version.twig');
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use AIO\Container\VersionState;
|
|||||||
use AIO\ContainerDefinitionFetcher;
|
use AIO\ContainerDefinitionFetcher;
|
||||||
use AIO\Data\ConfigurationManager;
|
use AIO\Data\ConfigurationManager;
|
||||||
use AIO\Data\DataConst;
|
use AIO\Data\DataConst;
|
||||||
|
use AIO\Helper\NetworkHelper;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
use http\Env\Response;
|
use http\Env\Response;
|
||||||
@@ -449,7 +450,7 @@ readonly class DockerActionManager {
|
|||||||
|
|
||||||
// Special things for the jellyfin community container
|
// Special things for the jellyfin community container
|
||||||
} elseif ($container->identifier === 'nextcloud-aio-jellyfin') {
|
} elseif ($container->identifier === 'nextcloud-aio-jellyfin') {
|
||||||
$lldapIp = DataConst::resolveHostname('nextcloud-aio-lldap');
|
$lldapIp = NetworkHelper::resolveHostname('nextcloud-aio-lldap');
|
||||||
if ($lldapIp !== 'nextcloud-aio-lldap') {
|
if ($lldapIp !== 'nextcloud-aio-lldap') {
|
||||||
$requestBody['HostConfig']['ExtraHosts'] = ['nextcloud-aio-lldap:' . $lldapIp];
|
$requestBody['HostConfig']['ExtraHosts'] = ['nextcloud-aio-lldap:' . $lldapIp];
|
||||||
}
|
}
|
||||||
|
|||||||
23
php/src/Helper/NetworkHelper.php
Normal file
23
php/src/Helper/NetworkHelper.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace AIO\Helper;
|
||||||
|
|
||||||
|
class NetworkHelper {
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user