From 0266e1a6671113ae375c2d574d566bd147fb361e Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Jun 2020 02:07:41 +0300 Subject: [PATCH 1/3] Updated env to mode --- app/app.php | 2 +- app/controllers/api/database.php | 2 +- app/controllers/api/locale.php | 2 +- app/controllers/shared/web.php | 4 ++-- app/init.php | 2 +- app/workers/certificates.php | 2 +- composer.json | 4 ++-- composer.lock | 32 ++++++++++++++++---------------- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/app.php b/app/app.php index 31dc0d4afd..c1c9414715 100644 --- a/app/app.php +++ b/app/app.php @@ -292,7 +292,7 @@ $utopia->error(function ($error /* @var $error Exception */) use ($request, $res $_SERVER = []; // Reset before reporting to error log to avoid keys being compromised - $output = ((App::ENV_TYPE_DEVELOPMENT == $env)) ? [ + $output = ((App::MODE_TYPE_DEVELOPMENT == $env)) ? [ 'message' => $error->getMessage(), 'code' => $error->getCode(), 'file' => $error->getFile(), diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 69d01e9dc7..5234518368 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -26,7 +26,7 @@ use GeoIp2\Database\Reader; include_once __DIR__ . '/../shared/api.php'; -$isDev = (App::ENV_TYPE_PRODUCTION !== $utopia->getEnv()); +$isDev = (App::MODE_TYPE_PRODUCTION !== $utopia->getMode()); $utopia->post('/v1/database/collections') ->desc('Create Collection') diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index 64978ac355..a58d861133 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -26,7 +26,7 @@ $utopia->get('/v1/locale') $countries = Locale::getText('countries'); $continents = Locale::getText('continents'); - if (App::ENV_TYPE_PRODUCTION !== $utopia->getEnv()) { + if (App::MODE_TYPE_PRODUCTION !== $utopia->getMode()) { $ip = '79.177.241.94'; } diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index 42afb283e6..513914df98 100644 --- a/app/controllers/shared/web.php +++ b/app/controllers/shared/web.php @@ -28,12 +28,12 @@ $layout ->setParam('class', 'unknown') ->setParam('icon', '/images/favicon.png') ->setParam('roles', $roles) - ->setParam('env', $utopia->getEnv()) + ->setParam('env', $utopia->getMode()) ; $utopia->init(function () use ($utopia, $response, $request, $layout) { $time = (60 * 60 * 24 * 45); // 45 days cache - $isDev = (\Utopia\App::ENV_TYPE_DEVELOPMENT == Config::getParam('env')); + $isDev = (\Utopia\App::MODE_TYPE_DEVELOPMENT == Config::getParam('env')); $response ->addHeader('Cache-Control', 'public, max-age='.$time) diff --git a/app/init.php b/app/init.php index 06f58f2ef4..aee80e9542 100644 --- a/app/init.php +++ b/app/init.php @@ -60,7 +60,7 @@ Config::load('platforms', __DIR__.'/../app/config/platforms.php'); Config::load('locales', __DIR__.'/../app/config/locales.php'); Config::load('collections', __DIR__.'/../app/config/collections.php'); -Config::setParam('env', $request->getServer('_APP_ENV', App::ENV_TYPE_PRODUCTION)); +Config::setParam('env', $request->getServer('_APP_ENV', App::MODE_TYPE_PRODUCTION)); Config::setParam('domain', $request->getServer('HTTP_HOST', '')); Config::setParam('domainVerification', false); Config::setParam('version', $request->getServer('_APP_VERSION', 'UNKNOWN')); diff --git a/app/workers/certificates.php b/app/workers/certificates.php index 6110046393..84b8b0aea7 100644 --- a/app/workers/certificates.php +++ b/app/workers/certificates.php @@ -105,7 +105,7 @@ class CertificatesV1 throw new Exception('Renew isn\'t required'); } - $staging = (Config::getParam('env') === App::ENV_TYPE_PRODUCTION) ? '' : ' --dry-run'; + $staging = (Config::getParam('env') === App::MODE_TYPE_PRODUCTION) ? '' : ' --dry-run'; $response = shell_exec("certbot certonly --webroot --noninteractive --agree-tos{$staging} --email security@appwrite.io \ -w ".APP_STORAGE_CERTIFICATES." \ diff --git a/composer.json b/composer.json index a692b56baa..04fe7ccd59 100644 --- a/composer.json +++ b/composer.json @@ -32,11 +32,11 @@ "appwrite/php-clamav": "1.0.*", - "utopia-php/framework": "0.2.*", + "utopia-php/framework": "0.3.1", "utopia-php/abuse": "0.2.*", "utopia-php/audit": "0.3.*", "utopia-php/cache": "0.2.*", - "utopia-php/cli": "0.5.*", + "utopia-php/cli": "0.6.1", "utopia-php/config": "0.2.*", "utopia-php/locale": "0.2.*", "utopia-php/registry": "0.2.*", diff --git a/composer.lock b/composer.lock index ef3e3d104d..7fa0f139ed 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e93c84ab77f0085004222c942dcba6f4", + "content-hash": "79b5c353af354f8df106d2f933750102", "packages": [ { "name": "appwrite/php-clamav", @@ -1452,21 +1452,21 @@ }, { "name": "utopia-php/cli", - "version": "0.5.0", + "version": "0.6.1", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "c66255fed87f00c5a8f7cc0c482cdb082260cd32" + "reference": "0e88da425122f81020e90d575cbe80232f364b68" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/c66255fed87f00c5a8f7cc0c482cdb082260cd32", - "reference": "c66255fed87f00c5a8f7cc0c482cdb082260cd32", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/0e88da425122f81020e90d575cbe80232f364b68", + "reference": "0e88da425122f81020e90d575cbe80232f364b68", "shasum": "" }, "require": { "php": ">=7.1", - "utopia-php/framework": "0.2.*" + "utopia-php/framework": "0.*.*" }, "require-dev": { "phpunit/phpunit": "^7.0" @@ -1496,7 +1496,7 @@ "upf", "utopia" ], - "time": "2020-05-05T09:02:10+00:00" + "time": "2020-06-18T23:00:19+00:00" }, { "name": "utopia-php/config", @@ -1596,16 +1596,16 @@ }, { "name": "utopia-php/framework", - "version": "0.2.0", + "version": "0.3.1", "source": { "type": "git", "url": "https://github.com/utopia-php/framework.git", - "reference": "e3d88b794badbd5ededcf62d708b31009111f860" + "reference": "b480f9dd01ad7990a12e90e5e4d11ded558dd8fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/e3d88b794badbd5ededcf62d708b31009111f860", - "reference": "e3d88b794badbd5ededcf62d708b31009111f860", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/b480f9dd01ad7990a12e90e5e4d11ded558dd8fc", + "reference": "b480f9dd01ad7990a12e90e5e4d11ded558dd8fc", "shasum": "" }, "require": { @@ -1636,7 +1636,7 @@ "php", "upf" ], - "time": "2020-03-08T15:42:21+00:00" + "time": "2020-06-18T22:58:05+00:00" }, { "name": "utopia-php/locale", @@ -2141,12 +2141,12 @@ "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e" + "reference": "5892a510fe31de9c4200e6f9ae30e91dc5cd5a41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", - "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/5892a510fe31de9c4200e6f9ae30e91dc5cd5a41", + "reference": "5892a510fe31de9c4200e6f9ae30e91dc5cd5a41", "shasum": "" }, "require": { @@ -2186,7 +2186,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2020-02-22T12:28:44+00:00" + "time": "2020-06-18T20:57:11+00:00" }, { "name": "phpdocumentor/type-resolver", From 2803e627695a44dea276074c602ef57800da0673 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Jun 2020 03:04:09 +0300 Subject: [PATCH 2/3] work in progress --- app/app.php | 2 +- app/init.php | 7 ++++--- composer.json | 2 +- composer.lock | 12 ++++++------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/app.php b/app/app.php index c1c9414715..c26821bd5b 100644 --- a/app/app.php +++ b/app/app.php @@ -83,7 +83,7 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $ * As recommended at: * @see https://www.owasp.org/index.php/List_of_useful_HTTP_headers */ - if ($request->getServer('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'enabled') { // Force HTTPS + if ($utopia->getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'enabled') { // Force HTTPS if(Config::getParam('protocol') !== 'https') { return $response->redirect('https://' . Config::getParam('domain').$request->getServer('REQUEST_URI')); } diff --git a/app/init.php b/app/init.php index aee80e9542..294fcc270d 100644 --- a/app/init.php +++ b/app/init.php @@ -50,6 +50,9 @@ const APP_SOCIAL_DEV = 'https://dev.to/appwrite'; $register = new Registry(); $request = new Request(); $response = new Response(); +$utopia = new App('Asia/Tel_Aviv'); + +$utopia->setMode($utopia->getEnv('_APP_ENV', App::MODE_TYPE_PRODUCTION)); /* * ENV vars @@ -60,7 +63,7 @@ Config::load('platforms', __DIR__.'/../app/config/platforms.php'); Config::load('locales', __DIR__.'/../app/config/locales.php'); Config::load('collections', __DIR__.'/../app/config/collections.php'); -Config::setParam('env', $request->getServer('_APP_ENV', App::MODE_TYPE_PRODUCTION)); +Config::setParam('env', $utopia->getMode()); Config::setParam('domain', $request->getServer('HTTP_HOST', '')); Config::setParam('domainVerification', false); Config::setParam('version', $request->getServer('_APP_VERSION', 'UNKNOWN')); @@ -68,8 +71,6 @@ Config::setParam('protocol', $request->getServer('HTTP_X_FORWARDED_PROTO', $requ Config::setParam('port', (string) parse_url(Config::getParam('protocol').'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_PORT)); Config::setParam('hostname', parse_url(Config::getParam('protocol').'://'.$request->getServer('HTTP_HOST', null), PHP_URL_HOST)); -$utopia = new App('Asia/Tel_Aviv', Config::getParam('env')); - Resque::setBackend($request->getServer('_APP_REDIS_HOST', '') .':'.$request->getServer('_APP_REDIS_PORT', '')); diff --git a/composer.json b/composer.json index 04fe7ccd59..97ef4285ad 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "appwrite/php-clamav": "1.0.*", - "utopia-php/framework": "0.3.1", + "utopia-php/framework": "0.3.3", "utopia-php/abuse": "0.2.*", "utopia-php/audit": "0.3.*", "utopia-php/cache": "0.2.*", diff --git a/composer.lock b/composer.lock index 7fa0f139ed..416add6c30 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "79b5c353af354f8df106d2f933750102", + "content-hash": "b40a5280315184407b21232e6c607b85", "packages": [ { "name": "appwrite/php-clamav", @@ -1596,16 +1596,16 @@ }, { "name": "utopia-php/framework", - "version": "0.3.1", + "version": "0.3.3", "source": { "type": "git", "url": "https://github.com/utopia-php/framework.git", - "reference": "b480f9dd01ad7990a12e90e5e4d11ded558dd8fc" + "reference": "dae7464b257663cd250e58244b21781a996134c2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/b480f9dd01ad7990a12e90e5e4d11ded558dd8fc", - "reference": "b480f9dd01ad7990a12e90e5e4d11ded558dd8fc", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/dae7464b257663cd250e58244b21781a996134c2", + "reference": "dae7464b257663cd250e58244b21781a996134c2", "shasum": "" }, "require": { @@ -1636,7 +1636,7 @@ "php", "upf" ], - "time": "2020-06-18T22:58:05+00:00" + "time": "2020-06-18T23:28:10+00:00" }, { "name": "utopia-php/locale", From 4c99caf578669932478cb30bca82a6ee33c261bb Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Jun 2020 10:30:46 +0300 Subject: [PATCH 3/3] Updated header and cookies default values --- app/init.php | 6 +++--- composer.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/init.php b/app/init.php index 294fcc270d..798f271231 100644 --- a/app/init.php +++ b/app/init.php @@ -166,7 +166,7 @@ $register->set('smtp', function () use ($request) { /* * Localization */ -$locale = $request->getParam('locale', $request->getHeader('X-Appwrite-Locale', null)); +$locale = $request->getParam('locale', $request->getHeader('X-Appwrite-Locale', '')); Locale::$exceptions = false; @@ -243,7 +243,7 @@ $consoleDB->setNamespace('app_console'); // Should be replaced with param if we $consoleDB->setMocks(Config::getParam('collections', [])); Authorization::disable(); -$project = $consoleDB->getDocument($request->getParam('project', $request->getHeader('X-Appwrite-Project', null))); +$project = $consoleDB->getDocument($request->getParam('project', $request->getHeader('X-Appwrite-Project', ''))); Authorization::enable(); @@ -267,7 +267,7 @@ $response->addHeader('X-Debug-Fallback', 'false'); if(empty($session['id']) && empty($session['secret'])) { $response->addHeader('X-Debug-Fallback', 'true'); - $fallback = $request->getHeader('X-Fallback-Cookies', null); + $fallback = $request->getHeader('X-Fallback-Cookies', ''); $fallback = json_decode($fallback, true); $session = Auth::decodeSession(((isset($fallback[Auth::$cookieName])) ? $fallback[Auth::$cookieName] : '')); } diff --git a/composer.json b/composer.json index 97ef4285ad..c7e99cd5c6 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "appwrite/php-clamav": "1.0.*", - "utopia-php/framework": "0.3.3", + "utopia-php/framework": "0.3.4", "utopia-php/abuse": "0.2.*", "utopia-php/audit": "0.3.*", "utopia-php/cache": "0.2.*",