diff --git a/.dockerignore b/.dockerignore index 601a8b4..41ef110 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,3 @@ .* -!.env.example +!.env.docker.example sessions/ \ No newline at end of file diff --git a/.env.docker.example b/.env.docker.example new file mode 100644 index 0000000..c232b42 --- /dev/null +++ b/.env.docker.example @@ -0,0 +1,20 @@ +SERVER_ADDRESS=0.0.0.0 +SERVER_PORT=9503 + +MEMORY_LIMIT=256M + +# List of allowed clients. Separate with comma. +# Leave blanc, to allow requests from all IP (dangerous!) +IP_WHITELIST=127.0.0.1 + +# TELEGRAM CLIENT +TELEGRAM_API_ID= +TELEGRAM_API_HASH= +# FATAL_ERROR = 0; ERROR = 1; WARNING = 2; const NOTICE = 3; VERBOSE = 4; ULTRA_VERBOSE = 5; +LOGGER_LEVEL=2 + +# TELEGRAM SOCKS5 PROXY (optional) +TELEGRAM_PROXY_ADDRESS= +TELEGRAM_PROXY_PORT= +TELEGRAM_PROXY_USERNAME= +TELEGRAM_PROXY_PASSWORD= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 452d34e..7d14e32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /app RUN apt-get update && apt-get upgrade -y \ && apt-get install apt-utils -y \ - && apt-get install git zip vim nano wget libzip-dev libgmp-dev libevent-dev libssl-dev libnghttp2-dev libffi-dev -y \ + && apt-get install git zip vim libzip-dev libgmp-dev libevent-dev libssl-dev libnghttp2-dev libffi-dev -y \ && docker-php-ext-install sockets zip gmp pcntl bcmath ffi \ && PHP_OPENSSL=yes pecl install apcu ev event \ && docker-php-ext-enable apcu ev event \ @@ -18,6 +18,10 @@ RUN apt-get update && apt-get upgrade -y \ VOLUME ["/app/sessions"] +#Creating symlink to save .env in volume +RUN touch '/app/sessions/.env.docker' && \ + ln -s '/app/sessions/.env.docker' '/app/.env.docker' + EXPOSE 9503 ENTRYPOINT php server.php --docker -s=* \ No newline at end of file diff --git a/bootstrap.php b/bootstrap.php index fb0a0df..83c71ba 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -22,20 +22,21 @@ $root = __DIR__; //Config init { if (!getenv('SERVER_ADDRESS')) { + $envFile = '.env'; if ($options['docker']) { - $envSource = file_exists(ROOT_DIR . '/.env') ? ROOT_DIR . '/.env' : ROOT_DIR . '/.env.example'; - $envContent = file_get_contents($envSource); - $envContent = str_replace( - ['SERVER_ADDRESS=127.0.0.1', 'IP_WHITELIST=127.0.0.1'], - ['SERVER_ADDRESS=0.0.0.0', 'IP_WHITELIST='], - $envContent - ); - file_put_contents(ROOT_DIR . '/.env', $envContent); - } elseif (!file_exists(ROOT_DIR . '/.env')) { - copy( ROOT_DIR . '/.env.example', ROOT_DIR . '/.env'); + $envFile .= '.docker'; } - Dotenv\Dotenv::createImmutable(ROOT_DIR)->load(); + $envPath = ROOT_DIR . '/' . $envFile; + $envPathExample = $envPath . '.example'; + + if (!is_file($envPath) || filesize($envPath) === 0) { + //Dont use copy because of docker symlinks + $envContent = file_get_contents($envPathExample); + file_put_contents($envPath, $envContent); + } + + Dotenv\Dotenv::createImmutable(ROOT_DIR, $envFile)->load(); } } diff --git a/composer.lock b/composer.lock index 5f11d68..5d25f20 100644 --- a/composer.lock +++ b/composer.lock @@ -2506,16 +2506,16 @@ }, { "name": "phpoption/phpoption", - "version": "1.7.3", + "version": "1.7.4", "source": { "type": "git", "url": "https://github.com/schmittjoh/php-option.git", - "reference": "4acfd6a4b33a509d8c88f50e5222f734b6aeebae" + "reference": "b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/4acfd6a4b33a509d8c88f50e5222f734b6aeebae", - "reference": "4acfd6a4b33a509d8c88f50e5222f734b6aeebae", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3", + "reference": "b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3", "shasum": "" }, "require": { @@ -2557,7 +2557,17 @@ "php", "type" ], - "time": "2020-03-21T18:07:53+00:00" + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption", + "type": "tidelift" + } + ], + "time": "2020-06-07T10:40:07+00:00" }, { "name": "psr/http-message", @@ -2775,16 +2785,16 @@ }, { "name": "vlucas/phpdotenv", - "version": "v4.1.5", + "version": "v4.1.6", "source": { "type": "git", "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "539bb6927c101a5605d31d11a2d17185a2ce2bf1" + "reference": "0b32505d67c1abbfa829283c86bfc0642a661bf6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/539bb6927c101a5605d31d11a2d17185a2ce2bf1", - "reference": "539bb6927c101a5605d31d11a2d17185a2ce2bf1", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/0b32505d67c1abbfa829283c86bfc0642a661bf6", + "reference": "0b32505d67c1abbfa829283c86bfc0642a661bf6", "shasum": "" }, "require": { @@ -2845,7 +2855,7 @@ "type": "tidelift" } ], - "time": "2020-05-02T14:08:57+00:00" + "time": "2020-05-23T09:43:32+00:00" } ], "packages-dev": [ @@ -2855,12 +2865,12 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "e38de1df609b39d97144514d28b0804ad4daaddb" + "reference": "de6fda3af9b36c77fdeb62b968157032f7111b09" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/e38de1df609b39d97144514d28b0804ad4daaddb", - "reference": "e38de1df609b39d97144514d28b0804ad4daaddb", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/de6fda3af9b36c77fdeb62b968157032f7111b09", + "reference": "de6fda3af9b36c77fdeb62b968157032f7111b09", "shasum": "" }, "conflict": { @@ -2914,8 +2924,9 @@ "ezsystems/ezplatform": ">=1.7,<1.7.9.1|>=1.13,<1.13.5.1|>=2.5,<2.5.4", "ezsystems/ezplatform-admin-ui": ">=1.3,<1.3.5|>=1.4,<1.4.6", "ezsystems/ezplatform-admin-ui-assets": ">=4,<4.2", + "ezsystems/ezplatform-kernel": ">=1,<1.0.2.1", "ezsystems/ezplatform-user": ">=1,<1.0.1", - "ezsystems/ezpublish-kernel": ">=5.3,<5.3.12.1|>=5.4,<5.4.14.1|>=6,<6.7.9.1|>=6.8,<6.13.6.2|>=7,<7.2.4.1|>=7.3,<7.3.2.1|>=7.5,<7.5.6.2", + "ezsystems/ezpublish-kernel": ">=5.3,<5.3.12.1|>=5.4,<5.4.14.2|>=6,<6.7.9.1|>=6.8,<6.13.6.3|>=7,<7.2.4.1|>=7.3,<7.3.2.1|>=7.5,<7.5.7.1", "ezsystems/ezpublish-legacy": ">=5.3,<5.3.12.6|>=5.4,<5.4.14.1|>=2011,<2017.12.7.2|>=2018.6,<2018.6.1.4|>=2018.9,<2018.9.1.3|>=2019.3,<2019.3.4.2", "ezsystems/repository-forms": ">=2.3,<2.3.2.1", "ezyang/htmlpurifier": "<4.1.1", @@ -2953,6 +2964,7 @@ "monolog/monolog": ">=1.8,<1.12", "namshi/jose": "<2.2", "nzo/url-encryptor-bundle": ">=4,<4.3.2|>=5,<5.0.1", + "october/october": ">=1.0.319,<1.0.466", "onelogin/php-saml": "<2.10.4", "oneup/uploader-bundle": "<1.9.3|>=2,<2.1.5", "openid/php-openid": "<2.3", @@ -2964,7 +2976,7 @@ "paypal/merchant-sdk-php": "<3.12", "pear/archive_tar": "<1.4.4", "phpfastcache/phpfastcache": ">=5,<5.0.13", - "phpmailer/phpmailer": ">=5,<5.2.27|>=6,<6.0.6", + "phpmailer/phpmailer": "<6.1.6", "phpmyadmin/phpmyadmin": "<4.9.2", "phpoffice/phpexcel": "<1.8.2", "phpoffice/phpspreadsheet": "<1.8", @@ -2979,6 +2991,7 @@ "propel/propel": ">=2-alpha.1,<=2-alpha.7", "propel/propel1": ">=1,<=1.7.1", "pusher/pusher-php-server": "<2.2.1", + "rainlab/debugbar-plugin": "<3.1", "robrichards/xmlseclibs": "<3.0.4", "sabre/dav": ">=1.6,<1.6.99|>=1.7,<1.7.11|>=1.8,<1.8.9", "scheb/two-factor-bundle": ">=0,<3.26|>=4,<4.11", @@ -3127,7 +3140,7 @@ "type": "tidelift" } ], - "time": "2020-05-22T06:49:22+00:00" + "time": "2020-06-04T00:00:55+00:00" } ], "aliases": [], diff --git a/src/Server/Authorization.php b/src/Server/Authorization.php index 7a1b7de..f409f28 100644 --- a/src/Server/Authorization.php +++ b/src/Server/Authorization.php @@ -17,6 +17,10 @@ class Authorization implements Middleware public function __construct() { $this->ipWhitelist = (array) Config::getInstance()->get('api.ip_whitelist', []); + //Add self ip for docker. + if (\count($this->ipWhitelist) > 0) { + $this->ipWhitelist[] = getHostByName(php_uname('n')); + } } public function handleRequest(Request $request, RequestHandler $next): Promise {