Path: blob/1.0-develop/app/Console/Commands/Environment/AppSettingsCommand.php
7461 views
<?php12namespace Pterodactyl\Console\Commands\Environment;34use Illuminate\Console\Command;5use Illuminate\Contracts\Console\Kernel;6use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;78class AppSettingsCommand extends Command9{10use EnvironmentWriterTrait;1112public const CACHE_DRIVERS = [13'redis' => 'Redis (recommended)',14'memcached' => 'Memcached',15'file' => 'Filesystem',16];1718public const SESSION_DRIVERS = [19'redis' => 'Redis (recommended)',20'memcached' => 'Memcached',21'database' => 'MySQL Database',22'file' => 'Filesystem',23'cookie' => 'Cookie',24];2526public const QUEUE_DRIVERS = [27'redis' => 'Redis (recommended)',28'database' => 'MySQL Database',29'sync' => 'Sync',30];3132protected $description = 'Configure basic environment settings for the Panel.';3334protected $signature = 'p:environment:setup35{--new-salt : Whether or not to generate a new salt for Hashids.}36{--author= : The email that services created on this instance should be linked to.}37{--url= : The URL that this Panel is running on.}38{--timezone= : The timezone to use for Panel times.}39{--cache= : The cache driver backend to use.}40{--session= : The session driver backend to use.}41{--queue= : The queue driver backend to use.}42{--redis-host= : Redis host to use for connections.}43{--redis-pass= : Password used to connect to redis.}44{--redis-port= : Port to connect to redis over.}45{--settings-ui= : Enable or disable the settings UI.}46{--telemetry= : Enable or disable anonymous telemetry.}';4748protected array $variables = [];4950/**51* AppSettingsCommand constructor.52*/53public function __construct(private Kernel $console)54{55parent::__construct();56}5758/**59* Handle command execution.60*61* @throws \Pterodactyl\Exceptions\PterodactylException62*/63public function handle(): int64{65if (empty(config('hashids.salt')) || $this->option('new-salt')) {66$this->variables['HASHIDS_SALT'] = str_random(20);67}6869$this->output->comment('Provide the email address that eggs exported by this Panel should be from. This should be a valid email address.');70$this->variables['APP_SERVICE_AUTHOR'] = $this->option('author') ?? $this->ask(71'Egg Author Email',72config('pterodactyl.service.author', '[email protected]')73);7475if (!filter_var($this->variables['APP_SERVICE_AUTHOR'], FILTER_VALIDATE_EMAIL)) {76$this->output->error('The service author email provided is invalid.');7778return 1;79}8081$this->output->comment('The application URL MUST begin with https:// or http:// depending on if you are using SSL or not. If you do not include the scheme your emails and other content will link to the wrong location.');82$this->variables['APP_URL'] = $this->option('url') ?? $this->ask(83'Application URL',84config('app.url', 'https://example.com')85);8687$this->output->comment('The timezone should match one of PHP\'s supported timezones. If you are unsure, please reference https://php.net/manual/en/timezones.php.');88$this->variables['APP_TIMEZONE'] = $this->option('timezone') ?? $this->anticipate(89'Application Timezone',90\DateTimeZone::listIdentifiers(),91config('app.timezone')92);9394$selected = config('cache.default', 'redis');95$this->variables['CACHE_DRIVER'] = $this->option('cache') ?? $this->choice(96'Cache Driver',97self::CACHE_DRIVERS,98array_key_exists($selected, self::CACHE_DRIVERS) ? $selected : null99);100101$selected = config('session.driver', 'redis');102$this->variables['SESSION_DRIVER'] = $this->option('session') ?? $this->choice(103'Session Driver',104self::SESSION_DRIVERS,105array_key_exists($selected, self::SESSION_DRIVERS) ? $selected : null106);107108$selected = config('queue.default', 'redis');109$this->variables['QUEUE_CONNECTION'] = $this->option('queue') ?? $this->choice(110'Queue Driver',111self::QUEUE_DRIVERS,112array_key_exists($selected, self::QUEUE_DRIVERS) ? $selected : null113);114115if (!is_null($this->option('settings-ui'))) {116$this->variables['APP_ENVIRONMENT_ONLY'] = $this->option('settings-ui') == 'true' ? 'false' : 'true';117} else {118$this->variables['APP_ENVIRONMENT_ONLY'] = $this->confirm('Enable UI based settings editor?', true) ? 'false' : 'true';119}120121$this->output->comment('Please reference https://pterodactyl.io/panel/1.0/additional_configuration.html#telemetry for more detailed information regarding telemetry data and collection.');122$this->variables['PTERODACTYL_TELEMETRY_ENABLED'] = $this->option('telemetry') ?? $this->confirm(123'Enable sending anonymous telemetry data?',124config('pterodactyl.telemetry.enabled', true)125) ? 'true' : 'false';126127// Make sure session cookies are set as "secure" when using HTTPS128if (str_starts_with($this->variables['APP_URL'], 'https://')) {129$this->variables['SESSION_SECURE_COOKIE'] = 'true';130}131132$this->checkForRedis();133$this->writeToEnvironment($this->variables);134135$this->info($this->console->output());136137return 0;138}139140/**141* Check if redis is selected, if so, request connection details and verify them.142*/143private function checkForRedis()144{145$items = collect($this->variables)->filter(function ($item) {146return $item === 'redis';147});148149// Redis was not selected, no need to continue.150if (count($items) === 0) {151return;152}153154$this->output->note('You\'ve selected the Redis driver for one or more options, please provide valid connection information below. In most cases you can use the defaults provided unless you have modified your setup.');155$this->variables['REDIS_HOST'] = $this->option('redis-host') ?? $this->ask(156'Redis Host',157config('database.redis.default.host')158);159160$askForRedisPassword = true;161if (!empty(config('database.redis.default.password'))) {162$this->variables['REDIS_PASSWORD'] = config('database.redis.default.password');163$askForRedisPassword = $this->confirm('It seems a password is already defined for Redis, would you like to change it?');164}165166if ($askForRedisPassword) {167$this->output->comment('By default a Redis server instance has no password as it is running locally and inaccessible to the outside world. If this is the case, simply hit enter without entering a value.');168$this->variables['REDIS_PASSWORD'] = $this->option('redis-pass') ?? $this->output->askHidden(169'Redis Password'170);171}172173if (empty($this->variables['REDIS_PASSWORD'])) {174$this->variables['REDIS_PASSWORD'] = 'null';175}176177$this->variables['REDIS_PORT'] = $this->option('redis-port') ?? $this->ask(178'Redis Port',179config('database.redis.default.port')180);181}182}183184185