diff --git a/app/app.php b/app/app.php index 4cd79b345..089598edc 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 90c0000f2..369cba85f 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 ad1beef9a..b5f239046 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 5ded8df37..253d69f44 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 2f1535b66..6b63bb53a 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 6a6b83032..97c745bf2 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 4d433ec9a..39fc68c43 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 7c208a855..696c8986f 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 5880a8d38..227712b4a 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 ''; } /**