From 482b279f3c1ba352eaa2cf05382f5cdcf38c51b3 Mon Sep 17 00:00:00 2001 From: szaimen Date: Fri, 8 Jul 2022 17:11:49 +0200 Subject: [PATCH] allow to specify an apache ip-binding Signed-off-by: szaimen --- Containers/mastercontainer/start.sh | 7 +++++++ php/src/Data/ConfigurationManager.php | 7 +++++++ php/src/Docker/DockerActionManager.php | 21 +++++++++++++++------ tests/QA/060-environmental-variables.md | 1 + 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Containers/mastercontainer/start.sh b/Containers/mastercontainer/start.sh index ba725e55..19cc02b7 100755 --- a/Containers/mastercontainer/start.sh +++ b/Containers/mastercontainer/start.sh @@ -114,6 +114,13 @@ It is set to '$APACHE_PORT'." exit 1 fi fi +if [ -n "$APACHE_IP_BINDING" ]; then + if ! echo "$APACHE_IP_BINDING" | grep -q '^[0-9.]\+$'; then + echo "You provided an ip-address for the apache container's ip-binding but it was not a valid ip-address. +It is set to '$APACHE_IP_BINDING'." + exit 1 + fi +fi if [ -n "$TALK_PORT" ]; then if ! check_if_number "$TALK_PORT"; then echo "You provided an Talk port but did not only use numbers. diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index 3598bd36..d740a6c8 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -599,4 +599,11 @@ class ConfigurationManager $config['collabora_dictionaries'] = ''; $this->WriteConfig($config); } + + public function GetApacheIPBinding() : string { + $envVariableName = 'APACHE_IP_BINDING'; + $configName = 'apache_ip_binding'; + $defaultValue = ''; + return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue); + } } diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index cf521a49..ffd74ef7 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -314,13 +314,22 @@ class DockerActionManager if(count($exposedPorts) > 0) { $requestBody['ExposedPorts'] = $exposedPorts; - foreach($container->GetPorts()->GetPorts() as $port) { + foreach ($container->GetPorts()->GetPorts() as $port) { $portNumber = explode("/", $port); - $requestBody['HostConfig']['PortBindings'][$port] = [ - [ - 'HostPort' => $portNumber[0], - ] - ]; + if ($this->configurationManager->GetApachePort() === $portNumber[0] && $this->configurationManager->GetApacheIPBinding() !== '') { + $requestBody['HostConfig']['PortBindings'][$port] = [ + [ + 'HostPort' => $portNumber[0], + 'HostIp' => $this->configurationManager->GetApacheIPBinding(), + ] + ]; + } else { + $requestBody['HostConfig']['PortBindings'][$port] = [ + [ + 'HostPort' => $portNumber[0], + ] + ]; + } } } diff --git a/tests/QA/060-environmental-variables.md b/tests/QA/060-environmental-variables.md index 550e7f24..69625f9a 100644 --- a/tests/QA/060-environmental-variables.md +++ b/tests/QA/060-environmental-variables.md @@ -1,6 +1,7 @@ # Environmental variables - [ ] When starting the mastercontainer with `-e APACHE_PORT=11000` on a clean instance, the domaincheck container should be started with that same port published. That makes sure that also the Apache container will use that port later on. Using a value here that is not a port will not allow the mastercontainer to start correctly. +- [ ] When starting the mastercontainer with `-e APACHE_IP_BINDING=127.0.0.1` on a clean instance, the domaincheck container's apache port should only listen on localhost on the host. Using a value here that is not a number or dot will not allow the mastercontainer to start correctly. - [ ] When starting the mastercontainer with `-e TALK_PORT=3479` on a clean instance, the talk container should use this port later on. Using a value here that is not a port will not allow the mastercontainer to start correctly. Also it should stop if apache_port and talk_port are set to the same value. - [ ] Make also sure that reverse proxies work by following https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md#reverse-proxy-documentation and following [001-initial-setup.md](./001-initial-setup.md) and [002-new-instance.md](./002-new-instance.md) - [ ] When starting the mastercontainer with `-e SKIP_DOMAIN_VALIDATION=true` on a clean instance, it should skip the domain verification. So it should accept any domain that you type in then.