Skip to content

Commit d4758ef

Browse files
committed
Implement fix for console spam when using invalid environment variable values
1 parent 1fcad8d commit d4758ef

File tree

4 files changed

+51
-26
lines changed

4 files changed

+51
-26
lines changed

.env.example

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ APP_ENV=production
22
APP_DEBUG=false
33
APP_KEY=SomeRandomString3232RandomString
44
APP_THEME=pterodactyl
5-
APP_TIMEZONE=UTC
5+
APP_TIMEZONE=America/New_York
66
APP_CLEAR_TASKLOG=720
77
APP_DELETE_MINUTES=10
8-
APP_URL=http://yoursite.com/
8+
APP_URL=
99

1010
DB_HOST=127.0.0.1
1111
DB_PORT=3306
1212
DB_DATABASE=panel
1313
DB_USERNAME=pterodactyl
1414
DB_PASSWORD=
1515

16-
CACHE_DRIVER=redis
17-
SESSION_DRIVER=database
16+
CACHE_DRIVER=
17+
SESSION_DRIVER=
1818

1919
HASHIDS_SALT=
2020
HASHIDS_LENGTH=8
@@ -25,9 +25,9 @@ MAIL_PORT=2525
2525
MAIL_USERNAME=
2626
MAIL_PASSWORD=
2727
MAIL_ENCRYPTION=tls
28-
MAIL_FROM=you@example.com
28+
MAIL_FROM=no-reply@example.com
2929

30-
QUEUE_DRIVER=database
30+
QUEUE_DRIVER=
3131
QUEUE_HIGH=high
3232
QUEUE_STANDARD=standard
3333
QUEUE_LOW=low

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ This file is a running track of new features and fixes to each version of the pa
33

44
This project follows [Semantic Versioning](http://semver.org) guidelines.
55

6+
## v0.7.0-beta.3 (Derelict Dermodactylus)
7+
### Fixed
8+
* `[beta.2]` — Fixes a bug that would cause an endless exception message stream in the console when attemping to setup environment settings in certain instances.
9+
610
## v0.7.0-beta.2 (Derelict Dermodactylus)
711
### Fixed
812
* `[beta.1]` — Fixes a CORS header issue due to a wrong API endpoint being provided in the administrative node listing.

app/Console/Commands/Environment/AppSettingsCommand.php

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Pterodactyl\Console\Commands\Environment;
1111

12+
use DateTimeZone;
1213
use Illuminate\Console\Command;
1314
use Illuminate\Contracts\Console\Kernel;
1415
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
@@ -18,6 +19,25 @@ class AppSettingsCommand extends Command
1819
{
1920
use EnvironmentWriterTrait;
2021

22+
const ALLOWED_CACHE_DRIVERS = [
23+
'redis' => 'Redis (recommended)',
24+
'memcached' => 'Memcached'
25+
];
26+
27+
const ALLOWED_SESSION_DRIVERS = [
28+
'redis' => 'Redis (recommended)',
29+
'memcached' => 'Memcached',
30+
'database' => 'MySQL Database',
31+
'file' => 'Filesystem',
32+
'cookie' => 'Cookie',
33+
];
34+
35+
const ALLOWED_QUEUE_DRIVERS = [
36+
'redis' => 'Redis (recommended)',
37+
'database' => 'MySQL Database',
38+
'sync' => 'Sync',
39+
];
40+
2141
/**
2242
* @var \Illuminate\Contracts\Console\Kernel
2343
*/
@@ -37,11 +57,13 @@ class AppSettingsCommand extends Command
3757
* @var string
3858
*/
3959
protected $signature = 'p:environment:setup
60+
{--new-salt : Wether or not to generate a new salt for Hashids.}
4061
{--author= : The email that services created on this instance should be linked to.}
4162
{--url= : The URL that this Panel is running on.}
4263
{--timezone= : The timezone to use for Panel times.}
4364
{--cache= : The cache driver backend to use.}
4465
{--session= : The session driver backend to use.}
66+
{--queue= : The queue driver backend to use.}
4567
{--redis-host= : Redis host to use for connections.}
4668
{--redis-pass= : Password used to connect to redis.}
4769
{--redis-port= : Port to connect to redis over.}';
@@ -72,7 +94,7 @@ public function __construct(ConfigRepository $config, Kernel $command)
7294
*/
7395
public function handle()
7496
{
75-
if (empty($this->config->get('hashids.salt')) || $this->option('--new-salt')) {
97+
if (empty($this->config->get('hashids.salt')) || $this->option('new-salt')) {
7698
$this->variables['HASHIDS_SALT'] = str_random(20);
7799
}
78100

@@ -87,33 +109,31 @@ public function handle()
87109
);
88110

89111
$this->output->comment(trans('command/messages.environment.app.timezone_help'));
90-
$this->variables['APP_TIMEZONE'] = $this->option('timezone') ?? $this->ask(
91-
trans('command/messages.environment.app.timezone'), $this->config->get('app.timezone')
112+
$this->variables['APP_TIMEZONE'] = $this->option('timezone') ?? $this->anticipate(
113+
trans('command/messages.environment.app.timezone'),
114+
DateTimeZone::listIdentifiers(DateTimeZone::ALL),
115+
$this->config->get('app.timezone')
92116
);
93117

118+
$selected = $this->config->get('cache.default', 'redis');
94119
$this->variables['CACHE_DRIVER'] = $this->option('cache') ?? $this->choice(
95-
trans('command/messages.environment.app.cache_driver'), [
96-
'redis' => 'Redis (recommended)',
97-
'memcached' => 'Memcached',
98-
], $this->config->get('cache.default', 'redis')
120+
trans('command/messages.environment.app.cache_driver'),
121+
self::ALLOWED_CACHE_DRIVERS,
122+
array_key_exists($selected, self::ALLOWED_CACHE_DRIVERS) ? $selected : null
99123
);
100124

125+
$selected = $this->config->get('session.driver', 'redis');
101126
$this->variables['SESSION_DRIVER'] = $this->option('session') ?? $this->choice(
102-
trans('command/messages.environment.app.session_driver'), [
103-
'redis' => 'Redis (recommended)',
104-
'memcached' => 'Memcached',
105-
'database' => 'MySQL Database',
106-
'file' => 'Filesystem',
107-
'cookie' => 'Cookie',
108-
], $this->config->get('session.driver', 'redis')
127+
trans('command/messages.environment.app.session_driver'),
128+
self::ALLOWED_SESSION_DRIVERS,
129+
array_key_exists($selected, self::ALLOWED_SESSION_DRIVERS) ? $selected : null
109130
);
110131

111-
$this->variables['QUEUE_DRIVER'] = $this->option('session') ?? $this->choice(
112-
trans('command/messages.environment.app.session_driver'), [
113-
'redis' => 'Redis (recommended)',
114-
'database' => 'MySQL Database',
115-
'sync' => 'Sync',
116-
], $this->config->get('queue.driver', 'redis')
132+
$selected = $this->config->get('queue.default', 'redis');
133+
$this->variables['QUEUE_DRIVER'] = $this->option('queue') ?? $this->choice(
134+
trans('command/messages.environment.app.queue_driver'),
135+
self::ALLOWED_QUEUE_DRIVERS,
136+
array_key_exists($selected, self::ALLOWED_QUEUE_DRIVERS) ? $selected : null
117137
);
118138

119139
$this->checkForRedis();

resources/lang/en/command/messages.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
'timezone' => 'Application Timezone',
8383
'cache_driver' => 'Cache Driver',
8484
'session_driver' => 'Session Driver',
85+
'queue_driver' => 'Queue Driver',
8586
'using_redis' => '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.',
8687
'redis_host' => 'Redis Host',
8788
'redis_password' => 'Redis Password',

0 commit comments

Comments
 (0)