Skip to content

Commit 4c09f6f

Browse files
authored
Merge branch 'develop' into feature/search-box-fix
2 parents 674628c + a710bdf commit 4c09f6f

File tree

18 files changed

+121
-135
lines changed

18 files changed

+121
-135
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

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ services:
1313
before_install:
1414
- mysql -e 'CREATE DATABASE IF NOT EXISTS travis;'
1515
before_script:
16+
- echo 'opcache.enable_cli=1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
1617
- cp .env.travis .env
17-
- composer install --no-interaction --prefer-dist --no-suggest --verbose
18-
- php artisan migrate --seed -v
18+
- composer install --no-interaction --prefer-dist --no-suggest
19+
- php artisan migrate --seed
1920
script:
2021
- vendor/bin/phpunit --coverage-clover coverage.xml
2122
notifications:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ 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+
* `[beta.2]` — Fixes a bug causing the dropdown menu for a server's egg to display the wrong selected value.
10+
* `[beta.2]` — Fixes a bug that would throw a red page of death when submitting an invalid egg variable value for a server in the Admin CP.
11+
* `[beta.2]` — Someone found a `@todo` that I never `@todid` and thus database hosts could not be created without being linked to a node. This is fixed...
12+
613
## v0.7.0-beta.2 (Derelict Dermodactylus)
714
### Fixed
815
* `[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();

app/Exceptions/DisplayValidationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
namespace Pterodactyl\Exceptions;
1111

12-
class DisplayValidationException extends PterodactylException
12+
class DisplayValidationException extends DisplayException
1313
{
1414
}

app/Http/Controllers/Admin/ServersController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,22 @@ public function viewBuild($server)
319319
/**
320320
* Display startup configuration page for a server.
321321
*
322-
* @param int $server
322+
* @param \Pterodactyl\Models\Server $server
323323
* @return \Illuminate\View\View
324324
*
325325
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
326326
*/
327-
public function viewStartup($server)
327+
public function viewStartup(Server $server)
328328
{
329-
$parameters = $this->repository->getVariablesWithValues($server, true);
329+
$parameters = $this->repository->getVariablesWithValues($server->id, true);
330330
if (! $parameters->server->installed) {
331331
abort(404);
332332
}
333333

334334
$nests = $this->nestRepository->getWithEggs();
335335

336336
Javascript::put([
337+
'server' => $server,
337338
'nests' => $nests->map(function ($item) {
338339
return array_merge($item->toArray(), [
339340
'eggs' => $item->eggs->keyBy('id')->toArray(),

app/Http/Requests/Admin/DatabaseHostFormRequest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class DatabaseHostFormRequest extends AdminFormRequest
1818
*/
1919
public function rules()
2020
{
21+
if (! $this->has('node_id')) {
22+
$this->merge(['node_id' => null]);
23+
}
24+
2125
if ($this->method() !== 'POST') {
2226
return DatabaseHost::getUpdateRulesForId($this->route()->parameter('host')->id);
2327
}

app/Models/DatabaseHost.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,21 @@ class DatabaseHost extends Model implements CleansAttributes, ValidableContract
6363
'host' => 'required',
6464
'port' => 'required',
6565
'username' => 'required',
66-
'node_id' => 'sometimes|required',
66+
'node_id' => 'sometimes',
6767
];
6868

6969
/**
7070
* Validation rules to assign to this model.
7171
*
7272
* @var array
73-
* @todo the node_id field doesn't validate correctly if no node is provided in request
7473
*/
7574
protected static $dataIntegrityRules = [
7675
'name' => 'string|max:255',
7776
'host' => 'ip|unique:database_hosts,host',
7877
'port' => 'numeric|between:1,65535',
7978
'username' => 'string|max:32',
8079
'password' => 'nullable|string',
81-
'node_id' => 'nullable|exists:nodes,id',
80+
'node_id' => 'nullable|integer|exists:nodes,id',
8281
];
8382

8483
/**

app/Services/Servers/StartupModificationService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ public function __construct(
7878
* @param \Pterodactyl\Models\Server $server
7979
* @param array $data
8080
*
81-
* @throws \Pterodactyl\Exceptions\DisplayException
81+
* @throws \Illuminate\Validation\ValidationException
8282
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
8383
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
84+
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
8485
*/
8586
public function handle(Server $server, array $data)
8687
{

app/Services/Servers/VariableValidatorService.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
use Pterodactyl\Models\User;
1313
use Illuminate\Support\Collection;
14+
use Illuminate\Validation\ValidationException;
1415
use Pterodactyl\Traits\Services\HasUserLevels;
15-
use Pterodactyl\Exceptions\DisplayValidationException;
1616
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
1717
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
1818
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
@@ -25,22 +25,22 @@ class VariableValidatorService
2525
/**
2626
* @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface
2727
*/
28-
protected $optionVariableRepository;
28+
private $optionVariableRepository;
2929

3030
/**
3131
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
3232
*/
33-
protected $serverRepository;
33+
private $serverRepository;
3434

3535
/**
3636
* @var \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface
3737
*/
38-
protected $serverVariableRepository;
38+
private $serverVariableRepository;
3939

4040
/**
4141
* @var \Illuminate\Contracts\Validation\Factory
4242
*/
43-
protected $validator;
43+
private $validator;
4444

4545
/**
4646
* VariableValidatorService constructor.
@@ -68,32 +68,32 @@ public function __construct(
6868
* @param int $egg
6969
* @param array $fields
7070
* @return \Illuminate\Support\Collection
71+
* @throws \Illuminate\Validation\ValidationException
7172
*/
7273
public function handle(int $egg, array $fields = []): Collection
7374
{
7475
$variables = $this->optionVariableRepository->findWhere([['egg_id', '=', $egg]]);
76+
$messages = $this->validator->make([], []);
7577

76-
return $variables->map(function ($item) use ($fields) {
78+
$response = $variables->map(function ($item) use ($fields, $messages) {
7779
// Skip doing anything if user is not an admin and
7880
// variable is not user viewable or editable.
7981
if (! $this->isUserLevel(User::USER_LEVEL_ADMIN) && (! $item->user_editable || ! $item->user_viewable)) {
8082
return false;
8183
}
8284

83-
$validator = $this->validator->make([
85+
$v = $this->validator->make([
8486
'variable_value' => array_get($fields, $item->env_variable),
8587
], [
8688
'variable_value' => $item->rules,
89+
], [], [
90+
'variable_value' => trans('validation.internal.variable_value', ['env' => $item->name]),
8791
]);
8892

89-
if ($validator->fails()) {
90-
throw new DisplayValidationException(json_encode(
91-
collect([
92-
'notice' => [
93-
trans('admin/server.exceptions.bad_variable', ['name' => $item->name]),
94-
],
95-
])->merge($validator->errors()->toArray())
96-
));
93+
if ($v->fails()) {
94+
foreach ($v->getMessageBag()->all() as $message) {
95+
$messages->getMessageBag()->add($item->env_variable, $message);
96+
}
9797
}
9898

9999
return (object) [
@@ -104,5 +104,11 @@ public function handle(int $egg, array $fields = []): Collection
104104
})->filter(function ($item) {
105105
return is_object($item);
106106
});
107+
108+
if (! empty($messages->getMessageBag()->all())) {
109+
throw new ValidationException($messages);
110+
}
111+
112+
return $response;
107113
}
108114
}

0 commit comments

Comments
 (0)