Merge branch 'develop' into feature/api-v1
This commit is contained in:
commit
4c57b5e8ee
21 changed files with 125 additions and 136 deletions
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace Pterodactyl\Console\Commands\Environment;
|
||||
|
||||
use DateTimeZone;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
|
||||
|
@ -18,6 +19,25 @@ class AppSettingsCommand extends Command
|
|||
{
|
||||
use EnvironmentWriterTrait;
|
||||
|
||||
const ALLOWED_CACHE_DRIVERS = [
|
||||
'redis' => 'Redis (recommended)',
|
||||
'memcached' => 'Memcached',
|
||||
];
|
||||
|
||||
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',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Console\Kernel
|
||||
*/
|
||||
|
@ -37,11 +57,13 @@ class AppSettingsCommand extends Command
|
|||
* @var string
|
||||
*/
|
||||
protected $signature = 'p:environment:setup
|
||||
{--new-salt : Wether or not to generate a new salt for Hashids.}
|
||||
{--author= : The email that services created on this instance should be linked to.}
|
||||
{--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.}
|
||||
{--queue= : The queue driver backend to use.}
|
||||
{--redis-host= : Redis host to use for connections.}
|
||||
{--redis-pass= : Password used to connect to redis.}
|
||||
{--redis-port= : Port to connect to redis over.}';
|
||||
|
@ -72,7 +94,7 @@ class AppSettingsCommand extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (empty($this->config->get('hashids.salt')) || $this->option('--new-salt')) {
|
||||
if (empty($this->config->get('hashids.salt')) || $this->option('new-salt')) {
|
||||
$this->variables['HASHIDS_SALT'] = str_random(20);
|
||||
}
|
||||
|
||||
|
@ -87,33 +109,31 @@ class AppSettingsCommand extends Command
|
|||
);
|
||||
|
||||
$this->output->comment(trans('command/messages.environment.app.timezone_help'));
|
||||
$this->variables['APP_TIMEZONE'] = $this->option('timezone') ?? $this->ask(
|
||||
trans('command/messages.environment.app.timezone'), $this->config->get('app.timezone')
|
||||
$this->variables['APP_TIMEZONE'] = $this->option('timezone') ?? $this->anticipate(
|
||||
trans('command/messages.environment.app.timezone'),
|
||||
DateTimeZone::listIdentifiers(DateTimeZone::ALL),
|
||||
$this->config->get('app.timezone')
|
||||
);
|
||||
|
||||
$selected = $this->config->get('cache.default', 'redis');
|
||||
$this->variables['CACHE_DRIVER'] = $this->option('cache') ?? $this->choice(
|
||||
trans('command/messages.environment.app.cache_driver'), [
|
||||
'redis' => 'Redis (recommended)',
|
||||
'memcached' => 'Memcached',
|
||||
], $this->config->get('cache.default', 'redis')
|
||||
trans('command/messages.environment.app.cache_driver'),
|
||||
self::ALLOWED_CACHE_DRIVERS,
|
||||
array_key_exists($selected, self::ALLOWED_CACHE_DRIVERS) ? $selected : null
|
||||
);
|
||||
|
||||
$selected = $this->config->get('session.driver', 'redis');
|
||||
$this->variables['SESSION_DRIVER'] = $this->option('session') ?? $this->choice(
|
||||
trans('command/messages.environment.app.session_driver'), [
|
||||
'redis' => 'Redis (recommended)',
|
||||
'memcached' => 'Memcached',
|
||||
'database' => 'MySQL Database',
|
||||
'file' => 'Filesystem',
|
||||
'cookie' => 'Cookie',
|
||||
], $this->config->get('session.driver', 'redis')
|
||||
trans('command/messages.environment.app.session_driver'),
|
||||
self::ALLOWED_SESSION_DRIVERS,
|
||||
array_key_exists($selected, self::ALLOWED_SESSION_DRIVERS) ? $selected : null
|
||||
);
|
||||
|
||||
$this->variables['QUEUE_DRIVER'] = $this->option('session') ?? $this->choice(
|
||||
trans('command/messages.environment.app.session_driver'), [
|
||||
'redis' => 'Redis (recommended)',
|
||||
'database' => 'MySQL Database',
|
||||
'sync' => 'Sync',
|
||||
], $this->config->get('queue.driver', 'redis')
|
||||
$selected = $this->config->get('queue.default', 'redis');
|
||||
$this->variables['QUEUE_DRIVER'] = $this->option('queue') ?? $this->choice(
|
||||
trans('command/messages.environment.app.queue_driver'),
|
||||
self::ALLOWED_QUEUE_DRIVERS,
|
||||
array_key_exists($selected, self::ALLOWED_QUEUE_DRIVERS) ? $selected : null
|
||||
);
|
||||
|
||||
$this->checkForRedis();
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
|
||||
namespace Pterodactyl\Exceptions;
|
||||
|
||||
class DisplayValidationException extends PterodactylException
|
||||
class DisplayValidationException extends DisplayException
|
||||
{
|
||||
}
|
||||
|
|
|
@ -319,14 +319,14 @@ class ServersController extends Controller
|
|||
/**
|
||||
* Display startup configuration page for a server.
|
||||
*
|
||||
* @param int $server
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function viewStartup($server)
|
||||
public function viewStartup(Server $server)
|
||||
{
|
||||
$parameters = $this->repository->getVariablesWithValues($server, true);
|
||||
$parameters = $this->repository->getVariablesWithValues($server->id, true);
|
||||
if (! $parameters->server->installed) {
|
||||
abort(404);
|
||||
}
|
||||
|
@ -334,6 +334,7 @@ class ServersController extends Controller
|
|||
$nests = $this->nestRepository->getWithEggs();
|
||||
|
||||
Javascript::put([
|
||||
'server' => $server,
|
||||
'nests' => $nests->map(function ($item) {
|
||||
return array_merge($item->toArray(), [
|
||||
'eggs' => $item->eggs->keyBy('id')->toArray(),
|
||||
|
|
|
@ -38,6 +38,9 @@ class ConsoleController extends Controller
|
|||
$server = $request->attributes->get('server');
|
||||
|
||||
$this->setRequest($request)->injectJavascript([
|
||||
'server' => [
|
||||
'cpu' => $server->cpu,
|
||||
],
|
||||
'meta' => [
|
||||
'saveFile' => route('server.files.save', $server->uuidShort),
|
||||
'csrfToken' => csrf_token(),
|
||||
|
|
|
@ -18,6 +18,10 @@ class DatabaseHostFormRequest extends AdminFormRequest
|
|||
*/
|
||||
public function rules()
|
||||
{
|
||||
if (! $this->has('node_id')) {
|
||||
$this->merge(['node_id' => null]);
|
||||
}
|
||||
|
||||
if ($this->method() !== 'POST') {
|
||||
return DatabaseHost::getUpdateRulesForId($this->route()->parameter('host')->id);
|
||||
}
|
||||
|
|
|
@ -63,14 +63,13 @@ class DatabaseHost extends Model implements CleansAttributes, ValidableContract
|
|||
'host' => 'required',
|
||||
'port' => 'required',
|
||||
'username' => 'required',
|
||||
'node_id' => 'sometimes|required',
|
||||
'node_id' => 'sometimes',
|
||||
];
|
||||
|
||||
/**
|
||||
* Validation rules to assign to this model.
|
||||
*
|
||||
* @var array
|
||||
* @todo the node_id field doesn't validate correctly if no node is provided in request
|
||||
*/
|
||||
protected static $dataIntegrityRules = [
|
||||
'name' => 'string|max:255',
|
||||
|
@ -78,7 +77,7 @@ class DatabaseHost extends Model implements CleansAttributes, ValidableContract
|
|||
'port' => 'numeric|between:1,65535',
|
||||
'username' => 'string|max:32',
|
||||
'password' => 'nullable|string',
|
||||
'node_id' => 'nullable|exists:nodes,id',
|
||||
'node_id' => 'nullable|integer|exists:nodes,id',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -78,9 +78,10 @@ class StartupModificationService
|
|||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param array $data
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function handle(Server $server, array $data)
|
||||
{
|
||||
|
|
|
@ -11,8 +11,8 @@ namespace Pterodactyl\Services\Servers;
|
|||
|
||||
use Pterodactyl\Models\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Pterodactyl\Traits\Services\HasUserLevels;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
|
||||
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
|
||||
|
@ -25,22 +25,22 @@ class VariableValidatorService
|
|||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface
|
||||
*/
|
||||
protected $optionVariableRepository;
|
||||
private $optionVariableRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
*/
|
||||
protected $serverRepository;
|
||||
private $serverRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface
|
||||
*/
|
||||
protected $serverVariableRepository;
|
||||
private $serverVariableRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Validation\Factory
|
||||
*/
|
||||
protected $validator;
|
||||
private $validator;
|
||||
|
||||
/**
|
||||
* VariableValidatorService constructor.
|
||||
|
@ -68,32 +68,32 @@ class VariableValidatorService
|
|||
* @param int $egg
|
||||
* @param array $fields
|
||||
* @return \Illuminate\Support\Collection
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function handle(int $egg, array $fields = []): Collection
|
||||
{
|
||||
$variables = $this->optionVariableRepository->findWhere([['egg_id', '=', $egg]]);
|
||||
$messages = $this->validator->make([], []);
|
||||
|
||||
return $variables->map(function ($item) use ($fields) {
|
||||
$response = $variables->map(function ($item) use ($fields, $messages) {
|
||||
// Skip doing anything if user is not an admin and
|
||||
// variable is not user viewable or editable.
|
||||
if (! $this->isUserLevel(User::USER_LEVEL_ADMIN) && (! $item->user_editable || ! $item->user_viewable)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$validator = $this->validator->make([
|
||||
$v = $this->validator->make([
|
||||
'variable_value' => array_get($fields, $item->env_variable),
|
||||
], [
|
||||
'variable_value' => $item->rules,
|
||||
], [], [
|
||||
'variable_value' => trans('validation.internal.variable_value', ['env' => $item->name]),
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException(json_encode(
|
||||
collect([
|
||||
'notice' => [
|
||||
trans('admin/server.exceptions.bad_variable', ['name' => $item->name]),
|
||||
],
|
||||
])->merge($validator->errors()->toArray())
|
||||
));
|
||||
if ($v->fails()) {
|
||||
foreach ($v->getMessageBag()->all() as $message) {
|
||||
$messages->getMessageBag()->add($item->env_variable, $message);
|
||||
}
|
||||
}
|
||||
|
||||
return (object) [
|
||||
|
@ -104,5 +104,11 @@ class VariableValidatorService
|
|||
})->filter(function ($item) {
|
||||
return is_object($item);
|
||||
});
|
||||
|
||||
if (! empty($messages->getMessageBag()->all())) {
|
||||
throw new ValidationException($messages);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ trait JavascriptInjection
|
|||
$server = $request->attributes->get('server');
|
||||
$token = $request->attributes->get('server_token');
|
||||
|
||||
$response = array_merge([
|
||||
$response = array_merge_recursive([
|
||||
'server' => [
|
||||
'uuid' => $server->uuid,
|
||||
'uuidShort' => $server->uuidShort,
|
||||
|
|
Reference in a new issue