diff --git a/CHANGELOG.md b/CHANGELOG.md index fa25d0db..a623e9d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * `[beta.3]` — Fixes an edge case caused by the Laravel 5.5 upgrade that would try to perform an in_array check aganist a null value. * `[beta.3]` — Fixes a bug that would cause an error when attempting to create a new user on the Panel. * `[beta.3]` — Fixes error handling of the settings service provider when no migrations have been run. +* `[beta.3]` — Fixes validation error when trying to use 'None' as the 'Copy Script From' option for an egg script. +* Fixes a design bug in the database that prevented the storage of negative numbers, thus preventing a server from being assigned unlimited swap. + +### Added +* Nest and Egg listings now show the associated ID in order to make API requests easier. ## v0.7.0-beta.3 (Derelict Dermodactylus) ### Fixed diff --git a/app/Http/Controllers/Server/Files/FileActionsController.php b/app/Http/Controllers/Server/Files/FileActionsController.php index 9c5b77ea..08e6fa88 100644 --- a/app/Http/Controllers/Server/Files/FileActionsController.php +++ b/app/Http/Controllers/Server/Files/FileActionsController.php @@ -95,11 +95,10 @@ class FileActionsController extends Controller * @param string $file * @return \Illuminate\View\View * - * @throws \Illuminate\Auth\Access\AuthorizationException - * @throws \Pterodactyl\Exceptions\DisplayException + * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ - public function update(UpdateFileContentsFormRequest $request, string $uuid, string $file): View + public function view(UpdateFileContentsFormRequest $request, string $uuid, string $file): View { $server = $request->attributes->get('server'); diff --git a/app/Http/Controllers/Server/Files/RemoteRequestController.php b/app/Http/Controllers/Server/Files/RemoteRequestController.php index c087a555..e5ec8253 100644 --- a/app/Http/Controllers/Server/Files/RemoteRequestController.php +++ b/app/Http/Controllers/Server/Files/RemoteRequestController.php @@ -101,7 +101,7 @@ class RemoteRequestController extends Controller $this->repository->setNode($server->node_id) ->setAccessServer($server->uuid) ->setAccessToken($request->attributes->get('server_token')) - ->putContent($request->input('file'), $request->input('contents')); + ->putContent($request->input('file'), $request->input('contents') ?? ''); return response('', 204); } catch (RequestException $exception) { diff --git a/app/Http/Requests/Admin/UserFormRequest.php b/app/Http/Requests/Admin/UserFormRequest.php index ab760a7f..c6a35839 100644 --- a/app/Http/Requests/Admin/UserFormRequest.php +++ b/app/Http/Requests/Admin/UserFormRequest.php @@ -7,34 +7,21 @@ use Pterodactyl\Models\User; class UserFormRequest extends AdminFormRequest { /** - * {@inheritdoc} + * Rules to apply to requests for updating or creating a user + * in the Admin CP. */ public function rules() { + $rules = collect(User::getCreateRules()); if ($this->method() === 'PATCH') { - $rules = User::getUpdateRulesForId($this->route()->parameter('user')->id); - - return array_merge($rules, [ - 'ignore_connection_error' => 'sometimes|nullable|boolean', + $rules = collect(User::getUpdateRulesForId($this->route()->parameter('user')->id))->merge([ + 'ignore_connection_error' => ['sometimes', 'nullable', 'boolean'], ]); } - return User::getCreateRules(); - } - - /** - * @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', 'language', 'ignore_connection_error']) - ); - } - - return parent::normalize(); + return $rules->only([ + 'email', 'username', 'name_first', 'name_last', 'password', + 'language', 'ignore_connection_error', 'root_admin', + ])->toArray(); } } diff --git a/app/Http/Requests/Server/UpdateFileContentsFormRequest.php b/app/Http/Requests/Server/UpdateFileContentsFormRequest.php index 051e78db..d2337ba6 100644 --- a/app/Http/Requests/Server/UpdateFileContentsFormRequest.php +++ b/app/Http/Requests/Server/UpdateFileContentsFormRequest.php @@ -12,6 +12,7 @@ namespace Pterodactyl\Http\Requests\Server; use GuzzleHttp\Exception\RequestException; use Illuminate\Contracts\Config\Repository; use Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface; use Pterodactyl\Exceptions\Http\Server\FileTypeNotEditableException; use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; @@ -80,7 +81,12 @@ class UpdateFileContentsFormRequest extends ServerFormRequest ->setAccessToken($token) ->getFileStat($this->route()->parameter('file')); } catch (RequestException $exception) { - throw new DaemonConnectionException($exception); + switch ($exception->getCode()) { + case 404: + throw new NotFoundHttpException; + default: + throw new DaemonConnectionException($exception); + } } if (! $stats->file || ! in_array($stats->mime, $config->get('pterodactyl.files.editable'))) { diff --git a/app/Models/Server.php b/app/Models/Server.php index 04ac19e4..6b5af511 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -76,7 +76,7 @@ class Server extends Model implements CleansAttributes, ValidableContract 'owner_id' => 'exists:users,id', 'name' => 'regex:/^([\w .-]{1,200})$/', 'node_id' => 'exists:nodes,id', - 'description' => 'nullable|string', + 'description' => 'string', 'memory' => 'numeric|min:0', 'swap' => 'numeric|min:-1', 'io' => 'numeric|between:10,1000', diff --git a/app/Models/User.php b/app/Models/User.php index a7492431..7d064424 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -115,6 +115,7 @@ class User extends Model implements * @var array */ protected static $applicationRules = [ + 'uuid' => 'required', 'email' => 'required', 'username' => 'required', 'name_first' => 'required', @@ -130,6 +131,7 @@ class User extends Model implements * @var array */ protected static $dataIntegrityRules = [ + 'uuid' => 'string|size:36|unique:users,uuid', 'email' => 'email|unique:users,email', 'username' => 'alpha_dash|between:1,255|unique:users,username', 'name_first' => 'string|between:1,255', diff --git a/app/Notifications/AccountCreated.php b/app/Notifications/AccountCreated.php index d83ee3fc..8312c3bd 100644 --- a/app/Notifications/AccountCreated.php +++ b/app/Notifications/AccountCreated.php @@ -1,14 +1,8 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Notifications; +use Pterodactyl\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; @@ -19,7 +13,15 @@ class AccountCreated extends Notification implements ShouldQueue use Queueable; /** - * The password reset token to send. + * The authentication token to be used for the user to set their + * password for the first time. + * + * @var string|null + */ + public $token; + + /** + * The user model for the created user. * * @var object */ @@ -28,11 +30,13 @@ class AccountCreated extends Notification implements ShouldQueue /** * Create a new notification instance. * - * @param aray $user + * @param \Pterodactyl\Models\User $user + * @param string|null $token */ - public function __construct(array $user) + public function __construct(User $user, string $token = null) { - $this->user = (object) $user; + $this->token = $token; + $this->user = $user; } /** @@ -56,12 +60,12 @@ class AccountCreated extends Notification implements ShouldQueue { $message = (new MailMessage) ->greeting('Hello ' . $this->user->name . '!') - ->line('You are recieving this email because an account has been created for you on Pterodactyl Panel.') + ->line('You are recieving this email because an account has been created for you on ' . config('app.name') . '.') ->line('Username: ' . $this->user->username) - ->line('Email: ' . $notifiable->email); + ->line('Email: ' . $this->user->email); - if (! is_null($this->user->token)) { - return $message->action('Setup Your Account', url('/auth/password/reset/' . $this->user->token . '?email=' . $notifiable->email)); + if (! is_null($this->token)) { + return $message->action('Setup Your Account', url('/auth/password/reset/' . $this->token . '?email=' . $this->user->email)); } return $message; diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index bc4cd533..9aa1fa4c 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Services\Servers; @@ -113,6 +106,7 @@ class BuildModificationService * * @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function handle($server, array $data) { @@ -138,11 +132,11 @@ class BuildModificationService } $server = $this->repository->update($server->id, [ - 'memory' => array_get($data, 'memory', $server->memory), - 'swap' => array_get($data, 'swap', $server->swap), - 'io' => array_get($data, 'io', $server->io), - 'cpu' => array_get($data, 'cpu', $server->cpu), - 'disk' => array_get($data, 'disk', $server->disk), + 'memory' => (int) array_get($data, 'memory', $server->memory), + 'swap' => (int) array_get($data, 'swap', $server->swap), + 'io' => (int) array_get($data, 'io', $server->io), + 'cpu' => (int) array_get($data, 'cpu', $server->cpu), + 'disk' => (int) array_get($data, 'disk', $server->disk), 'allocation_id' => array_get($data, 'allocation_id', $server->allocation_id), ]); diff --git a/app/Services/Servers/DetailsModificationService.php b/app/Services/Servers/DetailsModificationService.php index 5149a886..d18bccd7 100644 --- a/app/Services/Servers/DetailsModificationService.php +++ b/app/Services/Servers/DetailsModificationService.php @@ -95,9 +95,9 @@ class DetailsModificationService $this->connection->beginTransaction(); $this->repository->withoutFresh()->update($server->id, [ - 'owner_id' => array_get($data, 'owner_id') ?? $server->owner_id, - 'name' => array_get($data, 'name') ?? $server->name, - 'description' => array_get($data, 'description') ?? $server->description, + 'owner_id' => array_get($data, 'owner_id'), + 'name' => array_get($data, 'name'), + 'description' => array_get($data, 'description', ''), ], true, true); if (array_get($data, 'owner_id') != $server->owner_id) { diff --git a/app/Services/Servers/ServerCreationService.php b/app/Services/Servers/ServerCreationService.php index 86e580a2..5aa1d7b2 100644 --- a/app/Services/Servers/ServerCreationService.php +++ b/app/Services/Servers/ServerCreationService.php @@ -106,6 +106,7 @@ class ServerCreationService * @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Illuminate\Validation\ValidationException */ public function create(array $data) { @@ -117,7 +118,7 @@ class ServerCreationService 'uuidShort' => str_random(8), 'node_id' => array_get($data, 'node_id'), 'name' => array_get($data, 'name'), - 'description' => array_get($data, 'description'), + 'description' => array_get($data, 'description', ''), 'skip_scripts' => isset($data['skip_scripts']), 'suspended' => false, 'owner_id' => array_get($data, 'owner_id'), diff --git a/app/Services/Users/UserCreationService.php b/app/Services/Users/UserCreationService.php index b267a18f..f4824e48 100644 --- a/app/Services/Users/UserCreationService.php +++ b/app/Services/Users/UserCreationService.php @@ -1,77 +1,52 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Services\Users; use Ramsey\Uuid\Uuid; -use Illuminate\Foundation\Application; use Illuminate\Contracts\Hashing\Hasher; use Illuminate\Database\ConnectionInterface; -use Illuminate\Notifications\ChannelManager; use Pterodactyl\Notifications\AccountCreated; use Pterodactyl\Services\Helpers\TemporaryPasswordService; use Pterodactyl\Contracts\Repository\UserRepositoryInterface; class UserCreationService { - /** - * @var \Illuminate\Foundation\Application - */ - protected $app; - /** * @var \Illuminate\Database\ConnectionInterface */ - protected $connection; + private $connection; /** * @var \Illuminate\Contracts\Hashing\Hasher */ - protected $hasher; - - /** - * @var \Illuminate\Notifications\ChannelManager - */ - protected $notification; + private $hasher; /** * @var \Pterodactyl\Services\Helpers\TemporaryPasswordService */ - protected $passwordService; + private $passwordService; /** * @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface */ - protected $repository; + private $repository; /** * CreationService constructor. * - * @param \Illuminate\Foundation\Application $application - * @param \Illuminate\Notifications\ChannelManager $notification * @param \Illuminate\Database\ConnectionInterface $connection * @param \Illuminate\Contracts\Hashing\Hasher $hasher * @param \Pterodactyl\Services\Helpers\TemporaryPasswordService $passwordService * @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository */ public function __construct( - Application $application, - ChannelManager $notification, ConnectionInterface $connection, Hasher $hasher, TemporaryPasswordService $passwordService, UserRepositoryInterface $repository ) { - $this->app = $application; $this->connection = $connection; $this->hasher = $hasher; - $this->notification = $notification; $this->passwordService = $passwordService; $this->repository = $repository; } @@ -97,20 +72,13 @@ class UserCreationService $token = $this->passwordService->handle($data['email']); } + /** @var \Pterodactyl\Models\User $user */ $user = $this->repository->create(array_merge($data, [ 'uuid' => Uuid::uuid4()->toString(), - ])); + ]), true, true); $this->connection->commit(); - - // @todo fire event, handle notification there - $this->notification->send($user, $this->app->makeWith(AccountCreated::class, [ - 'user' => [ - 'name' => $user->name_first, - 'username' => $user->username, - 'token' => $token ?? null, - ], - ])); + $user->notify(new AccountCreated($user, $token ?? null)); return $user; } diff --git a/composer.lock b/composer.lock index 40dbb34d..d7798684 100644 --- a/composer.lock +++ b/composer.lock @@ -61,16 +61,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.48.0", + "version": "3.48.6", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "f5aef5671cd7f6e3b9ede0a3ff17c131cc05f4d3" + "reference": "53e489f7d13c2f65bb28fde21d96a4f261092dda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/f5aef5671cd7f6e3b9ede0a3ff17c131cc05f4d3", - "reference": "f5aef5671cd7f6e3b9ede0a3ff17c131cc05f4d3", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/53e489f7d13c2f65bb28fde21d96a4f261092dda", + "reference": "53e489f7d13c2f65bb28fde21d96a4f261092dda", "shasum": "" }, "require": { @@ -137,7 +137,7 @@ "s3", "sdk" ], - "time": "2017-12-15T19:49:31+00:00" + "time": "2017-12-29T17:28:50+00:00" }, { "name": "dnoegel/php-xdg-base-dir", @@ -1250,16 +1250,16 @@ }, { "name": "laravel/framework", - "version": "v5.5.25", + "version": "v5.5.28", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "0a5b6112f325c56ae5a6679c08a0a10723153fe0" + "reference": "cfafae1f2043208390a7c984e3070696f4969605" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/0a5b6112f325c56ae5a6679c08a0a10723153fe0", - "reference": "0a5b6112f325c56ae5a6679c08a0a10723153fe0", + "url": "https://api.github.com/repos/laravel/framework/zipball/cfafae1f2043208390a7c984e3070696f4969605", + "reference": "cfafae1f2043208390a7c984e3070696f4969605", "shasum": "" }, "require": { @@ -1380,20 +1380,20 @@ "framework", "laravel" ], - "time": "2017-12-11T14:59:28+00:00" + "time": "2017-12-26T16:24:40+00:00" }, { "name": "laravel/tinker", - "version": "v1.0.2", + "version": "v1.0.3", "source": { "type": "git", "url": "https://github.com/laravel/tinker.git", - "reference": "203978fd67f118902acff95925847e70b72e3daf" + "reference": "852c2abe0b0991555a403f1c0583e64de6acb4a6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/tinker/zipball/203978fd67f118902acff95925847e70b72e3daf", - "reference": "203978fd67f118902acff95925847e70b72e3daf", + "url": "https://api.github.com/repos/laravel/tinker/zipball/852c2abe0b0991555a403f1c0583e64de6acb4a6", + "reference": "852c2abe0b0991555a403f1c0583e64de6acb4a6", "shasum": "" }, "require": { @@ -1402,7 +1402,7 @@ "illuminate/support": "~5.1", "php": ">=5.5.9", "psy/psysh": "0.7.*|0.8.*", - "symfony/var-dumper": "~3.0" + "symfony/var-dumper": "~3.0|~4.0" }, "require-dev": { "phpunit/phpunit": "~4.0|~5.0" @@ -1443,7 +1443,7 @@ "laravel", "psysh" ], - "time": "2017-07-13T13:11:05+00:00" + "time": "2017-12-18T16:25:11+00:00" }, { "name": "league/flysystem", @@ -1919,16 +1919,16 @@ }, { "name": "nikic/php-parser", - "version": "v3.1.2", + "version": "v3.1.3", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "08131e7ff29de6bb9f12275c7d35df71f25f4d89" + "reference": "579f4ce846734a1cf55d6a531d00ca07a43e3cda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/08131e7ff29de6bb9f12275c7d35df71f25f4d89", - "reference": "08131e7ff29de6bb9f12275c7d35df71f25f4d89", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/579f4ce846734a1cf55d6a531d00ca07a43e3cda", + "reference": "579f4ce846734a1cf55d6a531d00ca07a43e3cda", "shasum": "" }, "require": { @@ -1966,7 +1966,7 @@ "parser", "php" ], - "time": "2017-11-04T11:48:34+00:00" + "time": "2017-12-26T14:43:21+00:00" }, { "name": "paragonie/constant_time_encoding", @@ -2435,16 +2435,16 @@ }, { "name": "psy/psysh", - "version": "v0.8.16", + "version": "v0.8.17", "source": { "type": "git", "url": "https://github.com/bobthecow/psysh.git", - "reference": "d4c8eab0683dc056f2ca54ca67f5388527c068b1" + "reference": "5069b70e8c4ea492c2b5939b6eddc78bfe41cfec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bobthecow/psysh/zipball/d4c8eab0683dc056f2ca54ca67f5388527c068b1", - "reference": "d4c8eab0683dc056f2ca54ca67f5388527c068b1", + "url": "https://api.github.com/repos/bobthecow/psysh/zipball/5069b70e8c4ea492c2b5939b6eddc78bfe41cfec", + "reference": "5069b70e8c4ea492c2b5939b6eddc78bfe41cfec", "shasum": "" }, "require": { @@ -2503,7 +2503,7 @@ "interactive", "shell" ], - "time": "2017-12-10T21:49:27+00:00" + "time": "2017-12-28T16:14:16+00:00" }, { "name": "ramsey/uuid", @@ -5764,16 +5764,16 @@ }, { "name": "sebastian/comparator", - "version": "2.1.0", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1174d9018191e93cb9d719edec01257fc05f8158" + "reference": "b11c729f95109b56a0fe9650c6a63a0fcd8c439f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1174d9018191e93cb9d719edec01257fc05f8158", - "reference": "1174d9018191e93cb9d719edec01257fc05f8158", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/b11c729f95109b56a0fe9650c6a63a0fcd8c439f", + "reference": "b11c729f95109b56a0fe9650c6a63a0fcd8c439f", "shasum": "" }, "require": { @@ -5824,7 +5824,7 @@ "compare", "equality" ], - "time": "2017-11-03T07:16:52+00:00" + "time": "2017-12-22T14:50:35+00:00" }, { "name": "sebastian/diff", diff --git a/database/migrations/2018_01_01_122821_AllowNegativeValuesForServerSwap.php b/database/migrations/2018_01_01_122821_AllowNegativeValuesForServerSwap.php new file mode 100644 index 00000000..8f9938da --- /dev/null +++ b/database/migrations/2018_01_01_122821_AllowNegativeValuesForServerSwap.php @@ -0,0 +1,32 @@ +integer('swap')->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->unsignedInteger('swap')->change(); + }); + } +} diff --git a/resources/themes/pterodactyl/admin/eggs/scripts.blade.php b/resources/themes/pterodactyl/admin/eggs/scripts.blade.php index 8452cf26..44252b26 100644 --- a/resources/themes/pterodactyl/admin/eggs/scripts.blade.php +++ b/resources/themes/pterodactyl/admin/eggs/scripts.blade.php @@ -53,7 +53,7 @@