From ce52aaf250d05a31cfd07f1c7eb57039c78c1bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Thu, 27 Oct 2022 18:53:25 +0200 Subject: [PATCH] Fix #1098 Move the Movim configuration to DotEnv Fix #509 Make Movim cache and log path configurable --- .env.example | 18 +++ .gitignore | 2 +- app/helpers/UtilsHelper.php | 75 ++++++--- composer.json | 3 +- composer.lock | 237 +++++++++++++++++++++++++++- config/daemon.php | 13 ++ config/database.php | 14 ++ config/db.example.inc.php | 17 -- config/paths.php | 10 ++ linker.php | 4 +- phinx.php | 12 +- src/Movim/Bootstrap.php | 84 ++++------ src/Movim/Console/DaemonCommand.php | 30 +--- src/Movim/Daemon/Core.php | 12 +- 14 files changed, 391 insertions(+), 140 deletions(-) create mode 100644 .env.example create mode 100644 config/daemon.php create mode 100644 config/database.php delete mode 100644 config/db.example.inc.php create mode 100644 config/paths.php diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..486a81cfb --- /dev/null +++ b/.env.example @@ -0,0 +1,18 @@ +# Database configuration +DB_DRIVER=pgsql +DB_HOST=localhost +DB_PORT=5432 +DB_DATABASE=movim +DB_USERNAME=movim +DB_PASSWORD=movim + +# Daemon configuration +DAEMON_URL=https://public-movim.url/ # Public URL of your Movim insta +DAEMON_PORT=8080 # Port on which the daemon will listen +DAEMON_INTERFACE=localhost # Interface on which the daemon will listen +DAEMON_DEBUG=false +DAEMON_VERBOSE=false + +# Configurable paths, complete path required +CACHE_PATH= +LOG_PATH= \ No newline at end of file diff --git a/.gitignore b/.gitignore index fed3f73c4..632b6a4ad 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,5 @@ /cache /public/cache *~ -/config/db.inc.php /composer.phar +.env \ No newline at end of file diff --git a/app/helpers/UtilsHelper.php b/app/helpers/UtilsHelper.php index 9748f6516..40a1afe5e 100644 --- a/app/helpers/UtilsHelper.php +++ b/app/helpers/UtilsHelper.php @@ -1,5 +1,6 @@ 0 && getenv('debug')) { - $log = new Logger('movim'); + $log = new Logger('movim'); + $log->pushHandler(new SyslogHandler('movim')); + + $stream = new StreamHandler(LOG_PATH . '/errors.log'); + $stream->setFormatter(new LineFormatter(null, null, true)); + $log->pushHandler($stream); - $handler = new SyslogHandler('movim'); + $log->error($logs); + } - if (LOG_LEVEL > 1) { - $log->pushHandler(new StreamHandler(LOG_PATH . '/info.log')); - } + /** + * Log an info + */ + public static function info($message) + { + if (config('daemon.verbose')) { + $log = new Logger('movim'); + $log->pushHandler(new SyslogHandler('movim')); - $log->pushHandler($handler); + $stream = new StreamHandler(LOG_PATH . '/info.log'); + $stream->setFormatter(new LineFormatter(null, null, true)); + $log->pushHandler($stream); - $errlines = explode("\n", $message); - foreach ($errlines as $txt) { - $log->info($txt); - } + $log->info($message); } } @@ -40,21 +53,39 @@ class Utils $log->debug($logs); } } +} - /** - * Log a string, only used for debug purposes - */ - public static function error($logs) - { - $log = new Logger('movim'); - $log->pushHandler(new SyslogHandler('movim')); +/** + * Return a configuration variable + */ +function config(string $key, $default = null) +{ + $path = explode('.', $key); + $config = require(CONFIG_PATH . $path[0] . '.php'); + + if (!isset($path[1])) return $config; + + if (array_key_exists($path[1], $config) && !empty($config[$path[1]])) { + $casted = null; - if (defined('LOG_LEVEL') && LOG_LEVEL > 1) { - $log->pushHandler(new StreamHandler(LOG_PATH . '/errors.log')); + switch ($config[$path[1]]) { + case 'true': + $casted = true; + break; + + case 'false': + $casted = false; + break; + + default: + $casted = $config[$path[1]]; + break; } - $log->error($logs); + return $casted; } + + return $default; } /** diff --git a/composer.json b/composer.json index 54458da09..0b11b589e 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,8 @@ "react/http": "^1.6.0", "react/dns": "^1.9.0", "ratchet/pawl": "^0.4.1", - "minishlink/web-push": "^7.0" + "minishlink/web-push": "^7.0", + "vlucas/phpdotenv": "^5.5" }, "config": { "platform": { diff --git a/composer.lock b/composer.lock index bee43b01b..27fa0f338 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": "067c3516d4c5cf213024fc44c8cd9e07", + "content-hash": "8c329029b3a31c4f219cd2a352635c0d", "packages": [ { "name": "brick/math", @@ -576,16 +576,16 @@ }, { "name": "dflydev/dot-access-data", - "version": "v3.0.1", + "version": "v3.0.2", "source": { "type": "git", "url": "https://github.com/dflydev/dflydev-dot-access-data.git", - "reference": "0992cc19268b259a39e86f296da5f0677841f42c" + "reference": "f41715465d65213d644d3141a6a93081be5d3549" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dflydev/dflydev-dot-access-data/zipball/0992cc19268b259a39e86f296da5f0677841f42c", - "reference": "0992cc19268b259a39e86f296da5f0677841f42c", + "url": "https://api.github.com/repos/dflydev/dflydev-dot-access-data/zipball/f41715465d65213d644d3141a6a93081be5d3549", + "reference": "f41715465d65213d644d3141a6a93081be5d3549", "shasum": "" }, "require": { @@ -596,7 +596,7 @@ "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3", "scrutinizer/ocular": "1.6.0", "squizlabs/php_codesniffer": "^3.5", - "vimeo/psalm": "^3.14" + "vimeo/psalm": "^4.0.0" }, "type": "library", "extra": { @@ -645,9 +645,9 @@ ], "support": { "issues": "https://github.com/dflydev/dflydev-dot-access-data/issues", - "source": "https://github.com/dflydev/dflydev-dot-access-data/tree/v3.0.1" + "source": "https://github.com/dflydev/dflydev-dot-access-data/tree/v3.0.2" }, - "time": "2021-08-13T13:06:58+00:00" + "time": "2022-10-27T11:44:00+00:00" }, { "name": "dflydev/fig-cookies", @@ -1538,6 +1538,68 @@ }, "time": "2020-11-24T22:02:12+00:00" }, + { + "name": "graham-campbell/result-type", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/GrahamCampbell/Result-Type.git", + "reference": "a878d45c1914464426dc94da61c9e1d36ae262a8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/a878d45c1914464426dc94da61c9e1d36ae262a8", + "reference": "a878d45c1914464426dc94da61c9e1d36ae262a8", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "phpoption/phpoption": "^1.9" + }, + "require-dev": { + "phpunit/phpunit": "^8.5.28 || ^9.5.21" + }, + "type": "library", + "autoload": { + "psr-4": { + "GrahamCampbell\\ResultType\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + } + ], + "description": "An Implementation Of The Result Type", + "keywords": [ + "Graham Campbell", + "GrahamCampbell", + "Result Type", + "Result-Type", + "result" + ], + "support": { + "issues": "https://github.com/GrahamCampbell/Result-Type/issues", + "source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.1.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type", + "type": "tidelift" + } + ], + "time": "2022-07-30T15:56:11+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "7.5.0", @@ -3170,6 +3232,81 @@ }, "time": "2020-10-15T08:29:30+00:00" }, + { + "name": "phpoption/phpoption", + "version": "1.9.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/php-option.git", + "reference": "dc5ff11e274a90cc1c743f66c9ad700ce50db9ab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/dc5ff11e274a90cc1c743f66c9ad700ce50db9ab", + "reference": "dc5ff11e274a90cc1c743f66c9ad700ce50db9ab", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8", + "phpunit/phpunit": "^8.5.28 || ^9.5.21" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": true + }, + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpOption\\": "src/PhpOption/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com", + "homepage": "https://github.com/schmittjoh" + }, + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + } + ], + "description": "Option Type for PHP", + "keywords": [ + "language", + "option", + "php", + "type" + ], + "support": { + "issues": "https://github.com/schmittjoh/php-option/issues", + "source": "https://github.com/schmittjoh/php-option/tree/1.9.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption", + "type": "tidelift" + } + ], + "time": "2022-07-30T15:51:26+00:00" + }, { "name": "psr/cache", "version": "1.0.1", @@ -6323,6 +6460,90 @@ ], "time": "2022-06-27T16:58:25+00:00" }, + { + "name": "vlucas/phpdotenv", + "version": "v5.5.0", + "source": { + "type": "git", + "url": "https://github.com/vlucas/phpdotenv.git", + "reference": "1a7ea2afc49c3ee6d87061f5a233e3a035d0eae7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/1a7ea2afc49c3ee6d87061f5a233e3a035d0eae7", + "reference": "1a7ea2afc49c3ee6d87061f5a233e3a035d0eae7", + "shasum": "" + }, + "require": { + "ext-pcre": "*", + "graham-campbell/result-type": "^1.0.2", + "php": "^7.1.3 || ^8.0", + "phpoption/phpoption": "^1.8", + "symfony/polyfill-ctype": "^1.23", + "symfony/polyfill-mbstring": "^1.23.1", + "symfony/polyfill-php80": "^1.23.1" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "ext-filter": "*", + "phpunit/phpunit": "^7.5.20 || ^8.5.30 || ^9.5.25" + }, + "suggest": { + "ext-filter": "Required to use the boolean validator." + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": true + }, + "branch-alias": { + "dev-master": "5.5-dev" + } + }, + "autoload": { + "psr-4": { + "Dotenv\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Vance Lucas", + "email": "vance@vancelucas.com", + "homepage": "https://github.com/vlucas" + } + ], + "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "support": { + "issues": "https://github.com/vlucas/phpdotenv/issues", + "source": "https://github.com/vlucas/phpdotenv/tree/v5.5.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv", + "type": "tidelift" + } + ], + "time": "2022-10-16T01:01:54+00:00" + }, { "name": "voku/portable-ascii", "version": "1.6.1", diff --git a/config/daemon.php b/config/daemon.php new file mode 100644 index 000000000..6191af53a --- /dev/null +++ b/config/daemon.php @@ -0,0 +1,13 @@ + env('DAEMON_URL', null), + 'port' => env('DAEMON_PORT', 8080), + 'interface' => env('DAEMON_INTERFACE', 'localhost'), + 'debug' => env('DAEMON_DEBUG', false), + 'verbose' => env('DAEMON_VERBOSE', false), +]; \ No newline at end of file diff --git a/config/database.php b/config/database.php new file mode 100644 index 000000000..e0fa4397a --- /dev/null +++ b/config/database.php @@ -0,0 +1,14 @@ + env('DB_DRIVER', 'pgsql'), + 'host' => env('DB_HOST', 'localhost'), + 'port' => (int)env('DB_PORT', 5432), + 'username' => env('DB_USERNAME', 'movim'), + 'password' => env('DB_PASSWORD', 'movim'), + 'database' => env('DB_DATABASE', 'movim') +]; \ No newline at end of file diff --git a/config/db.example.inc.php b/config/db.example.inc.php deleted file mode 100644 index c5c93b923..000000000 --- a/config/db.example.inc.php +++ /dev/null @@ -1,17 +0,0 @@ - 'pgsql', - # The database username - 'username' => 'username', - # The password - 'password' => 'password', - # Where can we find the database ? - 'host' => 'localhost', - # The port number, 3306 for MySQL and 5432 for PostgreSQL - 'port' => 5432, - # The database name - 'database' => 'movim' -]; diff --git a/config/paths.php b/config/paths.php new file mode 100644 index 000000000..0c1c8115a --- /dev/null +++ b/config/paths.php @@ -0,0 +1,10 @@ + env('CACHE_PATH', DOCUMENT_ROOT . '/cache/'), + 'log' => env('LOG_PATH', DOCUMENT_ROOT . '/log/'), +]; \ No newline at end of file diff --git a/linker.php b/linker.php index a55a600e8..fc8a06bb2 100644 --- a/linker.php +++ b/linker.php @@ -83,7 +83,7 @@ function writeXMPP($xml) $timestampSend = time(); $xmppSocket->write(trim($xml)); - if (getenv('debug')) { + if (config('daemon.debug')) { logOut(colorize(trim($xml).' ', 'yellow') . colorize('sent to XMPP', 'green')); } } @@ -275,7 +275,7 @@ $xmppBehaviour = function (React\Socket\Connection $stream) use (&$xmppSocket, $ $xmppSocket->on('data', function ($message) use (&$xmppSocket, $parser, &$timestampReceive) { if (!empty($message)) { - if (getenv('debug')) { + if (config('daemon.debug')) { logOut(colorize($message.' ', 'yellow') . colorize('received', 'green')); } diff --git a/phinx.php b/phinx.php index b6bdf56b8..a42fbc7e0 100644 --- a/phinx.php +++ b/phinx.php @@ -15,12 +15,12 @@ return [ 'default_database' => 'movim', 'default_environment' => 'movim', 'movim' => [ - 'adapter' => DB_TYPE, - 'host' => DB_HOST, - 'name' => DB_DATABASE, - 'user' => DB_USERNAME, - 'pass' => DB_PASSWORD, - 'port' => DB_PORT + 'adapter' => config('database.driver'), + 'host' => config('database.host'), + 'name' => config('database.database'), + 'user' => config('database.username'), + 'pass' => config('database.password'), + 'port' => config('database.port'), ] ] ]; diff --git a/src/Movim/Bootstrap.php b/src/Movim/Bootstrap.php index 0b1b0459a..61cc81212 100644 --- a/src/Movim/Bootstrap.php +++ b/src/Movim/Bootstrap.php @@ -10,6 +10,8 @@ use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Events\Dispatcher; use Illuminate\Container\Container; +use Dotenv\Dotenv; + use App\Session as DBSession; use App\User as DBUser; @@ -18,6 +20,7 @@ class Bootstrap public function boot($dbOnly = false) { $this->setLogs(); + $this->loadHelpers(); if (!defined('APP_TITLE')) { $this->setConstants(); @@ -36,10 +39,8 @@ class Bootstrap $this->loadCommonLibraries(); $this->loadDispatcher(); - $this->loadHelpers(); $this->setTimezone(); - $this->setLogLevel(); $this->startingSession(); $this->loadLanguage(); } @@ -61,17 +62,13 @@ class Bootstrap private function setConstants() { + (Dotenv::createImmutable(DOCUMENT_ROOT))->load(); + define('APP_TITLE', 'Movim'); define('APP_NAME', 'movim'); define('APP_VERSION', $this->getVersion()); define('SMALL_PICTURE_LIMIT', 768000); - if (file_exists(DOCUMENT_ROOT.'/config/db.inc.php')) { - require DOCUMENT_ROOT.'/config/db.inc.php'; - } else { - throw new \Exception('Cannot find config/db.inc.php file'); - } - if (isset($_SERVER['HTTP_HOST'])) { define('BASE_HOST', $_SERVER['HTTP_HOST']); } @@ -81,32 +78,19 @@ class Bootstrap } define('BASE_URI', $this->getBaseUri()); - - if (isset($_COOKIE['MOVIM_SESSION_ID'])) { - define('SESSION_ID', $_COOKIE['MOVIM_SESSION_ID']); - } else { - define('SESSION_ID', getenv('sid')); - } - - define('DB_TYPE', $conf['type']); - define('DB_HOST', $conf['host']); - define('DB_USERNAME', $conf['username']); - define('DB_PASSWORD', $conf['password']); - define('DB_PORT', $conf['port']); - define('DB_DATABASE', $conf['database']); + define('SESSION_ID', $_COOKIE['MOVIM_SESSION_ID'] ?? getenv('sid')); define('APP_PATH', DOCUMENT_ROOT . '/app/'); - define('LIB_PATH', DOCUMENT_ROOT . '/lib/'); define('LOCALES_PATH', DOCUMENT_ROOT . '/locales/'); - define('CACHE_PATH', DOCUMENT_ROOT . '/cache/'); define('PUBLIC_PATH', DOCUMENT_ROOT . '/public/'); define('PUBLIC_CACHE_PATH', DOCUMENT_ROOT . '/public/cache/'); - define('LOG_PATH', DOCUMENT_ROOT . '/log/'); define('CONFIG_PATH', DOCUMENT_ROOT . '/config/'); - define('VIEWS_PATH', DOCUMENT_ROOT . '/app/views/'); - define('HELPERS_PATH', DOCUMENT_ROOT . '/app/helpers/'); define('WIDGETS_PATH', DOCUMENT_ROOT . '/app/widgets/'); + + define('LOG_PATH', config('paths.log')); + define('CACHE_PATH', config('paths.cache')); + define('MOVIM_SQL_DATE', 'Y-m-d H:i:s'); define('DEFAULT_PICTURE_FORMAT', 'webp'); @@ -117,8 +101,7 @@ class Bootstrap private function getVersion() { - $file = 'VERSION'; - if ($f = fopen(DOCUMENT_ROOT.'/'.$file, 'r')) { + if ($f = fopen(DOCUMENT_ROOT.'/VERSION', 'r')) { return trim(fgets($f)); } } @@ -151,22 +134,16 @@ class Bootstrap private function loadCapsule() { - if (file_exists(DOCUMENT_ROOT.'/config/db.inc.php')) { - require DOCUMENT_ROOT.'/config/db.inc.php'; - } else { - throw new \Exception('Cannot find config/db.inc.php file'); - } - $capsule = new Capsule; $capsule->addConnection([ - 'driver' => $conf['type'], - 'host' => $conf['host'], - 'port' => $conf['port'], - 'database' => $conf['database'], - 'username' => $conf['username'], - 'password' => $conf['password'], - 'charset' => ($conf['type'] == 'mysql') ? 'utf8mb4' : 'utf8', - 'collation' => ($conf['type'] == 'mysql') ? 'utf8mb4_unicode_ci' : 'utf8_unicode_ci', + 'driver' => config('database.driver'), + 'host' => config('database.host'), + 'port' => config('database.port'), + 'database' => config('database.database'), + 'username' => config('database.username'), + 'password' => config('database.password'), + 'charset' => (config('database.driver') == 'mysql') ? 'utf8mb4' : 'utf8', + 'collation' => (config('database.driver') == 'mysql') ? 'utf8mb4_unicode_ci' : 'utf8_unicode_ci', ]); /** @@ -199,15 +176,15 @@ class Bootstrap private function loadCommonLibraries() { - require_once LIB_PATH . 'XMPPtoForm.php'; - require_once LIB_PATH . 'SDPtoJingle.php'; - require_once LIB_PATH . 'JingletoSDP.php'; + require_once DOCUMENT_ROOT . '/lib/XMPPtoForm.php'; + require_once DOCUMENT_ROOT . '/lib/SDPtoJingle.php'; + require_once DOCUMENT_ROOT . '/lib/JingletoSDP.php'; } private function loadHelpers() { - foreach (glob(HELPERS_PATH . '*Helper.php') as $file) { - require $file; + foreach (glob(DOCUMENT_ROOT.'/app/helpers/*Helper.php') as $file) { + require_once $file; } } @@ -313,12 +290,17 @@ class Bootstrap { if (\is_array($trace)) $trace = ''; - $error = $errstr . " in " . $errfile . ' (line ' . $errline . ")\n" . 'Trace' . "\n" . $trace; + $error = $errstr . " in " . $errfile . ' (line ' . $errline . ")\n"; + $fullError = $error . 'Trace' . "\n" . $trace; - if (class_exists('Utils')) { - \Utils::error($error); - } else { + if (php_sapi_name() != 'cli' && ob_get_contents() == '') { + echo 'An error occured during the Movim boot check the ' . config('paths.log') . 'error.log file' . "\n"; + } + + if (php_sapi_name() == 'cli' || !class_exists('Utils')) { echo $error; + } else { + \Utils::error($fullError); } return false; diff --git a/src/Movim/Console/DaemonCommand.php b/src/Movim/Console/DaemonCommand.php index 524e3df72..e3f2b08a6 100644 --- a/src/Movim/Console/DaemonCommand.php +++ b/src/Movim/Console/DaemonCommand.php @@ -31,26 +31,6 @@ class DaemonCommand extends Command $this ->setName('start') ->setDescription('Start the daemon') - ->addOption( - 'url', - 'u', - InputOption::VALUE_OPTIONAL, - 'Public URL of your Movim instance' - ) - ->addOption( - 'port', - 'p', - InputOption::VALUE_OPTIONAL, - 'Port on which the daemon will listen', - 8080 - ) - ->addOption( - 'interface', - 'i', - InputOption::VALUE_OPTIONAL, - 'Interface on which the daemon will listen', - '127.0.0.1' - ) ->addOption( 'debug', 'd', @@ -73,13 +53,13 @@ class DaemonCommand extends Command $loop = Loop::get(); - if ($input->getOption('url') && Validator::url()->notEmpty()->validate($input->getOption('url'))) { - $baseuri = rtrim($input->getOption('url'), '/') . '/'; + if (config('daemon.url') && Validator::url()->notEmpty()->validate(config('daemon.url'))) { + $baseuri = rtrim(config('daemon.url'), '/') . '/'; } elseif (file_exists(CACHE_PATH.'baseuri')) { $baseuri = file_get_contents(CACHE_PATH.'baseuri'); } else { $output->writeln('Please load the login page once before starting the daemon to cache the public URL'); - $output->writeln('or force a public URL using the --url parameter'); + $output->writeln('or configure DAEMON_URL in .env'); exit; } @@ -107,11 +87,11 @@ class DaemonCommand extends Command $output->writeln("\n".'Debug is enabled, check the logs in syslog or '.DOCUMENT_ROOT.'/log/'); } - $core = new Core($loop, $baseuri, $input); + $core = new Core($loop, $baseuri); $app = new HttpServer(new WsServer($core)); $socket = new SocketServer( - $input->getOption('interface').':'.$input->getOption('port') + config('daemon.interface') . ':' . config('daemon.port') ); $socketApi = new SocketServer('unix://' . API_SOCKET); diff --git a/src/Movim/Daemon/Core.php b/src/Movim/Daemon/Core.php index 430de6943..97a3b623c 100644 --- a/src/Movim/Daemon/Core.php +++ b/src/Movim/Daemon/Core.php @@ -18,7 +18,6 @@ use Minishlink\WebPush\VAPID; class Core implements MessageComponentInterface { public $sessions = []; - private $input; private $key; // Random key generate by the daemon to authenticate the internal Websockets public $loop; @@ -27,12 +26,11 @@ class Core implements MessageComponentInterface public $single = ['visio']; public $singlelocks = []; - public function __construct($loop, $baseuri, InputInterface $input) + public function __construct($loop, $baseuri) { - $this->input = $input; $this->key = \generateKey(32); - $this->setWebsocket($this->input->getOption('port')); + $this->setWebsocket(config('daemon.port')); $this->loop = $loop; $this->baseuri = $baseuri; @@ -113,12 +111,12 @@ class Core implements MessageComponentInterface $this->loop, $sid, $this->baseuri, - $this->input->getOption('port'), + config('daemon.port'), $this->key, $language, $offset, - $this->input->getOption('verbose'), - $this->input->getOption('debug') + config('daemon.verbose'), + config('daemon.debug') ); }