From 4cebc385096649e212034f437774b1dbb10ea371 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 14:22:17 -0400 Subject: [PATCH 01/69] Add base phpstan --- composer.json | 1 + composer.lock | 231 +++++++++++++++++++++++++++++++++++++++++++++++++- phpstan.neon | 18 ++++ 3 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index 160537b6bb..a03a9dcfc1 100644 --- a/composer.json +++ b/composer.json @@ -61,6 +61,7 @@ "laravel/sail": "~1.16", "mockery/mockery": "~1.5", "nunomaduro/collision": "~6.3", + "nunomaduro/larastan": "^2.0", "php-mock/php-mock-phpunit": "~2.6", "phpunit/phpunit": "~9.5", "spatie/laravel-ignition": "~1.5" diff --git a/composer.lock b/composer.lock index 9f4b73f6f9..381b321ae5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ae61e7d6e405e3a59c8a54f3eefa2c50", + "content-hash": "88999658a97429a6840f4da57ea115b1", "packages": [ { "name": "aws/aws-crt-php", @@ -9004,6 +9004,103 @@ ], "time": "2022-09-29T12:29:49+00:00" }, + { + "name": "nunomaduro/larastan", + "version": "2.2.7", + "source": { + "type": "git", + "url": "https://github.com/nunomaduro/larastan.git", + "reference": "a3f67a4a668e477751557b0b19ad2c870e1e4e56" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nunomaduro/larastan/zipball/a3f67a4a668e477751557b0b19ad2c870e1e4e56", + "reference": "a3f67a4a668e477751557b0b19ad2c870e1e4e56", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/console": "^9", + "illuminate/container": "^9", + "illuminate/contracts": "^9", + "illuminate/database": "^9", + "illuminate/http": "^9", + "illuminate/pipeline": "^9", + "illuminate/support": "^9", + "mockery/mockery": "^1.4.4", + "php": "^8.0.2", + "phpmyadmin/sql-parser": "^5.5", + "phpstan/phpstan": "^1.8.7" + }, + "require-dev": { + "nikic/php-parser": "^4.13.2", + "orchestra/testbench": "^7.0.0", + "phpunit/phpunit": "^9.5.11" + }, + "suggest": { + "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" + }, + "type": "phpstan-extension", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + }, + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "NunoMaduro\\Larastan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "larastan", + "laravel", + "package", + "php", + "static analysis" + ], + "support": { + "issues": "https://github.com/nunomaduro/larastan/issues", + "source": "https://github.com/nunomaduro/larastan/tree/2.2.7" + }, + "funding": [ + { + "url": "https://www.paypal.com/paypalme/enunomaduro", + "type": "custom" + }, + { + "url": "https://github.com/canvural", + "type": "github" + }, + { + "url": "https://github.com/nunomaduro", + "type": "github" + }, + { + "url": "https://www.patreon.com/nunomaduro", + "type": "patreon" + } + ], + "time": "2022-10-30T15:02:40+00:00" + }, { "name": "phar-io/manifest", "version": "2.0.3", @@ -9422,6 +9519,138 @@ }, "time": "2022-10-14T12:47:21+00:00" }, + { + "name": "phpmyadmin/sql-parser", + "version": "5.5.0", + "source": { + "type": "git", + "url": "https://github.com/phpmyadmin/sql-parser.git", + "reference": "8ab99cd0007d880f49f5aa1807033dbfa21b1cb5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/8ab99cd0007d880f49f5aa1807033dbfa21b1cb5", + "reference": "8ab99cd0007d880f49f5aa1807033dbfa21b1cb5", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0", + "symfony/polyfill-mbstring": "^1.3" + }, + "conflict": { + "phpmyadmin/motranslator": "<3.0" + }, + "require-dev": { + "phpmyadmin/coding-standard": "^3.0", + "phpmyadmin/motranslator": "^4.0 || ^5.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.2", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/php-code-coverage": "*", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "^0.16.1", + "vimeo/psalm": "^4.11", + "zumba/json-serializer": "^3.0" + }, + "suggest": { + "ext-mbstring": "For best performance", + "phpmyadmin/motranslator": "Translate messages to your favorite locale" + }, + "bin": [ + "bin/highlight-query", + "bin/lint-query", + "bin/tokenize-query" + ], + "type": "library", + "autoload": { + "psr-4": { + "PhpMyAdmin\\SqlParser\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "The phpMyAdmin Team", + "email": "developers@phpmyadmin.net", + "homepage": "https://www.phpmyadmin.net/team/" + } + ], + "description": "A validating SQL lexer and parser with a focus on MySQL dialect.", + "homepage": "https://github.com/phpmyadmin/sql-parser", + "keywords": [ + "analysis", + "lexer", + "parser", + "sql" + ], + "support": { + "issues": "https://github.com/phpmyadmin/sql-parser/issues", + "source": "https://github.com/phpmyadmin/sql-parser" + }, + "time": "2021-12-09T04:31:52+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "1.8.11", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "46e223dd68a620da18855c23046ddb00940b4014" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/46e223dd68a620da18855c23046ddb00940b4014", + "reference": "46e223dd68a620da18855c23046ddb00940b4014", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/1.8.11" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2022-10-24T15:45:13+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.17", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000000..cce1b79eb4 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,18 @@ +includes: + - ./vendor/nunomaduro/larastan/extension.neon + +parameters: + + paths: + - app/ + + # Level 9 is the highest level + level: 1 + +# ignoreErrors: +# - '#PHPDoc tag @var#' +# +# excludePaths: +# - ./*/*/FileToBeExcluded.php +# +# checkMissingIterableValueType: false From af593c8f171190f826cda3a9af6b58c9bc427fc6 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:16:37 -0400 Subject: [PATCH 02/69] Prevent issues with "new static" --- app/Exceptions/Handler.php | 2 +- app/Rules/Fqdn.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index bcc636b5c7..00cc8615ed 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -25,7 +25,7 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; -class Handler extends ExceptionHandler +final class Handler extends ExceptionHandler { /** * The validation parser in Laravel formats custom rules using the class name diff --git a/app/Rules/Fqdn.php b/app/Rules/Fqdn.php index 47baf510d7..499933548b 100644 --- a/app/Rules/Fqdn.php +++ b/app/Rules/Fqdn.php @@ -6,7 +6,7 @@ use Illuminate\Contracts\Validation\Rule; use Illuminate\Contracts\Validation\DataAwareRule; -class Fqdn implements Rule, DataAwareRule +final class Fqdn implements Rule, DataAwareRule { protected array $data = []; protected string $message = ''; From 8f38740b564c1310a043da39da2943023ecdfe6b Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:16:46 -0400 Subject: [PATCH 03/69] Add missing import --- app/Transformers/Api/Application/ServerVariableTransformer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Transformers/Api/Application/ServerVariableTransformer.php b/app/Transformers/Api/Application/ServerVariableTransformer.php index 25e8f879bd..e27d1e0135 100644 --- a/app/Transformers/Api/Application/ServerVariableTransformer.php +++ b/app/Transformers/Api/Application/ServerVariableTransformer.php @@ -4,6 +4,7 @@ use League\Fractal\Resource\Item; use Pterodactyl\Models\EggVariable; +use Pterodactyl\Models\ServerVariable; use League\Fractal\Resource\NullResource; use Pterodactyl\Services\Acl\Api\AdminAcl; From 88847b375727f83bd57140fe9645aad18a363522 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:16:58 -0400 Subject: [PATCH 04/69] Variable might not have been defined --- app/Services/Allocations/AssignmentService.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Services/Allocations/AssignmentService.php b/app/Services/Allocations/AssignmentService.php index ec79d18f18..11d3013224 100644 --- a/app/Services/Allocations/AssignmentService.php +++ b/app/Services/Allocations/AssignmentService.php @@ -40,23 +40,24 @@ public function __construct(protected AllocationRepositoryInterface $repository, */ public function handle(Node $node, array $data): void { - $explode = explode('/', $data['allocation_ip']); + $allocationIp = $data['allocation_ip']; + $explode = explode('/', $allocationIp); if (count($explode) !== 1) { if (!ctype_digit($explode[1]) || ($explode[1] > self::CIDR_MIN_BITS || $explode[1] < self::CIDR_MAX_BITS)) { throw new CidrOutOfRangeException(); } } + $underlying = 'Unknown IP'; try { // TODO: how should we approach supporting IPv6 with this? // gethostbyname only supports IPv4, but the alternative (dns_get_record) returns // an array of records, which is not ideal for this use case, we need a SINGLE // IP to use, not multiple. - $underlying = gethostbyname($data['allocation_ip']); + $underlying = gethostbyname($allocationIp); $parsed = Network::parse($underlying); } catch (Exception $exception) { - /* @noinspection PhpUndefinedVariableInspection */ - throw new DisplayException("Could not parse provided allocation IP address ({$underlying}): {$exception->getMessage()}", $exception); + throw new DisplayException("Could not parse provided allocation IP address for $allocationIp ($underlying): {$exception->getMessage()}", $exception); } $this->connection->beginTransaction(); From ecb6c5029b10bc0656665605ff913cc7a1597012 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:17:10 -0400 Subject: [PATCH 05/69] Be explicit --- app/Repositories/Eloquent/NodeRepository.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Repositories/Eloquent/NodeRepository.php b/app/Repositories/Eloquent/NodeRepository.php index fe019e50a9..388e48bb4c 100644 --- a/app/Repositories/Eloquent/NodeRepository.php +++ b/app/Repositories/Eloquent/NodeRepository.php @@ -147,6 +147,8 @@ public function getNodeWithResourceUsage(int $node_id): Node ->leftJoin('servers', 'servers.node_id', '=', 'nodes.id') ->where('nodes.id', $node_id); - return $instance->first(); + /** @var Node $node */ + $node = $instance->first(); + return $node; } } From c05dba8e2fb3f2a4e6fc1d864121b4276b20dfa1 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:17:21 -0400 Subject: [PATCH 06/69] Already imported --- app/Http/Controllers/Auth/AbstractLoginController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/AbstractLoginController.php b/app/Http/Controllers/Auth/AbstractLoginController.php index f07282fbac..519c354657 100644 --- a/app/Http/Controllers/Auth/AbstractLoginController.php +++ b/app/Http/Controllers/Auth/AbstractLoginController.php @@ -49,7 +49,7 @@ public function __construct() /** * Get the failed login response instance. * - * @throws \Pterodactyl\Exceptions\DisplayException + * @throws DisplayException */ protected function sendFailedLoginResponse(Request $request, Authenticatable $user = null, string $message = null) { From 4ecc046530cd7851cbe6d38ed4f7e7a9a44f9655 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:18:05 -0400 Subject: [PATCH 07/69] Easier to read and handle missing allocations --- app/Services/Servers/BuildModificationService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index 05553d7f10..51bb0ee980 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -88,16 +88,16 @@ private function processAllocations(Server $server, array &$data): void // Handle the addition of allocations to this server. Only assign allocations that are not currently // assigned to a different server, and only allocations on the same node as the server. if (!empty($data['add_allocations'])) { - $query = Allocation::query() - ->where('node_id', $server->node_id) + $allocations = $server->node->allocations() ->whereIn('id', $data['add_allocations']) - ->whereNull('server_id'); + ->whereNull('server_id') + ->get(); // Keep track of all the allocations we're just now adding so that we can use the first // one to reset the default allocation to. - $freshlyAllocated = $query->pluck('id')->first(); + $freshlyAllocated = $allocations->first()->id ?? null; - $query->update(['server_id' => $server->id, 'notes' => null]); + $allocations->update(['server_id' => $server->id, 'notes' => null]); } if (!empty($data['remove_allocations'])) { From ca9ab8403435270e386c94d3db5e237471ab02a8 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:38:24 -0400 Subject: [PATCH 08/69] Use aggregate functions --- .../Controllers/Admin/Servers/ServerTransferController.php | 5 ++--- app/Models/Node.php | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Admin/Servers/ServerTransferController.php b/app/Http/Controllers/Admin/Servers/ServerTransferController.php index 0962174186..7c6c4fdfd4 100644 --- a/app/Http/Controllers/Admin/Servers/ServerTransferController.php +++ b/app/Http/Controllers/Admin/Servers/ServerTransferController.php @@ -3,13 +3,13 @@ namespace Pterodactyl\Http\Controllers\Admin\Servers; use Illuminate\Http\Request; +use Pterodactyl\Models\Node; use Pterodactyl\Models\Server; use Illuminate\Http\RedirectResponse; use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Models\ServerTransfer; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Servers\TransferService; -use Pterodactyl\Repositories\Eloquent\NodeRepository; use Pterodactyl\Repositories\Wings\DaemonConfigurationRepository; use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface; @@ -21,7 +21,6 @@ class ServerTransferController extends Controller public function __construct( private AlertsMessageBag $alert, private AllocationRepositoryInterface $allocationRepository, - private NodeRepository $nodeRepository, private TransferService $transferService, private DaemonConfigurationRepository $daemonConfigurationRepository ) { @@ -45,7 +44,7 @@ public function transfer(Request $request, Server $server): RedirectResponse $additional_allocations = array_map('intval', $validatedData['allocation_additional'] ?? []); // Check if the node is viable for the transfer. - $node = $this->nodeRepository->getNodeWithResourceUsage($node_id); + $node = Node::query()->findOrFail($node_id); if ($node->isViable($server->memory, $server->disk)) { // Check if the selected daemon is online. $this->daemonConfigurationRepository->setNode($node)->getSystemInformation(); diff --git a/app/Models/Node.php b/app/Models/Node.php index 37aec760d6..0261e8b875 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -24,8 +24,10 @@ * @property bool $maintenance_mode * @property int $memory * @property int $memory_overallocate + * @property int $sum_memory * @property int $disk * @property int $disk_overallocate + * @property int $sum_disk * @property int $upload_size * @property string $daemon_token_id * @property string $daemon_token @@ -220,6 +222,9 @@ public function allocations(): HasMany */ public function isViable(int $memory, int $disk): bool { + $this->loadSum('servers as sum_memory', 'memory'); + $this->loadSum('servers as disk_memory', 'disk'); + $memoryLimit = $this->memory * (1 + ($this->memory_overallocate / 100)); $diskLimit = $this->disk * (1 + ($this->disk_overallocate / 100)); From 2d63516c0ef1ab08f3bdf01a9fedbfb88bf3ce11 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:39:03 -0400 Subject: [PATCH 09/69] Mark this as never returns, we can use the never return type in php 8.1 --- app/Http/Controllers/Auth/AbstractLoginController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/AbstractLoginController.php b/app/Http/Controllers/Auth/AbstractLoginController.php index 519c354657..bb7b6ff356 100644 --- a/app/Http/Controllers/Auth/AbstractLoginController.php +++ b/app/Http/Controllers/Auth/AbstractLoginController.php @@ -48,7 +48,7 @@ public function __construct() /** * Get the failed login response instance. - * + * @return never * @throws DisplayException */ protected function sendFailedLoginResponse(Request $request, Authenticatable $user = null, string $message = null) From c4fbbf0d4cde76b66298ba2cd8ac1a65a6df4492 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:41:11 -0400 Subject: [PATCH 10/69] This is probably correct --- .github/workflows/ci.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4da19b6ed2..542d388e55 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -59,6 +59,11 @@ jobs: - name: Install dependencies run: composer install --no-interaction --no-progress --no-suggest --prefer-dist + - name: Static analysis + uses: php-actions/phpstan@v3 + with: + path: src/ + - name: Unit tests run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests/Unit if: ${{ always() }} From da94f0d32f71ea421e1104ca7128da8a76ff2959 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:44:17 -0400 Subject: [PATCH 11/69] This is also probably more correctl --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 542d388e55..2e2de35215 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -62,7 +62,7 @@ jobs: - name: Static analysis uses: php-actions/phpstan@v3 with: - path: src/ + path: / - name: Unit tests run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests/Unit From 502e00f35e1dcd67351f9dd12e78f378764c22cb Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:46:29 -0400 Subject: [PATCH 12/69] php-cs-fixer --- app/Http/Controllers/Auth/AbstractLoginController.php | 2 ++ app/Repositories/Eloquent/NodeRepository.php | 1 + app/Rules/Fqdn.php | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Auth/AbstractLoginController.php b/app/Http/Controllers/Auth/AbstractLoginController.php index bb7b6ff356..74e7a9aa3a 100644 --- a/app/Http/Controllers/Auth/AbstractLoginController.php +++ b/app/Http/Controllers/Auth/AbstractLoginController.php @@ -48,7 +48,9 @@ public function __construct() /** * Get the failed login response instance. + * * @return never + * * @throws DisplayException */ protected function sendFailedLoginResponse(Request $request, Authenticatable $user = null, string $message = null) diff --git a/app/Repositories/Eloquent/NodeRepository.php b/app/Repositories/Eloquent/NodeRepository.php index 388e48bb4c..7f254cd1ed 100644 --- a/app/Repositories/Eloquent/NodeRepository.php +++ b/app/Repositories/Eloquent/NodeRepository.php @@ -149,6 +149,7 @@ public function getNodeWithResourceUsage(int $node_id): Node /** @var Node $node */ $node = $instance->first(); + return $node; } } diff --git a/app/Rules/Fqdn.php b/app/Rules/Fqdn.php index 499933548b..915ca40158 100644 --- a/app/Rules/Fqdn.php +++ b/app/Rules/Fqdn.php @@ -8,9 +8,9 @@ final class Fqdn implements Rule, DataAwareRule { - protected array $data = []; - protected string $message = ''; - protected ?string $schemeField = null; + private array $data = []; + private string $message = ''; + private ?string $schemeField = null; /** * @param array $data From fbb0d56cdadeffa2fd9ea522d123832f2ecc5b03 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 15:57:56 -0400 Subject: [PATCH 13/69] Increase memory --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2e2de35215..16507dd4d1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -63,6 +63,7 @@ jobs: uses: php-actions/phpstan@v3 with: path: / + memory_limit: 256M - name: Unit tests run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests/Unit From ce0c49773beb5e3272da5a4cff5138659c34972a Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 16:02:45 -0400 Subject: [PATCH 14/69] Just run it normally please --- .github/workflows/ci.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 16507dd4d1..c5f5224e46 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -60,10 +60,8 @@ jobs: run: composer install --no-interaction --no-progress --no-suggest --prefer-dist - name: Static analysis - uses: php-actions/phpstan@v3 - with: - path: / - memory_limit: 256M + run: vendor/bin/phpstan analyse + if: ${{ always() }} - name: Unit tests run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests/Unit From de67bc07d0a0c8ad5e1f31c2942c76c911b3e574 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 16:09:48 -0400 Subject: [PATCH 15/69] Simplify --- app/Services/Servers/BuildModificationService.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index 51bb0ee980..b7a22fdaae 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -88,16 +88,15 @@ private function processAllocations(Server $server, array &$data): void // Handle the addition of allocations to this server. Only assign allocations that are not currently // assigned to a different server, and only allocations on the same node as the server. if (!empty($data['add_allocations'])) { - $allocations = $server->node->allocations() + $query = $server->node->allocations() ->whereIn('id', $data['add_allocations']) - ->whereNull('server_id') - ->get(); + ->whereNull('server_id'); // Keep track of all the allocations we're just now adding so that we can use the first // one to reset the default allocation to. - $freshlyAllocated = $allocations->first()->id ?? null; + $freshlyAllocated = $query->first()->id ?? null; - $allocations->update(['server_id' => $server->id, 'notes' => null]); + $query->update(['server_id' => $server->id, 'notes' => null]); } if (!empty($data['remove_allocations'])) { From 6239ef2a8634be411fcff53962e75f438505a648 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:21:14 -0400 Subject: [PATCH 16/69] Ignore these as they're going to be replaced --- phpstan.neon | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index cce1b79eb4..eece840e63 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,8 +9,14 @@ parameters: # Level 9 is the highest level level: 1 -# ignoreErrors: -# - '#PHPDoc tag @var#' + ignoreErrors: + # Ignore dynamic methods from 3rd Party Vendor + - '#Call to an undefined method Prologue\\Alerts\\AlertsMessageBag::(success|info|warning|danger)\(\)#' + + # Ignore repository interface missing methods + - '#Call to an undefined method Pterodactyl\\Repositories\\Wings\\DaemonRepository::(\w+)\(\).#' + + # # excludePaths: # - ./*/*/FileToBeExcluded.php From 70dd61e515b1164e16fdbbe9ceb0fa025faa81dc Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:21:41 -0400 Subject: [PATCH 17/69] Replace this with an attribute... but is this even used anymore? --- app/Http/Controllers/Admin/UserController.php | 17 ++++------------- app/Models/User.php | 12 ++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 1d6db65691..220b8cc69d 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -6,13 +6,13 @@ use Illuminate\Http\Request; use Pterodactyl\Models\User; use Pterodactyl\Models\Model; -use Illuminate\Support\Collection; use Illuminate\Http\RedirectResponse; use Prologue\Alerts\AlertsMessageBag; use Spatie\QueryBuilder\QueryBuilder; use Illuminate\View\Factory as ViewFactory; use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Http\Controllers\Controller; +use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Contracts\Translation\Translator; use Pterodactyl\Services\Users\UserUpdateService; use Pterodactyl\Traits\Helpers\AvailableLanguages; @@ -132,22 +132,13 @@ public function update(UserFormRequest $request, User $user): RedirectResponse /** * Get a JSON response of users on the system. */ - public function json(Request $request): Model|Collection + public function json(Request $request): Model|LengthAwarePaginator { - $users = QueryBuilder::for(User::query())->allowedFilters(['email'])->paginate(25); - // Handle single user requests. if ($request->query('user_id')) { - $user = User::query()->findOrFail($request->input('user_id')); - $user->md5 = md5(strtolower($user->email)); - - return $user; + return User::query()->findOrFail($request->input('user_id')); } - return $users->map(function ($item) { - $item->md5 = md5(strtolower($item->email)); - - return $item; - }); + return QueryBuilder::for(User::query())->allowedFilters(['email'])->paginate(25); } } diff --git a/app/Models/User.php b/app/Models/User.php index df8271cf4f..1298f2dbdb 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Pterodactyl\Rules\Username; use Pterodactyl\Facades\Activity; use Illuminate\Support\Collection; @@ -127,6 +128,10 @@ class User extends Model implements 'root_admin', ]; + protected $appends = [ + 'md5', + ]; + /** * Cast values to correct type. */ @@ -257,6 +262,13 @@ public function activity(): MorphToMany return $this->morphToMany(ActivityLog::class, 'subject', 'activity_log_subjects'); } + public function md5(): Attribute + { + return Attribute::make( + get: fn () => md5(strtolower($this->email)), + ); + } + /** * Returns all the servers that a user can access by way of being the owner of the * server, or because they are assigned as a subuser for that server. From 8ce9e2cb15489a2e571d5645b63550acb33f368f Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:22:00 -0400 Subject: [PATCH 18/69] This has to be a User model or it will fail --- app/Http/Controllers/Auth/ResetPasswordController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 3325a1e6b3..47a57a9bcc 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -13,6 +13,7 @@ use Illuminate\Foundation\Auth\ResetsPasswords; use Pterodactyl\Http\Requests\Auth\ResetPasswordRequest; use Pterodactyl\Contracts\Repository\UserRepositoryInterface; +use Pterodactyl\Models\User; class ResetPasswordController extends Controller { @@ -67,13 +68,13 @@ function ($user, $password) { * account do not automatically log them in. In those cases, send the user back to the login * form with a note telling them their password was changed and to log back in. * - * @param \Illuminate\Contracts\Auth\CanResetPassword|\Pterodactyl\Models\User $user + * @param User $user * @param string $password * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ - protected function resetPassword($user, $password) + protected function resetPassword(User $user, $password) { $user = $this->userRepository->update($user->id, [ 'password' => $this->hasher->make($password), From 07a005ec0d6008bdecae350455fa8edd37d83dac Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:22:14 -0400 Subject: [PATCH 19/69] These will always be Nest instances --- app/Http/Controllers/Admin/Servers/CreateServerController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/Servers/CreateServerController.php b/app/Http/Controllers/Admin/Servers/CreateServerController.php index c7a1653ad4..12c1c696b8 100644 --- a/app/Http/Controllers/Admin/Servers/CreateServerController.php +++ b/app/Http/Controllers/Admin/Servers/CreateServerController.php @@ -4,6 +4,7 @@ use JavaScript; use Illuminate\View\View; +use Pterodactyl\Models\Nest; use Pterodactyl\Models\Node; use Pterodactyl\Models\Location; use Illuminate\Http\RedirectResponse; @@ -47,7 +48,7 @@ public function index(): View|RedirectResponse JavaScript::put([ 'nodeData' => $this->nodeRepository->getNodesForServerCreation(), - 'nests' => $nests->map(function ($item) { + 'nests' => $nests->map(function (Nest $item) { return array_merge($item->toArray(), [ 'eggs' => $item->eggs->keyBy('id')->toArray(), ]); From 0ab367c2ac73058dfd1b9a031302e63a0d8940d7 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:36:56 -0400 Subject: [PATCH 20/69] Remove wildcard --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index eece840e63..43a57b52bc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,7 +14,7 @@ parameters: - '#Call to an undefined method Prologue\\Alerts\\AlertsMessageBag::(success|info|warning|danger)\(\)#' # Ignore repository interface missing methods - - '#Call to an undefined method Pterodactyl\\Repositories\\Wings\\DaemonRepository::(\w+)\(\).#' + - '#Call to an undefined method Pterodactyl\\Repositories\\Wings\\DaemonRepository::(\w+)\(\)#' # From 38a84f61f84f1bb5e25cb6b4015ea06ea443647a Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:39:17 -0400 Subject: [PATCH 21/69] Be specific --- app/Http/Requests/Admin/LocationFormRequest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/Admin/LocationFormRequest.php b/app/Http/Requests/Admin/LocationFormRequest.php index b10e304a07..1d8c12f2ac 100644 --- a/app/Http/Requests/Admin/LocationFormRequest.php +++ b/app/Http/Requests/Admin/LocationFormRequest.php @@ -12,7 +12,9 @@ class LocationFormRequest extends AdminFormRequest public function rules(): array { if ($this->method() === 'PATCH') { - return Location::getRulesForUpdate($this->route()->parameter('location')->id); + /** @var Location $location */ + $location = $this->route()->parameter('location'); + return Location::getRulesForUpdate($location->id); } return Location::getRules(); From 7bcdd685407dc54f1d7e738a8abefbb500c441cb Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:39:33 -0400 Subject: [PATCH 22/69] Wrap this up in a neat method --- app/Models/Node.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Models/Node.php b/app/Models/Node.php index 0261e8b875..f20a45ae50 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -217,13 +217,20 @@ public function allocations(): HasMany return $this->hasMany(Allocation::class); } + public function loadServerSums(): self + { + $this->loadSum('servers as sum_memory', 'memory'); + $this->loadSum('servers as sum_disk', 'disk'); + + return $this; + } + /** * Returns a boolean if the node is viable for an additional server to be placed on it. */ - public function isViable(int $memory, int $disk): bool + public function isViable(int $memory = 0, int $disk = 0): bool { - $this->loadSum('servers as sum_memory', 'memory'); - $this->loadSum('servers as disk_memory', 'disk'); + $this->loadServerSums(); $memoryLimit = $this->memory * (1 + ($this->memory_overallocate / 100)); $diskLimit = $this->disk * (1 + ($this->disk_overallocate / 100)); From 6d892192223674c3ff006592af2e472b05b57fc4 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:39:57 -0400 Subject: [PATCH 23/69] This would be a good usage of an interface or abstract class --- .../Middleware/Api/Client/Server/ResourceBelongsToServer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php b/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php index 5d3530d865..b0f8ff5a83 100644 --- a/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php +++ b/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php @@ -45,6 +45,7 @@ public function handle(Request $request, Closure $next): mixed continue; } + /** @var Allocation|Backup|Database|Schedule|Subuser $model */ switch (get_class($model)) { // All of these models use "server_id" as the field key for the server // they are assigned to, so the logic is identical for them all. From 40ab159c81b3554641e2cf657ef19e9a65a6b7a5 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:40:17 -0400 Subject: [PATCH 24/69] Use method to populate node with aggregate counts --- app/Repositories/Eloquent/NodeRepository.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/Repositories/Eloquent/NodeRepository.php b/app/Repositories/Eloquent/NodeRepository.php index 7f254cd1ed..ab5f767a13 100644 --- a/app/Repositories/Eloquent/NodeRepository.php +++ b/app/Repositories/Eloquent/NodeRepository.php @@ -21,11 +21,7 @@ public function model(): string */ public function getUsageStats(Node $node): array { - $stats = $this->getBuilder() - ->selectRaw('IFNULL(SUM(servers.memory), 0) as sum_memory, IFNULL(SUM(servers.disk), 0) as sum_disk') - ->join('servers', 'servers.node_id', '=', 'nodes.id') - ->where('node_id', '=', $node->id) - ->first(); + $stats = $node->loadServerSums(); return Collection::make(['disk' => $stats->sum_disk, 'memory' => $stats->sum_memory]) ->mapWithKeys(function ($value, $key) use ($node) { From d87ab25a8d3578438ddc94ec1cac52bd49429ca0 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:54:26 -0400 Subject: [PATCH 25/69] Replace these --- app/Repositories/Eloquent/NodeRepository.php | 4 +--- app/Services/Deployment/FindViableNodesService.php | 9 ++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/Repositories/Eloquent/NodeRepository.php b/app/Repositories/Eloquent/NodeRepository.php index ab5f767a13..019c868c90 100644 --- a/app/Repositories/Eloquent/NodeRepository.php +++ b/app/Repositories/Eloquent/NodeRepository.php @@ -49,9 +49,7 @@ public function getUsageStats(Node $node): array */ public function getUsageStatsRaw(Node $node): array { - $stats = $this->getBuilder()->select( - $this->getBuilder()->raw('IFNULL(SUM(servers.memory), 0) as sum_memory, IFNULL(SUM(servers.disk), 0) as sum_disk') - )->join('servers', 'servers.node_id', '=', 'nodes.id')->where('node_id', $node->id)->first(); + $stats = $node->loadServerSums(); return collect(['disk' => $stats->sum_disk, 'memory' => $stats->sum_memory])->mapWithKeys(function ($value, $key) use ($node) { $maxUsage = $node->{$key}; diff --git a/app/Services/Deployment/FindViableNodesService.php b/app/Services/Deployment/FindViableNodesService.php index 71c830bf9e..ff36ff1a05 100644 --- a/app/Services/Deployment/FindViableNodesService.php +++ b/app/Services/Deployment/FindViableNodesService.php @@ -71,11 +71,10 @@ public function handle(int $perPage = null, int $page = null): LengthAwarePagina Assert::integer($this->disk, 'Disk space must be an int, got %s'); Assert::integer($this->memory, 'Memory usage must be an int, got %s'); - $query = Node::query()->select('nodes.*') - ->selectRaw('IFNULL(SUM(servers.memory), 0) as sum_memory') - ->selectRaw('IFNULL(SUM(servers.disk), 0) as sum_disk') - ->leftJoin('servers', 'servers.node_id', '=', 'nodes.id') - ->where('nodes.public', 1); + $query = Node::query() + ->withSum('servers as sum_memory', 'memory') + ->withSum('servers as sum_disk', 'disk') + ->where('public', 1); if (!empty($this->locations)) { $query = $query->whereIn('nodes.location_id', $this->locations); From 3baa4520023488bca85d856fe3d46b3f4a689523 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:54:34 -0400 Subject: [PATCH 26/69] This isn't used anywhere --- app/Repositories/Eloquent/NodeRepository.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/app/Repositories/Eloquent/NodeRepository.php b/app/Repositories/Eloquent/NodeRepository.php index 019c868c90..f03067d2f5 100644 --- a/app/Repositories/Eloquent/NodeRepository.php +++ b/app/Repositories/Eloquent/NodeRepository.php @@ -129,21 +129,4 @@ public function getNodesForServerCreation(): Collection ]; })->values(); } - - /** - * Returns a node with the given id with the Node's resource usage. - */ - public function getNodeWithResourceUsage(int $node_id): Node - { - $instance = $this->getBuilder() - ->select(['nodes.id', 'nodes.fqdn', 'nodes.scheme', 'nodes.daemon_token', 'nodes.daemonListen', 'nodes.memory', 'nodes.disk', 'nodes.memory_overallocate', 'nodes.disk_overallocate']) - ->selectRaw('IFNULL(SUM(servers.memory), 0) as sum_memory, IFNULL(SUM(servers.disk), 0) as sum_disk') - ->leftJoin('servers', 'servers.node_id', '=', 'nodes.id') - ->where('nodes.id', $node_id); - - /** @var Node $node */ - $node = $instance->first(); - - return $node; - } } From dccf52d6e44ec90b9e80f2d5085676f9b7d4d6b8 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:54:58 -0400 Subject: [PATCH 27/69] Not worth it --- phpstan.neon | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 43a57b52bc..c61e6af323 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -16,6 +16,8 @@ parameters: # Ignore repository interface missing methods - '#Call to an undefined method Pterodactyl\\Repositories\\Wings\\DaemonRepository::(\w+)\(\)#' + # Ignore magic spatie calls + - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Builder::allowed(\w+)\(\)#' # # excludePaths: From be8845c4497639d756035b501b0d9e725838f5d3 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:55:10 -0400 Subject: [PATCH 28/69] Be specific --- app/Models/Setting.php | 1 + app/Repositories/Eloquent/SettingsRepository.php | 1 + 2 files changed, 2 insertions(+) diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 52c7f1cffb..ec85a2ecf6 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Models; +/** @property string $value */ class Setting extends Model { /** diff --git a/app/Repositories/Eloquent/SettingsRepository.php b/app/Repositories/Eloquent/SettingsRepository.php index df22fce595..e8003129a1 100644 --- a/app/Repositories/Eloquent/SettingsRepository.php +++ b/app/Repositories/Eloquent/SettingsRepository.php @@ -46,6 +46,7 @@ public function get(string $key, mixed $default = null): mixed return value($default); } + /** @var Setting $instance */ $instance = $this->getBuilder()->where('key', $key)->first(); if (is_null($instance)) { self::$databaseMiss[$key] = true; From 6c5d04f08f693b0e782448bd42009d9cfe60dfb6 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 20:55:26 -0400 Subject: [PATCH 29/69] Help analyzer out --- app/Services/Backups/DeleteBackupService.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Services/Backups/DeleteBackupService.php b/app/Services/Backups/DeleteBackupService.php index fd65969c17..bbb54ce6a9 100644 --- a/app/Services/Backups/DeleteBackupService.php +++ b/app/Services/Backups/DeleteBackupService.php @@ -73,7 +73,10 @@ protected function deleteFromS3(Backup $backup): void /** @var \Pterodactyl\Extensions\Filesystem\S3Filesystem $adapter */ $adapter = $this->manager->adapter(Backup::ADAPTER_AWS_S3); - $adapter->getClient()->deleteObject([ + /** @var \Aws\S3\S3Client $client */ + $client = $adapter->getClient(); + + $client->deleteObject([ 'Bucket' => $adapter->getBucket(), 'Key' => sprintf('%s/%s.tar.gz', $backup->server->uuid, $backup->uuid), ]); From a67801097602c6a3e1a8a219d789788fb92684a0 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:10:48 -0400 Subject: [PATCH 30/69] Simplify --- app/Models/Node.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Models/Node.php b/app/Models/Node.php index f20a45ae50..add29c7b95 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -6,6 +6,7 @@ use Symfony\Component\Yaml\Yaml; use Illuminate\Container\Container; use Illuminate\Notifications\Notifiable; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Contracts\Encryption\Encrypter; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -34,12 +35,14 @@ * @property int $daemonListen * @property int $daemonSFTP * @property string $daemonBase + * @property int $servers_count * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property \Pterodactyl\Models\Location $location - * @property \Pterodactyl\Models\Mount[]|\Illuminate\Database\Eloquent\Collection $mounts - * @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers - * @property \Pterodactyl\Models\Allocation[]|\Illuminate\Database\Eloquent\Collection $allocations + * @property Location $location + * @property int[]|\Illuminate\Support\Collection $ports + * @property Mount[]|Collection $mounts + * @property Server[]|Collection $servers + * @property Allocation[]|Collection $allocations */ class Node extends Model { From 32daaa8dd83ae3558b97737ad5eb406c7c3972bc Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:11:07 -0400 Subject: [PATCH 31/69] Use agg method --- app/Repositories/Eloquent/NodeRepository.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Repositories/Eloquent/NodeRepository.php b/app/Repositories/Eloquent/NodeRepository.php index f03067d2f5..0ee703a795 100644 --- a/app/Repositories/Eloquent/NodeRepository.php +++ b/app/Repositories/Eloquent/NodeRepository.php @@ -78,9 +78,7 @@ public function loadLocationAndServerCount(Node $node, bool $refresh = false): N // This is quite ugly and can probably be improved down the road. // And by probably, I mean it should. if (is_null($node->servers_count) || $refresh) { - $node->load('servers'); - $node->setRelation('servers_count', count($node->getRelation('servers'))); - unset($node->servers); + $node->loadCount('servers'); } return $node; From ddc1d13edc8b62e75b3932cf36262b6e2aa14bd8 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:11:43 -0400 Subject: [PATCH 32/69] Be specific --- app/Repositories/Eloquent/EloquentRepository.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Repositories/Eloquent/EloquentRepository.php b/app/Repositories/Eloquent/EloquentRepository.php index a4e7f2fd78..cea9728c5d 100644 --- a/app/Repositories/Eloquent/EloquentRepository.php +++ b/app/Repositories/Eloquent/EloquentRepository.php @@ -75,6 +75,7 @@ public function getBuilder(): Builder */ public function create(array $fields, bool $validate = true, bool $force = false): Model|bool { + /** @var \Pterodactyl\Models\Model $instance */ $instance = $this->getBuilder()->newModelInstance(); ($force) ? $instance->forceFill($fields) : $instance->fill($fields); @@ -160,6 +161,7 @@ public function deleteWhere(array $attributes, bool $force = false): int public function update(int $id, array $fields, bool $validate = true, bool $force = false): Model|bool { try { + /** @var \Pterodactyl\Models\Model $instance */ $instance = $this->getBuilder()->where('id', $id)->firstOrFail(); } catch (ModelNotFoundException) { throw new RecordNotFoundException(); From 14aa1c506dfb30ed9ec3b48b123574e1f1cd9886 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:11:57 -0400 Subject: [PATCH 33/69] Ignore the rest of these, they're getting removed --- phpstan.neon | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index c61e6af323..c5888eba2e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -19,8 +19,8 @@ parameters: # Ignore magic spatie calls - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Builder::allowed(\w+)\(\)#' -# -# excludePaths: -# - ./*/*/FileToBeExcluded.php + excludePaths: + - app/Repositories + # # checkMissingIterableValueType: false From bba28776969dfe462ad168a2689c52ad7f16c278 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:18:41 -0400 Subject: [PATCH 34/69] Use same name --- app/Notifications/ServerInstalled.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Notifications/ServerInstalled.php b/app/Notifications/ServerInstalled.php index 46f38ff84e..7f8412f99c 100644 --- a/app/Notifications/ServerInstalled.php +++ b/app/Notifications/ServerInstalled.php @@ -26,12 +26,12 @@ class ServerInstalled extends Notification implements ShouldQueue, ReceivesEvent * Handle a direct call to this notification from the server installed event. This is configured * in the event service provider. */ - public function handle(Event|Installed $event): void + public function handle(Event|Installed $notification): void { - $event->server->loadMissing('user'); + $notification->server->loadMissing('user'); - $this->server = $event->server; - $this->user = $event->server->user; + $this->server = $notification->server; + $this->user = $notification->server->user; // Since we are calling this notification directly from an event listener we need to fire off the dispatcher // to send the email now. Don't use send() or you'll end up firing off two different events. From 3a6856a75cd189aee1525ec86c68b810739f8cd5 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:21:06 -0400 Subject: [PATCH 35/69] Simplify --- app/Models/EggVariable.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Models/EggVariable.php b/app/Models/EggVariable.php index 8c34bb3980..dbbf8e0bd0 100644 --- a/app/Models/EggVariable.php +++ b/app/Models/EggVariable.php @@ -18,8 +18,9 @@ * @property \Carbon\CarbonImmutable $created_at * @property \Carbon\CarbonImmutable $updated_at * @property bool $required - * @property \Pterodactyl\Models\Egg $egg - * @property \Pterodactyl\Models\ServerVariable $serverVariable + * @property Egg $egg + * @property ServerVariable $serverVariable + * @property string $field_type * * The "server_value" variable is only present on the object if you've loaded this model * using the server relationship. From f36f9d481760993dbf098d4eed0bde48a489926f Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:21:14 -0400 Subject: [PATCH 36/69] This will fail either way --- app/Notifications/ServerInstalled.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Notifications/ServerInstalled.php b/app/Notifications/ServerInstalled.php index 7f8412f99c..3eb93e79db 100644 --- a/app/Notifications/ServerInstalled.php +++ b/app/Notifications/ServerInstalled.php @@ -28,6 +28,8 @@ class ServerInstalled extends Notification implements ShouldQueue, ReceivesEvent */ public function handle(Event|Installed $notification): void { + abort_unless($notification instanceof Installed, 500); + /* @var Installed $notification */ $notification->server->loadMissing('user'); $this->server = $notification->server; From 7722e3ed7fa4ff5d3bc459c1bffc02969925227d Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:30:16 -0400 Subject: [PATCH 37/69] Var doesn't exist --- app/Http/Requests/Api/Client/Servers/Subusers/SubuserRequest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Requests/Api/Client/Servers/Subusers/SubuserRequest.php b/app/Http/Requests/Api/Client/Servers/Subusers/SubuserRequest.php index 7c4fab9d22..1381e5cb92 100644 --- a/app/Http/Requests/Api/Client/Servers/Subusers/SubuserRequest.php +++ b/app/Http/Requests/Api/Client/Servers/Subusers/SubuserRequest.php @@ -63,7 +63,6 @@ protected function validatePermissionsCanBeAssigned(array $permissions) // Otherwise, get the current subuser's permission set, and ensure that the // permissions they are trying to assign are not _more_ than the ones they // already have. - /** @var \Pterodactyl\Models\Subuser|null $subuser */ /** @var \Pterodactyl\Services\Servers\GetUserPermissionsService $service */ $service = $this->container->make(GetUserPermissionsService::class); From 7edf9ce416391847a2fbce02a8d02f53b78d322b Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:30:46 -0400 Subject: [PATCH 38/69] Specify types --- .../Middleware/Api/Client/Server/ResourceBelongsToServer.php | 1 + app/Http/Requests/Admin/MountFormRequest.php | 4 +++- .../Api/Application/Locations/UpdateLocationRequest.php | 4 +++- .../Requests/Api/Application/Nodes/UpdateNodeRequest.php | 5 +++-- .../Servers/Databases/StoreServerDatabaseRequest.php | 2 ++ .../Api/Client/Servers/Databases/StoreDatabaseRequest.php | 1 + app/Models/Model.php | 1 + 7 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php b/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php index b0f8ff5a83..4688a9f6d4 100644 --- a/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php +++ b/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php @@ -72,6 +72,7 @@ public function handle(Request $request, Closure $next): mixed // Tasks are special since they're (currently) the only item in the API // that requires something in addition to the server in order to be accessed. case Task::class: + /** @var Schedule $schedule */ $schedule = $request->route()->parameter('schedule'); if ($model->schedule_id !== $schedule->id || $schedule->server_id !== $server->id) { throw $exception; diff --git a/app/Http/Requests/Admin/MountFormRequest.php b/app/Http/Requests/Admin/MountFormRequest.php index 074ea4a503..39c19f552a 100644 --- a/app/Http/Requests/Admin/MountFormRequest.php +++ b/app/Http/Requests/Admin/MountFormRequest.php @@ -12,7 +12,9 @@ class MountFormRequest extends AdminFormRequest public function rules(): array { if ($this->method() === 'PATCH') { - return Mount::getRulesForUpdate($this->route()->parameter('mount')->id); + /** @var Mount $mount */ + $mount = $this->route()->parameter('mount'); + return Mount::getRulesForUpdate($mount->id); } return Mount::getRules(); diff --git a/app/Http/Requests/Api/Application/Locations/UpdateLocationRequest.php b/app/Http/Requests/Api/Application/Locations/UpdateLocationRequest.php index ce42e6f051..b7acac9781 100644 --- a/app/Http/Requests/Api/Application/Locations/UpdateLocationRequest.php +++ b/app/Http/Requests/Api/Application/Locations/UpdateLocationRequest.php @@ -11,7 +11,9 @@ class UpdateLocationRequest extends StoreLocationRequest */ public function rules(): array { - $locationId = $this->route()->parameter('location')->id; + /** @var Location $location */ + $location = $this->route()->parameter('location'); + $locationId = $location->id; return collect(Location::getRulesForUpdate($locationId))->only([ 'short', diff --git a/app/Http/Requests/Api/Application/Nodes/UpdateNodeRequest.php b/app/Http/Requests/Api/Application/Nodes/UpdateNodeRequest.php index 7133bd0b52..de6b7b45c9 100644 --- a/app/Http/Requests/Api/Application/Nodes/UpdateNodeRequest.php +++ b/app/Http/Requests/Api/Application/Nodes/UpdateNodeRequest.php @@ -12,8 +12,9 @@ class UpdateNodeRequest extends StoreNodeRequest */ public function rules(array $rules = null): array { - $node = $this->route()->parameter('node')->id; + /** @var Node $node */ + $node = $this->route()->parameter('node'); - return parent::rules(Node::getRulesForUpdate($node)); + return parent::rules(Node::getRulesForUpdate($node->id)); } } diff --git a/app/Http/Requests/Api/Application/Servers/Databases/StoreServerDatabaseRequest.php b/app/Http/Requests/Api/Application/Servers/Databases/StoreServerDatabaseRequest.php index d53a0a75ef..f52bed805d 100644 --- a/app/Http/Requests/Api/Application/Servers/Databases/StoreServerDatabaseRequest.php +++ b/app/Http/Requests/Api/Application/Servers/Databases/StoreServerDatabaseRequest.php @@ -21,6 +21,7 @@ class StoreServerDatabaseRequest extends ApplicationApiRequest */ public function rules(): array { + /** @var Server $server */ $server = $this->route()->parameter('server'); return [ @@ -67,6 +68,7 @@ public function attributes(): array */ public function databaseName(): string { + /** @var Server $server */ $server = $this->route()->parameter('server'); Assert::isInstanceOf($server, Server::class); diff --git a/app/Http/Requests/Api/Client/Servers/Databases/StoreDatabaseRequest.php b/app/Http/Requests/Api/Client/Servers/Databases/StoreDatabaseRequest.php index be4f4a719d..41569cfabf 100644 --- a/app/Http/Requests/Api/Client/Servers/Databases/StoreDatabaseRequest.php +++ b/app/Http/Requests/Api/Client/Servers/Databases/StoreDatabaseRequest.php @@ -21,6 +21,7 @@ public function permission(): string public function rules(): array { + /** @var Server $server */ $server = $this->route()->parameter('server'); Assert::isInstanceOf($server, Server::class); diff --git a/app/Models/Model.php b/app/Models/Model.php index 2e371d9d9c..34b856c385 100644 --- a/app/Models/Model.php +++ b/app/Models/Model.php @@ -155,6 +155,7 @@ public function validate(): void return; } + /** @var \Illuminate\Validation\Validator $validator */ $validator = $this->getValidator(); $validator->setData( // Trying to do self::toArray() here will leave out keys based on the whitelist/blacklist From f8efbef0452b3ed368bd1b64340c7cb66ea5cf49 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:44:09 -0400 Subject: [PATCH 39/69] Add doc blocks --- .../Api/Remote/Servers/ServerDetailsController.php | 7 +++++-- .../Requests/Api/Application/ApplicationApiRequest.php | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/Remote/Servers/ServerDetailsController.php b/app/Http/Controllers/Api/Remote/Servers/ServerDetailsController.php index 8ce88e89ee..8d8b0de92a 100644 --- a/app/Http/Controllers/Api/Remote/Servers/ServerDetailsController.php +++ b/app/Http/Controllers/Api/Remote/Servers/ServerDetailsController.php @@ -3,6 +3,7 @@ namespace Pterodactyl\Http\Controllers\Api\Remote\Servers; use Illuminate\Http\Request; +use Pterodactyl\Models\Backup; use Pterodactyl\Models\Server; use Illuminate\Http\JsonResponse; use Pterodactyl\Facades\Activity; @@ -98,9 +99,11 @@ public function resetState(Request $request): JsonResponse if ($subject = $activity->subjects->where('subject_type', 'backup')->first()) { // Just create a new audit entry for this event and update the server state // so that power actions, file management, and backups can resume as normal. + /** @var Backup $actualSubject */ + $actualSubject = $subject->subject; Activity::event('server:backup.restore-failed') - ->subject($server, $subject->subject) - ->property('name', $subject->subject->name) + ->subject($server, $actualSubject) + ->property('name', $actualSubject->name) ->log(); } } diff --git a/app/Http/Requests/Api/Application/ApplicationApiRequest.php b/app/Http/Requests/Api/Application/ApplicationApiRequest.php index 2e0ed133a5..082bc6921f 100644 --- a/app/Http/Requests/Api/Application/ApplicationApiRequest.php +++ b/app/Http/Requests/Api/Application/ApplicationApiRequest.php @@ -29,7 +29,7 @@ abstract class ApplicationApiRequest extends FormRequest * Determine if the current user is authorized to perform * the requested action against the API. * - * @throws \Pterodactyl\Exceptions\PterodactylException + * @throws PterodactylException */ public function authorize(): bool { @@ -42,6 +42,7 @@ public function authorize(): bool return true; } + /** @var ApiKey $token */ if ($token->key_type === ApiKey::TYPE_ACCOUNT) { return true; } @@ -81,6 +82,7 @@ public function withValidator(Validator $validator): void */ public function parameter(string $key, string $expect) { + /** @var ApiKey $value */ $value = $this->route()->parameter($key); Assert::isInstanceOf($value, $expect); From d4656d824e1da3e29e7f4f9462e32b7f480843d3 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:44:45 -0400 Subject: [PATCH 40/69] php-cs-fixer --- app/Http/Controllers/Auth/ResetPasswordController.php | 3 +-- app/Http/Requests/Admin/LocationFormRequest.php | 1 + app/Http/Requests/Admin/MountFormRequest.php | 1 + app/Models/User.php | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 47a57a9bcc..9b22f6f988 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -3,6 +3,7 @@ namespace Pterodactyl\Http\Controllers\Auth; use Illuminate\Support\Str; +use Pterodactyl\Models\User; use Illuminate\Http\JsonResponse; use Illuminate\Contracts\Hashing\Hasher; use Illuminate\Support\Facades\Password; @@ -13,7 +14,6 @@ use Illuminate\Foundation\Auth\ResetsPasswords; use Pterodactyl\Http\Requests\Auth\ResetPasswordRequest; use Pterodactyl\Contracts\Repository\UserRepositoryInterface; -use Pterodactyl\Models\User; class ResetPasswordController extends Controller { @@ -68,7 +68,6 @@ function ($user, $password) { * account do not automatically log them in. In those cases, send the user back to the login * form with a note telling them their password was changed and to log back in. * - * @param User $user * @param string $password * * @throws \Pterodactyl\Exceptions\Model\DataValidationException diff --git a/app/Http/Requests/Admin/LocationFormRequest.php b/app/Http/Requests/Admin/LocationFormRequest.php index 1d8c12f2ac..57fa0310b8 100644 --- a/app/Http/Requests/Admin/LocationFormRequest.php +++ b/app/Http/Requests/Admin/LocationFormRequest.php @@ -14,6 +14,7 @@ public function rules(): array if ($this->method() === 'PATCH') { /** @var Location $location */ $location = $this->route()->parameter('location'); + return Location::getRulesForUpdate($location->id); } diff --git a/app/Http/Requests/Admin/MountFormRequest.php b/app/Http/Requests/Admin/MountFormRequest.php index 39c19f552a..22b2475f4c 100644 --- a/app/Http/Requests/Admin/MountFormRequest.php +++ b/app/Http/Requests/Admin/MountFormRequest.php @@ -14,6 +14,7 @@ public function rules(): array if ($this->method() === 'PATCH') { /** @var Mount $mount */ $mount = $this->route()->parameter('mount'); + return Mount::getRulesForUpdate($mount->id); } diff --git a/app/Models/User.php b/app/Models/User.php index 1298f2dbdb..5d4b07216d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,7 +2,6 @@ namespace Pterodactyl\Models; -use Illuminate\Database\Eloquent\Casts\Attribute; use Pterodactyl\Rules\Username; use Pterodactyl\Facades\Activity; use Illuminate\Support\Collection; @@ -12,6 +11,7 @@ use Illuminate\Database\Eloquent\Builder; use Pterodactyl\Models\Traits\HasAccessTokens; use Illuminate\Auth\Passwords\CanResetPassword; +use Illuminate\Database\Eloquent\Casts\Attribute; use Pterodactyl\Traits\Helpers\AvailableLanguages; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\Access\Authorizable; From 7353bd4b94c818b60df1442deb071766c1bfac85 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 21:44:53 -0400 Subject: [PATCH 41/69] Up the level! --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index c5888eba2e..104bfecb89 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,7 +7,7 @@ parameters: - app/ # Level 9 is the highest level - level: 1 + level: 2 ignoreErrors: # Ignore dynamic methods from 3rd Party Vendor From 43412370e85720f19c07f4f57867fa7b2dd63211 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 23:10:53 -0400 Subject: [PATCH 42/69] Return type is never used --- app/Services/Users/UserDeletionService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Services/Users/UserDeletionService.php b/app/Services/Users/UserDeletionService.php index f7f060cee4..0f373240f9 100644 --- a/app/Services/Users/UserDeletionService.php +++ b/app/Services/Users/UserDeletionService.php @@ -25,7 +25,7 @@ public function __construct( * * @throws \Pterodactyl\Exceptions\DisplayException */ - public function handle(int|User $user): ?bool + public function handle(int|User $user): void { if ($user instanceof User) { $user = $user->id; @@ -36,6 +36,6 @@ public function handle(int|User $user): ?bool throw new DisplayException($this->translator->get('admin/user.exceptions.user_has_servers')); } - return $this->repository->delete($user); + $this->repository->delete($user); } } From dcabf5c0eda67999af608367d54330637ebdbb0b Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 23:12:11 -0400 Subject: [PATCH 43/69] Use view helper instead --- app/Http/Controllers/Admin/ApiController.php | 4 ++-- app/Http/Controllers/Admin/BaseController.php | 2 +- .../Controllers/Admin/DatabaseController.php | 4 ++-- .../Controllers/Admin/LocationController.php | 4 ++-- app/Http/Controllers/Admin/MountController.php | 4 ++-- .../Controllers/Admin/Nests/EggController.php | 4 ++-- .../Admin/Nests/EggScriptController.php | 2 +- .../Admin/Nests/EggVariableController.php | 2 +- .../Controllers/Admin/Nests/NestController.php | 6 +++--- .../Controllers/Admin/Nodes/NodeController.php | 2 +- .../Admin/Nodes/NodeViewController.php | 10 +++++----- app/Http/Controllers/Admin/NodesController.php | 2 +- .../Admin/Servers/CreateServerController.php | 2 +- .../Admin/Servers/ServerController.php | 2 +- .../Admin/Servers/ServerViewController.php | 16 ++++++++-------- .../Admin/Settings/AdvancedController.php | 2 +- .../Admin/Settings/IndexController.php | 2 +- .../Admin/Settings/MailController.php | 2 +- app/Http/Controllers/Admin/UserController.php | 6 +++--- app/Http/Controllers/Auth/LoginController.php | 2 +- app/Http/Controllers/Base/IndexController.php | 2 +- 21 files changed, 41 insertions(+), 41 deletions(-) diff --git a/app/Http/Controllers/Admin/ApiController.php b/app/Http/Controllers/Admin/ApiController.php index 02ad6e540d..4250db09fc 100644 --- a/app/Http/Controllers/Admin/ApiController.php +++ b/app/Http/Controllers/Admin/ApiController.php @@ -33,7 +33,7 @@ public function __construct( */ public function index(Request $request): View { - return $this->view->make('admin.api.index', [ + return view('admin.api.index', [ 'keys' => $this->repository->getApplicationKeys($request->user()), ]); } @@ -48,7 +48,7 @@ public function create(): View $resources = AdminAcl::getResourceList(); sort($resources); - return $this->view->make('admin.api.new', [ + return view('admin.api.new', [ 'resources' => $resources, 'permissions' => [ 'r' => AdminAcl::READ, diff --git a/app/Http/Controllers/Admin/BaseController.php b/app/Http/Controllers/Admin/BaseController.php index 53f53ce54c..0e707d2812 100644 --- a/app/Http/Controllers/Admin/BaseController.php +++ b/app/Http/Controllers/Admin/BaseController.php @@ -21,6 +21,6 @@ public function __construct(private SoftwareVersionService $version, private Vie */ public function index(): View { - return $this->view->make('admin.index', ['version' => $this->version]); + return view('admin.index', ['version' => $this->version]); } } diff --git a/app/Http/Controllers/Admin/DatabaseController.php b/app/Http/Controllers/Admin/DatabaseController.php index e0dc0dc577..b631ed77d4 100644 --- a/app/Http/Controllers/Admin/DatabaseController.php +++ b/app/Http/Controllers/Admin/DatabaseController.php @@ -40,7 +40,7 @@ public function __construct( */ public function index(): View { - return $this->view->make('admin.databases.index', [ + return view('admin.databases.index', [ 'locations' => $this->locationRepository->getAllWithNodes(), 'hosts' => $this->repository->getWithViewDetails(), ]); @@ -53,7 +53,7 @@ public function index(): View */ public function view(int $host): View { - return $this->view->make('admin.databases.view', [ + return view('admin.databases.view', [ 'locations' => $this->locationRepository->getAllWithNodes(), 'host' => $this->repository->find($host), 'databases' => $this->databaseRepository->getDatabasesForHost($host), diff --git a/app/Http/Controllers/Admin/LocationController.php b/app/Http/Controllers/Admin/LocationController.php index ea01cbaa90..41ed581db7 100644 --- a/app/Http/Controllers/Admin/LocationController.php +++ b/app/Http/Controllers/Admin/LocationController.php @@ -35,7 +35,7 @@ public function __construct( */ public function index(): View { - return $this->view->make('admin.locations.index', [ + return view('admin.locations.index', [ 'locations' => $this->repository->getAllWithDetails(), ]); } @@ -47,7 +47,7 @@ public function index(): View */ public function view(int $id): View { - return $this->view->make('admin.locations.view', [ + return view('admin.locations.view', [ 'location' => $this->repository->getWithNodes($id), ]); } diff --git a/app/Http/Controllers/Admin/MountController.php b/app/Http/Controllers/Admin/MountController.php index 097ad6690b..8f4138989a 100644 --- a/app/Http/Controllers/Admin/MountController.php +++ b/app/Http/Controllers/Admin/MountController.php @@ -37,7 +37,7 @@ public function __construct( */ public function index(): View { - return $this->view->make('admin.mounts.index', [ + return view('admin.mounts.index', [ 'mounts' => $this->repository->getAllWithDetails(), ]); } @@ -52,7 +52,7 @@ public function view(string $id): View $nests = Nest::query()->with('eggs')->get(); $locations = Location::query()->with('nodes')->get(); - return $this->view->make('admin.mounts.view', [ + return view('admin.mounts.view', [ 'mount' => $this->repository->getWithRelations($id), 'nests' => $nests, 'locations' => $locations, diff --git a/app/Http/Controllers/Admin/Nests/EggController.php b/app/Http/Controllers/Admin/Nests/EggController.php index 010c28af00..1efccfd5d0 100644 --- a/app/Http/Controllers/Admin/Nests/EggController.php +++ b/app/Http/Controllers/Admin/Nests/EggController.php @@ -42,7 +42,7 @@ public function create(): View $nests = $this->nestRepository->getWithEggs(); JavaScript::put(['nests' => $nests->keyBy('id')]); - return $this->view->make('admin.eggs.new', ['nests' => $nests]); + return view('admin.eggs.new', ['nests' => $nests]); } /** @@ -67,7 +67,7 @@ public function store(EggFormRequest $request): RedirectResponse */ public function view(Egg $egg): View { - return $this->view->make('admin.eggs.view', [ + return view('admin.eggs.view', [ 'egg' => $egg, 'images' => array_map( fn ($key, $value) => $key === $value ? $value : "$key|$value", diff --git a/app/Http/Controllers/Admin/Nests/EggScriptController.php b/app/Http/Controllers/Admin/Nests/EggScriptController.php index 4f997e5a86..b68a211ac1 100644 --- a/app/Http/Controllers/Admin/Nests/EggScriptController.php +++ b/app/Http/Controllers/Admin/Nests/EggScriptController.php @@ -41,7 +41,7 @@ public function index(int $egg): View ['copy_script_from', '=', $egg->id], ]); - return $this->view->make('admin.eggs.scripts', [ + return view('admin.eggs.scripts', [ 'copyFromOptions' => $copy, 'relyOnScript' => $rely, 'egg' => $egg, diff --git a/app/Http/Controllers/Admin/Nests/EggVariableController.php b/app/Http/Controllers/Admin/Nests/EggVariableController.php index 40274b3239..c94a8dc284 100644 --- a/app/Http/Controllers/Admin/Nests/EggVariableController.php +++ b/app/Http/Controllers/Admin/Nests/EggVariableController.php @@ -39,7 +39,7 @@ public function view(int $egg): View { $egg = $this->repository->getWithVariables($egg); - return $this->view->make('admin.eggs.variables', ['egg' => $egg]); + return view('admin.eggs.variables', ['egg' => $egg]); } /** diff --git a/app/Http/Controllers/Admin/Nests/NestController.php b/app/Http/Controllers/Admin/Nests/NestController.php index 037dd09430..fb24f10693 100644 --- a/app/Http/Controllers/Admin/Nests/NestController.php +++ b/app/Http/Controllers/Admin/Nests/NestController.php @@ -35,7 +35,7 @@ public function __construct( */ public function index(): View { - return $this->view->make('admin.nests.index', [ + return view('admin.nests.index', [ 'nests' => $this->repository->getWithCounts(), ]); } @@ -45,7 +45,7 @@ public function index(): View */ public function create(): View { - return $this->view->make('admin.nests.new'); + return view('admin.nests.new'); } /** @@ -68,7 +68,7 @@ public function store(StoreNestFormRequest $request): RedirectResponse */ public function view(int $nest): View { - return $this->view->make('admin.nests.view', [ + return view('admin.nests.view', [ 'nest' => $this->repository->getWithEggServers($nest), ]); } diff --git a/app/Http/Controllers/Admin/Nodes/NodeController.php b/app/Http/Controllers/Admin/Nodes/NodeController.php index d80df6c80d..c2b6ea91c0 100644 --- a/app/Http/Controllers/Admin/Nodes/NodeController.php +++ b/app/Http/Controllers/Admin/Nodes/NodeController.php @@ -30,6 +30,6 @@ public function index(Request $request): View ->allowedSorts(['id']) ->paginate(25); - return $this->view->make('admin.nodes.index', ['nodes' => $nodes]); + return view('admin.nodes.index', ['nodes' => $nodes]); } } diff --git a/app/Http/Controllers/Admin/Nodes/NodeViewController.php b/app/Http/Controllers/Admin/Nodes/NodeViewController.php index 6738903230..aed2381267 100644 --- a/app/Http/Controllers/Admin/Nodes/NodeViewController.php +++ b/app/Http/Controllers/Admin/Nodes/NodeViewController.php @@ -40,7 +40,7 @@ public function index(Request $request, Node $node): View { $node = $this->repository->loadLocationAndServerCount($node); - return $this->view->make('admin.nodes.view.index', [ + return view('admin.nodes.view.index', [ 'node' => $node, 'stats' => $this->repository->getUsageStats($node), 'version' => $this->versionService, @@ -52,7 +52,7 @@ public function index(Request $request, Node $node): View */ public function settings(Request $request, Node $node): View { - return $this->view->make('admin.nodes.view.settings', [ + return view('admin.nodes.view.settings', [ 'node' => $node, 'locations' => $this->locationRepository->all(), ]); @@ -63,7 +63,7 @@ public function settings(Request $request, Node $node): View */ public function configuration(Request $request, Node $node): View { - return $this->view->make('admin.nodes.view.configuration', compact('node')); + return view('admin.nodes.view.configuration', compact('node')); } /** @@ -75,7 +75,7 @@ public function allocations(Request $request, Node $node): View $this->plainInject(['node' => Collection::wrap($node)->only(['id'])]); - return $this->view->make('admin.nodes.view.allocation', [ + return view('admin.nodes.view.allocation', [ 'node' => $node, 'allocations' => Allocation::query()->where('node_id', $node->id) ->groupBy('ip') @@ -94,7 +94,7 @@ public function servers(Request $request, Node $node): View ->only(['scheme', 'fqdn', 'daemonListen', 'daemon_token_id', 'daemon_token']), ]); - return $this->view->make('admin.nodes.view.servers', [ + return view('admin.nodes.view.servers', [ 'node' => $node, 'servers' => $this->serverRepository->loadAllServersForNode($node->id, 25), ]); diff --git a/app/Http/Controllers/Admin/NodesController.php b/app/Http/Controllers/Admin/NodesController.php index 573a1d9f8d..6d7cba7ffd 100644 --- a/app/Http/Controllers/Admin/NodesController.php +++ b/app/Http/Controllers/Admin/NodesController.php @@ -60,7 +60,7 @@ public function create(): View|RedirectResponse return redirect()->route('admin.locations'); } - return $this->view->make('admin.nodes.new', ['locations' => $locations]); + return view('admin.nodes.new', ['locations' => $locations]); } /** diff --git a/app/Http/Controllers/Admin/Servers/CreateServerController.php b/app/Http/Controllers/Admin/Servers/CreateServerController.php index 12c1c696b8..5d7c66c420 100644 --- a/app/Http/Controllers/Admin/Servers/CreateServerController.php +++ b/app/Http/Controllers/Admin/Servers/CreateServerController.php @@ -55,7 +55,7 @@ public function index(): View|RedirectResponse })->keyBy('id'), ]); - return $this->view->make('admin.servers.new', [ + return view('admin.servers.new', [ 'locations' => Location::all(), 'nests' => $nests, ]); diff --git a/app/Http/Controllers/Admin/Servers/ServerController.php b/app/Http/Controllers/Admin/Servers/ServerController.php index 430c3f2b91..8161c00404 100644 --- a/app/Http/Controllers/Admin/Servers/ServerController.php +++ b/app/Http/Controllers/Admin/Servers/ServerController.php @@ -33,6 +33,6 @@ public function index(Request $request): View ]) ->paginate(config()->get('pterodactyl.paginate.admin.servers')); - return $this->view->make('admin.servers.index', ['servers' => $servers]); + return view('admin.servers.index', ['servers' => $servers]); } } diff --git a/app/Http/Controllers/Admin/Servers/ServerViewController.php b/app/Http/Controllers/Admin/Servers/ServerViewController.php index 7cf64a2f57..86d55b5fdc 100644 --- a/app/Http/Controllers/Admin/Servers/ServerViewController.php +++ b/app/Http/Controllers/Admin/Servers/ServerViewController.php @@ -43,7 +43,7 @@ public function __construct( */ public function index(Request $request, Server $server): View { - return $this->view->make('admin.servers.view.index', compact('server')); + return view('admin.servers.view.index', compact('server')); } /** @@ -51,7 +51,7 @@ public function index(Request $request, Server $server): View */ public function details(Request $request, Server $server): View { - return $this->view->make('admin.servers.view.details', compact('server')); + return view('admin.servers.view.details', compact('server')); } /** @@ -61,7 +61,7 @@ public function build(Request $request, Server $server): View { $allocations = $server->node->allocations->toBase(); - return $this->view->make('admin.servers.view.build', [ + return view('admin.servers.view.build', [ 'server' => $server, 'assigned' => $allocations->where('server_id', $server->id)->sortBy('port')->sortBy('ip'), 'unassigned' => $allocations->where('server_id', null)->sortBy('port')->sortBy('ip'), @@ -88,7 +88,7 @@ public function startup(Request $request, Server $server): View })->keyBy('id'), ]); - return $this->view->make('admin.servers.view.startup', compact('server', 'nests')); + return view('admin.servers.view.startup', compact('server', 'nests')); } /** @@ -96,7 +96,7 @@ public function startup(Request $request, Server $server): View */ public function database(Request $request, Server $server): View { - return $this->view->make('admin.servers.view.database', [ + return view('admin.servers.view.database', [ 'hosts' => $this->databaseHostRepository->all(), 'server' => $server, ]); @@ -109,7 +109,7 @@ public function mounts(Request $request, Server $server): View { $server->load('mounts'); - return $this->view->make('admin.servers.view.mounts', [ + return view('admin.servers.view.mounts', [ 'mounts' => $this->mountRepository->getMountListForServer($server), 'server' => $server, ]); @@ -138,7 +138,7 @@ public function manage(Request $request, Server $server): View 'nodeData' => $this->nodeRepository->getNodesForServerCreation(), ]); - return $this->view->make('admin.servers.view.manage', [ + return view('admin.servers.view.manage', [ 'server' => $server, 'locations' => $this->locationRepository->all(), 'canTransfer' => $canTransfer, @@ -150,6 +150,6 @@ public function manage(Request $request, Server $server): View */ public function delete(Request $request, Server $server): View { - return $this->view->make('admin.servers.view.delete', compact('server')); + return view('admin.servers.view.delete', compact('server')); } } diff --git a/app/Http/Controllers/Admin/Settings/AdvancedController.php b/app/Http/Controllers/Admin/Settings/AdvancedController.php index bf68832325..4df1982bb4 100644 --- a/app/Http/Controllers/Admin/Settings/AdvancedController.php +++ b/app/Http/Controllers/Admin/Settings/AdvancedController.php @@ -39,7 +39,7 @@ public function index(): View $showRecaptchaWarning = true; } - return $this->view->make('admin.settings.advanced', [ + return view('admin.settings.advanced', [ 'showRecaptchaWarning' => $showRecaptchaWarning, ]); } diff --git a/app/Http/Controllers/Admin/Settings/IndexController.php b/app/Http/Controllers/Admin/Settings/IndexController.php index eabede932c..722e995ae9 100644 --- a/app/Http/Controllers/Admin/Settings/IndexController.php +++ b/app/Http/Controllers/Admin/Settings/IndexController.php @@ -34,7 +34,7 @@ public function __construct( */ public function index(): View { - return $this->view->make('admin.settings.index', [ + return view('admin.settings.index', [ 'version' => $this->versionService, 'languages' => $this->getAvailableLanguages(true), ]); diff --git a/app/Http/Controllers/Admin/Settings/MailController.php b/app/Http/Controllers/Admin/Settings/MailController.php index 2db87fd58f..ea7a05e306 100644 --- a/app/Http/Controllers/Admin/Settings/MailController.php +++ b/app/Http/Controllers/Admin/Settings/MailController.php @@ -38,7 +38,7 @@ public function __construct( */ public function index(): View { - return $this->view->make('admin.settings.mail', [ + return view('admin.settings.mail', [ 'disabled' => $this->config->get('mail.default') !== 'smtp', ]); } diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 220b8cc69d..ef22189d4a 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -57,7 +57,7 @@ public function index(Request $request): View ->allowedSorts(['id', 'uuid']) ->paginate(50); - return $this->view->make('admin.users.index', ['users' => $users]); + return view('admin.users.index', ['users' => $users]); } /** @@ -65,7 +65,7 @@ public function index(Request $request): View */ public function create(): View { - return $this->view->make('admin.users.new', [ + return view('admin.users.new', [ 'languages' => $this->getAvailableLanguages(true), ]); } @@ -75,7 +75,7 @@ public function create(): View */ public function view(User $user): View { - return $this->view->make('admin.users.view', [ + return view('admin.users.view', [ 'user' => $user, 'languages' => $this->getAvailableLanguages(true), ]); diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 2dbb34ee36..0be6451cfa 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -29,7 +29,7 @@ public function __construct(private ViewFactory $view) */ public function index(): View { - return $this->view->make('templates/auth.core'); + return view('templates/auth.core'); } /** diff --git a/app/Http/Controllers/Base/IndexController.php b/app/Http/Controllers/Base/IndexController.php index fecaa91a3e..ffa278b63b 100644 --- a/app/Http/Controllers/Base/IndexController.php +++ b/app/Http/Controllers/Base/IndexController.php @@ -23,6 +23,6 @@ public function __construct( */ public function index(): View { - return $this->view->make('templates/base.core'); + return view('templates/base.core'); } } From 4efd72c1dae38341e34b2227f118a837d95e89fe Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Mon, 31 Oct 2022 23:12:31 -0400 Subject: [PATCH 44/69] Get the actual array --- app/Http/Controllers/Admin/Servers/ServerTransferController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/Servers/ServerTransferController.php b/app/Http/Controllers/Admin/Servers/ServerTransferController.php index 7c6c4fdfd4..22eaaf60f4 100644 --- a/app/Http/Controllers/Admin/Servers/ServerTransferController.php +++ b/app/Http/Controllers/Admin/Servers/ServerTransferController.php @@ -59,7 +59,7 @@ public function transfer(Request $request, Server $server): RedirectResponse $transfer->new_node = $node_id; $transfer->old_allocation = $server->allocation_id; $transfer->new_allocation = $allocation_id; - $transfer->old_additional_allocations = $server->allocations->where('id', '!=', $server->allocation_id)->pluck('id'); + $transfer->old_additional_allocations = $server->allocations->where('id', '!=', $server->allocation_id)->pluck('id')->all(); $transfer->new_additional_allocations = $additional_allocations; $transfer->save(); From b65604af52c98b3ed2a77268d3fa1beabd50eb31 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 00:07:42 -0400 Subject: [PATCH 45/69] Switch these over --- app/Services/Deployment/FindViableNodesService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Services/Deployment/FindViableNodesService.php b/app/Services/Deployment/FindViableNodesService.php index ff36ff1a05..751d06ee9e 100644 --- a/app/Services/Deployment/FindViableNodesService.php +++ b/app/Services/Deployment/FindViableNodesService.php @@ -77,12 +77,12 @@ public function handle(int $perPage = null, int $page = null): LengthAwarePagina ->where('public', 1); if (!empty($this->locations)) { - $query = $query->whereIn('nodes.location_id', $this->locations); + $query = $query->whereIn('location_id', $this->locations); } - $results = $query->groupBy('nodes.id') - ->havingRaw('(IFNULL(SUM(servers.memory), 0) + ?) <= (nodes.memory * (1 + (nodes.memory_overallocate / 100)))', [$this->memory]) - ->havingRaw('(IFNULL(SUM(servers.disk), 0) + ?) <= (nodes.disk * (1 + (nodes.disk_overallocate / 100)))', [$this->disk]); + $results = $query->groupBy('id') + ->havingRaw('(sum_memory + ?) <= (memory * (1 + (memory_overallocate / 100)))', [$this->memory]) + ->havingRaw('(sum_disk + ?) <= (disk * (1 + (disk_overallocate / 100)))', [$this->disk]); if (!is_null($page)) { $results = $results->paginate($perPage ?? 50, ['*'], 'page', $page); From f13bdb16e853fb3a4a05270cf830e2b2abcc70df Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 13:54:21 -0400 Subject: [PATCH 46/69] Simplify --- app/Services/Servers/ServerCreationService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Services/Servers/ServerCreationService.php b/app/Services/Servers/ServerCreationService.php index 2c9b4cf844..62e848aa0a 100644 --- a/app/Services/Servers/ServerCreationService.php +++ b/app/Services/Servers/ServerCreationService.php @@ -82,7 +82,7 @@ public function handle(array $data, DeploymentObject $deployment = null): Server // // If that connection fails out we will attempt to perform a cleanup by just // deleting the server itself from the system. - /** @var \Pterodactyl\Models\Server $server */ + /** @var Server $server */ $server = $this->connection->transaction(function () use ($data, $eggVariableData) { // Create the server and assign any additional allocations to it. $server = $this->createModel($data); @@ -115,7 +115,7 @@ public function handle(array $data, DeploymentObject $deployment = null): Server */ private function configureDeployment(array $data, DeploymentObject $deployment): Allocation { - /** @var \Illuminate\Support\Collection $nodes */ + /** @var Collection $nodes */ $nodes = $this->findViableNodesService->setLocations($deployment->getLocations()) ->setDisk(Arr::get($data, 'disk')) ->setMemory(Arr::get($data, 'memory')) @@ -136,7 +136,7 @@ private function createModel(array $data): Server { $uuid = $this->generateUniqueUuidCombo(); - /** @var \Pterodactyl\Models\Server $model */ + /** @var Server $model */ $model = $this->repository->create([ 'external_id' => Arr::get($data, 'external_id'), 'uuid' => $uuid, From 14f59bfa2542e89ecc7e62e0c88dee60ec89dc16 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 13:56:31 -0400 Subject: [PATCH 47/69] Reset this back, it'd be much easier to do this one if it weren't a paginator --- app/Services/Deployment/FindViableNodesService.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Services/Deployment/FindViableNodesService.php b/app/Services/Deployment/FindViableNodesService.php index 751d06ee9e..0d8e829158 100644 --- a/app/Services/Deployment/FindViableNodesService.php +++ b/app/Services/Deployment/FindViableNodesService.php @@ -71,10 +71,11 @@ public function handle(int $perPage = null, int $page = null): LengthAwarePagina Assert::integer($this->disk, 'Disk space must be an int, got %s'); Assert::integer($this->memory, 'Memory usage must be an int, got %s'); - $query = Node::query() - ->withSum('servers as sum_memory', 'memory') - ->withSum('servers as sum_disk', 'disk') - ->where('public', 1); + $query = Node::query()->select('nodes.*') + ->selectRaw('IFNULL(SUM(servers.memory), 0) as sum_memory') + ->selectRaw('IFNULL(SUM(servers.disk), 0) as sum_disk') + ->leftJoin('servers', 'servers.node_id', '=', 'nodes.id') + ->where('nodes.public', 1); if (!empty($this->locations)) { $query = $query->whereIn('location_id', $this->locations); From 1cec6d9869748f0abaf2120fb492963de91f2aa9 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:00:17 -0400 Subject: [PATCH 48/69] Give up --- phpstan.neon | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 104bfecb89..6d0badf616 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -19,6 +19,9 @@ parameters: # Ignore magic spatie calls - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Builder::allowed(\w+)\(\)#' + # This should be replaced with resources instead of a magic transformer factory, robots in disguise + - '#Method Pterodactyl\\Http\\Controllers\\Api\\Client\\ClientApiController::getTransformer\(\) should return T#' + excludePaths: - app/Repositories From 79887c2909060c790bdd317eede13a785dacc2e2 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:00:25 -0400 Subject: [PATCH 49/69] Up it again! --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 6d0badf616..c951c39a42 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,7 +7,7 @@ parameters: - app/ # Level 9 is the highest level - level: 2 + level: 3 ignoreErrors: # Ignore dynamic methods from 3rd Party Vendor From 7c4f006e4b1665196d232aaf2be4729b922fe5a3 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:14:32 -0400 Subject: [PATCH 50/69] Better readability --- app/Http/Middleware/RequireTwoFactorAuthentication.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Http/Middleware/RequireTwoFactorAuthentication.php b/app/Http/Middleware/RequireTwoFactorAuthentication.php index e3307727f2..ca6d88dd8d 100644 --- a/app/Http/Middleware/RequireTwoFactorAuthentication.php +++ b/app/Http/Middleware/RequireTwoFactorAuthentication.php @@ -7,6 +7,7 @@ use Illuminate\Http\Request; use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Exceptions\Http\TwoFactorAuthRequiredException; +use Pterodactyl\Models\User; class RequireTwoFactorAuthentication { @@ -36,12 +37,17 @@ public function __construct(private AlertsMessageBag $alert) */ public function handle(Request $request, Closure $next): mixed { - /** @var \Pterodactyl\Models\User $user */ + /** @var User $user */ $user = $request->user(); $uri = rtrim($request->getRequestUri(), '/') . '/'; $current = $request->route()->getName(); - if (!$user || Str::startsWith($uri, ['/auth/']) || Str::startsWith($current, ['auth.', 'account.'])) { + // Must be logged in + if (!$user instanceof User) { + return $next($request); + } + + if (Str::startsWith($uri, ['/auth/']) || Str::startsWith($current, ['auth.', 'account.'])) { return $next($request); } From 9ac2fae77f47030d28ca1e7d9e8907d85220991f Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:14:59 -0400 Subject: [PATCH 51/69] Typing --- .../Api/Client/Server/ResourceBelongsToServer.php | 2 +- app/Models/Egg.php | 6 +++--- app/Services/Backups/InitiateBackupService.php | 4 ++-- app/Services/Databases/DatabaseManagementService.php | 1 + app/Services/Schedules/ProcessScheduleService.php | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php b/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php index 4688a9f6d4..ed695abd31 100644 --- a/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php +++ b/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php @@ -33,7 +33,7 @@ public function handle(Request $request, Closure $next): mixed throw new InvalidArgumentException('This middleware cannot be used in a context that is missing a server in the parameters.'); } - /** @var \Pterodactyl\Models\Server $server */ + /** @var Server $server */ $server = $request->route()->parameter('server'); $exception = new NotFoundHttpException('The requested resource was not found for this server.'); foreach ($params as $key => $model) { diff --git a/app/Models/Egg.php b/app/Models/Egg.php index 31c3e34200..c33e5b194c 100644 --- a/app/Models/Egg.php +++ b/app/Models/Egg.php @@ -26,9 +26,9 @@ * @property string|null $startup * @property bool $script_is_privileged * @property string|null $script_install - * @property string $script_entry - * @property string $script_container - * @property int|null $copy_script_from + * @property ?string $script_entry + * @property ?string $script_container + * @property ?int $copy_script_from * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property string|null $copy_script_install diff --git a/app/Services/Backups/InitiateBackupService.php b/app/Services/Backups/InitiateBackupService.php index be8f966326..f142754031 100644 --- a/app/Services/Backups/InitiateBackupService.php +++ b/app/Services/Backups/InitiateBackupService.php @@ -98,17 +98,17 @@ public function handle(Server $server, string $name = null, bool $override = fal // Get the oldest backup the server has that is not "locked" (indicating a backup that should // never be automatically purged). If we find a backup we will delete it and then continue with // this process. If no backup is found that can be used an exception is thrown. - /** @var \Pterodactyl\Models\Backup $oldest */ $oldest = $successful->where('is_locked', false)->orderBy('created_at')->first(); if (!$oldest) { throw new TooManyBackupsException($server->backup_limit); } + /* @var Backup $oldest */ $this->deleteBackupService->handle($oldest); } return $this->connection->transaction(function () use ($server, $name) { - /** @var \Pterodactyl\Models\Backup $backup */ + /** @var Backup $backup */ $backup = $this->repository->create([ 'server_id' => $server->id, 'uuid' => Uuid::uuid4()->toString(), diff --git a/app/Services/Databases/DatabaseManagementService.php b/app/Services/Databases/DatabaseManagementService.php index b70cb8b4dc..0635c1c70c 100644 --- a/app/Services/Databases/DatabaseManagementService.php +++ b/app/Services/Databases/DatabaseManagementService.php @@ -119,6 +119,7 @@ public function create(Server $server, array $data): Database }); } catch (Exception $exception) { try { + /** @var ?Database $database */ if ($database instanceof Database) { $this->repository->dropDatabase($database->database); $this->repository->dropUser($database->username, $database->remote); diff --git a/app/Services/Schedules/ProcessScheduleService.php b/app/Services/Schedules/ProcessScheduleService.php index cfbc7e5cad..d1b5811a88 100644 --- a/app/Services/Schedules/ProcessScheduleService.php +++ b/app/Services/Schedules/ProcessScheduleService.php @@ -27,13 +27,13 @@ public function __construct(private ConnectionInterface $connection, private Dis */ public function handle(Schedule $schedule, bool $now = false): void { - /** @var \Pterodactyl\Models\Task $task */ $task = $schedule->tasks()->orderBy('sequence_id')->first(); if (is_null($task)) { throw new DisplayException('Cannot process schedule for task execution: no tasks are registered.'); } + /* @var \Pterodactyl\Models\Task $task */ $this->connection->transaction(function () use ($schedule, $task) { $schedule->forceFill([ 'is_processing' => true, From d6e20efe3699c7e019b4ed0cbee1fcda10bd5fe7 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:15:08 -0400 Subject: [PATCH 52/69] Order of operations --- app/Http/Controllers/Auth/LoginCheckpointController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/LoginCheckpointController.php b/app/Http/Controllers/Auth/LoginCheckpointController.php index af05c55ef7..0cadcf9de3 100644 --- a/app/Http/Controllers/Auth/LoginCheckpointController.php +++ b/app/Http/Controllers/Auth/LoginCheckpointController.php @@ -72,7 +72,7 @@ public function __invoke(LoginCheckpointRequest $request): JsonResponse } else { $decrypted = $this->encrypter->decrypt($user->totp_secret); - if ($this->google2FA->verifyKey($decrypted, (string) $request->input('authentication_code') ?? '', config('pterodactyl.auth.2fa.window'))) { + if ($this->google2FA->verifyKey($decrypted, ((string) $request->input('authentication_code')) ?? '', config('pterodactyl.auth.2fa.window'))) { Event::dispatch(new ProvidedAuthenticationToken($user)); return $this->sendLoginResponse($user, $request); From 6f89c1e315702a93ac61b0f925302ad36f447d7e Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:15:30 -0400 Subject: [PATCH 53/69] Impossible for this to be null, isset is called in the library method --- .../Middleware/Api/Client/Server/ResourceBelongsToServer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php b/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php index ed695abd31..337f4af713 100644 --- a/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php +++ b/app/Http/Middleware/Api/Client/Server/ResourceBelongsToServer.php @@ -29,7 +29,7 @@ class ResourceBelongsToServer public function handle(Request $request, Closure $next): mixed { $params = $request->route()->parameters(); - if (is_null($params) || !$params['server'] instanceof Server) { + if (!$params['server'] instanceof Server) { throw new InvalidArgumentException('This middleware cannot be used in a context that is missing a server in the parameters.'); } From 85cb724edb5a5449f609686e738d306456daab86 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:34:28 -0400 Subject: [PATCH 54/69] Ignoring our problems until they go away! --- phpstan.neon | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index c951c39a42..ec44800a99 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -25,5 +25,11 @@ parameters: excludePaths: - app/Repositories + # Bug in Laravel Framework #44807 + - app/Console/Commands/Overrides/UpCommand.php + + # More magic spatie to be replaced + - app/Extensions/Spatie/Fractalistic/Fractal.php + # # checkMissingIterableValueType: false From e12af380eeaf1ea813d6a2a63f771a0fdd2c6f23 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:35:08 -0400 Subject: [PATCH 55/69] Remove unused repositories --- app/Http/Controllers/Admin/ApiController.php | 4 +--- app/Http/Controllers/Admin/BaseController.php | 3 +-- app/Http/Controllers/Admin/DatabaseController.php | 4 +--- app/Http/Controllers/Admin/Nodes/NodeController.php | 8 -------- app/Http/Controllers/Admin/Nodes/NodeViewController.php | 6 +----- .../Controllers/Admin/Servers/CreateServerController.php | 4 +--- app/Http/Controllers/Admin/Servers/ServerController.php | 8 -------- .../Controllers/Admin/Servers/ServerViewController.php | 6 +----- .../Controllers/Admin/Settings/AdvancedController.php | 4 +--- app/Http/Controllers/Admin/Settings/IndexController.php | 4 +--- app/Http/Controllers/Admin/Settings/MailController.php | 4 +--- app/Http/Controllers/Auth/LoginController.php | 9 --------- 12 files changed, 9 insertions(+), 55 deletions(-) diff --git a/app/Http/Controllers/Admin/ApiController.php b/app/Http/Controllers/Admin/ApiController.php index 4250db09fc..247aaee00b 100644 --- a/app/Http/Controllers/Admin/ApiController.php +++ b/app/Http/Controllers/Admin/ApiController.php @@ -9,7 +9,6 @@ use Illuminate\Http\RedirectResponse; use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Services\Acl\Api\AdminAcl; -use Illuminate\View\Factory as ViewFactory; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Api\KeyCreationService; use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface; @@ -23,8 +22,7 @@ class ApiController extends Controller public function __construct( private AlertsMessageBag $alert, private ApiKeyRepositoryInterface $repository, - private KeyCreationService $keyCreationService, - private ViewFactory $view, + private KeyCreationService $keyCreationService ) { } diff --git a/app/Http/Controllers/Admin/BaseController.php b/app/Http/Controllers/Admin/BaseController.php index 0e707d2812..2b69330740 100644 --- a/app/Http/Controllers/Admin/BaseController.php +++ b/app/Http/Controllers/Admin/BaseController.php @@ -3,7 +3,6 @@ namespace Pterodactyl\Http\Controllers\Admin; use Illuminate\View\View; -use Illuminate\View\Factory as ViewFactory; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Helpers\SoftwareVersionService; @@ -12,7 +11,7 @@ class BaseController extends Controller /** * BaseController constructor. */ - public function __construct(private SoftwareVersionService $version, private ViewFactory $view) + public function __construct(private SoftwareVersionService $version) { } diff --git a/app/Http/Controllers/Admin/DatabaseController.php b/app/Http/Controllers/Admin/DatabaseController.php index b631ed77d4..dc436ffaa1 100644 --- a/app/Http/Controllers/Admin/DatabaseController.php +++ b/app/Http/Controllers/Admin/DatabaseController.php @@ -8,7 +8,6 @@ use Pterodactyl\Models\DatabaseHost; use Illuminate\Http\RedirectResponse; use Prologue\Alerts\AlertsMessageBag; -use Illuminate\View\Factory as ViewFactory; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Databases\Hosts\HostUpdateService; use Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest; @@ -30,8 +29,7 @@ public function __construct( private HostCreationService $creationService, private HostDeletionService $deletionService, private HostUpdateService $updateService, - private LocationRepositoryInterface $locationRepository, - private ViewFactory $view + private LocationRepositoryInterface $locationRepository ) { } diff --git a/app/Http/Controllers/Admin/Nodes/NodeController.php b/app/Http/Controllers/Admin/Nodes/NodeController.php index c2b6ea91c0..7936772406 100644 --- a/app/Http/Controllers/Admin/Nodes/NodeController.php +++ b/app/Http/Controllers/Admin/Nodes/NodeController.php @@ -7,17 +7,9 @@ use Pterodactyl\Models\Node; use Spatie\QueryBuilder\QueryBuilder; use Pterodactyl\Http\Controllers\Controller; -use Illuminate\Contracts\View\Factory as ViewFactory; class NodeController extends Controller { - /** - * NodeController constructor. - */ - public function __construct(private ViewFactory $view) - { - } - /** * Returns a listing of nodes on the system. */ diff --git a/app/Http/Controllers/Admin/Nodes/NodeViewController.php b/app/Http/Controllers/Admin/Nodes/NodeViewController.php index aed2381267..0ec60a7a03 100644 --- a/app/Http/Controllers/Admin/Nodes/NodeViewController.php +++ b/app/Http/Controllers/Admin/Nodes/NodeViewController.php @@ -8,13 +8,11 @@ use Illuminate\Support\Collection; use Pterodactyl\Models\Allocation; use Pterodactyl\Http\Controllers\Controller; -use Illuminate\Contracts\View\Factory as ViewFactory; use Pterodactyl\Repositories\Eloquent\NodeRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Traits\Controllers\JavascriptInjection; use Pterodactyl\Services\Helpers\SoftwareVersionService; use Pterodactyl\Repositories\Eloquent\LocationRepository; -use Pterodactyl\Repositories\Eloquent\AllocationRepository; class NodeViewController extends Controller { @@ -24,12 +22,10 @@ class NodeViewController extends Controller * NodeViewController constructor. */ public function __construct( - private AllocationRepository $allocationRepository, private LocationRepository $locationRepository, private NodeRepository $repository, private ServerRepository $serverRepository, - private SoftwareVersionService $versionService, - private ViewFactory $view + private SoftwareVersionService $versionService ) { } diff --git a/app/Http/Controllers/Admin/Servers/CreateServerController.php b/app/Http/Controllers/Admin/Servers/CreateServerController.php index 5d7c66c420..4ba37411bf 100644 --- a/app/Http/Controllers/Admin/Servers/CreateServerController.php +++ b/app/Http/Controllers/Admin/Servers/CreateServerController.php @@ -9,7 +9,6 @@ use Pterodactyl\Models\Location; use Illuminate\Http\RedirectResponse; use Prologue\Alerts\AlertsMessageBag; -use Illuminate\View\Factory as ViewFactory; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Repositories\Eloquent\NestRepository; use Pterodactyl\Repositories\Eloquent\NodeRepository; @@ -25,8 +24,7 @@ public function __construct( private AlertsMessageBag $alert, private NestRepository $nestRepository, private NodeRepository $nodeRepository, - private ServerCreationService $creationService, - private ViewFactory $view + private ServerCreationService $creationService ) { } diff --git a/app/Http/Controllers/Admin/Servers/ServerController.php b/app/Http/Controllers/Admin/Servers/ServerController.php index 8161c00404..80de68ef93 100644 --- a/app/Http/Controllers/Admin/Servers/ServerController.php +++ b/app/Http/Controllers/Admin/Servers/ServerController.php @@ -9,17 +9,9 @@ use Spatie\QueryBuilder\AllowedFilter; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Models\Filters\AdminServerFilter; -use Illuminate\Contracts\View\Factory as ViewFactory; class ServerController extends Controller { - /** - * ServerController constructor. - */ - public function __construct(private ViewFactory $view) - { - } - /** * Returns all the servers that exist on the system using a paginated result set. If * a query is passed along in the request it is also passed to the repository function. diff --git a/app/Http/Controllers/Admin/Servers/ServerViewController.php b/app/Http/Controllers/Admin/Servers/ServerViewController.php index 86d55b5fdc..3e662d479d 100644 --- a/app/Http/Controllers/Admin/Servers/ServerViewController.php +++ b/app/Http/Controllers/Admin/Servers/ServerViewController.php @@ -10,11 +10,9 @@ use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Servers\EnvironmentService; -use Illuminate\Contracts\View\Factory as ViewFactory; use Pterodactyl\Repositories\Eloquent\NestRepository; use Pterodactyl\Repositories\Eloquent\NodeRepository; use Pterodactyl\Repositories\Eloquent\MountRepository; -use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Traits\Controllers\JavascriptInjection; use Pterodactyl\Repositories\Eloquent\LocationRepository; use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository; @@ -32,9 +30,7 @@ public function __construct( private MountRepository $mountRepository, private NestRepository $nestRepository, private NodeRepository $nodeRepository, - private ServerRepository $repository, - private EnvironmentService $environmentService, - private ViewFactory $view + private EnvironmentService $environmentService ) { } diff --git a/app/Http/Controllers/Admin/Settings/AdvancedController.php b/app/Http/Controllers/Admin/Settings/AdvancedController.php index 4df1982bb4..20f8f3c036 100644 --- a/app/Http/Controllers/Admin/Settings/AdvancedController.php +++ b/app/Http/Controllers/Admin/Settings/AdvancedController.php @@ -6,7 +6,6 @@ use Illuminate\Http\RedirectResponse; use Prologue\Alerts\AlertsMessageBag; use Illuminate\Contracts\Console\Kernel; -use Illuminate\View\Factory as ViewFactory; use Pterodactyl\Http\Controllers\Controller; use Illuminate\Contracts\Config\Repository as ConfigRepository; use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface; @@ -21,8 +20,7 @@ public function __construct( private AlertsMessageBag $alert, private ConfigRepository $config, private Kernel $kernel, - private SettingsRepositoryInterface $settings, - private ViewFactory $view + private SettingsRepositoryInterface $settings ) { } diff --git a/app/Http/Controllers/Admin/Settings/IndexController.php b/app/Http/Controllers/Admin/Settings/IndexController.php index 722e995ae9..ca92e7d033 100644 --- a/app/Http/Controllers/Admin/Settings/IndexController.php +++ b/app/Http/Controllers/Admin/Settings/IndexController.php @@ -6,7 +6,6 @@ use Illuminate\Http\RedirectResponse; use Prologue\Alerts\AlertsMessageBag; use Illuminate\Contracts\Console\Kernel; -use Illuminate\View\Factory as ViewFactory; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Traits\Helpers\AvailableLanguages; use Pterodactyl\Services\Helpers\SoftwareVersionService; @@ -24,8 +23,7 @@ public function __construct( private AlertsMessageBag $alert, private Kernel $kernel, private SettingsRepositoryInterface $settings, - private SoftwareVersionService $versionService, - private ViewFactory $view + private SoftwareVersionService $versionService ) { } diff --git a/app/Http/Controllers/Admin/Settings/MailController.php b/app/Http/Controllers/Admin/Settings/MailController.php index ea7a05e306..8c9365641a 100644 --- a/app/Http/Controllers/Admin/Settings/MailController.php +++ b/app/Http/Controllers/Admin/Settings/MailController.php @@ -8,7 +8,6 @@ use Illuminate\Http\Response; use Illuminate\Contracts\Console\Kernel; use Pterodactyl\Notifications\MailTested; -use Illuminate\View\Factory as ViewFactory; use Illuminate\Support\Facades\Notification; use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Http\Controllers\Controller; @@ -27,8 +26,7 @@ public function __construct( private ConfigRepository $config, private Encrypter $encrypter, private Kernel $kernel, - private SettingsRepositoryInterface $settings, - private ViewFactory $view + private SettingsRepositoryInterface $settings ) { } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 0be6451cfa..49a17378da 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -9,19 +9,10 @@ use Illuminate\Http\JsonResponse; use Pterodactyl\Facades\Activity; use Illuminate\Contracts\View\View; -use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Database\Eloquent\ModelNotFoundException; class LoginController extends AbstractLoginController { - /** - * LoginController constructor. - */ - public function __construct(private ViewFactory $view) - { - parent::__construct(); - } - /** * Handle all incoming requests for the authentication routes and render the * base authentication view component. React will take over at this point and From 2d21a2f28d366e61bafbc47367bb592098b235f0 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:35:21 -0400 Subject: [PATCH 56/69] No need to cast this --- app/Http/Controllers/Auth/LoginCheckpointController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/LoginCheckpointController.php b/app/Http/Controllers/Auth/LoginCheckpointController.php index 0cadcf9de3..82580edc0b 100644 --- a/app/Http/Controllers/Auth/LoginCheckpointController.php +++ b/app/Http/Controllers/Auth/LoginCheckpointController.php @@ -72,7 +72,7 @@ public function __invoke(LoginCheckpointRequest $request): JsonResponse } else { $decrypted = $this->encrypter->decrypt($user->totp_secret); - if ($this->google2FA->verifyKey($decrypted, ((string) $request->input('authentication_code')) ?? '', config('pterodactyl.auth.2fa.window'))) { + if ($this->google2FA->verifyKey($decrypted, $request->input('authentication_code') ?? '', config('pterodactyl.auth.2fa.window'))) { Event::dispatch(new ProvidedAuthenticationToken($user)); return $this->sendLoginResponse($user, $request); From 0bb3e0af1ae4502e3a88ae545ed08d45c35b31f2 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:35:33 -0400 Subject: [PATCH 57/69] Technically more correct --- app/Http/Controllers/Api/Client/Servers/StartupController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/Client/Servers/StartupController.php b/app/Http/Controllers/Api/Client/Servers/StartupController.php index 9548be25e9..b674145ff2 100644 --- a/app/Http/Controllers/Api/Client/Servers/StartupController.php +++ b/app/Http/Controllers/Api/Client/Servers/StartupController.php @@ -52,7 +52,6 @@ public function index(GetStartupRequest $request, Server $server): array */ public function update(UpdateStartupVariableRequest $request, Server $server): array { - /** @var \Pterodactyl\Models\EggVariable $variable */ $variable = $server->variables()->where('env_variable', $request->input('key'))->first(); $original = $variable->server_value; @@ -62,6 +61,8 @@ public function update(UpdateStartupVariableRequest $request, Server $server): a throw new BadRequestHttpException('The environment variable you are trying to edit is read-only.'); } + /* @var \Pterodactyl\Models\EggVariable $variable */ + // Revalidate the variable value using the egg variable specific validation rules for it. $this->validate($request, ['value' => $variable->rules]); From e13dc994d4507d8c68fb5ced1fdbaf93b7fe225d Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:35:49 -0400 Subject: [PATCH 58/69] php-cs-fixer --- app/Http/Middleware/RequireTwoFactorAuthentication.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Middleware/RequireTwoFactorAuthentication.php b/app/Http/Middleware/RequireTwoFactorAuthentication.php index ca6d88dd8d..cffcc50116 100644 --- a/app/Http/Middleware/RequireTwoFactorAuthentication.php +++ b/app/Http/Middleware/RequireTwoFactorAuthentication.php @@ -5,9 +5,9 @@ use Closure; use Illuminate\Support\Str; use Illuminate\Http\Request; +use Pterodactyl\Models\User; use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Exceptions\Http\TwoFactorAuthRequiredException; -use Pterodactyl\Models\User; class RequireTwoFactorAuthentication { From 2569c2a58db47d61bfaefccfcbcfbd5cae121f37 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:39:53 -0400 Subject: [PATCH 59/69] Higher we go --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index ec44800a99..e12e72eb50 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,7 +7,7 @@ parameters: - app/ # Level 9 is the highest level - level: 3 + level: 4 ignoreErrors: # Ignore dynamic methods from 3rd Party Vendor From cd0916452c30f1b486ac09f58dd3099571f83daf Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:40:02 -0400 Subject: [PATCH 60/69] Separate this out --- .github/workflows/analysis.yaml | 49 +++++++++++++++++++++++++++++++++ .github/workflows/ci.yaml | 4 --- 2 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/analysis.yaml diff --git a/.github/workflows/analysis.yaml b/.github/workflows/analysis.yaml new file mode 100644 index 0000000000..d7846e0f20 --- /dev/null +++ b/.github/workflows/analysis.yaml @@ -0,0 +1,49 @@ +name: Static Analysis + +on: + push: + branches: + - "develop" + pull_request: + branches: + - "develop" + +jobs: + tests: + name: Static Analysis + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + php: [8.0, 8.1] + steps: + - name: Code Checkout + uses: actions/checkout@v3 + + - name: Get cache directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer-${{ matrix.php }}- + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: bcmath, cli, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip + tools: composer:v2 + coverage: none + + - name: Install dependencies + run: composer install --no-interaction --no-progress --no-suggest --prefer-dist + + - name: Analyze + run: vendor/bin/phpstan analyse + if: ${{ always() }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c5f5224e46..4da19b6ed2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -59,10 +59,6 @@ jobs: - name: Install dependencies run: composer install --no-interaction --no-progress --no-suggest --prefer-dist - - name: Static analysis - run: vendor/bin/phpstan analyse - if: ${{ always() }} - - name: Unit tests run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests/Unit if: ${{ always() }} From fa3e9980b47ae9d3414cb7f734682484c4aaf091 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Tue, 1 Nov 2022 14:45:05 -0400 Subject: [PATCH 61/69] Put this back --- .github/workflows/analysis.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/analysis.yaml b/.github/workflows/analysis.yaml index d7846e0f20..6ea5886ecc 100644 --- a/.github/workflows/analysis.yaml +++ b/.github/workflows/analysis.yaml @@ -41,6 +41,9 @@ jobs: tools: composer:v2 coverage: none + - name: Setup .env + run: cp .env.ci .env + - name: Install dependencies run: composer install --no-interaction --no-progress --no-suggest --prefer-dist From 44cf57d6a00b0bde0271fa53591b8f2cc0967414 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sun, 27 Nov 2022 23:08:04 -0500 Subject: [PATCH 62/69] Remove unnecessary service --- .../Controllers/Admin/Servers/ServerTransferController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/Servers/ServerTransferController.php b/app/Http/Controllers/Admin/Servers/ServerTransferController.php index 7297093407..3027287669 100644 --- a/app/Http/Controllers/Admin/Servers/ServerTransferController.php +++ b/app/Http/Controllers/Admin/Servers/ServerTransferController.php @@ -26,8 +26,7 @@ public function __construct( private AllocationRepositoryInterface $allocationRepository, private ConnectionInterface $connection, private DaemonTransferRepository $daemonTransferRepository, - private NodeJWTService $nodeJWTService, - private NodeRepository $nodeRepository + private NodeJWTService $nodeJWTService ) { } From a98a761fd7e06c7c538cd16b95c738145f55dd7c Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sun, 27 Nov 2022 23:10:14 -0500 Subject: [PATCH 63/69] php-cs-fixer --- app/Http/Controllers/Admin/Servers/ServerTransferController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Controllers/Admin/Servers/ServerTransferController.php b/app/Http/Controllers/Admin/Servers/ServerTransferController.php index 3027287669..6d94963500 100644 --- a/app/Http/Controllers/Admin/Servers/ServerTransferController.php +++ b/app/Http/Controllers/Admin/Servers/ServerTransferController.php @@ -12,7 +12,6 @@ use Illuminate\Database\ConnectionInterface; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Nodes\NodeJWTService; -use Pterodactyl\Repositories\Eloquent\NodeRepository; use Pterodactyl\Repositories\Wings\DaemonTransferRepository; use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface; From 6e6fea7dfc06b8c9f4cb730cdb22f2399336c43f Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sun, 27 Nov 2022 23:13:02 -0500 Subject: [PATCH 64/69] Remove cache --- .github/workflows/analysis.yaml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/analysis.yaml b/.github/workflows/analysis.yaml index 6ea5886ecc..0dc4f6f133 100644 --- a/.github/workflows/analysis.yaml +++ b/.github/workflows/analysis.yaml @@ -20,19 +20,6 @@ jobs: - name: Code Checkout uses: actions/checkout@v3 - - name: Get cache directory - id: composer-cache - run: | - echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer-${{ matrix.php }}- - - name: Setup PHP uses: shivammathur/setup-php@v2 with: From 532db103768ce0d5e7fd515958f0a3b5b74bd14c Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sun, 27 Nov 2022 23:15:48 -0500 Subject: [PATCH 65/69] This no longer exists --- .github/workflows/analysis.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/analysis.yaml b/.github/workflows/analysis.yaml index 0dc4f6f133..0a7fd56abb 100644 --- a/.github/workflows/analysis.yaml +++ b/.github/workflows/analysis.yaml @@ -28,8 +28,6 @@ jobs: tools: composer:v2 coverage: none - - name: Setup .env - run: cp .env.ci .env - name: Install dependencies run: composer install --no-interaction --no-progress --no-suggest --prefer-dist From 18601cc18efca59e8073b325ee261c06737f83cb Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sun, 27 Nov 2022 23:16:53 -0500 Subject: [PATCH 66/69] Remove extra space --- .github/workflows/analysis.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/analysis.yaml b/.github/workflows/analysis.yaml index 0a7fd56abb..8cbf07f158 100644 --- a/.github/workflows/analysis.yaml +++ b/.github/workflows/analysis.yaml @@ -28,7 +28,6 @@ jobs: tools: composer:v2 coverage: none - - name: Install dependencies run: composer install --no-interaction --no-progress --no-suggest --prefer-dist From bd3bd76207fbccdc4dc83f213c56a3494f327c2f Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sun, 27 Nov 2022 23:19:25 -0500 Subject: [PATCH 67/69] Add some env vars in --- .github/workflows/analysis.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/analysis.yaml b/.github/workflows/analysis.yaml index 8cbf07f158..de9f09a924 100644 --- a/.github/workflows/analysis.yaml +++ b/.github/workflows/analysis.yaml @@ -16,6 +16,10 @@ jobs: fail-fast: false matrix: php: [8.0, 8.1] + env: + APP_ENV: testing + APP_DEBUG: "true" + APP_KEY: SomeRandomString3232RandomString steps: - name: Code Checkout uses: actions/checkout@v3 From ea075bd5e9efc3d3a7a2f69afc1ec016e0e75b2d Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sun, 27 Nov 2022 23:21:33 -0500 Subject: [PATCH 68/69] Add s'more --- .github/workflows/analysis.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/analysis.yaml b/.github/workflows/analysis.yaml index de9f09a924..2362c7dedd 100644 --- a/.github/workflows/analysis.yaml +++ b/.github/workflows/analysis.yaml @@ -20,6 +20,10 @@ jobs: APP_ENV: testing APP_DEBUG: "true" APP_KEY: SomeRandomString3232RandomString + CACHE_DRIVER: array + MAIL_MAILER: array + SESSION_DRIVER: array + QUEUE_CONNECTION: sync steps: - name: Code Checkout uses: actions/checkout@v3 From bdfcff587c6a0a9cad2425e229140dff35bd7e37 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Mon, 28 Nov 2022 09:50:21 -0700 Subject: [PATCH 69/69] ci: organize workflows --- .github/workflows/analysis.yaml | 44 ---------- .github/workflows/docker.yaml | 12 +-- .github/workflows/{ci.yaml => laravel.yaml} | 96 +++++++++++++++------ .github/workflows/lint.yaml | 33 ------- .github/workflows/release.yaml | 12 +-- .github/workflows/ui.yaml | 35 ++++++-- 6 files changed, 108 insertions(+), 124 deletions(-) delete mode 100644 .github/workflows/analysis.yaml rename .github/workflows/{ci.yaml => laravel.yaml} (70%) delete mode 100644 .github/workflows/lint.yaml diff --git a/.github/workflows/analysis.yaml b/.github/workflows/analysis.yaml deleted file mode 100644 index 2362c7dedd..0000000000 --- a/.github/workflows/analysis.yaml +++ /dev/null @@ -1,44 +0,0 @@ -name: Static Analysis - -on: - push: - branches: - - "develop" - pull_request: - branches: - - "develop" - -jobs: - tests: - name: Static Analysis - runs-on: ubuntu-20.04 - strategy: - fail-fast: false - matrix: - php: [8.0, 8.1] - env: - APP_ENV: testing - APP_DEBUG: "true" - APP_KEY: SomeRandomString3232RandomString - CACHE_DRIVER: array - MAIL_MAILER: array - SESSION_DRIVER: array - QUEUE_CONNECTION: sync - steps: - - name: Code Checkout - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: bcmath, cli, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip - tools: composer:v2 - coverage: none - - - name: Install dependencies - run: composer install --no-interaction --no-progress --no-suggest --prefer-dist - - - name: Analyze - run: vendor/bin/phpstan analyse - if: ${{ always() }} diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index bd44fecd0d..65cef226d3 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -1,4 +1,4 @@ -name: Publish Docker Image +name: Docker on: push: @@ -8,16 +8,16 @@ on: jobs: push: - name: Push Image to GitHub Packages + name: Push runs-on: ubuntu-20.04 # Always run against a tag, even if the commit into the tag has [docker skip] # within the commit message. if: "!contains(github.ref, 'develop') || (!contains(github.event.head_commit.message, 'skip docker') && !contains(github.event.head_commit.message, 'docker skip'))" steps: - - name: Code Checkout + - name: Code checkout uses: actions/checkout@v3 - - name: Docker Metadata + - name: Docker metadata uses: docker/metadata-action@v4 id: docker_meta with: @@ -26,10 +26,10 @@ jobs: - name: Setup QEMU uses: docker/setup-qemu-action@v2 - - name: Setup Docker Buildx + - name: Setup Docker buildx uses: docker/setup-buildx-action@v2 - - name: Docker Login + - name: Docker login uses: docker/login-action@v2 with: registry: ghcr.io diff --git a/.github/workflows/ci.yaml b/.github/workflows/laravel.yaml similarity index 70% rename from .github/workflows/ci.yaml rename to .github/workflows/laravel.yaml index 28ce63e4a7..56a597b480 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/laravel.yaml @@ -1,4 +1,4 @@ -name: Tests +name: Laravel on: push: @@ -11,8 +11,58 @@ on: - "1.0-develop" jobs: + analysis: + name: Static Analysis + runs-on: ubuntu-20.04 + env: + APP_ENV: testing + APP_DEBUG: "true" + APP_KEY: SomeRandomString3232RandomString + CACHE_DRIVER: array + MAIL_MAILER: array + SESSION_DRIVER: array + QUEUE_CONNECTION: sync + steps: + - name: Code checkout + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + extensions: bcmath, cli, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip + tools: composer:v2 + coverage: none + + - name: Install dependencies + run: composer install --no-interaction --no-progress --no-suggest --prefer-dist + + - name: Analyze + run: vendor/bin/phpstan analyse + + lint: + name: Lint + runs-on: ubuntu-20.04 + steps: + - name: Code checkout + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + extensions: bcmath, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip + tools: composer:v2 + coverage: none + + - name: Install dependencies + run: composer install --no-interaction --no-progress --no-suggest --prefer-dist + + - name: PHP CS Fixer + run: vendor/bin/php-cs-fixer fix --dry-run --diff + mysql: - name: MySQL + name: Tests (MySQL) runs-on: ubuntu-20.04 strategy: fail-fast: false @@ -36,20 +86,17 @@ jobs: APP_TIMEZONE: UTC APP_URL: http://localhost/ APP_ENVIRONMENT_ONLY: "true" - - DB_CONNECTION: mysql - DB_HOST: 127.0.0.1 - DB_DATABASE: testing - DB_USERNAME: root - CACHE_DRIVER: array MAIL_MAILER: array SESSION_DRIVER: array QUEUE_CONNECTION: sync - HASHIDS_SALT: test123 + DB_CONNECTION: mysql + DB_HOST: 127.0.0.1 + DB_DATABASE: testing + DB_USERNAME: root steps: - - name: Code Checkout + - name: Code checkout uses: actions/checkout@v3 - name: Get cache directory @@ -78,7 +125,6 @@ jobs: - name: Unit tests run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests/Unit - if: ${{ always() }} env: DB_HOST: UNIT_NO_DB @@ -88,7 +134,7 @@ jobs: DB_PORT: ${{ job.services.database.ports[3306] }} postgres: - name: PostgreSQL + name: Tests (PostgreSQL) runs-on: ubuntu-20.04 if: "!contains(github.event.head_commit.message, 'skip ci') && !contains(github.event.head_commit.message, 'ci skip')" strategy: @@ -114,35 +160,32 @@ jobs: APP_TIMEZONE: UTC APP_URL: http://localhost/ APP_ENVIRONMENT_ONLY: "true" - - DB_CONNECTION: pgsql - DB_HOST: 127.0.0.1 - DB_DATABASE: testing - DB_USERNAME: postgres - DB_PASSWORD: postgres - CACHE_DRIVER: array MAIL_MAILER: array SESSION_DRIVER: array QUEUE_CONNECTION: sync - HASHIDS_SALT: test123 + DB_CONNECTION: pgsql + DB_HOST: 127.0.0.1 + DB_DATABASE: testing + DB_USERNAME: postgres + DB_PASSWORD: postgres steps: - - name: Code Checkout + - name: Code checkout uses: actions/checkout@v3 - name: Get cache directory id: composer-cache run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache uses: actions/cache@v3 with: - path: | - ~/.php_cs.cache - ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-cache-${{ matrix.php }}-${{ hashFiles('**.composer.lock') }} + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer-${{ matrix.php }}- - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -157,7 +200,6 @@ jobs: - name: Unit tests run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests/Unit - if: ${{ always() }} env: DB_HOST: UNIT_NO_DB diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index a48c6b14ed..0000000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: Lint - -on: - push: - branches: - - "develop" - - "1.0-develop" - pull_request: - branches: - - "develop" - - "1.0-develop" - -jobs: - lint: - name: Lint - runs-on: ubuntu-20.04 - steps: - - name: Code Checkout - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "8.1" - extensions: bcmath, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip - tools: composer:v2 - coverage: none - - - name: Install dependencies - run: composer install --no-interaction --no-progress --no-suggest --prefer-dist - - - name: PHP CS Fixer - run: vendor/bin/php-cs-fixer fix --dry-run --diff diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 09ab86410a..7c4a72bffb 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,20 +10,20 @@ jobs: name: Release runs-on: ubuntu-20.04 steps: - - name: Code Checkout + - name: Code checkout uses: actions/checkout@v3 - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 16 - cache: "yarn" + node-version: 18 + cache: yarn - name: Install dependencies run: yarn install --frozen-lockfile - name: Build - run: yarn build:production + run: yarn build - name: Create release branch and bump version env: @@ -41,7 +41,7 @@ jobs: - name: Create release archive run: | - rm -rf node_modules/ test/ codecov.yml CODE_OF_CONDUCT.md CONTRIBUTING.md phpunit.xml Vagrantfile + rm -rf node_modules/ tests/ CODE_OF_CONDUCT.md CONTRIBUTING.md phpstan.neon phpunit.xml tar -czf panel.tar.gz * .env.example .eslintignore .eslintrc.js - name: Extract changelog @@ -58,7 +58,7 @@ jobs: echo -e "\n#### SHA256 Checksum\n\n\`\`\`\n$SUM\n\`\`\`\n" >> ./RELEASE_CHANGELOG echo $SUM > checksum.txt - - name: Create Release + - name: Create release id: create_release uses: actions/create-release@v1 env: diff --git a/.github/workflows/ui.yaml b/.github/workflows/ui.yaml index e743de4667..e61696c1ce 100644 --- a/.github/workflows/ui.yaml +++ b/.github/workflows/ui.yaml @@ -11,28 +11,47 @@ on: - "1.0-develop" jobs: - build-and-test: - name: Build and Test + lint: + name: Lint + runs-on: ubuntu-20.04 + steps: + - name: Code checkout + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: yarn + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Lint + run: yarn run lint + + tests: + name: Tests runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: - node-version: [16, 18] + node: [16, 18] steps: - - name: Code Checkout + - name: Code checkout uses: actions/checkout@v3 - name: Setup Node uses: actions/setup-node@v3 with: - node-version: ${{ matrix.node-version }} - cache: "yarn" + node-version: ${{ matrix.node }} + cache: yarn - name: Install dependencies run: yarn install --frozen-lockfile - name: Build - run: yarn build + run: yarn run build - name: Tests - run: yarn test + run: yarn run test