From 892aab656e5b28893d6775de5136c85564860f87 Mon Sep 17 00:00:00 2001 From: Sergio Casizzone Date: Thu, 25 Mar 2021 18:36:50 +0100 Subject: [PATCH] docker environment variable --- Dockerfile | 6 +++--- components/Seclib.php | 9 ++++++++- docker-compose.yml | 2 +- web/phpinfo.php | 3 +++ 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 web/phpinfo.php diff --git a/Dockerfile b/Dockerfile index 625c7d5..b042aa8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,6 @@ RUN apt-get install openssh-server sudo -y RUN service ssh start #RUN apt-get install -y net-tools -EXPOSE 22 - - COPY assets /var/www/assets COPY commands /var/www/commands COPY components /var/www/components @@ -34,3 +31,6 @@ RUN chmod +x /var/www/yii RUN mv /var/www/config/db-docker.php /var/www/config/db.php RUN chown -R www-data:www-data /var/www + +EXPOSE 22 +ENV DOCKERCONTAINER=true diff --git a/components/Seclib.php b/components/Seclib.php index b8c1526..619ae5b 100644 --- a/components/Seclib.php +++ b/components/Seclib.php @@ -25,7 +25,14 @@ public function execInBackground($cmd) if (substr(php_uname(), 0, 7) == "Windows"){ pclose(popen("start /B ". $cmd, "r")); } else { - $ssh = new \phpseclib\Net\SSH2('172.18.0.1', 22); + // determine whether we are running in a docker container + if (isset($_ENV['DOCKERCONTAINER']) && $_ENV['DOCKERCONTAINER'] == true){ + $host_address = $_SERVER['REMOTE_ADDR']; + } else { + $host_address = 'localhost'; + } + + $ssh = new \phpseclib\Net\SSH2($host_address, 22); if (!$ssh->login(WebApp::decrypt(Settings::load()->sshuser), WebApp::decrypt(Settings::load()->sshpassword))) { return array('error' => 'Login to localhost server failed'); } diff --git a/docker-compose.yml b/docker-compose.yml index 4a49ec3..8c0607c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: '3' services: - yii2-php: + yii2: #image: yiisoftware/yii2-php:7.2-apache build: . volumes: diff --git a/web/phpinfo.php b/web/phpinfo.php new file mode 100644 index 0000000..d1e12c5 --- /dev/null +++ b/web/phpinfo.php @@ -0,0 +1,3 @@ +