From e7e50bc45d44f768eef03b9f83b9c58982b1de24 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 18 Feb 2018 20:39:43 -0600 Subject: [PATCH 01/14] Add a few new internal configs to the node config --- app/Models/Node.php | 10 ++++++++++ public/themes/pterodactyl/js/frontend/console.js | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Models/Node.php b/app/Models/Node.php index d5d5ac9bd..12556cdee 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -157,6 +157,16 @@ class Node extends Model implements CleansAttributes, ValidableContract 'filesystem' => [ 'server_logs' => '/tmp/pterodactyl', ], + 'internals' => [ + 'disk_use_seconds' => 30, + 'set_permissions_on_boot' => true, + 'throttle' => [ + 'kill_at_count' => 5, + 'decay' => 10, + 'bytes' => 4096, + 'check_interval_ms' => 100, + ], + ], 'sftp' => [ 'path' => $this->daemonBase, 'ip' => '0.0.0.0', diff --git a/public/themes/pterodactyl/js/frontend/console.js b/public/themes/pterodactyl/js/frontend/console.js index 97bd73854..8943da42a 100644 --- a/public/themes/pterodactyl/js/frontend/console.js +++ b/public/themes/pterodactyl/js/frontend/console.js @@ -151,14 +151,14 @@ function pushToTerminal(string) { if (TerminalQueue.length > 0) { var scrolledDown = isTerminalScrolledDown(); - + for (var i = 0; i < CONSOLE_PUSH_COUNT && TerminalQueue.length > 0; i++) { pushToTerminal(TerminalQueue[0]); window.ConsoleElements++; TerminalQueue.shift(); } - + if (scrolledDown) { window.scrollToBottom(); } else if ($scrollNotify.hasClass('hidden')) { From 620c624e6fc328e75a0cb30bfd3c5208ff58b589 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 11:11:57 -0600 Subject: [PATCH 02/14] Fix exception thrown when accessing /nests/:id/eggs/:id API endpoint --- CHANGELOG.md | 4 ++++ .../Api/Application/ApplicationApiRequest.php | 16 +++++++++------- .../Api/Application/Nests/Eggs/GetEggRequest.php | 4 +++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54484b889..9c7c0f2b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ This file is a running track of new features and fixes to each version of the pa This project follows [Semantic Versioning](http://semver.org) guidelines. +## v0.7.2 (Derelict Dermodactylus) +### Fixed +* Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint. + ## v0.7.1 (Derelict Dermodactylus) ### Fixed * Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted. diff --git a/app/Http/Requests/Api/Application/ApplicationApiRequest.php b/app/Http/Requests/Api/Application/ApplicationApiRequest.php index 126e6d604..ada9b4b00 100644 --- a/app/Http/Requests/Api/Application/ApplicationApiRequest.php +++ b/app/Http/Requests/Api/Application/ApplicationApiRequest.php @@ -9,6 +9,7 @@ use Illuminate\Foundation\Http\FormRequest; use Pterodactyl\Exceptions\PterodactylException; use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\Routing\Exception\InvalidParameterException; abstract class ApplicationApiRequest extends FormRequest { @@ -76,22 +77,23 @@ abstract class ApplicationApiRequest extends FormRequest } /** - * Grab a model from the route parameters. If no model exists under - * the specified key a default response is returned. + * Grab a model from the route parameters. If no model is found in the + * binding mappings an exception will be thrown. * * @param string $model - * @param mixed $default * @return mixed + * + * @throws \Symfony\Component\Routing\Exception\InvalidParameterException */ - public function getModel(string $model, $default = null) + public function getModel(string $model) { $parameterKey = array_get(array_flip(ApiSubstituteBindings::getMappings()), $model); - if (! is_null($parameterKey)) { - $model = $this->route()->parameter($parameterKey); + if (is_null($parameterKey)) { + throw new InvalidParameterException; } - return $model ?? $default; + return $this->route()->parameter($parameterKey); } /* diff --git a/app/Http/Requests/Api/Application/Nests/Eggs/GetEggRequest.php b/app/Http/Requests/Api/Application/Nests/Eggs/GetEggRequest.php index b3f1a08a0..fb364d1ae 100644 --- a/app/Http/Requests/Api/Application/Nests/Eggs/GetEggRequest.php +++ b/app/Http/Requests/Api/Application/Nests/Eggs/GetEggRequest.php @@ -2,6 +2,8 @@ namespace Pterodactyl\Http\Requests\Api\Application\Nests\Eggs; +use Pterodactyl\Models\Egg; +use Pterodactyl\Models\Nest; use Pterodactyl\Services\Acl\Api\AdminAcl; use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest; @@ -24,6 +26,6 @@ class GetEggRequest extends ApplicationApiRequest */ public function resourceExists(): bool { - return $this->getModel('nest')->id === $this->getModel('egg')->nest_id; + return $this->getModel(Nest::class)->id === $this->getModel(Egg::class)->nest_id; } } From be6b398e2d6030b38693201fed313a81517ed8b7 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 11:17:21 -0600 Subject: [PATCH 03/14] add support for egg variables, closes #974 --- CHANGELOG.md | 3 +++ .../Api/Application/EggTransformer.php | 24 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c7c0f2b6..a02f1975a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Fixed * Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint. +### Added +* Adds ability to include egg variables on an API request. + ## v0.7.1 (Derelict Dermodactylus) ### Fixed * Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted. diff --git a/app/Transformers/Api/Application/EggTransformer.php b/app/Transformers/Api/Application/EggTransformer.php index 3454547bd..b73500bb8 100644 --- a/app/Transformers/Api/Application/EggTransformer.php +++ b/app/Transformers/Api/Application/EggTransformer.php @@ -5,6 +5,7 @@ namespace Pterodactyl\Transformers\Api\Application; use Pterodactyl\Models\Egg; use Pterodactyl\Models\Nest; use Pterodactyl\Models\Server; +use Pterodactyl\Models\EggVariable; use Pterodactyl\Services\Acl\Api\AdminAcl; class EggTransformer extends BaseTransformer @@ -15,7 +16,7 @@ class EggTransformer extends BaseTransformer * @var array */ protected $availableIncludes = [ - 'nest', 'servers', 'config', 'script', + 'nest', 'servers', 'config', 'script', 'variables', ]; /** @@ -147,4 +148,25 @@ class EggTransformer extends BaseTransformer ]; }); } + + /** + * Include the variables that are defined for this Egg. + * + * @param \Pterodactyl\Models\Egg $model + * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource + */ + public function includeVariables(Egg $model) + { + if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) { + return $this->null(); + } + + $model->loadMissing('variables'); + + return $this->collection( + $model->getRelation('variables'), + $this->makeTransformer(EggVariableTransformer::class), + EggVariable::RESOURCE_NAME + ); + } } From f655188c58f2d0f985cde315c81a93b83c86f286 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 11:48:24 -0600 Subject: [PATCH 04/14] Fix searching servers --- CHANGELOG.md | 1 + app/Http/Controllers/Admin/ServersController.php | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a02f1975a..dbb5c7c38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ## v0.7.2 (Derelict Dermodactylus) ### Fixed * Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint. +* Fixes search on server listing page. ### Added * Adds ability to include egg variables on an API request. diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index c64e76711..9e22bc1ed 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -201,12 +201,13 @@ class ServersController extends Controller /** * Display the index page with all servers currently on the system. * + * @param \Illuminate\Http\Request $request * @return \Illuminate\View\View */ - public function index() + public function index(Request $request) { return view('admin.servers.index', [ - 'servers' => $this->repository->getAllServers( + 'servers' => $this->repository->setSearchTerm($request->input('query'))->getAllServers( $this->config->get('pterodactyl.paginate.admin.servers') ), ]); From edaf895e450ecfd4bd14c1184134a41fadac39a3 Mon Sep 17 00:00:00 2001 From: DoNotSpamPls <7570108+DoNotSpamPls@users.noreply.github.com> Date: Sat, 24 Feb 2018 19:54:40 +0200 Subject: [PATCH 05/14] Remove even more mentions of the forum (#971) --- CONTRIBUTING.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5f2512847..8f701c8a2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,4 +41,4 @@ If you've found what you believe is a security issue please email us at `support ### Where to find Us You can find us in a couple places online. First and foremost, we're active right here on Github. If you encounter a bug or other problem open an issue on here for us to take a look at it. We also accept feature requests here as well. -You can also find us on [Discord](https://pterodactyl.io/discord). In the event that you need to get in contact with us privately feel free to contact us at `support@pterodactyl.io`. Try not to email us with requests for support regarding the panel, we'll probably just direct you to our forums or Discord. +You can also find us on [Discord](https://pterodactyl.io/discord). In the event that you need to get in contact with us privately feel free to contact us at `support@pterodactyl.io`. Try not to email us with requests for support regarding the panel, we'll probably just direct you to our Discord. diff --git a/README.md b/README.md index c74fa7945..358e74fa5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Pterodactyl Panel is the free, open-source, game agnostic, self-hosted control panel for users, networks, and game service providers. Pterodactyl supports games and servers such as Minecraft (including Spigot, Bungeecord, and Sponge), ARK: Evolution Evolved, CS:GO, Team Fortress 2, Insurgency, Teamspeak 3, Mumble, and many more. Control all of your games from one unified interface. ## Support & Documentation -Support for using Pterodactyl can be found on our [Documentation Website](https://docs.pterodactyl.io), our [Discord Chat](https://discord.gg/QRDZvVm), or via our [Forums](https://forums.pterodactyl.io). +Support for using Pterodactyl can be found on our [Documentation Website](https://docs.pterodactyl.io) or via our [Discord Chat](https://discord.gg/QRDZvVm). ## License ``` From 633bba6d6ec52ccebd6a17c13152509b23a249dc Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 11:57:12 -0600 Subject: [PATCH 06/14] Add support for external_id on servers, closes #975 --- CHANGELOG.md | 1 + .../Controllers/Admin/ServersController.php | 2 +- .../Servers/StoreServerRequest.php | 1 + app/Models/Server.php | 15 +++++---- .../Servers/DetailsModificationService.php | 1 + .../Servers/ServerCreationService.php | 1 + .../Api/Application/ServerTransformer.php | 6 ++-- ...dd_external_id_column_to_servers_table.php | 32 +++++++++++++++++++ .../admin/servers/view/details.blade.php | 9 ++++-- .../admin/servers/view/index.blade.php | 16 ++++++++-- .../DetailsModificationServiceTest.php | 4 ++- 11 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 database/migrations/2018_02_24_112356_add_external_id_column_to_servers_table.php diff --git a/CHANGELOG.md b/CHANGELOG.md index dbb5c7c38..cf3161d61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Added * Adds ability to include egg variables on an API request. +* Added `external_id` column to servers that allows for easier linking with external services such as WHMCS. ## v0.7.1 (Derelict Dermodactylus) ### Fixed diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 9e22bc1ed..6b9d44cbb 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -406,7 +406,7 @@ class ServersController extends Controller public function setDetails(Request $request, Server $server) { $this->detailsModificationService->handle($server, $request->only([ - 'owner_id', 'name', 'description', + 'owner_id', 'external_id', 'name', 'description', ])); $this->alert->success(trans('admin/server.alerts.details_updated'))->flash(); diff --git a/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php b/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php index ff389e05e..997c2e396 100644 --- a/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php +++ b/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php @@ -31,6 +31,7 @@ class StoreServerRequest extends ApplicationApiRequest $rules = Server::getCreateRules(); return [ + 'external_id' => $rules['external_id'], 'name' => $rules['name'], 'description' => array_merge(['nullable'], $rules['description']), 'user' => $rules['owner_id'], diff --git a/app/Models/Server.php b/app/Models/Server.php index f10e52b1d..458bff1d6 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -53,6 +53,7 @@ class Server extends Model implements CleansAttributes, ValidableContract * @var array */ protected static $applicationRules = [ + 'external_id' => 'sometimes', 'owner_id' => 'required', 'name' => 'required', 'memory' => 'required', @@ -74,6 +75,7 @@ class Server extends Model implements CleansAttributes, ValidableContract * @var array */ protected static $dataIntegrityRules = [ + 'external_id' => 'nullable|string|between:1,191|unique:servers', 'owner_id' => 'integer|exists:users,id', 'name' => 'string|min:1|max:255', 'node_id' => 'exists:nodes,id', @@ -122,13 +124,14 @@ class Server extends Model implements CleansAttributes, ValidableContract * @var array */ protected $searchableColumns = [ - 'name' => 50, - 'uuidShort' => 10, - 'uuid' => 10, - 'pack.name' => 5, - 'user.email' => 20, - 'user.username' => 20, + 'name' => 100, + 'uuid' => 80, + 'uuidShort' => 80, + 'external_id' => 50, + 'user.email' => 40, + 'user.username' => 30, 'node.name' => 10, + 'pack.name' => 10, ]; /** diff --git a/app/Services/Servers/DetailsModificationService.php b/app/Services/Servers/DetailsModificationService.php index 78d8eb31e..523185f2e 100644 --- a/app/Services/Servers/DetailsModificationService.php +++ b/app/Services/Servers/DetailsModificationService.php @@ -69,6 +69,7 @@ class DetailsModificationService $this->connection->beginTransaction(); $response = $this->repository->setFreshModel($this->getUpdatedModel())->update($server->id, [ + 'external_id' => array_get($data, 'external_id'), 'owner_id' => array_get($data, 'owner_id'), 'name' => array_get($data, 'name'), 'description' => array_get($data, 'description') ?? '', diff --git a/app/Services/Servers/ServerCreationService.php b/app/Services/Servers/ServerCreationService.php index a57e7712b..0c5ecd0d4 100644 --- a/app/Services/Servers/ServerCreationService.php +++ b/app/Services/Servers/ServerCreationService.php @@ -211,6 +211,7 @@ class ServerCreationService private function createModel(array $data): Server { return $this->repository->create([ + 'external_id' => array_get($data, 'external_id'), 'uuid' => Uuid::uuid4()->toString(), 'uuidShort' => str_random(8), 'node_id' => array_get($data, 'node_id'), diff --git a/app/Transformers/Api/Application/ServerTransformer.php b/app/Transformers/Api/Application/ServerTransformer.php index 914449ef2..69115d1ed 100644 --- a/app/Transformers/Api/Application/ServerTransformer.php +++ b/app/Transformers/Api/Application/ServerTransformer.php @@ -2,7 +2,6 @@ namespace Pterodactyl\Transformers\Api\Application; -use Cake\Chronos\Chronos; use Pterodactyl\Models\Server; use Pterodactyl\Services\Acl\Api\AdminAcl; use Pterodactyl\Services\Servers\EnvironmentService; @@ -63,6 +62,7 @@ class ServerTransformer extends BaseTransformer { return [ 'id' => $server->getKey(), + 'external_id' => $server->external_id, 'uuid' => $server->uuid, 'identifier' => $server->uuidShort, 'name' => $server->name, @@ -87,8 +87,8 @@ class ServerTransformer extends BaseTransformer 'installed' => (int) $server->installed === 1, 'environment' => $this->environmentService->handle($server), ], - 'created_at' => Chronos::createFromFormat(Chronos::DEFAULT_TO_STRING_FORMAT, $server->created_at)->setTimezone('UTC')->toIso8601String(), - 'updated_at' => Chronos::createFromFormat(Chronos::DEFAULT_TO_STRING_FORMAT, $server->updated_at)->setTimezone('UTC')->toIso8601String(), + $server->getUpdatedAtColumn() => $this->formatTimestamp($server->updated_at), + $server->getCreatedAtColumn() => $this->formatTimestamp($server->created_at), ]; } diff --git a/database/migrations/2018_02_24_112356_add_external_id_column_to_servers_table.php b/database/migrations/2018_02_24_112356_add_external_id_column_to_servers_table.php new file mode 100644 index 000000000..2c8af99e2 --- /dev/null +++ b/database/migrations/2018_02_24_112356_add_external_id_column_to_servers_table.php @@ -0,0 +1,32 @@ +string('external_id')->after('id')->nullable()->unique(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('external_id'); + }); + } +} diff --git a/resources/themes/pterodactyl/admin/servers/view/details.blade.php b/resources/themes/pterodactyl/admin/servers/view/details.blade.php index 60bcded6d..bd4a5aef2 100644 --- a/resources/themes/pterodactyl/admin/servers/view/details.blade.php +++ b/resources/themes/pterodactyl/admin/servers/view/details.blade.php @@ -47,12 +47,17 @@
- +

Character limits: a-zA-Z0-9_- and [Space] (max 35 characters).

- + + +

Leave empty to not assign an external identifier for this server. The external ID should be unique to this server and not be in use by any other servers.

+
+
+ diff --git a/resources/themes/pterodactyl/admin/servers/view/index.blade.php b/resources/themes/pterodactyl/admin/servers/view/index.blade.php index 58deaa924..1d377a195 100644 --- a/resources/themes/pterodactyl/admin/servers/view/index.blade.php +++ b/resources/themes/pterodactyl/admin/servers/view/index.blade.php @@ -47,6 +47,18 @@
+ + + + + + + @if(is_null($server->external_id)) + + @else + + @endif + @@ -127,7 +139,7 @@
-

{{ str_limit($server->user->username, 8) }}

+

{{ str_limit($server->user->username, 16) }}

Server Owner

@@ -139,7 +151,7 @@
-

{{ str_limit($server->node->name, 8) }}

+

{{ str_limit($server->node->name, 16) }}

Server Node

diff --git a/tests/Unit/Services/Servers/DetailsModificationServiceTest.php b/tests/Unit/Services/Servers/DetailsModificationServiceTest.php index bd049d018..bbb7ab1ff 100644 --- a/tests/Unit/Services/Servers/DetailsModificationServiceTest.php +++ b/tests/Unit/Services/Servers/DetailsModificationServiceTest.php @@ -58,6 +58,7 @@ class DetailsModificationServiceTest extends TestCase $this->connection->shouldReceive('beginTransaction')->once()->withNoArgs()->andReturnNull(); $this->repository->shouldReceive('setFreshModel')->once()->with(false)->andReturnSelf(); $this->repository->shouldReceive('update')->once()->with($server->id, [ + 'external_id' => null, 'owner_id' => $data['owner_id'], 'name' => $data['name'], 'description' => $data['description'], @@ -95,11 +96,12 @@ class DetailsModificationServiceTest extends TestCase 'owner_id' => 1, ]); - $data = ['owner_id' => 2, 'name' => 'New Name', 'description' => 'New Description']; + $data = ['owner_id' => 2, 'name' => 'New Name', 'description' => 'New Description', 'external_id' => 'abcd1234']; $this->connection->shouldReceive('beginTransaction')->once()->withNoArgs()->andReturnNull(); $this->repository->shouldReceive('setFreshModel')->once()->with(false)->andReturnSelf(); $this->repository->shouldReceive('update')->once()->with($server->id, [ + 'external_id' => 'abcd1234', 'owner_id' => $data['owner_id'], 'name' => $data['name'], 'description' => $data['description'], From 807521b97c2de8e388be7392db018434422d4e8e Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 12:04:14 -0600 Subject: [PATCH 07/14] Fix schedules with no names being uneditable --- CHANGELOG.md | 1 + app/Http/Requests/Server/ScheduleCreationFormRequest.php | 2 +- resources/themes/pterodactyl/server/schedules/index.blade.php | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf3161d61..68a3a6f9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Fixed * Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint. * Fixes search on server listing page. +* Schedules with no names are now clickable to allow editing. ### Added * Adds ability to include egg variables on an API request. diff --git a/app/Http/Requests/Server/ScheduleCreationFormRequest.php b/app/Http/Requests/Server/ScheduleCreationFormRequest.php index 2be18434f..a90dd749a 100644 --- a/app/Http/Requests/Server/ScheduleCreationFormRequest.php +++ b/app/Http/Requests/Server/ScheduleCreationFormRequest.php @@ -33,7 +33,7 @@ class ScheduleCreationFormRequest extends ServerFormRequest public function rules() { return [ - 'name' => 'string|max:255', + 'name' => 'nullable|string|max:255', 'cron_day_of_week' => 'required|string', 'cron_day_of_month' => 'required|string', 'cron_hour' => 'required|string', diff --git a/resources/themes/pterodactyl/server/schedules/index.blade.php b/resources/themes/pterodactyl/server/schedules/index.blade.php index b51ee089c..aefcef5de 100644 --- a/resources/themes/pterodactyl/server/schedules/index.blade.php +++ b/resources/themes/pterodactyl/server/schedules/index.blade.php @@ -43,7 +43,9 @@
is_active)class="muted muted-hover"@endif>
Internal Identifier{{ $server->id }}
External IdentifierNot Set{{ $server->external_id }}
UUID / Docker Container ID {{ $server->uuid }}
@can('edit-schedule', $server) - {{ $schedule->name }} + + {{ $schedule->name ?? trans('server.schedule.unnamed') }} + @else {{ $schedule->name ?? trans('server.schedule.unnamed') }} @endcan From baeffef24be620c0d1fe5096407a4a93b84e722f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 12:15:21 -0600 Subject: [PATCH 08/14] Fix bad permissions check on server API route --- CHANGELOG.md | 1 + .../Application/Servers/ServerController.php | 5 +++-- .../Application/Servers/GetServerRequest.php | 19 +++++++++++++++++++ .../Application/Servers/GetServersRequest.php | 15 +-------------- 4 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 app/Http/Requests/Api/Application/Servers/GetServerRequest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 68a3a6f9d..44d320e82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint. * Fixes search on server listing page. * Schedules with no names are now clickable to allow editing. +* Fixes broken permissions check that would deny access to API keys that did in fact have permission. ### Added * Adds ability to include egg variables on an API request. diff --git a/app/Http/Controllers/Api/Application/Servers/ServerController.php b/app/Http/Controllers/Api/Application/Servers/ServerController.php index f869393af..1ef1e0b62 100644 --- a/app/Http/Controllers/Api/Application/Servers/ServerController.php +++ b/app/Http/Controllers/Api/Application/Servers/ServerController.php @@ -9,6 +9,7 @@ use Pterodactyl\Services\Servers\ServerCreationService; use Pterodactyl\Services\Servers\ServerDeletionService; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; use Pterodactyl\Transformers\Api\Application\ServerTransformer; +use Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest; use Pterodactyl\Http\Requests\Api\Application\Servers\GetServersRequest; use Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest; use Pterodactyl\Http\Requests\Api\Application\Servers\StoreServerRequest; @@ -91,10 +92,10 @@ class ServerController extends ApplicationApiController /** * Show a single server transformed for the application API. * - * @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request + * @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest $request * @return array */ - public function view(ServerWriteRequest $request): array + public function view(GetServerRequest $request): array { return $this->fractal->item($request->getModel(Server::class)) ->transformWith($this->getTransformer(ServerTransformer::class)) diff --git a/app/Http/Requests/Api/Application/Servers/GetServerRequest.php b/app/Http/Requests/Api/Application/Servers/GetServerRequest.php new file mode 100644 index 000000000..82d12687c --- /dev/null +++ b/app/Http/Requests/Api/Application/Servers/GetServerRequest.php @@ -0,0 +1,19 @@ + Date: Sat, 24 Feb 2018 12:27:41 -0600 Subject: [PATCH 09/14] Slightly more clear errors --- app/Http/Middleware/Api/Application/AuthenticateUser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Middleware/Api/Application/AuthenticateUser.php b/app/Http/Middleware/Api/Application/AuthenticateUser.php index 5bbce8296..7208dbaf9 100644 --- a/app/Http/Middleware/Api/Application/AuthenticateUser.php +++ b/app/Http/Middleware/Api/Application/AuthenticateUser.php @@ -19,7 +19,7 @@ class AuthenticateUser public function handle(Request $request, Closure $next) { if (is_null($request->user()) || ! $request->user()->root_admin) { - throw new AccessDeniedHttpException; + throw new AccessDeniedHttpException('This account does not have permission to access the API.'); } return $next($request); From a1e704d3a7b9df21dc0774e2b01dc63fea3fdd4e Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 13:58:48 -0600 Subject: [PATCH 10/14] Add back server sidebar list --- CHANGELOG.md | 1 + .../Repository/ServerRepositoryInterface.php | 5 +- app/Http/ViewComposers/ServerListComposer.php | 51 +++++++++++++++++++ app/Providers/ViewComposerServiceProvider.php | 11 ++-- .../Eloquent/ServerRepository.php | 16 +++--- .../pterodactyl/layouts/master.blade.php | 33 ++++++++++-- 6 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 app/Http/ViewComposers/ServerListComposer.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 44d320e82..b4edd9765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Added * Adds ability to include egg variables on an API request. * Added `external_id` column to servers that allows for easier linking with external services such as WHMCS. +* Added back the sidebar when viewing servers that allows for quick-switching to a different server. ## v0.7.1 (Derelict Dermodactylus) ### Fixed diff --git a/app/Contracts/Repository/ServerRepositoryInterface.php b/app/Contracts/Repository/ServerRepositoryInterface.php index 6d1c14e78..0ca74bf40 100644 --- a/app/Contracts/Repository/ServerRepositoryInterface.php +++ b/app/Contracts/Repository/ServerRepositoryInterface.php @@ -103,9 +103,10 @@ interface ServerRepositoryInterface extends RepositoryInterface, SearchableInter * * @param \Pterodactyl\Models\User $user * @param int $level - * @return \Illuminate\Pagination\LengthAwarePaginator + * @param bool $paginate + * @return \Illuminate\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection */ - public function filterUserAccessServers(User $user, int $level): LengthAwarePaginator; + public function filterUserAccessServers(User $user, int $level, bool $paginate = true); /** * Return a server by UUID. diff --git a/app/Http/ViewComposers/ServerListComposer.php b/app/Http/ViewComposers/ServerListComposer.php new file mode 100644 index 000000000..4c3ac71fb --- /dev/null +++ b/app/Http/ViewComposers/ServerListComposer.php @@ -0,0 +1,51 @@ +request = $request; + $this->repository = $repository; + } + + /** + * Attach a list of servers the user can access to the view. + * + * @param \Illuminate\View\View $view + */ + public function compose(View $view) + { + if (! $this->request->user()) { + return; + } + + $servers = $this->repository + ->setColumns(['id', 'owner_id', 'uuidShort', 'name', 'description']) + ->filterUserAccessServers($this->request->user(), User::FILTER_LEVEL_SUBUSER, false); + + $view->with('sidebarServerList', $servers); + } +} diff --git a/app/Providers/ViewComposerServiceProvider.php b/app/Providers/ViewComposerServiceProvider.php index dddc925f4..ab8c9e164 100644 --- a/app/Providers/ViewComposerServiceProvider.php +++ b/app/Providers/ViewComposerServiceProvider.php @@ -1,15 +1,9 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Providers; use Illuminate\Support\ServiceProvider; +use Pterodactyl\Http\ViewComposers\ServerListComposer; use Pterodactyl\Http\ViewComposers\Server\ServerDataComposer; class ViewComposerServiceProvider extends ServiceProvider @@ -20,5 +14,8 @@ class ViewComposerServiceProvider extends ServiceProvider public function boot() { $this->app->make('view')->composer('server.*', ServerDataComposer::class); + + // Add data to make the sidebar work when viewing a server. + $this->app->make('view')->composer(['server.*'], ServerListComposer::class); } } diff --git a/app/Repositories/Eloquent/ServerRepository.php b/app/Repositories/Eloquent/ServerRepository.php index 4bf058a72..7bca12691 100644 --- a/app/Repositories/Eloquent/ServerRepository.php +++ b/app/Repositories/Eloquent/ServerRepository.php @@ -211,11 +211,12 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt * * @param \Pterodactyl\Models\User $user * @param int $level - * @return \Illuminate\Pagination\LengthAwarePaginator + * @param bool $paginate + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection */ - public function filterUserAccessServers(User $user, int $level): LengthAwarePaginator + public function filterUserAccessServers(User $user, int $level, bool $paginate = true) { - $instance = $this->getBuilder()->with(['user']); + $instance = $this->getBuilder()->select($this->getColumns())->with(['user']); // If access level is set to owner, only display servers // that the user owns. @@ -224,8 +225,9 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt } // If set to all, display all servers they can access, including - // those they access as an admin. If set to subuser, only return the servers they can access because - // they are owner, or marked as a subuser of the server. + // those they access as an admin. If set to subuser, only return + // the servers they can access because they are owner, or marked + // as a subuser of the server. elseif (($level === User::FILTER_LEVEL_ALL && ! $user->root_admin) || $level === User::FILTER_LEVEL_SUBUSER) { $instance->whereIn('id', $this->getUserAccessServers($user->id)); } @@ -236,7 +238,9 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt $instance->whereNotIn('id', $this->getUserAccessServers($user->id)); } - return $instance->search($this->getSearchTerm())->paginate(25); + $instance->search($this->getSearchTerm()); + + return $paginate ? $instance->paginate(25) : $instance->get(); } /** diff --git a/resources/themes/pterodactyl/layouts/master.blade.php b/resources/themes/pterodactyl/layouts/master.blade.php index 7ffb06847..39e5a9dd6 100644 --- a/resources/themes/pterodactyl/layouts/master.blade.php +++ b/resources/themes/pterodactyl/layouts/master.blade.php @@ -60,9 +60,13 @@ - {{--
  • --}} - {{----}} - {{--
  • --}} + @if(isset($sidebarServerList)) +
  • + + + +
  • + @endif @if(Auth::user()->root_admin)
  • @@ -240,6 +244,29 @@ Copyright © 2015 - {{ date('Y') }} Pterodactyl Software. + @if(isset($sidebarServerList)) + + @endif
    @section('footer-scripts') From fb1b2406b55c6ce79df938dc841bedeeae54fbc7 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 14:09:09 -0600 Subject: [PATCH 11/14] Add API endpoint to get a server by external ID --- CHANGELOG.md | 1 + .../Servers/ExternalServerController.php | 23 ++++++++ .../Servers/GetExternalServerRequest.php | 57 +++++++++++++++++++ routes/api-application.php | 1 + 4 files changed, 82 insertions(+) create mode 100644 app/Http/Controllers/Api/Application/Servers/ExternalServerController.php create mode 100644 app/Http/Requests/Api/Application/Servers/GetExternalServerRequest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index b4edd9765..104256f65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * Adds ability to include egg variables on an API request. * Added `external_id` column to servers that allows for easier linking with external services such as WHMCS. * Added back the sidebar when viewing servers that allows for quick-switching to a different server. +* Added API endpoint to get a server by external ID. ## v0.7.1 (Derelict Dermodactylus) ### Fixed diff --git a/app/Http/Controllers/Api/Application/Servers/ExternalServerController.php b/app/Http/Controllers/Api/Application/Servers/ExternalServerController.php new file mode 100644 index 000000000..391c5645c --- /dev/null +++ b/app/Http/Controllers/Api/Application/Servers/ExternalServerController.php @@ -0,0 +1,23 @@ +fractal->item($request->getServerModel()) + ->transformWith($this->getTransformer(ServerTransformer::class)) + ->toArray(); + } +} diff --git a/app/Http/Requests/Api/Application/Servers/GetExternalServerRequest.php b/app/Http/Requests/Api/Application/Servers/GetExternalServerRequest.php new file mode 100644 index 000000000..f783dc715 --- /dev/null +++ b/app/Http/Requests/Api/Application/Servers/GetExternalServerRequest.php @@ -0,0 +1,57 @@ +container->make(ServerRepositoryInterface::class); + + try { + $this->serverModel = $repository->findFirstWhere([ + ['external_id', '=', $this->route()->parameter('external_id')], + ]); + } catch (RecordNotFoundException $exception) { + return false; + } + + return true; + } + + /** + * Return the server model for the requested external server. + * + * @return \Pterodactyl\Models\Server + */ + public function getServerModel(): Server + { + return $this->serverModel; + } +} diff --git a/routes/api-application.php b/routes/api-application.php index 900de8c6a..9b3b4f073 100644 --- a/routes/api-application.php +++ b/routes/api-application.php @@ -74,6 +74,7 @@ Route::group(['prefix' => '/locations'], function () { Route::group(['prefix' => '/servers'], function () { Route::get('/', 'Servers\ServerController@index')->name('api.application.servers'); Route::get('/{server}', 'Servers\ServerController@view')->name('api.application.servers.view'); + Route::get('/external/{external_id}', 'Servers\ExternalServerController@index')->name('api.application.servers.external'); Route::patch('/{server}/details', 'Servers\ServerDetailsController@details')->name('api.application.servers.details'); Route::patch('/{server}/build', 'Servers\ServerDetailsController@build')->name('api.application.servers.build'); From 5c4200dc0c8c977bcf2a7b634981eddd8fd23318 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 14:47:53 -0600 Subject: [PATCH 12/14] Make external_id fillable --- app/Models/User.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/User.php b/app/Models/User.php index 88960994f..10c710f19 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -64,6 +64,7 @@ class User extends Model implements * @var array */ protected $fillable = [ + 'external_id', 'username', 'email', 'name_first', From bdbed7706d866ff4aba792a79ae56ce4ef188100 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 16:00:53 -0600 Subject: [PATCH 13/14] Set much higher throttle limits by default --- app/Models/Node.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Models/Node.php b/app/Models/Node.php index 12556cdee..0134b7c7a 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -161,9 +161,10 @@ class Node extends Model implements CleansAttributes, ValidableContract 'disk_use_seconds' => 30, 'set_permissions_on_boot' => true, 'throttle' => [ + 'enabled' => true, 'kill_at_count' => 5, 'decay' => 10, - 'bytes' => 4096, + 'bytes' => 30720, 'check_interval_ms' => 100, ], ], From 2460d99eb64ded1758f8a2f05fa3e8d4471bc4d7 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 16:28:05 -0600 Subject: [PATCH 14/14] bump for release --- config/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/app.php b/config/app.php index c1c94fa61..bb4b66015 100644 --- a/config/app.php +++ b/config/app.php @@ -9,7 +9,7 @@ return [ | change this value if you are not maintaining your own internal versions. */ - 'version' => 'canary', + 'version' => '0.7.2', /* |--------------------------------------------------------------------------