From 7faedecbe49dd377c396fd4a1bdb29bd46f423d4 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 19 Feb 2020 14:12:48 +0200 Subject: [PATCH 01/87] Added empty certs worker --- app/app.php | 1 + app/workers/certs.php | 38 ++++++++++++++++++++++++++++++++++++++ docker/supervisord.conf | 15 +++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 app/workers/certs.php diff --git a/app/app.php b/app/app.php index 089598edcf..4cd79b3458 100644 --- a/app/app.php +++ b/app/app.php @@ -28,6 +28,7 @@ $services = include __DIR__.'/config/services.php'; // List of services $webhook = new Event('v1-webhooks', 'WebhooksV1'); $audit = new Event('v1-audits', 'AuditsV1'); $usage = new Event('v1-usage', 'UsageV1'); +$certs = new Event('v1-certs', 'CertsV1'); /** * Get All verified client URLs for both console and current projects diff --git a/app/workers/certs.php b/app/workers/certs.php new file mode 100644 index 0000000000..4d433ec9af --- /dev/null +++ b/app/workers/certs.php @@ -0,0 +1,38 @@ + Date: Wed, 19 Feb 2020 14:41:23 +0200 Subject: [PATCH 02/87] Added volumes constants --- app/app.php | 1 - app/controllers/api/avatars.php | 6 +++--- app/controllers/api/health.php | 2 +- app/controllers/api/storage.php | 4 ++-- app/controllers/mock.php | 2 +- app/init.php | 3 +++ app/workers/certs.php | 12 +++++++++--- docker/supervisord.conf | 4 ++-- src/Storage/Devices/S3.php | 2 +- 9 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/app.php b/app/app.php index 4cd79b3458..089598edcf 100644 --- a/app/app.php +++ b/app/app.php @@ -28,7 +28,6 @@ $services = include __DIR__.'/config/services.php'; // List of services $webhook = new Event('v1-webhooks', 'WebhooksV1'); $audit = new Event('v1-audits', 'AuditsV1'); $usage = new Event('v1-usage', 'UsageV1'); -$certs = new Event('v1-certs', 'CertsV1'); /** * Get All verified client URLs for both console and current projects diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 90c0000f20..369cba85fd 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -49,7 +49,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types throw new Exception('File not readable in '.$path, 500); } - $cache = new Cache(new Filesystem('/storage/cache/app-0')); // Limit file number or size + $cache = new Cache(new Filesystem(APP_STORAGE_CACHE.'/app-0')); // Limit file number or size $data = $cache->load($key, 60 * 60 * 24 * 30 * 3 /* 3 months */); if ($data) { @@ -146,7 +146,7 @@ $utopia->get('/v1/avatars/image') $date = date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache $key = md5('/v2/avatars/images-'.$url.'-'.$width.'/'.$height.'/'.$quality); $type = 'png'; - $cache = new Cache(new Filesystem('/storage/cache/app-0')); // Limit file number or size + $cache = new Cache(new Filesystem(APP_STORAGE_CACHE.'/app-0')); // Limit file number or size $data = $cache->load($key, 60 * 60 * 24 * 7 /* 1 week */); if ($data) { @@ -214,7 +214,7 @@ $utopia->get('/v1/avatars/favicon') $date = date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache $key = md5('/v2/avatars/favicon-'.$url); $type = 'png'; - $cache = new Cache(new Filesystem('/storage/cache/app-0')); // Limit file number or size + $cache = new Cache(new Filesystem(APP_STORAGE_CACHE.'/app-0')); // Limit file number or size $data = $cache->load($key, 60 * 60 * 24 * 30 * 3 /* 3 months */); if ($data) { diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index ad1beef9a4..b5f239046c 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -119,7 +119,7 @@ $utopia->get('/v1/health/storage/local') ->label('docs', false) ->action( function () use ($response) { - $device = new Local('/storage/uploads/'); + $device = new Local(APP_STORAGE_UPLOADS.'/'); if (!is_readable($device->getRoot().'/..')) { throw new Exception('Device is not readable'); diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 5ded8df37a..253d69f44e 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -25,7 +25,7 @@ use OpenSSL\OpenSSL; include_once __DIR__ . '/../shared/api.php'; -Storage::addDevice('local', new Local('/storage/uploads/app-'.$project->getId())); +Storage::addDevice('local', new Local(APP_STORAGE_UPLOADS.'/app-'.$project->getId())); $fileLogos = [ // Based on this list @see http://stackoverflow.com/a/4212908/2299554 'default' => 'default.gif', @@ -357,7 +357,7 @@ $utopia->get('/v1/storage/files/:fileId/preview') throw new Exception('File not found in '.$path, 404); } - $cache = new Cache(new Filesystem('/storage/cache/app-'.$project->getId())); // Limit file number or size + $cache = new Cache(new Filesystem(APP_STORAGE_CACHE.'/app-'.$project->getId())); // Limit file number or size $data = $cache->load($key, 60 * 60 * 24 * 30 * 3 /* 3 months */); if ($data) { diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 2f1535b662..6b63bb53ad 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -321,7 +321,7 @@ $utopia->get('/v1/mock/tests/general/oauth2/failure') $utopia->shutdown(function() use ($response, $request, &$result, $utopia) { $route = $utopia->match($request); - $path = '/storage/cache/tests.json'; + $path = APP_STORAGE_CACHE.'/tests.json'; $tests = (file_exists($path)) ? json_decode(file_get_contents($path), true) : []; if(!is_array($tests)) { diff --git a/app/init.php b/app/init.php index 6a6b830321..97c745bf2f 100644 --- a/app/init.php +++ b/app/init.php @@ -26,6 +26,9 @@ const APP_USERAGENT = APP_NAME.'-Server/%s Please report abuse at '.APP_EMAIL_SE const APP_MODE_ADMIN = 'admin'; const APP_PAGING_LIMIT = 15; const APP_VERSION_STABLE = '0.5.0'; +const APP_STORAGE_UPLOADS = '/storage/uploads'; +const APP_STORAGE_CACHE = '/storage/cache'; +const APP_STORAGE_CERTIFICATES = '/storage/certificates'; $register = new Registry(); $request = new Request(); diff --git a/app/workers/certs.php b/app/workers/certs.php index 4d433ec9af..39fc68c43b 100644 --- a/app/workers/certs.php +++ b/app/workers/certs.php @@ -2,9 +2,9 @@ require_once __DIR__.'/../init.php'; -cli_set_process_title('Certs V1 Worker'); +cli_set_process_title('Certificates V1 Worker'); -echo APP_NAME.' certs worker v1 has started'; +echo APP_NAME.' certificates worker v1 has started'; class CertsV1 { @@ -18,17 +18,23 @@ class CertsV1 { global $register; + $domain = $this->args['domain']; /** * 1. Get new domain * 2. Fetch all subdomains * 3. Check if certificate already exists * 4. Check if certificate has been changed - * 4.1. Create / Renew certificate + * 4.1. Create / renew certificate * 4.2. Update loadblancer * 4.3. Update certificate (domains, change date, expiry) */ + $response = shell_exec("certbot certonly --webroot --noninteractive --agree-tos --email security@appwrite.io \ + -w ./certs \ + -d {$domain}"); // cert2.tests.appwrite.org + + } public function tearDown() diff --git a/docker/supervisord.conf b/docker/supervisord.conf index 7c208a855a..696c8986f4 100644 --- a/docker/supervisord.conf +++ b/docker/supervisord.conf @@ -108,12 +108,12 @@ startretries=10 stderr_logfile=/dev/stderr stderr_logfile_maxbytes = 0 -[program:v1-certs] +[program:v1-certificates] command=php /usr/share/nginx/html/vendor/bin/resque autostart=true autorestart=true priority=10 -environment=QUEUE='v1-certs',APP_INCLUDE='/usr/share/nginx/html/app/workers/certs.php',REDIS_BACKEND='%(ENV__APP_REDIS_HOST)s:%(ENV__APP_REDIS_PORT)s' +environment=QUEUE='v1-certificates',APP_INCLUDE='/usr/share/nginx/html/app/workers/certificates.php',REDIS_BACKEND='%(ENV__APP_REDIS_HOST)s:%(ENV__APP_REDIS_PORT)s' stdout_events_enabled=true stderr_events_enabled=true stopsignal=QUIT diff --git a/src/Storage/Devices/S3.php b/src/Storage/Devices/S3.php index 5880a8d389..227712b4a6 100644 --- a/src/Storage/Devices/S3.php +++ b/src/Storage/Devices/S3.php @@ -27,7 +27,7 @@ class S3 extends Device */ public function getRoot() { - return '/storage/uploads'; + return ''; } /** From e8cc10ec2db9673c04b825c5e186358d1e100e94 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 20 Feb 2020 22:42:54 +0200 Subject: [PATCH 03/87] Added proper error handling --- app/app.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/app/app.php b/app/app.php index 089598edcf..1cba331488 100644 --- a/app/app.php +++ b/app/app.php @@ -369,27 +369,19 @@ $utopia->get('/.well-known/acme-challenge') $absolute = realpath($base.'/'.$path); if(!$absolute) { - //throw new Exception('Unknown Path', 404); - $response->json([ - 'error' => 'unknown path', - 'base' => scandir($base), - 'base/well' => scandir($base . '/.well-known/'), - 'base/well/acme' => scandir($base . '/.well-known/acme-challenge/'), - 'base/well/acme/query' => ($absolute) ? scandir($absolute) : ['not-a-dir'], - ]); - return; + throw new Exception('Unknown Path', 404); + // $response->json([ + // 'error' => 'unknown path', + // 'base' => scandir($base), + // 'base/well' => scandir($base . '/.well-known/'), + // 'base/well/acme' => scandir($base . '/.well-known/acme-challenge/'), + // 'base/well/acme/query' => ($absolute) ? scandir($absolute) : ['not-a-dir'], + // ]); + // return; } if(!substr($absolute, 0, strlen($base)) === $base) { - //throw new Exception('Invalid Path', 401); - $response->json([ - 'error' => 'invalid path', - 'base' => scandir($base), - 'base/well' => scandir($base . '/.well-known/'), - 'base/well/acme' => scandir($base . '/.well-known/acme-challenge/'), - 'base/well/acme/query' => ($absolute) ? scandir($absolute) : ['not-a-dir'], - ]); - return; + throw new Exception('Invalid Path', 401); } $response->text(file_get_contents($absolute)); From 9bc6c72b7321516c91c13eabc65eddbfa34ad306 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 20 Feb 2020 22:43:06 +0200 Subject: [PATCH 04/87] Added social constants --- app/init.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/init.php b/app/init.php index 97c745bf2f..3390ea3788 100644 --- a/app/init.php +++ b/app/init.php @@ -29,6 +29,13 @@ const APP_VERSION_STABLE = '0.5.0'; const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_CACHE = '/storage/cache'; const APP_STORAGE_CERTIFICATES = '/storage/certificates'; +const APP_SOCIAL_TWITTER = 'https://twitter.com/appwrite_io'; +const APP_SOCIAL_TWITTER_HANDLE = 'appwrite_io'; +const APP_SOCIAL_FACEBOOK = 'https://www.facebook.com/appwrite.io'; +const APP_SOCIAL_LINKEDIN = 'https://www.linkedin.com/company/appwrite'; +const APP_SOCIAL_INSTAGRAM = 'https://www.instagram.com/appwrite.io'; +const APP_SOCIAL_GITHUB = 'https://github.com/appwrite'; +const APP_SOCIAL_DISCORD = 'https://discord.gg/GSeTUeA'; $register = new Registry(); $request = new Request(); From 1fe8a216b3b3f8ca88b72a2b37e30ffc0036dd2c Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 20 Feb 2020 22:43:21 +0200 Subject: [PATCH 05/87] Added new collection --- app/config/collections.php | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/app/config/collections.php b/app/config/collections.php index 45ad9a3a5b..60c6bca10d 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -931,6 +931,60 @@ $collections = [ ], ], ], + Database::SYSTEM_COLLECTION_DOMAINS => [ + '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, + '$id' => Database::SYSTEM_COLLECTION_DOMAINS, + '$permissions' => ['read' => ['*']], + 'name' => 'Domains', + 'structure' => true, + 'rules' => [ + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Domain', + 'key' => 'domain', + 'type' => 'text', + 'default' => null, + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Status', + 'key' => 'status', + 'type' => 'text', + 'default' => '', + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Updated', + 'key' => 'updated', + 'type' => 'numeric', + 'default' => '', + 'required' => false, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Verification', + 'key' => 'verification', + 'type' => 'boolean', + 'default' => false, + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Certificate ID', + 'key' => 'certificateId', + 'type' => 'boolean', + 'default' => false, + 'required' => true, + 'array' => false, + ], + ], + ], Database::SYSTEM_COLLECTION_FILES => [ '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, '$id' => Database::SYSTEM_COLLECTION_FILES, From 64e290ce533a068c4f5ca2c8ce66e2b3f9561fbc Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 20 Feb 2020 22:44:35 +0200 Subject: [PATCH 06/87] Upgraded console homepage --- app/views/console/comps/header.phtml | 7 +++- app/views/console/index.phtml | 56 +++++++++++++++++++++------ app/views/layouts/default.phtml | 2 +- public/dist/styles/default-ltr.css | 2 +- public/dist/styles/default-rtl.css | 2 +- public/styles/comps/box.less | 6 +++ public/styles/comps/modal.less | 14 +++++++ public/styles/default.less | 15 +++---- public/styles/dependencies/prism.less | 1 + public/styles/forms.less | 9 ++++- public/styles/grid.less | 14 ++++++- public/styles/scopes/console.less | 47 +++++++++++++--------- public/styles/tabels.less | 14 +++++-- 13 files changed, 142 insertions(+), 47 deletions(-) diff --git a/app/views/console/comps/header.phtml b/app/views/console/comps/header.phtml index 1e96267ac6..88991b09af 100644 --- a/app/views/console/comps/header.phtml +++ b/app/views/console/comps/header.phtml @@ -1,4 +1,9 @@
+ +    
-