1
0
Fork 0
mirror of synced 2024-07-17 04:16:19 +12:00
appwrite/app/tasks/ssl.php

36 lines
1.2 KiB
PHP
Raw Normal View History

2020-07-29 07:48:51 +12:00
<?php
global $cli;
2022-04-11 19:56:58 +12:00
use Appwrite\Event\Event;
2020-07-29 07:48:51 +12:00
use Utopia\App;
use Utopia\CLI\Console;
2022-04-11 19:56:58 +12:00
use Utopia\Validator\Hostname;
2020-07-29 07:48:51 +12:00
$cli
->task('ssl')
->desc('Validate server certificates')
2022-04-11 19:56:58 +12:00
->param('domain', App::getEnv('_APP_DOMAIN', ''), new Hostname(), 'Domain to generate certificate for. If empty, main domain will be used.', true)
->action(function ($domain) {
// HTTTP ping to check if domain is Appwrite server
$ch = \curl_init();
\curl_setopt($ch, CURLOPT_URL, 'http://appwrite/manifest.json');
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
\curl_setopt($ch, CURLOPT_TIMEOUT, 5);
\curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
\curl_exec($ch);
$statusCode = \curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = \curl_error($ch);
\curl_close($ch);
2020-07-29 07:48:51 +12:00
2022-04-11 19:56:58 +12:00
if($statusCode < 100) {
return Console::error('Appwrite connection refused with message: ' . $error);
}
2022-04-10 21:38:22 +12:00
2022-04-11 19:56:58 +12:00
Console::success('Schedule a job to issue a TLS certificate for domain:' . $domain);
2020-07-29 07:48:51 +12:00
2022-04-11 19:56:58 +12:00
// Scheduje a job
Resque::enqueue(Event::CERTIFICATES_QUEUE_NAME, Event::CERTIFICATES_CLASS_NAME, [
2020-07-29 07:48:51 +12:00
'domain' => $domain,
]);
});