Merge branch 'develop' into feature/api-v1

This commit is contained in:
Dane Everitt 2018-01-01 13:33:06 -06:00
commit d21f70c04b
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
20 changed files with 205 additions and 231 deletions

View File

@ -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 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 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 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) ## v0.7.0-beta.3 (Derelict Dermodactylus)
### Fixed ### Fixed

View File

@ -95,11 +95,10 @@ class FileActionsController extends Controller
* @param string $file * @param string $file
* @return \Illuminate\View\View * @return \Illuminate\View\View
* *
* @throws \Illuminate\Auth\Access\AuthorizationException * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @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'); $server = $request->attributes->get('server');

View File

@ -101,7 +101,7 @@ class RemoteRequestController extends Controller
$this->repository->setNode($server->node_id) $this->repository->setNode($server->node_id)
->setAccessServer($server->uuid) ->setAccessServer($server->uuid)
->setAccessToken($request->attributes->get('server_token')) ->setAccessToken($request->attributes->get('server_token'))
->putContent($request->input('file'), $request->input('contents')); ->putContent($request->input('file'), $request->input('contents') ?? '');
return response('', 204); return response('', 204);
} catch (RequestException $exception) { } catch (RequestException $exception) {

View File

@ -7,34 +7,21 @@ use Pterodactyl\Models\User;
class UserFormRequest extends AdminFormRequest class UserFormRequest extends AdminFormRequest
{ {
/** /**
* {@inheritdoc} * Rules to apply to requests for updating or creating a user
* in the Admin CP.
*/ */
public function rules() public function rules()
{ {
$rules = collect(User::getCreateRules());
if ($this->method() === 'PATCH') { if ($this->method() === 'PATCH') {
$rules = User::getUpdateRulesForId($this->route()->parameter('user')->id); $rules = collect(User::getUpdateRulesForId($this->route()->parameter('user')->id))->merge([
'ignore_connection_error' => ['sometimes', 'nullable', 'boolean'],
return array_merge($rules, [
'ignore_connection_error' => 'sometimes|nullable|boolean',
]); ]);
} }
return User::getCreateRules(); return $rules->only([
} 'email', 'username', 'name_first', 'name_last', 'password',
'language', 'ignore_connection_error', 'root_admin',
/** ])->toArray();
* @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();
} }
} }

View File

@ -12,6 +12,7 @@ namespace Pterodactyl\Http\Requests\Server;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Config\Repository;
use Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException; use Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface; use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
use Pterodactyl\Exceptions\Http\Server\FileTypeNotEditableException; use Pterodactyl\Exceptions\Http\Server\FileTypeNotEditableException;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
@ -80,7 +81,12 @@ class UpdateFileContentsFormRequest extends ServerFormRequest
->setAccessToken($token) ->setAccessToken($token)
->getFileStat($this->route()->parameter('file')); ->getFileStat($this->route()->parameter('file'));
} catch (RequestException $exception) { } 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'))) { if (! $stats->file || ! in_array($stats->mime, $config->get('pterodactyl.files.editable'))) {

View File

@ -76,7 +76,7 @@ class Server extends Model implements CleansAttributes, ValidableContract
'owner_id' => 'exists:users,id', 'owner_id' => 'exists:users,id',
'name' => 'regex:/^([\w .-]{1,200})$/', 'name' => 'regex:/^([\w .-]{1,200})$/',
'node_id' => 'exists:nodes,id', 'node_id' => 'exists:nodes,id',
'description' => 'nullable|string', 'description' => 'string',
'memory' => 'numeric|min:0', 'memory' => 'numeric|min:0',
'swap' => 'numeric|min:-1', 'swap' => 'numeric|min:-1',
'io' => 'numeric|between:10,1000', 'io' => 'numeric|between:10,1000',

View File

@ -115,6 +115,7 @@ class User extends Model implements
* @var array * @var array
*/ */
protected static $applicationRules = [ protected static $applicationRules = [
'uuid' => 'required',
'email' => 'required', 'email' => 'required',
'username' => 'required', 'username' => 'required',
'name_first' => 'required', 'name_first' => 'required',
@ -130,6 +131,7 @@ class User extends Model implements
* @var array * @var array
*/ */
protected static $dataIntegrityRules = [ protected static $dataIntegrityRules = [
'uuid' => 'string|size:36|unique:users,uuid',
'email' => 'email|unique:users,email', 'email' => 'email|unique:users,email',
'username' => 'alpha_dash|between:1,255|unique:users,username', 'username' => 'alpha_dash|between:1,255|unique:users,username',
'name_first' => 'string|between:1,255', 'name_first' => 'string|between:1,255',

View File

@ -1,14 +1,8 @@
<?php <?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\Notifications; namespace Pterodactyl\Notifications;
use Pterodactyl\Models\User;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification; use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
@ -19,7 +13,15 @@ class AccountCreated extends Notification implements ShouldQueue
use Queueable; 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 * @var object
*/ */
@ -28,11 +30,13 @@ class AccountCreated extends Notification implements ShouldQueue
/** /**
* Create a new notification instance. * 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) $message = (new MailMessage)
->greeting('Hello ' . $this->user->name . '!') ->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('Username: ' . $this->user->username)
->line('Email: ' . $notifiable->email); ->line('Email: ' . $this->user->email);
if (! is_null($this->user->token)) { if (! is_null($this->token)) {
return $message->action('Setup Your Account', url('/auth/password/reset/' . $this->user->token . '?email=' . $notifiable->email)); return $message->action('Setup Your Account', url('/auth/password/reset/' . $this->token . '?email=' . $this->user->email));
} }
return $message; return $message;

View File

@ -1,11 +1,4 @@
<?php <?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\Servers; namespace Pterodactyl\Services\Servers;
@ -113,6 +106,7 @@ class BuildModificationService
* *
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function handle($server, array $data) public function handle($server, array $data)
{ {
@ -138,11 +132,11 @@ class BuildModificationService
} }
$server = $this->repository->update($server->id, [ $server = $this->repository->update($server->id, [
'memory' => array_get($data, 'memory', $server->memory), 'memory' => (int) array_get($data, 'memory', $server->memory),
'swap' => array_get($data, 'swap', $server->swap), 'swap' => (int) array_get($data, 'swap', $server->swap),
'io' => array_get($data, 'io', $server->io), 'io' => (int) array_get($data, 'io', $server->io),
'cpu' => array_get($data, 'cpu', $server->cpu), 'cpu' => (int) array_get($data, 'cpu', $server->cpu),
'disk' => array_get($data, 'disk', $server->disk), 'disk' => (int) array_get($data, 'disk', $server->disk),
'allocation_id' => array_get($data, 'allocation_id', $server->allocation_id), 'allocation_id' => array_get($data, 'allocation_id', $server->allocation_id),
]); ]);

View File

@ -95,9 +95,9 @@ class DetailsModificationService
$this->connection->beginTransaction(); $this->connection->beginTransaction();
$this->repository->withoutFresh()->update($server->id, [ $this->repository->withoutFresh()->update($server->id, [
'owner_id' => array_get($data, 'owner_id') ?? $server->owner_id, 'owner_id' => array_get($data, 'owner_id'),
'name' => array_get($data, 'name') ?? $server->name, 'name' => array_get($data, 'name'),
'description' => array_get($data, 'description') ?? $server->description, 'description' => array_get($data, 'description', ''),
], true, true); ], true, true);
if (array_get($data, 'owner_id') != $server->owner_id) { if (array_get($data, 'owner_id') != $server->owner_id) {

View File

@ -106,6 +106,7 @@ class ServerCreationService
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Validation\ValidationException
*/ */
public function create(array $data) public function create(array $data)
{ {
@ -117,7 +118,7 @@ class ServerCreationService
'uuidShort' => str_random(8), 'uuidShort' => str_random(8),
'node_id' => array_get($data, 'node_id'), 'node_id' => array_get($data, 'node_id'),
'name' => array_get($data, 'name'), 'name' => array_get($data, 'name'),
'description' => array_get($data, 'description'), 'description' => array_get($data, 'description', ''),
'skip_scripts' => isset($data['skip_scripts']), 'skip_scripts' => isset($data['skip_scripts']),
'suspended' => false, 'suspended' => false,
'owner_id' => array_get($data, 'owner_id'), 'owner_id' => array_get($data, 'owner_id'),

View File

@ -1,77 +1,52 @@
<?php <?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\Users; namespace Pterodactyl\Services\Users;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use Illuminate\Foundation\Application;
use Illuminate\Contracts\Hashing\Hasher; use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
use Illuminate\Notifications\ChannelManager;
use Pterodactyl\Notifications\AccountCreated; use Pterodactyl\Notifications\AccountCreated;
use Pterodactyl\Services\Helpers\TemporaryPasswordService; use Pterodactyl\Services\Helpers\TemporaryPasswordService;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface; use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
class UserCreationService class UserCreationService
{ {
/**
* @var \Illuminate\Foundation\Application
*/
protected $app;
/** /**
* @var \Illuminate\Database\ConnectionInterface * @var \Illuminate\Database\ConnectionInterface
*/ */
protected $connection; private $connection;
/** /**
* @var \Illuminate\Contracts\Hashing\Hasher * @var \Illuminate\Contracts\Hashing\Hasher
*/ */
protected $hasher; private $hasher;
/**
* @var \Illuminate\Notifications\ChannelManager
*/
protected $notification;
/** /**
* @var \Pterodactyl\Services\Helpers\TemporaryPasswordService * @var \Pterodactyl\Services\Helpers\TemporaryPasswordService
*/ */
protected $passwordService; private $passwordService;
/** /**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface * @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/ */
protected $repository; private $repository;
/** /**
* CreationService constructor. * CreationService constructor.
* *
* @param \Illuminate\Foundation\Application $application
* @param \Illuminate\Notifications\ChannelManager $notification
* @param \Illuminate\Database\ConnectionInterface $connection * @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Contracts\Hashing\Hasher $hasher * @param \Illuminate\Contracts\Hashing\Hasher $hasher
* @param \Pterodactyl\Services\Helpers\TemporaryPasswordService $passwordService * @param \Pterodactyl\Services\Helpers\TemporaryPasswordService $passwordService
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository * @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
*/ */
public function __construct( public function __construct(
Application $application,
ChannelManager $notification,
ConnectionInterface $connection, ConnectionInterface $connection,
Hasher $hasher, Hasher $hasher,
TemporaryPasswordService $passwordService, TemporaryPasswordService $passwordService,
UserRepositoryInterface $repository UserRepositoryInterface $repository
) { ) {
$this->app = $application;
$this->connection = $connection; $this->connection = $connection;
$this->hasher = $hasher; $this->hasher = $hasher;
$this->notification = $notification;
$this->passwordService = $passwordService; $this->passwordService = $passwordService;
$this->repository = $repository; $this->repository = $repository;
} }
@ -97,20 +72,13 @@ class UserCreationService
$token = $this->passwordService->handle($data['email']); $token = $this->passwordService->handle($data['email']);
} }
/** @var \Pterodactyl\Models\User $user */
$user = $this->repository->create(array_merge($data, [ $user = $this->repository->create(array_merge($data, [
'uuid' => Uuid::uuid4()->toString(), 'uuid' => Uuid::uuid4()->toString(),
])); ]), true, true);
$this->connection->commit(); $this->connection->commit();
$user->notify(new AccountCreated($user, $token ?? null));
// @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,
],
]));
return $user; return $user;
} }

62
composer.lock generated
View File

@ -61,16 +61,16 @@
}, },
{ {
"name": "aws/aws-sdk-php", "name": "aws/aws-sdk-php",
"version": "3.48.0", "version": "3.48.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/aws/aws-sdk-php.git", "url": "https://github.com/aws/aws-sdk-php.git",
"reference": "f5aef5671cd7f6e3b9ede0a3ff17c131cc05f4d3" "reference": "53e489f7d13c2f65bb28fde21d96a4f261092dda"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/f5aef5671cd7f6e3b9ede0a3ff17c131cc05f4d3", "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/53e489f7d13c2f65bb28fde21d96a4f261092dda",
"reference": "f5aef5671cd7f6e3b9ede0a3ff17c131cc05f4d3", "reference": "53e489f7d13c2f65bb28fde21d96a4f261092dda",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -137,7 +137,7 @@
"s3", "s3",
"sdk" "sdk"
], ],
"time": "2017-12-15T19:49:31+00:00" "time": "2017-12-29T17:28:50+00:00"
}, },
{ {
"name": "dnoegel/php-xdg-base-dir", "name": "dnoegel/php-xdg-base-dir",
@ -1250,16 +1250,16 @@
}, },
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v5.5.25", "version": "v5.5.28",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/framework.git", "url": "https://github.com/laravel/framework.git",
"reference": "0a5b6112f325c56ae5a6679c08a0a10723153fe0" "reference": "cfafae1f2043208390a7c984e3070696f4969605"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/0a5b6112f325c56ae5a6679c08a0a10723153fe0", "url": "https://api.github.com/repos/laravel/framework/zipball/cfafae1f2043208390a7c984e3070696f4969605",
"reference": "0a5b6112f325c56ae5a6679c08a0a10723153fe0", "reference": "cfafae1f2043208390a7c984e3070696f4969605",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1380,20 +1380,20 @@
"framework", "framework",
"laravel" "laravel"
], ],
"time": "2017-12-11T14:59:28+00:00" "time": "2017-12-26T16:24:40+00:00"
}, },
{ {
"name": "laravel/tinker", "name": "laravel/tinker",
"version": "v1.0.2", "version": "v1.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/tinker.git", "url": "https://github.com/laravel/tinker.git",
"reference": "203978fd67f118902acff95925847e70b72e3daf" "reference": "852c2abe0b0991555a403f1c0583e64de6acb4a6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/tinker/zipball/203978fd67f118902acff95925847e70b72e3daf", "url": "https://api.github.com/repos/laravel/tinker/zipball/852c2abe0b0991555a403f1c0583e64de6acb4a6",
"reference": "203978fd67f118902acff95925847e70b72e3daf", "reference": "852c2abe0b0991555a403f1c0583e64de6acb4a6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1402,7 +1402,7 @@
"illuminate/support": "~5.1", "illuminate/support": "~5.1",
"php": ">=5.5.9", "php": ">=5.5.9",
"psy/psysh": "0.7.*|0.8.*", "psy/psysh": "0.7.*|0.8.*",
"symfony/var-dumper": "~3.0" "symfony/var-dumper": "~3.0|~4.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.0|~5.0" "phpunit/phpunit": "~4.0|~5.0"
@ -1443,7 +1443,7 @@
"laravel", "laravel",
"psysh" "psysh"
], ],
"time": "2017-07-13T13:11:05+00:00" "time": "2017-12-18T16:25:11+00:00"
}, },
{ {
"name": "league/flysystem", "name": "league/flysystem",
@ -1919,16 +1919,16 @@
}, },
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
"version": "v3.1.2", "version": "v3.1.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/nikic/PHP-Parser.git", "url": "https://github.com/nikic/PHP-Parser.git",
"reference": "08131e7ff29de6bb9f12275c7d35df71f25f4d89" "reference": "579f4ce846734a1cf55d6a531d00ca07a43e3cda"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/08131e7ff29de6bb9f12275c7d35df71f25f4d89", "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/579f4ce846734a1cf55d6a531d00ca07a43e3cda",
"reference": "08131e7ff29de6bb9f12275c7d35df71f25f4d89", "reference": "579f4ce846734a1cf55d6a531d00ca07a43e3cda",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1966,7 +1966,7 @@
"parser", "parser",
"php" "php"
], ],
"time": "2017-11-04T11:48:34+00:00" "time": "2017-12-26T14:43:21+00:00"
}, },
{ {
"name": "paragonie/constant_time_encoding", "name": "paragonie/constant_time_encoding",
@ -2435,16 +2435,16 @@
}, },
{ {
"name": "psy/psysh", "name": "psy/psysh",
"version": "v0.8.16", "version": "v0.8.17",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/bobthecow/psysh.git", "url": "https://github.com/bobthecow/psysh.git",
"reference": "d4c8eab0683dc056f2ca54ca67f5388527c068b1" "reference": "5069b70e8c4ea492c2b5939b6eddc78bfe41cfec"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/bobthecow/psysh/zipball/d4c8eab0683dc056f2ca54ca67f5388527c068b1", "url": "https://api.github.com/repos/bobthecow/psysh/zipball/5069b70e8c4ea492c2b5939b6eddc78bfe41cfec",
"reference": "d4c8eab0683dc056f2ca54ca67f5388527c068b1", "reference": "5069b70e8c4ea492c2b5939b6eddc78bfe41cfec",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2503,7 +2503,7 @@
"interactive", "interactive",
"shell" "shell"
], ],
"time": "2017-12-10T21:49:27+00:00" "time": "2017-12-28T16:14:16+00:00"
}, },
{ {
"name": "ramsey/uuid", "name": "ramsey/uuid",
@ -5764,16 +5764,16 @@
}, },
{ {
"name": "sebastian/comparator", "name": "sebastian/comparator",
"version": "2.1.0", "version": "2.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git", "url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "1174d9018191e93cb9d719edec01257fc05f8158" "reference": "b11c729f95109b56a0fe9650c6a63a0fcd8c439f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1174d9018191e93cb9d719edec01257fc05f8158", "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/b11c729f95109b56a0fe9650c6a63a0fcd8c439f",
"reference": "1174d9018191e93cb9d719edec01257fc05f8158", "reference": "b11c729f95109b56a0fe9650c6a63a0fcd8c439f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -5824,7 +5824,7 @@
"compare", "compare",
"equality" "equality"
], ],
"time": "2017-11-03T07:16:52+00:00" "time": "2017-12-22T14:50:35+00:00"
}, },
{ {
"name": "sebastian/diff", "name": "sebastian/diff",

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AllowNegativeValuesForServerSwap extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('servers', function (Blueprint $table) {
$table->integer('swap')->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('servers', function (Blueprint $table) {
$table->unsignedInteger('swap')->change();
});
}
}

View File

@ -53,7 +53,7 @@
<div class="form-group col-sm-4"> <div class="form-group col-sm-4">
<label class="control-label">Copy Script From</label> <label class="control-label">Copy Script From</label>
<select id="pCopyScriptFrom" name="copy_script_from"> <select id="pCopyScriptFrom" name="copy_script_from">
<option value="0">None</option> <option value="">None</option>
@foreach($copyFromOptions as $opt) @foreach($copyFromOptions as $opt)
<option value="{{ $opt->id }}" {{ $egg->copy_script_from !== $opt->id ?: 'selected' }}>{{ $opt->name }}</option> <option value="{{ $opt->id }}" {{ $egg->copy_script_from !== $opt->id ?: 'selected' }}>{{ $opt->name }}</option>
@endforeach @endforeach

View File

@ -38,6 +38,7 @@
<div class="box-body table-responsive no-padding"> <div class="box-body table-responsive no-padding">
<table class="table table-hover"> <table class="table table-hover">
<tr> <tr>
<th>ID</th>
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th class="text-center">Eggs</th> <th class="text-center">Eggs</th>
@ -46,11 +47,12 @@
</tr> </tr>
@foreach($nests as $nest) @foreach($nests as $nest)
<tr> <tr>
<td class="middle"><code>{{ $nest->id }}</code></td>
<td class="middle"><a href="{{ route('admin.nests.view', $nest->id) }}" data-toggle="tooltip" data-placement="right" title="{{ $nest->author }}">{{ $nest->name }}</a></td> <td class="middle"><a href="{{ route('admin.nests.view', $nest->id) }}" data-toggle="tooltip" data-placement="right" title="{{ $nest->author }}">{{ $nest->name }}</a></td>
<td class="col-xs-6 middle">{{ $nest->description }}</td> <td class="col-xs-6 middle">{{ $nest->description }}</td>
<td class="text-center middle"><code>{{ $nest->eggs_count }}</code></td> <td class="text-center middle">{{ $nest->eggs_count }}</td>
<td class="text-center middle"><code>{{ $nest->packs_count }}</code></td> <td class="text-center middle">{{ $nest->packs_count }}</td>
<td class="text-center middle"><code>{{ $nest->servers_count }}</code></td> <td class="text-center middle">{{ $nest->servers_count }}</td>
</tr> </tr>
@endforeach @endforeach
</table> </table>

View File

@ -49,6 +49,13 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="box"> <div class="box">
<div class="box-body"> <div class="box-body">
<div class="form-group">
<label class="control-label">Nest ID</label>
<div>
<input type="text" readonly class="form-control" value="{{ $nest->id }}" />
<p class="text-muted small">A unique ID used for identification of this nest internally and through the API.</p>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="control-label">Author</label> <label class="control-label">Author</label>
<div> <div>
@ -60,7 +67,7 @@
<label class="control-label">UUID</label> <label class="control-label">UUID</label>
<div> <div>
<input type="text" readonly class="form-control" value="{{ $nest->uuid }}" /> <input type="text" readonly class="form-control" value="{{ $nest->uuid }}" />
<p class="text-muted small">A unique identifier that all servers using this option are assigned for identification purposes.</p> <p class="text-muted small">A UUID that all servers using this option are assigned for identification purposes.</p>
</div> </div>
</div> </div>
</div> </div>
@ -76,6 +83,7 @@
<div class="box-body table-responsive no-padding"> <div class="box-body table-responsive no-padding">
<table class="table table-hover"> <table class="table table-hover">
<tr> <tr>
<th>ID</th>
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th class="text-center">Servers</th> <th class="text-center">Servers</th>
@ -83,6 +91,7 @@
</tr> </tr>
@foreach($nest->eggs as $egg) @foreach($nest->eggs as $egg)
<tr> <tr>
<td class="align-middle"><code>{{ $egg->id }}</code></td>
<td class="align-middle"><a href="{{ route('admin.nests.egg.view', $egg->id) }}" data-toggle="tooltip" data-placement="right" title="{{ $egg->author }}">{{ $egg->name }}</a></td> <td class="align-middle"><a href="{{ route('admin.nests.egg.view', $egg->id) }}" data-toggle="tooltip" data-placement="right" title="{{ $egg->author }}">{{ $egg->name }}</a></td>
<td class="col-xs-8 align-middle">{!! $egg->description !!}</td> <td class="col-xs-8 align-middle">{!! $egg->description !!}</td>
<td class="text-center align-middle"><code>{{ $egg->servers->count() }}</code></td> <td class="text-center align-middle"><code>{{ $egg->servers->count() }}</code></td>

View File

@ -137,7 +137,7 @@
<td data-identifier="name" data-name="{{ rawurlencode($file['entry']) }}" data-path="@if($file['directory'] !== ''){{ rawurlencode($file['directory']) }}@endif/"> <td data-identifier="name" data-name="{{ rawurlencode($file['entry']) }}" data-path="@if($file['directory'] !== ''){{ rawurlencode($file['directory']) }}@endif/">
@if(in_array($file['mime'], $editableMime)) @if(in_array($file['mime'], $editableMime))
@can('edit-files', $server) @can('edit-files', $server)
<a href="/server/{{ $server->uuidShort }}/files/edit/@if($file['directory'] !== ''){{ rawurlencode($file['directory']) }}/@endif{{ rawurlencode($file['entry']) }}" class="edit_file">{{ $file['entry'] }}</a> <a href="/server/{{ $server->uuidShort }}/files/edit/@if($file['directory'] !== ''){{ $file['directory'] }}/@endif{{ $file['entry'] }}" class="edit_file">{{ $file['entry'] }}</a>
@else @else
{{ $file['entry'] }} {{ $file['entry'] }}
@endcan @endcan

View File

@ -52,7 +52,7 @@ Route::group(['prefix' => 'databases'], function () {
Route::group(['prefix' => 'files'], function () { Route::group(['prefix' => 'files'], function () {
Route::get('/', 'Files\FileActionsController@index')->name('server.files.index'); Route::get('/', 'Files\FileActionsController@index')->name('server.files.index');
Route::get('/add', 'Files\FileActionsController@create')->name('server.files.add'); Route::get('/add', 'Files\FileActionsController@create')->name('server.files.add');
Route::get('/edit/{file}', 'Files\FileActionsController@update')->name('server.files.edit')->where('file', '.*'); Route::get('/edit/{file}', 'Files\FileActionsController@view')->name('server.files.edit')->where('file', '.*');
Route::get('/download/{file}', 'Files\DownloadController@index')->name('server.files.edit')->where('file', '.*'); Route::get('/download/{file}', 'Files\DownloadController@index')->name('server.files.edit')->where('file', '.*');
Route::post('/directory-list', 'Files\RemoteRequestController@directory')->name('server.files.directory-list'); Route::post('/directory-list', 'Files\RemoteRequestController@directory')->name('server.files.directory-list');

View File

@ -4,11 +4,11 @@ namespace Tests\Unit\Services;
use Mockery as m; use Mockery as m;
use Tests\TestCase; use Tests\TestCase;
use Pterodactyl\Models\User;
use Tests\Traits\MocksUuids; use Tests\Traits\MocksUuids;
use Illuminate\Foundation\Application;
use Illuminate\Contracts\Hashing\Hasher; use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
use Illuminate\Notifications\ChannelManager; use Illuminate\Support\Facades\Notification;
use Pterodactyl\Notifications\AccountCreated; use Pterodactyl\Notifications\AccountCreated;
use Pterodactyl\Services\Users\UserCreationService; use Pterodactyl\Services\Users\UserCreationService;
use Pterodactyl\Services\Helpers\TemporaryPasswordService; use Pterodactyl\Services\Helpers\TemporaryPasswordService;
@ -19,39 +19,24 @@ class UserCreationServiceTest extends TestCase
use MocksUuids; use MocksUuids;
/** /**
* @var \Illuminate\Foundation\Application * @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
*/ */
protected $appMock; private $connection;
/** /**
* @var \Illuminate\Database\ConnectionInterface * @var \Illuminate\Contracts\Hashing\Hasher|\Mockery\Mock
*/ */
protected $database; private $hasher;
/** /**
* @var \Illuminate\Contracts\Hashing\Hasher * @var \Pterodactyl\Services\Helpers\TemporaryPasswordService|\Mockery\Mock
*/ */
protected $hasher; private $passwordService;
/** /**
* @var \Illuminate\Notifications\ChannelManager * @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
*/ */
protected $notification; private $repository;
/**
* @var \Pterodactyl\Services\Helpers\TemporaryPasswordService
*/
protected $passwordService;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/
protected $repository;
/**
* @var \Pterodactyl\Services\Users\UserCreationService
*/
protected $service;
/** /**
* Setup tests. * Setup tests.
@ -60,21 +45,11 @@ class UserCreationServiceTest extends TestCase
{ {
parent::setUp(); parent::setUp();
$this->appMock = m::mock(Application::class); Notification::fake();
$this->database = m::mock(ConnectionInterface::class); $this->connection = m::mock(ConnectionInterface::class);
$this->hasher = m::mock(Hasher::class); $this->hasher = m::mock(Hasher::class);
$this->notification = m::mock(ChannelManager::class);
$this->passwordService = m::mock(TemporaryPasswordService::class); $this->passwordService = m::mock(TemporaryPasswordService::class);
$this->repository = m::mock(UserRepositoryInterface::class); $this->repository = m::mock(UserRepositoryInterface::class);
$this->service = new UserCreationService(
$this->appMock,
$this->notification,
$this->database,
$this->hasher,
$this->passwordService,
$this->repository
);
} }
/** /**
@ -82,35 +57,27 @@ class UserCreationServiceTest extends TestCase
*/ */
public function testUserIsCreatedWhenPasswordIsProvided() public function testUserIsCreatedWhenPasswordIsProvided()
{ {
$user = (object) [ $user = factory(User::class)->make();
'name_first' => 'FirstName',
'username' => 'user_name',
];
$this->hasher->shouldReceive('make')->with('raw-password')->once()->andReturn('enc-password'); $this->hasher->shouldReceive('make')->with('raw-password')->once()->andReturn('enc-password');
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull(); $this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
$this->repository->shouldReceive('create')->with([ $this->repository->shouldReceive('create')->with([
'password' => 'enc-password', 'password' => 'enc-password',
'uuid' => $this->getKnownUuid(), 'uuid' => $this->getKnownUuid(),
])->once()->andReturn($user); ], true, true)->once()->andReturn($user);
$this->database->shouldReceive('commit')->withNoArgs()->once()->andReturnNull(); $this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
$this->appMock->shouldReceive('makeWith')->with(AccountCreated::class, [
'user' => [
'name' => 'FirstName',
'username' => 'user_name',
'token' => null,
],
])->once()->andReturnNull();
$this->notification->shouldReceive('send')->with($user, null)->once()->andReturnNull(); $response = $this->getService()->handle([
$response = $this->service->handle([
'password' => 'raw-password', 'password' => 'raw-password',
]); ]);
$this->assertNotNull($response); $this->assertNotNull($response);
$this->assertEquals($user->username, $response->username); Notification::assertSentTo($user, AccountCreated::class, function ($notification) use ($user) {
$this->assertEquals($user->name_first, 'FirstName'); $this->assertSame($user, $notification->user);
$this->assertNull($notification->token);
return true;
});
} }
/** /**
@ -119,29 +86,29 @@ class UserCreationServiceTest extends TestCase
*/ */
public function testUuidPassedInDataIsIgnored() public function testUuidPassedInDataIsIgnored()
{ {
$user = (object) [ $user = factory(User::class)->make();
'name_first' => 'FirstName',
'username' => 'user_name',
];
$this->hasher->shouldReceive('make')->andReturn('enc-password'); $this->hasher->shouldReceive('make')->andReturn('enc-password');
$this->database->shouldReceive('beginTransaction')->andReturnNull(); $this->connection->shouldReceive('beginTransaction')->andReturnNull();
$this->repository->shouldReceive('create')->with([ $this->repository->shouldReceive('create')->with([
'password' => 'enc-password', 'password' => 'enc-password',
'uuid' => $this->getKnownUuid(), 'uuid' => $this->getKnownUuid(),
])->once()->andReturn($user); ], true, true)->once()->andReturn($user);
$this->database->shouldReceive('commit')->andReturnNull(); $this->connection->shouldReceive('commit')->andReturnNull();
$this->appMock->shouldReceive('makeWith')->andReturnNull();
$this->notification->shouldReceive('send')->andReturnNull();
$response = $this->service->handle([ $response = $this->getService()->handle([
'password' => 'raw-password', 'password' => 'raw-password',
'uuid' => 'test-uuid', 'uuid' => 'test-uuid',
]); ]);
$this->assertNotNull($response); $this->assertNotNull($response);
$this->assertEquals($user->username, $response->username); $this->assertInstanceOf(User::class, $response);
$this->assertEquals($user->name_first, 'FirstName'); Notification::assertSentTo($user, AccountCreated::class, function ($notification) use ($user) {
$this->assertSame($user, $notification->user);
$this->assertNull($notification->token);
return true;
});
} }
/** /**
@ -149,44 +116,42 @@ class UserCreationServiceTest extends TestCase
*/ */
public function testUserIsCreatedWhenNoPasswordIsProvided() public function testUserIsCreatedWhenNoPasswordIsProvided()
{ {
$user = (object) [ $user = factory(User::class)->make();
'name_first' => 'FirstName',
'username' => 'user_name',
'email' => 'user@example.com',
];
$this->hasher->shouldNotReceive('make'); $this->hasher->shouldNotReceive('make');
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull(); $this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
$this->hasher->shouldReceive('make')->once()->andReturn('created-enc-password'); $this->hasher->shouldReceive('make')->once()->andReturn('created-enc-password');
$this->passwordService->shouldReceive('handle') $this->passwordService->shouldReceive('handle')->with($user->email)->once()->andReturn('random-token');
->with('user@example.com')
->once()
->andReturn('random-token');
$this->repository->shouldReceive('create')->with([ $this->repository->shouldReceive('create')->with([
'password' => 'created-enc-password', 'password' => 'created-enc-password',
'email' => 'user@example.com', 'email' => $user->email,
'uuid' => $this->getKnownUuid(), 'uuid' => $this->getKnownUuid(),
])->once()->andReturn($user); ], true, true)->once()->andReturn($user);
$this->database->shouldReceive('commit')->withNoArgs()->once()->andReturnNull(); $this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
$this->appMock->shouldReceive('makeWith')->with(AccountCreated::class, [
'user' => [
'name' => 'FirstName',
'username' => 'user_name',
'token' => 'random-token',
],
])->once()->andReturnNull();
$this->notification->shouldReceive('send')->with($user, null)->once()->andReturnNull(); $response = $this->getService()->handle([
'email' => $user->email,
$response = $this->service->handle([
'email' => 'user@example.com',
]); ]);
$this->assertNotNull($response); $this->assertNotNull($response);
$this->assertEquals($user->username, $response->username); $this->assertInstanceOf(User::class, $response);
$this->assertEquals($user->name_first, 'FirstName'); Notification::assertSentTo($user, AccountCreated::class, function ($notification) use ($user) {
$this->assertEquals($user->email, $response->email); $this->assertSame($user, $notification->user);
$this->assertSame('random-token', $notification->token);
return true;
});
}
/**
* Return a new instance of the service using mocked dependencies.
*
* @return \Pterodactyl\Services\Users\UserCreationService
*/
private function getService(): UserCreationService
{
return new UserCreationService($this->connection, $this->hasher, $this->passwordService, $this->repository);
} }
} }