2017-09-23 02:19:57 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-09-23 02:19:57 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-09-23 02:19:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Console\Commands\Environment;
|
|
|
|
|
2017-11-23 21:08:35 +00:00
|
|
|
use DateTimeZone;
|
2017-09-23 02:19:57 +00:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Contracts\Console\Kernel;
|
|
|
|
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
|
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
|
|
|
|
|
|
|
class AppSettingsCommand extends Command
|
|
|
|
{
|
|
|
|
use EnvironmentWriterTrait;
|
|
|
|
|
2017-11-23 21:08:35 +00:00
|
|
|
const ALLOWED_CACHE_DRIVERS = [
|
|
|
|
'redis' => 'Redis (recommended)',
|
2017-11-23 21:08:43 +00:00
|
|
|
'memcached' => 'Memcached',
|
2018-03-02 00:46:59 +00:00
|
|
|
'file' => 'Filesystem',
|
2017-11-23 21:08:35 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const ALLOWED_SESSION_DRIVERS = [
|
|
|
|
'redis' => 'Redis (recommended)',
|
|
|
|
'memcached' => 'Memcached',
|
|
|
|
'database' => 'MySQL Database',
|
|
|
|
'file' => 'Filesystem',
|
|
|
|
'cookie' => 'Cookie',
|
|
|
|
];
|
|
|
|
|
|
|
|
const ALLOWED_QUEUE_DRIVERS = [
|
|
|
|
'redis' => 'Redis (recommended)',
|
|
|
|
'database' => 'MySQL Database',
|
|
|
|
'sync' => 'Sync',
|
|
|
|
];
|
|
|
|
|
2017-09-23 02:19:57 +00:00
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Console\Kernel
|
|
|
|
*/
|
|
|
|
protected $command;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Config\Repository
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Configure basic environment settings for the Panel.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'p:environment:setup
|
2018-05-13 14:50:56 +00:00
|
|
|
{--new-salt : Whether or not to generate a new salt for Hashids.}
|
2017-10-03 03:51:13 +00:00
|
|
|
{--author= : The email that services created on this instance should be linked to.}
|
2017-09-23 02:19:57 +00:00
|
|
|
{--url= : The URL that this Panel is running on.}
|
|
|
|
{--timezone= : The timezone to use for Panel times.}
|
|
|
|
{--cache= : The cache driver backend to use.}
|
|
|
|
{--session= : The session driver backend to use.}
|
2017-11-23 21:08:35 +00:00
|
|
|
{--queue= : The queue driver backend to use.}
|
2017-09-23 02:19:57 +00:00
|
|
|
{--redis-host= : Redis host to use for connections.}
|
|
|
|
{--redis-pass= : Password used to connect to redis.}
|
2017-12-30 22:33:00 +00:00
|
|
|
{--redis-port= : Port to connect to redis over.}
|
2019-07-26 15:05:57 +00:00
|
|
|
{--settings-ui= : Enable or disable the settings UI.}';
|
2017-09-23 02:19:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $variables = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AppSettingsCommand constructor.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Contracts\Config\Repository $config
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Illuminate\Contracts\Console\Kernel $command
|
2017-09-23 02:19:57 +00:00
|
|
|
*/
|
|
|
|
public function __construct(ConfigRepository $config, Kernel $command)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->command = $command;
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle command execution.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\PterodactylException
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2017-11-23 21:08:35 +00:00
|
|
|
if (empty($this->config->get('hashids.salt')) || $this->option('new-salt')) {
|
2017-11-05 18:58:25 +00:00
|
|
|
$this->variables['HASHIDS_SALT'] = str_random(20);
|
|
|
|
}
|
|
|
|
|
2017-10-03 03:51:13 +00:00
|
|
|
$this->output->comment(trans('command/messages.environment.app.author_help'));
|
2017-11-04 21:27:15 +00:00
|
|
|
$this->variables['APP_SERVICE_AUTHOR'] = $this->option('author') ?? $this->ask(
|
2019-09-06 04:32:57 +00:00
|
|
|
trans('command/messages.environment.app.author'), $this->config->get('pterodactyl.service.author', 'unknown@unknown.com')
|
|
|
|
);
|
2017-09-23 02:19:57 +00:00
|
|
|
|
|
|
|
$this->output->comment(trans('command/messages.environment.app.app_url_help'));
|
|
|
|
$this->variables['APP_URL'] = $this->option('url') ?? $this->ask(
|
2019-09-06 04:32:57 +00:00
|
|
|
trans('command/messages.environment.app.app_url'), $this->config->get('app.url', 'http://example.org')
|
|
|
|
);
|
2017-09-23 02:19:57 +00:00
|
|
|
|
|
|
|
$this->output->comment(trans('command/messages.environment.app.timezone_help'));
|
2017-11-23 21:08:35 +00:00
|
|
|
$this->variables['APP_TIMEZONE'] = $this->option('timezone') ?? $this->anticipate(
|
2019-09-06 04:32:57 +00:00
|
|
|
trans('command/messages.environment.app.timezone'),
|
|
|
|
DateTimeZone::listIdentifiers(DateTimeZone::ALL),
|
|
|
|
$this->config->get('app.timezone')
|
|
|
|
);
|
2017-09-23 02:19:57 +00:00
|
|
|
|
2017-11-23 21:08:35 +00:00
|
|
|
$selected = $this->config->get('cache.default', 'redis');
|
2017-09-23 02:19:57 +00:00
|
|
|
$this->variables['CACHE_DRIVER'] = $this->option('cache') ?? $this->choice(
|
2019-09-06 04:32:57 +00:00
|
|
|
trans('command/messages.environment.app.cache_driver'),
|
|
|
|
self::ALLOWED_CACHE_DRIVERS,
|
|
|
|
array_key_exists($selected, self::ALLOWED_CACHE_DRIVERS) ? $selected : null
|
|
|
|
);
|
2017-09-23 02:19:57 +00:00
|
|
|
|
2017-11-23 21:08:35 +00:00
|
|
|
$selected = $this->config->get('session.driver', 'redis');
|
2017-09-23 02:19:57 +00:00
|
|
|
$this->variables['SESSION_DRIVER'] = $this->option('session') ?? $this->choice(
|
2019-09-06 04:32:57 +00:00
|
|
|
trans('command/messages.environment.app.session_driver'),
|
|
|
|
self::ALLOWED_SESSION_DRIVERS,
|
|
|
|
array_key_exists($selected, self::ALLOWED_SESSION_DRIVERS) ? $selected : null
|
|
|
|
);
|
2017-09-23 02:19:57 +00:00
|
|
|
|
2017-11-23 21:08:35 +00:00
|
|
|
$selected = $this->config->get('queue.default', 'redis');
|
2018-11-26 00:25:18 +00:00
|
|
|
$this->variables['QUEUE_CONNECTION'] = $this->option('queue') ?? $this->choice(
|
2019-09-06 04:32:57 +00:00
|
|
|
trans('command/messages.environment.app.queue_driver'),
|
|
|
|
self::ALLOWED_QUEUE_DRIVERS,
|
|
|
|
array_key_exists($selected, self::ALLOWED_QUEUE_DRIVERS) ? $selected : null
|
|
|
|
);
|
2017-12-30 22:33:00 +00:00
|
|
|
|
2019-07-26 15:05:57 +00:00
|
|
|
if (! is_null($this->option('settings-ui'))) {
|
|
|
|
$this->variables['APP_ENVIRONMENT_ONLY'] = $this->option('settings-ui') == 'true' ? 'false' : 'true';
|
2017-12-30 22:33:00 +00:00
|
|
|
} else {
|
2017-12-30 22:34:22 +00:00
|
|
|
$this->variables['APP_ENVIRONMENT_ONLY'] = $this->confirm(trans('command/messages.environment.app.settings'), true) ? 'false' : 'true';
|
2017-12-30 22:33:00 +00:00
|
|
|
}
|
2017-09-23 02:19:57 +00:00
|
|
|
|
|
|
|
$this->checkForRedis();
|
|
|
|
$this->writeToEnvironment($this->variables);
|
|
|
|
|
|
|
|
$this->info($this->command->output());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if redis is selected, if so, request connection details and verify them.
|
|
|
|
*/
|
|
|
|
private function checkForRedis()
|
|
|
|
{
|
|
|
|
$items = collect($this->variables)->filter(function ($item) {
|
|
|
|
return $item === 'redis';
|
|
|
|
});
|
|
|
|
|
|
|
|
// Redis was not selected, no need to continue.
|
|
|
|
if (count($items) === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->output->note(trans('command/messages.environment.app.using_redis'));
|
|
|
|
$this->variables['REDIS_HOST'] = $this->option('redis-host') ?? $this->ask(
|
2019-09-06 04:32:57 +00:00
|
|
|
trans('command/messages.environment.app.redis_host'), $this->config->get('database.redis.default.host')
|
|
|
|
);
|
2017-09-23 02:19:57 +00:00
|
|
|
|
|
|
|
$askForRedisPassword = true;
|
|
|
|
if (! empty($this->config->get('database.redis.default.password'))) {
|
|
|
|
$this->variables['REDIS_PASSWORD'] = $this->config->get('database.redis.default.password');
|
|
|
|
$askForRedisPassword = $this->confirm(trans('command/messages.environment.app.redis_pass_defined'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($askForRedisPassword) {
|
|
|
|
$this->output->comment(trans('command/messages.environment.app.redis_pass_help'));
|
|
|
|
$this->variables['REDIS_PASSWORD'] = $this->option('redis-pass') ?? $this->output->askHidden(
|
2019-09-06 04:32:57 +00:00
|
|
|
trans('command/messages.environment.app.redis_password')
|
|
|
|
);
|
2017-09-23 02:19:57 +00:00
|
|
|
}
|
|
|
|
|
2017-11-04 21:40:48 +00:00
|
|
|
if (empty($this->variables['REDIS_PASSWORD'])) {
|
2017-11-04 21:46:18 +00:00
|
|
|
$this->variables['REDIS_PASSWORD'] = 'null';
|
2017-11-04 21:40:48 +00:00
|
|
|
}
|
|
|
|
|
2017-09-23 02:19:57 +00:00
|
|
|
$this->variables['REDIS_PORT'] = $this->option('redis-port') ?? $this->ask(
|
2019-09-06 04:32:57 +00:00
|
|
|
trans('command/messages.environment.app.redis_port'), $this->config->get('database.redis.default.port')
|
|
|
|
);
|
2017-09-23 02:19:57 +00:00
|
|
|
}
|
|
|
|
}
|