Merge branch 'develop' into feature/api-v1
This commit is contained in:
commit
46d7ba7585
32 changed files with 247 additions and 201 deletions
|
@ -66,7 +66,8 @@ class AppSettingsCommand extends Command
|
|||
{--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.}';
|
||||
{--redis-port= : Port to connect to redis over.}
|
||||
{--disable-settings-ui}';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
@ -136,6 +137,12 @@ class AppSettingsCommand extends Command
|
|||
array_key_exists($selected, self::ALLOWED_QUEUE_DRIVERS) ? $selected : null
|
||||
);
|
||||
|
||||
if ($this->option('disable-settings-ui')) {
|
||||
$this->variables['APP_ENVIRONMENT_ONLY'] = 'true';
|
||||
} else {
|
||||
$this->variables['APP_ENVIRONMENT_ONLY'] = $this->confirm(trans('command/messages.environment.app.settings'), true) ? 'false' : 'true';
|
||||
}
|
||||
|
||||
$this->checkForRedis();
|
||||
$this->writeToEnvironment($this->variables);
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ class DisplayException extends PterodactylException
|
|||
if ($request->expectsJson()) {
|
||||
return response()->json(Handler::convertToArray($this, [
|
||||
'detail' => $this->getMessage(),
|
||||
]), 500);
|
||||
]), method_exists($this, 'getStatusCode') ? $this->getStatusCode() : 500);
|
||||
}
|
||||
|
||||
app()->make(AlertsMessageBag::class)->danger($this->getMessage())->flash();
|
||||
|
|
|
@ -7,18 +7,38 @@ use Pterodactyl\Exceptions\DisplayException;
|
|||
|
||||
class DaemonConnectionException extends DisplayException
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $statusCode = 500;
|
||||
|
||||
/**
|
||||
* Throw a displayable exception caused by a daemon connection error.
|
||||
*
|
||||
* @param \GuzzleHttp\Exception\GuzzleException $previous
|
||||
* @param bool $useStatusCode
|
||||
*/
|
||||
public function __construct(GuzzleException $previous)
|
||||
public function __construct(GuzzleException $previous, bool $useStatusCode = false)
|
||||
{
|
||||
/** @var \GuzzleHttp\Psr7\Response|null $response */
|
||||
$response = method_exists($previous, 'getResponse') ? $previous->getResponse() : null;
|
||||
|
||||
if ($useStatusCode) {
|
||||
$this->statusCode = is_null($response) ? 500 : $response->getStatusCode();
|
||||
}
|
||||
|
||||
parent::__construct(trans('admin/server.exceptions.daemon_exception', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]), $previous, DisplayException::LEVEL_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTTP status code for this exception.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use Pterodactyl\Exceptions\DisplayException;
|
|||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Translation\Translator;
|
||||
use Pterodactyl\Services\Users\UserUpdateService;
|
||||
use Pterodactyl\Traits\Helpers\AvailableLanguages;
|
||||
use Pterodactyl\Services\Users\UserCreationService;
|
||||
use Pterodactyl\Services\Users\UserDeletionService;
|
||||
use Pterodactyl\Http\Requests\Admin\UserFormRequest;
|
||||
|
@ -16,6 +17,8 @@ use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
|||
|
||||
class UserController extends Controller
|
||||
{
|
||||
use AvailableLanguages;
|
||||
|
||||
/**
|
||||
* @var \Prologue\Alerts\AlertsMessageBag
|
||||
*/
|
||||
|
@ -92,7 +95,9 @@ class UserController extends Controller
|
|||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('admin.users.new');
|
||||
return view('admin.users.new', [
|
||||
'languages' => $this->getAvailableLanguages(true),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,7 +108,10 @@ class UserController extends Controller
|
|||
*/
|
||||
public function view(User $user)
|
||||
{
|
||||
return view('admin.users.view', ['user' => $user]);
|
||||
return view('admin.users.view', [
|
||||
'user' => $user,
|
||||
'languages' => $this->getAvailableLanguages(true),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Admin;
|
||||
|
||||
|
@ -39,11 +32,11 @@ abstract class AdminFormRequest extends FormRequest
|
|||
* Return only the fields that we are interested in from the request.
|
||||
* This will include empty fields as a null value.
|
||||
*
|
||||
* @param array $only
|
||||
* @param array|null $only
|
||||
* @return array
|
||||
*/
|
||||
public function normalize($only = [])
|
||||
public function normalize(array $only = null)
|
||||
{
|
||||
return $this->all(empty($only) ? array_keys($this->rules()) : $only);
|
||||
return $this->only($only ?? array_keys($this->rules()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,12 +22,16 @@ class UserFormRequest extends AdminFormRequest
|
|||
return User::getCreateRules();
|
||||
}
|
||||
|
||||
public function normalize($only = [])
|
||||
/**
|
||||
* @param array|null $only
|
||||
* @return array
|
||||
*/
|
||||
public function normalize(array $only = null)
|
||||
{
|
||||
if ($this->method === 'PATCH') {
|
||||
return array_merge(
|
||||
$this->all(['password']),
|
||||
$this->only(['email', 'username', 'name_first', 'name_last', 'root_admin', 'ignore_connection_error'])
|
||||
$this->only(['email', 'username', 'name_first', 'name_last', 'root_admin', 'language', 'ignore_connection_error'])
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
|
@ -127,6 +120,8 @@ class User extends Model implements
|
|||
'name_first' => 'required',
|
||||
'name_last' => 'required',
|
||||
'password' => 'sometimes',
|
||||
'language' => 'sometimes',
|
||||
'use_totp' => 'sometimes',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,27 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Observers;
|
||||
|
||||
use Pterodactyl\Events;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Services\Components\UuidService;
|
||||
|
||||
class UserObserver
|
||||
{
|
||||
protected $uuid;
|
||||
|
||||
public function __construct(UuidService $uuid)
|
||||
{
|
||||
$this->uuid = $uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to the User creating event.
|
||||
*
|
||||
|
@ -29,8 +16,6 @@ class UserObserver
|
|||
*/
|
||||
public function creating(User $user)
|
||||
{
|
||||
$user->uuid = $this->uuid->generate('users', 'uuid');
|
||||
|
||||
event(new Events\User\Creating($user));
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,18 @@ class AppServiceProvider extends ServiceProvider
|
|||
View::share('appIsGit', $this->versionData()['is_git'] ?? false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register application service providers.
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Only load the settings service provider if the environment
|
||||
// is configured to allow it.
|
||||
if (! config('pterodactyl.load_environment_only', false) && $this->app->environment() !== 'testing') {
|
||||
$this->app->register(SettingsServiceProvider::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return version information for the footer.
|
||||
*
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Providers;
|
||||
|
||||
use Illuminate\Contracts\Logging\Log;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
|
@ -60,23 +62,26 @@ class SettingsServiceProvider extends ServiceProvider
|
|||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
|
||||
* @param \Illuminate\Contracts\Logging\Log $log
|
||||
* @param \Pterodactyl\Contracts\Repository\SettingsRepositoryInterface $settings
|
||||
*/
|
||||
public function boot(ConfigRepository $config, Encrypter $encrypter, SettingsRepositoryInterface $settings)
|
||||
public function boot(ConfigRepository $config, Encrypter $encrypter, Log $log, SettingsRepositoryInterface $settings)
|
||||
{
|
||||
if ($config->get('pterodactyl.load_environment_only', false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only set the email driver settings from the database if we
|
||||
// are configured using SMTP as the driver.
|
||||
if ($config->get('mail.driver') === 'smtp') {
|
||||
$this->keys = array_merge($this->keys, $this->emailKeys);
|
||||
}
|
||||
|
||||
$values = $settings->all()->mapWithKeys(function ($setting) {
|
||||
return [$setting->key => $setting->value];
|
||||
})->toArray();
|
||||
try {
|
||||
$values = $settings->all()->mapWithKeys(function ($setting) {
|
||||
return [$setting->key => $setting->value];
|
||||
})->toArray();
|
||||
} catch (QueryException $exception) {
|
||||
$log->notice('A query exception was encountered while trying to load settings from the database.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->keys as $key) {
|
||||
$value = array_get($values, 'settings::' . $key, $config->get(str_replace(':', '.', $key)));
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Components;
|
||||
|
||||
use DB;
|
||||
use Uuid;
|
||||
|
||||
class UuidService
|
||||
{
|
||||
/**
|
||||
* Generate a unique UUID validating against specified table and column.
|
||||
* Defaults to `users.uuid`.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $field
|
||||
* @param int $type
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
public function generate($table = 'users', $field = 'uuid', $type = 4)
|
||||
{
|
||||
$return = false;
|
||||
do {
|
||||
$uuid = Uuid::generate($type);
|
||||
if (! DB::table($table)->where($field, $uuid)->exists()) {
|
||||
$return = $uuid;
|
||||
}
|
||||
} while (! $return);
|
||||
|
||||
return (string) $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a ShortUUID code which is 8 characters long and is used for identifying servers in the system.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $field
|
||||
* @param null|string $attachedUuid
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
public function generateShort($table = 'servers', $field = 'uuidShort', $attachedUuid = null)
|
||||
{
|
||||
$return = false;
|
||||
do {
|
||||
$short = (is_null($attachedUuid)) ? substr(Uuid::generate(4), 0, 8) : substr($attachedUuid, 0, 8);
|
||||
$attachedUuid = null;
|
||||
|
||||
if (! DB::table($table)->where($field, $short)->exists()) {
|
||||
$return = $short;
|
||||
}
|
||||
} while (! $return);
|
||||
|
||||
return (string) $return;
|
||||
}
|
||||
}
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Eggs\Variables;
|
||||
|
||||
|
@ -49,7 +42,7 @@ class VariableCreationService
|
|||
));
|
||||
}
|
||||
|
||||
$options = array_get($data, 'options', []);
|
||||
$options = array_get($data, 'options') ?? [];
|
||||
|
||||
return $this->repository->create(array_merge($data, [
|
||||
'egg_id' => $egg,
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Eggs\Variables;
|
||||
|
||||
|
@ -69,7 +62,7 @@ class VariableUpdateService
|
|||
}
|
||||
}
|
||||
|
||||
$options = array_get($data, 'options', []);
|
||||
$options = array_get($data, 'options') ?? [];
|
||||
|
||||
return $this->repository->withoutFresh()->update($variable->id, array_merge($data, [
|
||||
'user_viewable' => in_array('user_viewable', $options),
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace Pterodactyl\Services\Users;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
@ -96,7 +97,10 @@ class UserCreationService
|
|||
$token = $this->passwordService->handle($data['email']);
|
||||
}
|
||||
|
||||
$user = $this->repository->create($data);
|
||||
$user = $this->repository->create(array_merge($data, [
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
]));
|
||||
|
||||
$this->connection->commit();
|
||||
|
||||
// @todo fire event, handle notification there
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue