Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Console/Commands/Environment/AppSettingsCommand.php
7461 views
1
<?php
2
3
namespace Pterodactyl\Console\Commands\Environment;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Contracts\Console\Kernel;
7
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
8
9
class AppSettingsCommand extends Command
10
{
11
use EnvironmentWriterTrait;
12
13
public const CACHE_DRIVERS = [
14
'redis' => 'Redis (recommended)',
15
'memcached' => 'Memcached',
16
'file' => 'Filesystem',
17
];
18
19
public const SESSION_DRIVERS = [
20
'redis' => 'Redis (recommended)',
21
'memcached' => 'Memcached',
22
'database' => 'MySQL Database',
23
'file' => 'Filesystem',
24
'cookie' => 'Cookie',
25
];
26
27
public const QUEUE_DRIVERS = [
28
'redis' => 'Redis (recommended)',
29
'database' => 'MySQL Database',
30
'sync' => 'Sync',
31
];
32
33
protected $description = 'Configure basic environment settings for the Panel.';
34
35
protected $signature = 'p:environment:setup
36
{--new-salt : Whether or not to generate a new salt for Hashids.}
37
{--author= : The email that services created on this instance should be linked to.}
38
{--url= : The URL that this Panel is running on.}
39
{--timezone= : The timezone to use for Panel times.}
40
{--cache= : The cache driver backend to use.}
41
{--session= : The session driver backend to use.}
42
{--queue= : The queue driver backend to use.}
43
{--redis-host= : Redis host to use for connections.}
44
{--redis-pass= : Password used to connect to redis.}
45
{--redis-port= : Port to connect to redis over.}
46
{--settings-ui= : Enable or disable the settings UI.}
47
{--telemetry= : Enable or disable anonymous telemetry.}';
48
49
protected array $variables = [];
50
51
/**
52
* AppSettingsCommand constructor.
53
*/
54
public function __construct(private Kernel $console)
55
{
56
parent::__construct();
57
}
58
59
/**
60
* Handle command execution.
61
*
62
* @throws \Pterodactyl\Exceptions\PterodactylException
63
*/
64
public function handle(): int
65
{
66
if (empty(config('hashids.salt')) || $this->option('new-salt')) {
67
$this->variables['HASHIDS_SALT'] = str_random(20);
68
}
69
70
$this->output->comment('Provide the email address that eggs exported by this Panel should be from. This should be a valid email address.');
71
$this->variables['APP_SERVICE_AUTHOR'] = $this->option('author') ?? $this->ask(
72
'Egg Author Email',
73
config('pterodactyl.service.author', '[email protected]')
74
);
75
76
if (!filter_var($this->variables['APP_SERVICE_AUTHOR'], FILTER_VALIDATE_EMAIL)) {
77
$this->output->error('The service author email provided is invalid.');
78
79
return 1;
80
}
81
82
$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.');
83
$this->variables['APP_URL'] = $this->option('url') ?? $this->ask(
84
'Application URL',
85
config('app.url', 'https://example.com')
86
);
87
88
$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.');
89
$this->variables['APP_TIMEZONE'] = $this->option('timezone') ?? $this->anticipate(
90
'Application Timezone',
91
\DateTimeZone::listIdentifiers(),
92
config('app.timezone')
93
);
94
95
$selected = config('cache.default', 'redis');
96
$this->variables['CACHE_DRIVER'] = $this->option('cache') ?? $this->choice(
97
'Cache Driver',
98
self::CACHE_DRIVERS,
99
array_key_exists($selected, self::CACHE_DRIVERS) ? $selected : null
100
);
101
102
$selected = config('session.driver', 'redis');
103
$this->variables['SESSION_DRIVER'] = $this->option('session') ?? $this->choice(
104
'Session Driver',
105
self::SESSION_DRIVERS,
106
array_key_exists($selected, self::SESSION_DRIVERS) ? $selected : null
107
);
108
109
$selected = config('queue.default', 'redis');
110
$this->variables['QUEUE_CONNECTION'] = $this->option('queue') ?? $this->choice(
111
'Queue Driver',
112
self::QUEUE_DRIVERS,
113
array_key_exists($selected, self::QUEUE_DRIVERS) ? $selected : null
114
);
115
116
if (!is_null($this->option('settings-ui'))) {
117
$this->variables['APP_ENVIRONMENT_ONLY'] = $this->option('settings-ui') == 'true' ? 'false' : 'true';
118
} else {
119
$this->variables['APP_ENVIRONMENT_ONLY'] = $this->confirm('Enable UI based settings editor?', true) ? 'false' : 'true';
120
}
121
122
$this->output->comment('Please reference https://pterodactyl.io/panel/1.0/additional_configuration.html#telemetry for more detailed information regarding telemetry data and collection.');
123
$this->variables['PTERODACTYL_TELEMETRY_ENABLED'] = $this->option('telemetry') ?? $this->confirm(
124
'Enable sending anonymous telemetry data?',
125
config('pterodactyl.telemetry.enabled', true)
126
) ? 'true' : 'false';
127
128
// Make sure session cookies are set as "secure" when using HTTPS
129
if (str_starts_with($this->variables['APP_URL'], 'https://')) {
130
$this->variables['SESSION_SECURE_COOKIE'] = 'true';
131
}
132
133
$this->checkForRedis();
134
$this->writeToEnvironment($this->variables);
135
136
$this->info($this->console->output());
137
138
return 0;
139
}
140
141
/**
142
* Check if redis is selected, if so, request connection details and verify them.
143
*/
144
private function checkForRedis()
145
{
146
$items = collect($this->variables)->filter(function ($item) {
147
return $item === 'redis';
148
});
149
150
// Redis was not selected, no need to continue.
151
if (count($items) === 0) {
152
return;
153
}
154
155
$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.');
156
$this->variables['REDIS_HOST'] = $this->option('redis-host') ?? $this->ask(
157
'Redis Host',
158
config('database.redis.default.host')
159
);
160
161
$askForRedisPassword = true;
162
if (!empty(config('database.redis.default.password'))) {
163
$this->variables['REDIS_PASSWORD'] = config('database.redis.default.password');
164
$askForRedisPassword = $this->confirm('It seems a password is already defined for Redis, would you like to change it?');
165
}
166
167
if ($askForRedisPassword) {
168
$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.');
169
$this->variables['REDIS_PASSWORD'] = $this->option('redis-pass') ?? $this->output->askHidden(
170
'Redis Password'
171
);
172
}
173
174
if (empty($this->variables['REDIS_PASSWORD'])) {
175
$this->variables['REDIS_PASSWORD'] = 'null';
176
}
177
178
$this->variables['REDIS_PORT'] = $this->option('redis-port') ?? $this->ask(
179
'Redis Port',
180
config('database.redis.default.port')
181
);
182
}
183
}
184
185