1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-21 16:42:29 +01:00

Upgrade to Laravel 9 (#4413)

Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
Matthew Penner 2022-10-14 10:59:20 -06:00 committed by GitHub
parent 95e15d2c8a
commit cbcf62086f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
573 changed files with 4387 additions and 9411 deletions

View File

@ -8,7 +8,7 @@ indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
[.*yml]
[*.yml]
indent_size = 2
[*.md]

View File

@ -2,9 +2,11 @@ APP_ENV=testing
APP_DEBUG=true
APP_KEY=SomeRandomString3232RandomString
APP_THEME=pterodactyl
APP_TIMEZONE=America/Los_Angeles
APP_TIMEZONE=UTC
APP_URL=http://localhost/
APP_ENVIRONMENT_ONLY=true
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=panel_test
DB_USERNAME=root
@ -16,4 +18,3 @@ MAIL_DRIVER=array
QUEUE_DRIVER=sync
HASHIDS_SALT=test123
APP_ENVIRONMENT_ONLY=true

View File

@ -2,40 +2,43 @@ APP_ENV=production
APP_DEBUG=false
APP_KEY=
APP_THEME=pterodactyl
APP_TIMEZONE=America/New_York
APP_CLEAR_TASKLOG=720
APP_DELETE_MINUTES=10
APP_ENVIRONMENT_ONLY=true
LOG_CHANNEL=daily
APP_LOCALE=en
APP_TIMEZONE=UTC
APP_URL=http://panel.example.com
APP_LOCALE=en
APP_ENVIRONMENT_ONLY=true
LOG_CHANNEL=daily
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=panel
DB_USERNAME=pterodactyl
DB_PASSWORD=
SESSION_DRIVER=file
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
HASHIDS_SALT=
HASHIDS_LENGTH=8
MAIL_DRIVER=smtp
MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=25
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
MAIL_FROM=no-reply@example.com
MAILGUN_ENDPOINT=api.mailgun.net
MAIL_FROM_ADDRESS=no-reply@example.com
MAIL_FROM_NAME="Pterodactyl Panel"
# You should set this to your domain to prevent it defaulting to 'localhost', causing
# mail servers such as Gmail to reject your mail.
#
# @see: https://github.com/pterodactyl/panel/pull/3110
# SERVER_NAME=panel.example.com
QUEUE_HIGH=high
QUEUE_STANDARD=standard
QUEUE_LOW=low

View File

@ -1,4 +1,6 @@
public
node_modules
resources/views
babel.config.js
tailwind.config.js
webpack.config.js

View File

@ -1,24 +1,32 @@
name: Build Panel
name: Build
on:
push:
branches:
- 'develop'
- 'v2'
pull_request:
jobs:
build:
ui:
name: UI
runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, 'skip ci') && !contains(github.event.head_commit.message, 'ci skip')"
strategy:
matrix:
node-version: [16.x]
node-version: [16]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
- name: Code Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install -g yarn
- run: yarn install
- run: yarn build:production
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn build:production

View File

@ -1,45 +1,51 @@
name: Publish Docker Image
on:
push:
branches:
- 'develop'
tags:
- 'v*'
- 'release/v*'
jobs:
push_to_registry:
push:
name: Push Image to GitHub Packages
runs-on: ubuntu-latest
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:
- uses: actions/checkout@v2
- uses: crazy-max/ghaction-docker-meta@v1
- name: Code Checkout
uses: actions/checkout@v3
- name: Docker Metadata
uses: docker/metadata-action@v4
id: docker_meta
with:
images: ghcr.io/pterodactyl/panel
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker Login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Bump Version
if: "!contains(github.ref, 'develop')"
env:
REF: ${{ github.ref }}
run: |
sed -i "s/ 'version' => 'canary',/ 'version' => '${REF:11}',/" config/app.php
- name: Release Production Build
- name: Release production build
uses: docker/build-push-action@v2
if: "!contains(github.ref, 'develop')"
if: "contains(github.ref, 'release/v')"
with:
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
- name: Release Development Build
- name: Release development build
uses: docker/build-push-action@v2
if: "contains(github.ref, 'develop')"
with:

View File

@ -1,16 +1,29 @@
name: Create Release
name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
name: Release
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- name: Code Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: 16
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn build:production
- name: Create release branch and bump version
env:
@ -26,11 +39,6 @@ jobs:
git commit -m "bump version for release"
git push
- name: Build assets
run: |
yarn install
yarn run build:production
- name: Create release archive
run: |
rm -rf node_modules/ test/ codecov.yml CODE_OF_CONDUCT.md CONTRIBUTING.md phpunit.xml Vagrantfile
@ -62,7 +70,7 @@ jobs:
draft: true
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }}
- name: Upload binary
- name: Upload release archive
id: upload-release-archive
uses: actions/upload-release-asset@v1
env:
@ -73,7 +81,7 @@ jobs:
asset_name: panel.tar.gz
asset_content_type: application/gzip
- name: Upload checksum
- name: Upload release checksum
id: upload-release-checksum
uses: actions/upload-release-asset@v1
env:

View File

@ -1,18 +1,21 @@
name: Run Tests
name: Tests
on:
push:
branches:
- 'develop'
- 'v2'
pull_request:
jobs:
tests:
name: Tests
runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, 'skip ci') && !contains(github.event.head_commit.message, 'ci skip')"
strategy:
fail-fast: false
matrix:
php: [ 7.4, 8.0, 8.1 ]
php: [8.0, 8.1]
database: ['mariadb:10.2', 'mysql:8']
services:
database:
@ -23,35 +26,48 @@ jobs:
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
name: "php-${{ matrix.php }} (${{ matrix.database }})"
steps:
- uses: actions/checkout@v2
- name: get cache directory
- 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)"
- uses: actions/cache@v2
- 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') }}
- uses: shivammathur/setup-php@v2
- 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
- run: cp .env.ci .env
- run: composer install --prefer-dist --no-interaction --no-progress
- run: vendor/bin/php-cs-fixer fix --dry-run --diff
- name: Setup .env
run: cp .env.ci .env
- 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
continue-on-error: true
- name: execute unit tests
- name: Unit tests
run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests/Unit
if: ${{ always() }}
env:
DB_HOST: UNIT_NO_DB
- name: execute integration tests
- name: Integration tests
run: vendor/bin/phpunit tests/Integration
env:
DB_PORT: ${{ job.services.database.ports[3306] }}

View File

@ -1 +0,0 @@
@types/react-native

View File

@ -31,19 +31,8 @@ class AppSettingsCommand extends Command
'sync' => 'Sync',
];
/**
* @var \Illuminate\Contracts\Console\Kernel
*/
protected $command;
/**
* @var string
*/
protected $description = 'Configure basic environment settings for the Panel.';
/**
* @var string
*/
protected $signature = 'p:environment:setup
{--new-salt : Whether or not to generate a new salt for Hashids.}
{--author= : The email that services created on this instance should be linked to.}
@ -57,19 +46,14 @@ class AppSettingsCommand extends Command
{--redis-port= : Port to connect to redis over.}
{--settings-ui= : Enable or disable the settings UI.}';
/**
* @var array
*/
protected $variables = [];
protected array $variables = [];
/**
* AppSettingsCommand constructor.
*/
public function __construct(Kernel $command)
public function __construct(private Kernel $console)
{
parent::__construct();
$this->command = $command;
}
/**
@ -77,7 +61,7 @@ class AppSettingsCommand extends Command
*
* @throws \Pterodactyl\Exceptions\PterodactylException
*/
public function handle()
public function handle(): int
{
if (empty(config('hashids.salt')) || $this->option('new-salt')) {
$this->variables['HASHIDS_SALT'] = str_random(20);
@ -98,13 +82,13 @@ class AppSettingsCommand extends Command
$this->output->comment('The application URL MUST begin with https:// or http:// depending on if you are using SSL or not. If you do not include the scheme your emails and other content will link to the wrong location.');
$this->variables['APP_URL'] = $this->option('url') ?? $this->ask(
'Application URL',
config('app.url', 'http://example.org')
config('app.url', 'https://example.com')
);
$this->output->comment('The timezone should match one of PHP\'s supported timezones. If you are unsure, please reference http://php.net/manual/en/timezones.php.');
$this->output->comment('The timezone should match one of PHP\'s supported timezones. If you are unsure, please reference https://php.net/manual/en/timezones.php.');
$this->variables['APP_TIMEZONE'] = $this->option('timezone') ?? $this->anticipate(
'Application Timezone',
DateTimeZone::listIdentifiers(DateTimeZone::ALL),
DateTimeZone::listIdentifiers(),
config('app.timezone')
);
@ -136,14 +120,16 @@ class AppSettingsCommand extends Command
}
// Make sure session cookies are set as "secure" when using HTTPS
if (strpos($this->variables['APP_URL'], 'https://') === 0) {
if (str_starts_with($this->variables['APP_URL'], 'https://')) {
$this->variables['SESSION_SECURE_COOKIE'] = 'true';
}
$this->checkForRedis();
$this->writeToEnvironment($this->variables);
$this->info($this->command->output());
$this->info($this->console->output());
return 0;
}
/**

View File

@ -12,24 +12,8 @@ class DatabaseSettingsCommand extends Command
{
use EnvironmentWriterTrait;
/**
* @var \Illuminate\Contracts\Console\Kernel
*/
protected $console;
/**
* @var \Illuminate\Database\DatabaseManager
*/
protected $database;
/**
* @var string
*/
protected $description = 'Configure database settings for the Panel.';
/**
* @var string
*/
protected $signature = 'p:environment:database
{--host= : The connection address for the MySQL server.}
{--port= : The connection port for the MySQL server.}
@ -37,30 +21,22 @@ class DatabaseSettingsCommand extends Command
{--username= : Username to use when connecting.}
{--password= : Password to use for this database.}';
/**
* @var array
*/
protected $variables = [];
protected array $variables = [];
/**
* DatabaseSettingsCommand constructor.
*/
public function __construct(DatabaseManager $database, Kernel $console)
public function __construct(private DatabaseManager $database, private Kernel $console)
{
parent::__construct();
$this->console = $console;
$this->database = $database;
}
/**
* Handle command execution.
*
* @return int
*
* @throws \Pterodactyl\Exceptions\PterodactylException
*/
public function handle()
public function handle(): int
{
$this->output->note('It is highly recommended to not use "localhost" as your database host as we have seen frequent socket connection issues. If you want to use a local connection you should be using "127.0.0.1".');
$this->variables['DB_HOST'] = $this->option('host') ?? $this->ask(

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Console\Commands\Environment;
@ -17,19 +10,8 @@ class EmailSettingsCommand extends Command
{
use EnvironmentWriterTrait;
/**
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/**
* @var string
*/
protected $description = 'Set or update the email sending configuration for the Panel.';
/**
* @var string
*/
protected $signature = 'p:environment:mail
{--driver= : The mail driver to use.}
{--email= : Email address that messages from the Panel will originate from.}
@ -41,19 +23,14 @@ class EmailSettingsCommand extends Command
{--username=}
{--password=}';
/**
* @var array
*/
protected $variables = [];
protected array $variables = [];
/**
* EmailSettingsCommand constructor.
*/
public function __construct(ConfigRepository $config)
public function __construct(private ConfigRepository $config)
{
parent::__construct();
$this->config = $config;
}
/**
@ -70,7 +47,7 @@ class EmailSettingsCommand extends Command
'mail' => 'PHP\'s Internal Mail Function',
'mailgun' => 'Mailgun Transactional Email',
'mandrill' => 'Mandrill Transactional Email',
'postmark' => 'Postmarkapp Transactional Email',
'postmark' => 'Postmark Transactional Email',
],
$this->config->get('mail.driver', 'smtp')
);

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Console\Commands;
@ -15,35 +8,16 @@ use Illuminate\Contracts\Config\Repository as ConfigRepository;
class InfoCommand extends Command
{
/**
* @var string
*/
protected $description = 'Displays the application, database, and email configurations along with the panel version.';
/**
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/**
* @var string
*/
protected $signature = 'p:info';
/**
* @var \Pterodactyl\Services\Helpers\SoftwareVersionService
*/
protected $versionService;
/**
* VersionCommand constructor.
*/
public function __construct(ConfigRepository $config, SoftwareVersionService $versionService)
public function __construct(private ConfigRepository $config, private SoftwareVersionService $versionService)
{
parent::__construct();
$this->config = $config;
$this->versionService = $versionService;
}
/**
@ -78,10 +52,10 @@ class InfoCommand extends Command
$driver = $this->config->get('database.default');
$this->table([], [
['Driver', $driver],
['Host', $this->config->get("database.connections.{$driver}.host")],
['Port', $this->config->get("database.connections.{$driver}.port")],
['Database', $this->config->get("database.connections.{$driver}.database")],
['Username', $this->config->get("database.connections.{$driver}.username")],
['Host', $this->config->get("database.connections.$driver.host")],
['Port', $this->config->get("database.connections.$driver.port")],
['Database', $this->config->get("database.connections.$driver.database")],
['Username', $this->config->get("database.connections.$driver.username")],
], 'compact');
$this->output->title('Email Configuration');
@ -98,13 +72,8 @@ class InfoCommand extends Command
/**
* Format output in a Name: Value manner.
*
* @param string $value
* @param string $opts
*
* @return string
*/
private function formatText($value, $opts = '')
private function formatText(string $value, string $opts = ''): string
{
return sprintf('<%s>%s</>', $opts, $value);
}

View File

@ -1,56 +1,28 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Console\Commands\Location;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Pterodactyl\Services\Locations\LocationDeletionService;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
class DeleteLocationCommand extends Command
{
/**
* @var \Pterodactyl\Services\Locations\LocationDeletionService
*/
protected $deletionService;
/**
* @var string
*/
protected $description = 'Deletes a location from the Panel.';
/**
* @var \Illuminate\Support\Collection
*/
protected $locations;
/**
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
*/
protected $repository;
/**
* @var string
*/
protected $signature = 'p:location:delete {--short= : The short code of the location to delete.}';
protected Collection $locations;
/**
* DeleteLocationCommand constructor.
*/
public function __construct(
LocationDeletionService $deletionService,
LocationRepositoryInterface $repository
private LocationDeletionService $deletionService,
private LocationRepositoryInterface $repository
) {
parent::__construct();
$this->deletionService = $deletionService;
$this->repository = $repository;
}
/**

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Console\Commands\Location;
@ -14,31 +7,18 @@ use Pterodactyl\Services\Locations\LocationCreationService;
class MakeLocationCommand extends Command
{
/**
* @var \Pterodactyl\Services\Locations\LocationCreationService
*/
protected $creationService;
/**
* @var string
*/
protected $signature = 'p:location:make
{--short= : The shortcode name of this location (ex. us1).}
{--long= : A longer description of this location.}';
/**
* @var string
*/
protected $description = 'Creates a new location on the system via the CLI.';
/**
* Create a new command instance.
*/
public function __construct(LocationCreationService $creationService)
public function __construct(private LocationCreationService $creationService)
{
parent::__construct();
$this->creationService = $creationService;
}
/**

View File

@ -5,27 +5,19 @@ namespace Pterodactyl\Console\Commands\Maintenance;
use SplFileInfo;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
class CleanServiceBackupFilesCommand extends Command
{
public const BACKUP_THRESHOLD_MINUTES = 5;
/**
* @var string
*/
protected $description = 'Clean orphaned .bak files created when modifying services.';
/**
* @var \Illuminate\Contracts\Filesystem\Filesystem
*/
protected $disk;
/**
* @var string
*/
protected $signature = 'p:maintenance:clean-service-backups';
protected Filesystem $disk;
/**
* CleanServiceBackupFilesCommand constructor.
*/

View File

@ -9,24 +9,26 @@ use Pterodactyl\Repositories\Eloquent\BackupRepository;
class PruneOrphanedBackupsCommand extends Command
{
/**
* @var string
*/
protected $signature = 'p:maintenance:prune-backups {--prune-age=}';
/**
* @var string
*/
protected $description = 'Marks all backups that have not completed in the last "n" minutes as being failed.';
public function handle(BackupRepository $repository)
/**
* PruneOrphanedBackupsCommand constructor.
*/
public function __construct(private BackupRepository $backupRepository)
{
parent::__construct();
}
public function handle()
{
$since = $this->option('prune-age') ?? config('backups.prune_age', 360);
if (!$since || !is_digit($since)) {
throw new InvalidArgumentException('The "--prune-age" argument must be a value greater than 0.');
}
$query = $repository->getBuilder()
$query = $this->backupRepository->getBuilder()
->whereNull('completed_at')
->where('created_at', '<=', CarbonImmutable::now()->subMinutes($since)->toDateTimeString());
@ -37,7 +39,7 @@ class PruneOrphanedBackupsCommand extends Command
return;
}
$this->warn("Marking {$count} backups that have not been marked as completed in the last {$since} minutes as failed.");
$this->warn("Marking $count backups that have not been marked as completed in the last $since minutes as failed.");
$query->update([
'is_successful' => false,

View File

@ -1,13 +1,5 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Console\Commands\Node;
use Illuminate\Console\Command;
@ -15,14 +7,6 @@ use Pterodactyl\Services\Nodes\NodeCreationService;
class MakeNodeCommand extends Command
{
/**
* @var \Pterodactyl\Services\Nodes\NodeCreationService
*/
protected $creationService;
/**
* @var string
*/
protected $signature = 'p:node:make
{--name= : A name to identify the node.}
{--description= : A description to identify the node.}
@ -41,20 +25,23 @@ class MakeNodeCommand extends Command
{--daemonSFTPPort= : Enter the wings SFTP listening port.}
{--daemonBase= : Enter the base folder.}';
/**
* @var string
*/
protected $description = 'Creates a new node on the system via the CLI.';
/**
* MakeNodeCommand constructor.
*/
public function __construct(private NodeCreationService $creationService)
{
parent::__construct();
}
/**
* Handle the command execution process.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function handle(NodeCreationService $creationService)
public function handle()
{
$this->creationService = $creationService;
$data['name'] = $this->option('name') ?? $this->ask('Enter a short identifier used to distinguish this node from others');
$data['description'] = $this->option('description') ?? $this->ask('Enter a description to identify the node');
$data['location_id'] = $this->option('locationId') ?? $this->ask('Enter a valid location id');

View File

@ -13,7 +13,7 @@ class NodeConfigurationCommand extends Command
protected $description = 'Displays the configuration for the specified node.';
public function handle()
public function handle(): int
{
$column = ctype_digit((string) $this->argument('node')) ? 'id' : 'uuid';
@ -28,7 +28,7 @@ class NodeConfigurationCommand extends Command
if (!in_array($format, ['yaml', 'yml', 'json'])) {
$this->error('Invalid format specified. Valid options are "yaml" and "json".');
exit(1);
return 1;
}
if ($format === 'json') {

View File

@ -9,7 +9,7 @@ class NodeListCommand extends Command
{
protected $signature = 'p:node:list {--format=text : The output format: "text" or "json". }';
public function handle()
public function handle(): int
{
$nodes = Node::query()->with('location')->get()->map(function (Node $node) {
return [

View File

@ -13,14 +13,14 @@ class SeedCommand extends BaseSeedCommand
* Block someone from running this seed command if they have not completed
* the migration process.
*/
public function handle()
public function handle(): int
{
if (!$this->hasCompletedMigrations()) {
$this->showMigrationWarning();
return;
return 1;
}
parent::handle();
return parent::handle();
}
}

View File

@ -13,14 +13,14 @@ class UpCommand extends BaseUpCommand
* Block someone from running this up command if they have not completed
* the migration process.
*/
public function handle()
public function handle(): int
{
if (!$this->hasCompletedMigrations()) {
$this->showMigrationWarning();
return;
return 1;
}
parent::handle();
return parent::handle();
}
}

View File

@ -12,20 +12,14 @@ use Pterodactyl\Services\Schedules\ProcessScheduleService;
class ProcessRunnableCommand extends Command
{
/**
* @var string
*/
protected $signature = 'p:schedule:process';
/**
* @var string
*/
protected $description = 'Process schedules in the database and determine which are ready to run.';
/**
* Handle command execution.
*/
public function handle()
public function handle(): int
{
$schedules = Schedule::query()
->with('tasks')
@ -38,7 +32,7 @@ class ProcessRunnableCommand extends Command
if ($schedules->count() < 1) {
$this->line('There are no scheduled tasks for servers that need to be run.');
return;
return 0;
}
$bar = $this->output->createProgressBar(count($schedules));
@ -50,6 +44,8 @@ class ProcessRunnableCommand extends Command
}
$this->line('');
return 0;
}
/**
@ -75,7 +71,7 @@ class ProcessRunnableCommand extends Command
} catch (Throwable|Exception $exception) {
Log::error($exception, ['schedule_id' => $schedule->id]);
$this->error("An error was encountered while processing Schedule #{$schedule->id}: " . $exception->getMessage());
$this->error("An error was encountered while processing Schedule #$schedule->id: " . $exception->getMessage());
}
}
}

View File

@ -4,6 +4,7 @@ namespace Pterodactyl\Console\Commands\Server;
use Pterodactyl\Models\Server;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Validation\ValidationException;
use Illuminate\Validation\Factory as ValidatorFactory;
use Pterodactyl\Repositories\Wings\DaemonPowerRepository;
@ -11,31 +12,33 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class BulkPowerActionCommand extends Command
{
/**
* @var string
*/
protected $signature = 'p:server:bulk-power
{action : The action to perform (start, stop, restart, kill)}
{--servers= : A comma separated list of servers.}
{--nodes= : A comma separated list of nodes.}';
/**
* @var string
*/
protected $description = 'Perform bulk power management on large groupings of servers or nodes at once.';
/**
* BulkPowerActionCommand constructor.
*/
public function __construct(private DaemonPowerRepository $powerRepository, private ValidatorFactory $validator)
{
parent::__construct();
}
/**
* Handle the bulk power request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function handle(DaemonPowerRepository $powerRepository, ValidatorFactory $validator)
public function handle()
{
$action = $this->argument('action');
$nodes = empty($this->option('nodes')) ? [] : explode(',', $this->option('nodes'));
$servers = empty($this->option('servers')) ? [] : explode(',', $this->option('servers'));
$validator = $validator->make([
$validator = $this->validator->make([
'action' => $action,
'nodes' => $nodes,
'servers' => $servers,
@ -61,6 +64,7 @@ class BulkPowerActionCommand extends Command
}
$bar = $this->output->createProgressBar($count);
$powerRepository = $this->powerRepository;
$this->getQueryBuilder($servers, $nodes)->each(function (Server $server) use ($action, $powerRepository, &$bar) {
$bar->clear();
@ -84,10 +88,8 @@ class BulkPowerActionCommand extends Command
/**
* Returns the query builder instance that will return the servers that should be affected.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function getQueryBuilder(array $servers, array $nodes)
protected function getQueryBuilder(array $servers, array $nodes): Builder
{
$instance = Server::query()->whereNull('status');

View File

@ -12,7 +12,6 @@ class UpgradeCommand extends Command
{
protected const DEFAULT_URL = 'https://github.com/pterodactyl/panel/releases/%s/panel.tar.gz';
/** @var string */
protected $signature = 'p:upgrade
{--user= : The user that PHP runs under. All files will be owned by this user.}
{--group= : The group that PHP runs under. All files will be owned by this group.}
@ -20,7 +19,6 @@ class UpgradeCommand extends Command
{--release= : A specific Pterodactyl version to download from GitHub. Leave blank to use latest.}
{--skip-download : If set no archive will be downloaded.}';
/** @var string */
protected $description = 'Downloads a new archive for Pterodactyl from GitHub and then executes the normal upgrade commands.';
/**
@ -92,7 +90,7 @@ class UpgradeCommand extends Command
}
}
ini_set('output_buffering', 0);
ini_set('output_buffering', '0');
$bar = $this->output->createProgressBar($skipDownload ? 9 : 10);
$bar->start();

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Console\Commands\User;
@ -16,42 +9,19 @@ use Pterodactyl\Services\Users\UserDeletionService;
class DeleteUserCommand extends Command
{
/**
* @var \Pterodactyl\Services\Users\UserDeletionService
*/
protected $deletionService;
/**
* @var string
*/
protected $description = 'Deletes a user from the Panel if no servers are attached to their account.';
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/
protected $repository;
/**
* @var string
*/
protected $signature = 'p:user:delete {--user=}';
/**
* DeleteUserCommand constructor.
*/
public function __construct(UserDeletionService $deletionService)
public function __construct(private UserDeletionService $deletionService)
{
parent::__construct();
$this->deletionService = $deletionService;
}
/**
* @return bool
*
* @throws \Pterodactyl\Exceptions\DisplayException
*/
public function handle()
public function handle(): int
{
$search = $this->option('user') ?? $this->ask(trans('command/messages.user.search_users'));
Assert::notEmpty($search, 'Search term should be an email address, got: %s.');
@ -68,7 +38,7 @@ class DeleteUserCommand extends Command
return $this->handle();
}
return false;
return 1;
}
if ($this->input->isInteractive()) {
@ -85,7 +55,7 @@ class DeleteUserCommand extends Command
if (count($results) > 1) {
$this->error(trans('command/messages.user.multiple_found'));
return false;
return 1;
}
$deleteUser = $results->first();
@ -95,5 +65,7 @@ class DeleteUserCommand extends Command
$this->deletionService->handle($deleteUser);
$this->info(trans('command/messages.user.deleted'));
}
return 0;
}
}

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Console\Commands\User;
@ -14,29 +7,16 @@ use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
class DisableTwoFactorCommand extends Command
{
/**
* @var string
*/
protected $description = 'Disable two-factor authentication for a specific user in the Panel.';
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/
protected $repository;
/**
* @var string
*/
protected $signature = 'p:user:disable2fa {--email= : The email of the user to disable 2-Factor for.}';
/**
* DisableTwoFactorCommand constructor.
*/
public function __construct(UserRepositoryInterface $repository)
public function __construct(private UserRepositoryInterface $repository)
{
parent::__construct();
$this->repository = $repository;
}
/**

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Console\Commands\User;
@ -14,29 +7,16 @@ use Pterodactyl\Services\Users\UserCreationService;
class MakeUserCommand extends Command
{
/**
* @var \Pterodactyl\Services\Users\UserCreationService
*/
protected $creationService;
/**
* @var string
*/
protected $description = 'Creates a user on the system via the CLI.';
/**
* @var string
*/
protected $signature = 'p:user:make {--email=} {--username=} {--name-first=} {--name-last=} {--password=} {--admin=} {--no-password}';
/**
* MakeUserCommand constructor.
*/
public function __construct(UserCreationService $creationService)
public function __construct(private UserCreationService $creationService)
{
parent::__construct();
$this->creationService = $creationService;
}
/**

View File

@ -33,7 +33,7 @@ trait RequiresDatabaseMigrations
* them to properly run the migrations rather than ignoring all of the other previous
* errors...
*/
protected function showMigrationWarning()
protected function showMigrationWarning(): void
{
$this->getOutput()->writeln('<options=bold>
| @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |

View File

@ -1,24 +1,14 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Contracts\Criteria;
use Illuminate\Database\Eloquent\Model;
use Pterodactyl\Repositories\Repository;
interface CriteriaInterface
{
/**
* Apply selected criteria to a repository call.
*
* @param \Illuminate\Database\Eloquent\Model $model
*
* @return mixed
*/
public function apply($model, Repository $repository);
public function apply(Model $model, Repository $repository): mixed;
}

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Contracts\Extensions;
@ -16,12 +9,7 @@ interface HashidsInterface extends VendorHashidsInterface
/**
* Decode an encoded hashid and return the first result.
*
* @param string $encoded
* @param null $default
*
* @return mixed
*
* @throws \InvalidArgumentException
*/
public function decodeFirst($encoded, $default = null);
public function decodeFirst(string $encoded, string $default = null): mixed;
}

View File

@ -6,7 +6,7 @@ interface ClientPermissionsRequest
{
/**
* Returns the permissions string indicating which permission should be used to
* validate that the authenticated user has permission to perform this action aganist
* validate that the authenticated user has permission to perform this action against
* the given resource (server).
*/
public function permission(): string;

View File

@ -2,18 +2,18 @@
namespace Pterodactyl\Contracts\Repository;
use Pterodactyl\Models\Allocation;
interface AllocationRepositoryInterface extends RepositoryInterface
{
/**
* Return all of the allocations that exist for a node that are not currently
* Return all the allocations that exist for a node that are not currently
* allocated.
*/
public function getUnassignedAllocationIds(int $node): array;
/**
* Return a single allocation from those meeting the requirements.
*
* @return \Pterodactyl\Models\Allocation|null
*/
public function getRandomAllocation(array $nodes, array $ports, bool $dedicated = false);
public function getRandomAllocation(array $nodes, array $ports, bool $dedicated = false): ?Allocation;
}

View File

@ -8,12 +8,12 @@ use Illuminate\Support\Collection;
interface ApiKeyRepositoryInterface extends RepositoryInterface
{
/**
* Get all of the account API keys that exist for a specific user.
* Get all the account API keys that exist for a specific user.
*/
public function getAccountKeys(User $user): Collection;
/**
* Get all of the application API keys that exist for a specific user.
* Get all the application API keys that exist for a specific user.
*/
public function getApplicationKeys(User $user): Collection;

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Contracts\Repository;

View File

@ -2,7 +2,6 @@
namespace Pterodactyl\Contracts\Repository;
use Pterodactyl\Models\Database;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
@ -12,10 +11,8 @@ interface DatabaseRepositoryInterface extends RepositoryInterface
/**
* Set the connection name to execute statements against.
*
* @return $this
*/
public function setConnection(string $connection);
public function setConnection(string $connection): self;
/**
* Return the connection to execute statements against.
@ -23,12 +20,12 @@ interface DatabaseRepositoryInterface extends RepositoryInterface
public function getConnection(): string;
/**
* Return all of the databases belonging to a server.
* Return all the databases belonging to a server.
*/
public function getDatabasesForServer(int $server): Collection;
/**
* Return all of the databases for a given host with the server relationship loaded.
* Return all the databases for a given host with the server relationship loaded.
*/
public function getDatabasesForHost(int $host, int $count = 25): LengthAwarePaginator;
@ -39,10 +36,8 @@ interface DatabaseRepositoryInterface extends RepositoryInterface
/**
* Create a new database user on a given connection.
*
* @param $max_connections
*/
public function createUser(string $username, string $remote, string $password, string $max_connections): bool;
public function createUser(string $username, string $remote, string $password, ?int $max_connections): bool;
/**
* Give a specific user access to a given database.
@ -61,8 +56,6 @@ interface DatabaseRepositoryInterface extends RepositoryInterface
/**
* Drop a given user on a specific connection.
*
* @return mixed
*/
public function dropUser(string $username, string $remote): bool;
}

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Contracts\Repository;
@ -28,13 +21,11 @@ interface EggRepositoryInterface extends RepositoryInterface
/**
* Return an egg with the scriptFrom and configFrom relations loaded onto the model.
*
* @param int|string $value
*/
public function getWithCopyAttributes($value, string $column = 'id'): Egg;
public function getWithCopyAttributes(int|string $value, string $column = 'id'): Egg;
/**
* Return all of the data needed to export a service.
* Return all the data needed to export a service.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Contracts\Repository;

View File

@ -13,14 +13,12 @@ interface LocationRepositoryInterface extends RepositoryInterface
public function getAllWithDetails(): Collection;
/**
* Return all of the available locations with the nodes as a relationship.
* Return all the available locations with the nodes as a relationship.
*/
public function getAllWithNodes(): Collection;
/**
* Return all of the nodes and their respective count of servers for a location.
*
* @return mixed
* Return all the nodes and their respective count of servers for a location.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
@ -29,8 +27,6 @@ interface LocationRepositoryInterface extends RepositoryInterface
/**
* Return a location and the count of nodes in that location.
*
* @return mixed
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithNodeCount(int $id): Location;

View File

@ -1,37 +1,25 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Contracts\Repository;
use Pterodactyl\Models\Nest;
use Illuminate\Database\Eloquent\Collection;
interface NestRepositoryInterface extends RepositoryInterface
{
/**
* Return a nest or all nests with their associated eggs and variables.
*
* @param int $id
*
* @return \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Nest
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithEggs(int $id = null);
public function getWithEggs(int $id = null): Collection|Nest;
/**
* Return a nest or all nests and the count of eggs and servers for that nest.
*
* @return \Pterodactyl\Models\Nest|\Illuminate\Database\Eloquent\Collection
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithCounts(int $id = null);
public function getWithCounts(int $id = null): Collection|Nest;
/**
* Return a nest along with its associated eggs and the servers relation on those eggs.

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Contracts\Repository;

View File

@ -3,87 +3,67 @@
namespace Pterodactyl\Contracts\Repository;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
interface RepositoryInterface
{
/**
* Return an identifier or Model object to be used by the repository.
*
* @return string|\Closure|object
*/
public function model();
public function model(): string;
/**
* Return the model being used for this repository instance.
*
* @return mixed
*/
public function getModel();
public function getModel(): Model;
/**
* Returns an instance of a query builder.
*
* @return mixed
*/
public function getBuilder();
public function getBuilder(): Builder;
/**
* Returns the columns to be selected or returned by the query.
*
* @return mixed
*/
public function getColumns();
public function getColumns(): array;
/**
* An array of columns to filter the response by.
*
* @param array|string $columns
*
* @return $this
*/
public function setColumns($columns = ['*']);
public function setColumns(array|string $columns = ['*']): self;
/**
* Stop repository update functions from returning a fresh
* model when changes are committed.
*
* @return $this
*/
public function withoutFreshModel();
public function withoutFreshModel(): self;
/**
* Return a fresh model with a repository updates a model.
*
* @return $this
*/
public function withFreshModel();
public function withFreshModel(): self;
/**
* Set whether or not the repository should return a fresh model
* Set whether the repository should return a fresh model
* when changes are committed.
*
* @return $this
*/
public function setFreshModel(bool $fresh = true);
public function setFreshModel(bool $fresh = true): self;
/**
* Create a new model instance and persist it to the database.
*
* @return mixed
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function create(array $fields, bool $validate = true, bool $force = false);
public function create(array $fields, bool $validate = true, bool $force = false): mixed;
/**
* Find a model that has the specific ID passed.
*
* @return mixed
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function find(int $id);
public function find(int $id): mixed;
/**
* Find a model matching an array of where clauses.
@ -93,11 +73,9 @@ interface RepositoryInterface
/**
* Find and return the first matching instance for the given fields.
*
* @return mixed
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function findFirstWhere(array $fields);
public function findFirstWhere(array $fields): mixed;
/**
* Return a count of records matching the passed arguments.
@ -117,14 +95,10 @@ interface RepositoryInterface
/**
* Update a given ID with the passed array of fields.
*
* @param int $id
*
* @return mixed
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function update($id, array $fields, bool $validate = true, bool $force = false);
public function update(int $id, array $fields, bool $validate = true, bool $force = false): mixed;
/**
* Perform a mass update where matching records are updated using whereIn.
@ -135,11 +109,9 @@ interface RepositoryInterface
/**
* Update a record if it exists in the database, otherwise create it.
*
* @return mixed
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function updateOrCreate(array $where, array $fields, bool $validate = true, bool $force = false);
public function updateOrCreate(array $where, array $fields, bool $validate = true, bool $force = false): mixed;
/**
* Return all records associated with the given model.

View File

@ -8,12 +8,12 @@ use Illuminate\Support\Collection;
interface ScheduleRepositoryInterface extends RepositoryInterface
{
/**
* Return all of the schedules for a given server.
* Return all the schedules for a given server.
*/
public function findServerSchedules(int $server): Collection;
/**
* Return a schedule model with all of the associated tasks as a relationship.
* Return a schedule model with all the associated tasks as a relationship.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/

View File

@ -67,7 +67,7 @@ interface ServerRepositoryInterface extends RepositoryInterface
public function isUniqueUuidCombo(string $uuid, string $short): bool;
/**
* Returns all of the servers that exist for a given node in a paginated response.
* Returns all the servers that exist for a given node in a paginated response.
*/
public function loadAllServersForNode(int $node, int $limit): LengthAwarePaginator;
}

View File

@ -7,14 +7,12 @@ use Illuminate\Support\Collection;
interface SessionRepositoryInterface extends RepositoryInterface
{
/**
* Return all of the active sessions for a user.
* Return all the active sessions for a user.
*/
public function getUserSessions(int $user): Collection;
/**
* Delete a session for a given user.
*
* @return int|null
*/
public function deleteUserSession(int $user, string $session);
public function deleteUserSession(int $user, string $session): ?int;
}

View File

@ -14,12 +14,8 @@ interface SettingsRepositoryInterface extends RepositoryInterface
/**
* Retrieve a persistent setting from the database.
*
* @param mixed $default
*
* @return mixed
*/
public function get(string $key, $default);
public function get(string $key, mixed $default): mixed;
/**
* Remove a key from the database cache.

View File

@ -15,8 +15,6 @@ interface TaskRepositoryInterface extends RepositoryInterface
/**
* Returns the next task in a schedule.
*
* @return \Pterodactyl\Models\Task|null
*/
public function getNextTask(int $schedule, int $index);
public function getNextTask(int $schedule, int $index): ?Task;
}

View File

@ -8,11 +8,8 @@ use Illuminate\Database\Eloquent\Model;
class ActivityLogged extends Event
{
public ActivityLog $model;
public function __construct(ActivityLog $model)
public function __construct(public ActivityLog $model)
{
$this->model = $model;
}
public function is(string $event): bool
@ -25,12 +22,12 @@ class ActivityLogged extends Event
return $this->isSystem() ? null : $this->model->actor;
}
public function isServerEvent()
public function isServerEvent(): bool
{
return Str::startsWith($this->model->event, 'server:');
}
public function isSystem()
public function isSystem(): bool
{
return is_null($this->model->actor_id);
}

View File

@ -0,0 +1,13 @@
<?php
namespace Pterodactyl\Events\Auth;
use Pterodactyl\Models\User;
use Pterodactyl\Events\Event;
class DirectLogin extends Event
{
public function __construct(public User $user, public bool $remember)
{
}
}

View File

@ -1,43 +1,18 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Auth;
use Pterodactyl\Events\Event;
use Illuminate\Queue\SerializesModels;
class FailedCaptcha
class FailedCaptcha extends Event
{
use SerializesModels;
/**
* The IP that the request originated from.
*
* @var string
*/
public $ip;
/**
* The domain that was used to try to verify the request with recaptcha api.
*
* @var string
*/
public $domain;
/**
* Create a new event instance.
*
* @param string $ip
* @param string $domain
*/
public function __construct($ip, $domain)
public function __construct(public string $ip, public string $domain)
{
$this->ip = $ip;
$this->domain = $domain;
}
}

View File

@ -1,43 +1,18 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Auth;
use Pterodactyl\Events\Event;
use Illuminate\Queue\SerializesModels;
class FailedPasswordReset
class FailedPasswordReset extends Event
{
use SerializesModels;
/**
* The IP that the request originated from.
*
* @var string
*/
public $ip;
/**
* The email address that was used when the reset request failed.
*
* @var string
*/
public $email;
/**
* Create a new event instance.
*
* @param string $ip
* @param string $email
*/
public function __construct($ip, $email)
public function __construct(public string $ip, public string $email)
{
$this->ip = $ip;
$this->email = $email;
}
}

View File

@ -3,16 +3,11 @@
namespace Pterodactyl\Events\Auth;
use Pterodactyl\Models\User;
use Pterodactyl\Events\Event;
class ProvidedAuthenticationToken
class ProvidedAuthenticationToken extends Event
{
public User $user;
public bool $recovery;
public function __construct(User $user, bool $recovery = false)
public function __construct(public User $user, public bool $recovery = false)
{
$this->user = $user;
$this->recovery = $recovery;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Server;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Server;
use Illuminate\Queue\SerializesModels;
class Created
class Created extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Server
*/
public $server;
/**
* Create a new event instance.
*/
public function __construct(Server $server)
public function __construct(public Server $server)
{
$this->server = $server;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Server;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Server;
use Illuminate\Queue\SerializesModels;
class Creating
class Creating extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Server
*/
public $server;
/**
* Create a new event instance.
*/
public function __construct(Server $server)
public function __construct(public Server $server)
{
$this->server = $server;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Server;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Server;
use Illuminate\Queue\SerializesModels;
class Deleted
class Deleted extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Server
*/
public $server;
/**
* Create a new event instance.
*/
public function __construct(Server $server)
public function __construct(public Server $server)
{
$this->server = $server;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Server;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Server;
use Illuminate\Queue\SerializesModels;
class Deleting
class Deleting extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Server
*/
public $server;
/**
* Create a new event instance.
*/
public function __construct(Server $server)
public function __construct(public Server $server)
{
$this->server = $server;
}
}

View File

@ -10,18 +10,10 @@ class Installed extends Event
{
use SerializesModels;
/**
* @var \Pterodactyl\Models\Server
*/
public $server;
/**
* Create a new event instance.
*
* @var \Pterodactyl\Models\Server
*/
public function __construct(Server $server)
public function __construct(public Server $server)
{
$this->server = $server;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Server;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Server;
use Illuminate\Queue\SerializesModels;
class Saved
class Saved extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Server
*/
public $server;
/**
* Create a new event instance.
*/
public function __construct(Server $server)
public function __construct(public Server $server)
{
$this->server = $server;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Server;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Server;
use Illuminate\Queue\SerializesModels;
class Saving
class Saving extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Server
*/
public $server;
/**
* Create a new event instance.
*/
public function __construct(Server $server)
public function __construct(public Server $server)
{
$this->server = $server;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Server;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Server;
use Illuminate\Queue\SerializesModels;
class Updated
class Updated extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Server
*/
public $server;
/**
* Create a new event instance.
*/
public function __construct(Server $server)
public function __construct(public Server $server)
{
$this->server = $server;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Server;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Server;
use Illuminate\Queue\SerializesModels;
class Updating
class Updating extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Server
*/
public $server;
/**
* Create a new event instance.
*/
public function __construct(Server $server)
public function __construct(public Server $server)
{
$this->server = $server;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Subuser;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Subuser;
use Illuminate\Queue\SerializesModels;
class Created
class Created extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Subuser
*/
public $subuser;
/**
* Create a new event instance.
*/
public function __construct(Subuser $subuser)
public function __construct(public Subuser $subuser)
{
$this->subuser = $subuser;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Subuser;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Subuser;
use Illuminate\Queue\SerializesModels;
class Creating
class Creating extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Subuser
*/
public $subuser;
/**
* Create a new event instance.
*/
public function __construct(Subuser $subuser)
public function __construct(public Subuser $subuser)
{
$this->subuser = $subuser;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Subuser;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Subuser;
use Illuminate\Queue\SerializesModels;
class Deleted
class Deleted extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Subuser
*/
public $subuser;
/**
* Create a new event instance.
*/
public function __construct(Subuser $subuser)
public function __construct(public Subuser $subuser)
{
$this->subuser = $subuser;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\Subuser;
use Pterodactyl\Events\Event;
use Pterodactyl\Models\Subuser;
use Illuminate\Queue\SerializesModels;
class Deleting
class Deleting extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\Subuser
*/
public $subuser;
/**
* Create a new event instance.
*/
public function __construct(Subuser $subuser)
public function __construct(public Subuser $subuser)
{
$this->subuser = $subuser;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\User;
use Pterodactyl\Models\User;
use Pterodactyl\Events\Event;
use Illuminate\Queue\SerializesModels;
class Created
class Created extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\User
*/
public $user;
/**
* Create a new event instance.
*/
public function __construct(User $user)
public function __construct(public User $user)
{
$this->user = $user;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\User;
use Pterodactyl\Models\User;
use Pterodactyl\Events\Event;
use Illuminate\Queue\SerializesModels;
class Creating
class Creating extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\User
*/
public $user;
/**
* Create a new event instance.
*/
public function __construct(User $user)
public function __construct(public User $user)
{
$this->user = $user;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\User;
use Pterodactyl\Models\User;
use Pterodactyl\Events\Event;
use Illuminate\Queue\SerializesModels;
class Deleted
class Deleted extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\User
*/
public $user;
/**
* Create a new event instance.
*/
public function __construct(User $user)
public function __construct(public User $user)
{
$this->user = $user;
}
}

View File

@ -1,33 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Events\User;
use Pterodactyl\Models\User;
use Pterodactyl\Events\Event;
use Illuminate\Queue\SerializesModels;
class Deleting
class Deleting extends Event
{
use SerializesModels;
/**
* The Eloquent model of the server.
*
* @var \Pterodactyl\Models\User
*/
public $user;
/**
* Create a new event instance.
*/
public function __construct(User $user)
public function __construct(public User $user)
{
$this->user = $user;
}
}

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions;

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions;

View File

@ -4,9 +4,12 @@ namespace Pterodactyl\Exceptions;
use Exception;
use Throwable;
use Illuminate\Http\Request;
use Psr\Log\LoggerInterface;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Illuminate\Container\Container;
use Illuminate\Http\RedirectResponse;
use Prologue\Alerts\AlertsMessageBag;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
@ -18,44 +21,24 @@ class DisplayException extends PterodactylException implements HttpExceptionInte
public const LEVEL_ERROR = 'error';
/**
* @var string
* DisplayException constructor.
*/
protected $level;
/**
* Exception constructor.
*
* @param string $message
* @param string $level
* @param int $code
*/
public function __construct($message, Throwable $previous = null, $level = self::LEVEL_ERROR, $code = 0)
public function __construct(string $message, ?Throwable $previous = null, protected string $level = self::LEVEL_ERROR, int $code = 0)
{
parent::__construct($message, $code, $previous);
$this->level = $level;
}
/**
* @return string
*/
public function getErrorLevel()
public function getErrorLevel(): string
{
return $this->level;
}
/**
* @return int
*/
public function getStatusCode()
public function getStatusCode(): int
{
return Response::HTTP_BAD_REQUEST;
}
/**
* @return array
*/
public function getHeaders()
public function getHeaders(): array
{
return [];
}
@ -64,12 +47,8 @@ class DisplayException extends PterodactylException implements HttpExceptionInte
* Render the exception to the user by adding a flashed message to the session
* and then redirecting them back to the page that they came from. If the
* request originated from an API hit, return the error in JSONAPI spec format.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
*/
public function render($request)
public function render(Request $request): JsonResponse|RedirectResponse
{
if ($request->expectsJson()) {
return response()->json(Handler::toArray($this), $this->getStatusCode(), $this->getHeaders());
@ -84,9 +63,7 @@ class DisplayException extends PterodactylException implements HttpExceptionInte
* Log the exception to the logs using the defined error level only if the previous
* exception is set.
*
* @return mixed
*
* @throws \Exception
* @throws \Throwable
*/
public function report()
{
@ -96,7 +73,7 @@ class DisplayException extends PterodactylException implements HttpExceptionInte
try {
$logger = Container::getInstance()->make(LoggerInterface::class);
} catch (Exception $ex) {
} catch (Exception) {
throw $this->getPrevious();
}

View File

@ -7,18 +7,20 @@ use Throwable;
use PDOException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Swift_TransportException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Illuminate\Container\Container;
use Illuminate\Database\Connection;
use Illuminate\Http\RedirectResponse;
use Illuminate\Foundation\Application;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Mailer\Exception\TransportException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
@ -26,7 +28,7 @@ use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
class Handler extends ExceptionHandler
{
/**
* Laravel's validation parser formats custom rules using the class name
* The validation parser in Laravel formats custom rules using the class name
* resulting in some weird rule names. This string will be parsed out and
* replaced with 'p_' in the response code.
*/
@ -34,8 +36,6 @@ class Handler extends ExceptionHandler
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
AuthenticationException::class,
@ -50,8 +50,6 @@ class Handler extends ExceptionHandler
/**
* Maps exceptions to a specific response code. This handles special exception
* types that don't have a defined response code.
*
* @var array<string, int>
*/
protected static array $exceptionResponseCodes = [
AuthenticationException::class => 401,
@ -61,8 +59,6 @@ class Handler extends ExceptionHandler
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'token',
@ -89,7 +85,7 @@ class Handler extends ExceptionHandler
$ex = $this->generateCleanedExceptionStack($ex);
});
$this->reportable(function (Swift_TransportException $ex) {
$this->reportable(function (TransportException $ex) {
$ex = $this->generateCleanedExceptionStack($ex);
});
}
@ -125,11 +121,9 @@ class Handler extends ExceptionHandler
*
* @param \Illuminate\Http\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
public function render($request, Throwable $e): Response
{
$connections = $this->container->make(Connection::class);
@ -146,7 +140,7 @@ class Handler extends ExceptionHandler
$connections->rollBack(0);
}
return parent::render($request, $exception);
return parent::render($request, $e);
}
/**
@ -154,10 +148,8 @@ class Handler extends ExceptionHandler
* calls to the API.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function invalidJson($request, ValidationException $exception)
public function invalidJson($request, ValidationException $exception): JsonResponse
{
$codes = Collection::make($exception->validator->failed())->mapWithKeys(function ($reasons, $field) {
$cleaned = [];
@ -197,21 +189,21 @@ class Handler extends ExceptionHandler
/**
* Return the exception as a JSONAPI representation for use on API requests.
*/
protected function convertExceptionToArray(Throwable $exception, array $override = []): array
protected function convertExceptionToArray(Throwable $e, array $override = []): array
{
$match = self::$exceptionResponseCodes[get_class($exception)] ?? null;
$match = self::$exceptionResponseCodes[get_class($e)] ?? null;
$error = [
'code' => class_basename($exception),
'status' => method_exists($exception, 'getStatusCode')
? strval($exception->getStatusCode())
'code' => class_basename($e),
'status' => method_exists($e, 'getStatusCode')
? strval($e->getStatusCode())
: strval($match ?? '500'),
'detail' => $exception instanceof HttpExceptionInterface || !is_null($match)
? $exception->getMessage()
'detail' => $e instanceof HttpExceptionInterface || !is_null($match)
? $e->getMessage()
: 'An unexpected error was encountered while processing this request, please try again.',
];
if ($exception instanceof ModelNotFoundException || $exception->getPrevious() instanceof ModelNotFoundException) {
if ($e instanceof ModelNotFoundException || $e->getPrevious() instanceof ModelNotFoundException) {
// Show a nicer error message compared to the standard "No query results for model"
// response that is normally returned. If we are in debug mode this will get overwritten
// with a more specific error message to help narrow down things.
@ -220,17 +212,17 @@ class Handler extends ExceptionHandler
if (config('app.debug')) {
$error = array_merge($error, [
'detail' => $exception->getMessage(),
'detail' => $e->getMessage(),
'source' => [
'line' => $exception->getLine(),
'file' => str_replace(Application::getInstance()->basePath(), '', $exception->getFile()),
'line' => $e->getLine(),
'file' => str_replace(Application::getInstance()->basePath(), '', $e->getFile()),
],
'meta' => [
'trace' => Collection::make($exception->getTrace())
'trace' => Collection::make($e->getTrace())
->map(fn ($trace) => Arr::except($trace, ['args']))
->all(),
'previous' => Collection::make($this->extractPrevious($exception))
->map(fn ($exception) => $exception->getTrace())
'previous' => Collection::make($this->extractPrevious($e))
->map(fn ($exception) => $e->getTrace())
->map(fn ($trace) => Arr::except($trace, ['args']))
->all(),
],
@ -252,10 +244,8 @@ class Handler extends ExceptionHandler
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
*/
protected function unauthenticated($request, AuthenticationException $exception)
protected function unauthenticated($request, AuthenticationException $exception): JsonResponse|RedirectResponse
{
if ($request->expectsJson()) {
return new JsonResponse($this->convertExceptionToArray($exception), JsonResponse::HTTP_UNAUTHORIZED);
@ -265,7 +255,7 @@ class Handler extends ExceptionHandler
}
/**
* Extracts all of the previous exceptions that lead to the one passed into this
* Extracts all the previous exceptions that lead to the one passed into this
* function being thrown.
*
* @return \Throwable[]

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Http\Base;

View File

@ -12,20 +12,15 @@ use Pterodactyl\Exceptions\DisplayException;
*/
class DaemonConnectionException extends DisplayException
{
/**
* @var int
*/
private $statusCode = Response::HTTP_GATEWAY_TIMEOUT;
private int $statusCode = Response::HTTP_GATEWAY_TIMEOUT;
/**
* Every request to the Wings instance will return a unique X-Request-Id header
* which allows for all errors to be efficiently tied to a specific request that
* triggered them, and gives users a more direct method of informing hosts when
* something goes wrong.
*
* @var string|null
*/
private $requestId;
private ?string $requestId;
/**
* Throw a displayable exception caused by a daemon connection error.
@ -34,7 +29,7 @@ class DaemonConnectionException extends DisplayException
{
/** @var \GuzzleHttp\Psr7\Response|null $response */
$response = method_exists($previous, 'getResponse') ? $previous->getResponse() : null;
$this->requestId = $response ? $response->getHeaderLine('X-Request-Id') : null;
$this->requestId = $response?->getHeaderLine('X-Request-Id');
if ($useStatusCode) {
$this->statusCode = is_null($response) ? $this->statusCode : $response->getStatusCode();
@ -72,8 +67,6 @@ class DaemonConnectionException extends DisplayException
/**
* Override the default reporting method for DisplayException by just logging immediately
* here and including the specific X-Request-Id header that was returned by the call.
*
* @return void
*/
public function report()
{
@ -84,18 +77,13 @@ class DaemonConnectionException extends DisplayException
/**
* Return the HTTP status code for this exception.
*
* @return int
*/
public function getStatusCode()
public function getStatusCode(): int
{
return $this->statusCode;
}
/**
* @return string|null
*/
public function getRequestId()
public function getRequestId(): ?string
{
return $this->requestId;
}

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Http\Server;

View File

@ -2,6 +2,7 @@
namespace Pterodactyl\Exceptions\Model;
use Illuminate\Support\MessageBag;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Validation\Validator;
use Pterodactyl\Exceptions\PterodactylException;
@ -10,20 +11,10 @@ use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
class DataValidationException extends PterodactylException implements HttpExceptionInterface, MessageProvider
{
/**
* The validator instance.
*/
protected Validator $validator;
/**
* The underlying model instance that triggered this exception.
*/
protected Model $model;
/**
* DataValidationException constructor.
*/
public function __construct(Validator $validator, Model $model)
public function __construct(protected Validator $validator, protected Model $model)
{
$message = sprintf(
'Could not save %s[%s]: failed to validate data: %s',
@ -33,35 +24,25 @@ class DataValidationException extends PterodactylException implements HttpExcept
);
parent::__construct($message);
$this->validator = $validator;
$this->model = $model;
}
/**
* Return the validator message bag.
*
* @return \Illuminate\Support\MessageBag
*/
public function getMessageBag()
public function getMessageBag(): MessageBag
{
return $this->validator->errors();
}
/**
* Return the status code for this request.
*
* @return int
*/
public function getStatusCode()
public function getStatusCode(): int
{
return 500;
}
/**
* @return array
*/
public function getHeaders()
public function getHeaders(): array
{
return [];
}

View File

@ -9,20 +9,16 @@ class RecordNotFoundException extends RepositoryException implements HttpExcepti
{
/**
* Returns the status code.
*
* @return int
*/
public function getStatusCode()
public function getStatusCode(): int
{
return Response::HTTP_NOT_FOUND;
}
/**
* Returns response headers.
*
* @return array
*/
public function getHeaders()
public function getHeaders(): array
{
return [];
}

View File

@ -8,10 +8,8 @@ class InvalidPortMappingException extends DisplayException
{
/**
* InvalidPortMappingException constructor.
*
* @param mixed $port
*/
public function __construct($port)
public function __construct(mixed $port)
{
parent::__construct(trans('exceptions.allocations.invalid_mapping', ['port' => $port]));
}

View File

@ -1,11 +1,4 @@
<?php
/*
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Service\Egg;

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Service\Egg;

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Service\Egg;

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Service\Egg\Variable;

View File

@ -7,10 +7,7 @@ use Pterodactyl\Exceptions\DisplayException;
class HasActiveServersException extends DisplayException
{
/**
* @return int
*/
public function getStatusCode()
public function getStatusCode(): int
{
return Response::HTTP_BAD_REQUEST;
}

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Service\Helper;

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Service;

View File

@ -7,10 +7,7 @@ use Pterodactyl\Exceptions\DisplayException;
class HasActiveNodesException extends DisplayException
{
/**
* @return int
*/
public function getStatusCode()
public function getStatusCode(): int
{
return Response::HTTP_BAD_REQUEST;
}

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Service\Schedule\Task;

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Service\Server;

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Service\Subuser;

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Service\Subuser;

View File

@ -9,64 +9,45 @@ use Illuminate\Support\Str;
use Webmozart\Assert\Assert;
use InvalidArgumentException;
use Illuminate\Foundation\Application;
use League\Flysystem\AdapterInterface;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Memory\MemoryAdapter;
use Illuminate\Contracts\Config\Repository;
use League\Flysystem\FilesystemAdapter;
use Pterodactyl\Extensions\Filesystem\S3Filesystem;
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
class BackupManager
{
/**
* @var \Illuminate\Foundation\Application
*/
protected $app;
/**
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
protected ConfigRepository $config;
/**
* The array of resolved backup drivers.
*
* @var \League\Flysystem\AdapterInterface[]
*/
protected $adapters = [];
protected array $adapters = [];
/**
* The registered custom driver creators.
*
* @var array
*/
protected $customCreators;
protected array $customCreators;
/**
* BackupManager constructor.
*/
public function __construct(Application $app)
public function __construct(protected Application $app)
{
$this->app = $app;
$this->config = $app->make(Repository::class);
$this->config = $app->make(ConfigRepository::class);
}
/**
* Returns a backup adapter instance.
*
* @return \League\Flysystem\AdapterInterface
*/
public function adapter(string $name = null)
public function adapter(string $name = null): FilesystemAdapter
{
return $this->get($name ?: $this->getDefaultAdapter());
}
/**
* Set the given backup adapter instance.
*
* @param \League\Flysystem\AdapterInterface $disk
*
* @return $this
*/
public function set(string $name, $disk)
public function set(string $name, FilesystemAdapter $disk): self
{
$this->adapters[$name] = $disk;
@ -75,25 +56,21 @@ class BackupManager
/**
* Gets a backup adapter.
*
* @return \League\Flysystem\AdapterInterface
*/
protected function get(string $name)
protected function get(string $name): FilesystemAdapter
{
return $this->adapters[$name] = $this->resolve($name);
}
/**
* Resolve the given backup disk.
*
* @return \League\Flysystem\AdapterInterface
*/
protected function resolve(string $name)
protected function resolve(string $name): FilesystemAdapter
{
$config = $this->getConfig($name);
if (empty($config['adapter'])) {
throw new InvalidArgumentException("Backup disk [{$name}] does not have a configured adapter.");
throw new InvalidArgumentException("Backup disk [$name] does not have a configured adapter.");
}
$adapter = $config['adapter'];
@ -106,44 +83,34 @@ class BackupManager
if (method_exists($this, $adapterMethod)) {
$instance = $this->{$adapterMethod}($config);
Assert::isInstanceOf($instance, AdapterInterface::class);
Assert::isInstanceOf($instance, FilesystemAdapter::class);
return $instance;
}
throw new InvalidArgumentException("Adapter [{$adapter}] is not supported.");
throw new InvalidArgumentException("Adapter [$adapter] is not supported.");
}
/**
* Calls a custom creator for a given adapter type.
*
* @return \League\Flysystem\AdapterInterface
*/
protected function callCustomCreator(array $config)
protected function callCustomCreator(array $config): mixed
{
$adapter = $this->customCreators[$config['adapter']]($this->app, $config);
Assert::isInstanceOf($adapter, AdapterInterface::class);
return $adapter;
return $this->customCreators[$config['adapter']]($this->app, $config);
}
/**
* Creates a new wings adapter.
*
* @return \League\Flysystem\AdapterInterface
* Creates a new Wings adapter.
*/
public function createWingsAdapter(array $config)
public function createWingsAdapter(array $config): FilesystemAdapter
{
return new MemoryAdapter(null);
return new InMemoryFilesystemAdapter(null);
}
/**
* Creates a new S3 adapter.
*
* @return \League\Flysystem\AdapterInterface
*/
public function createS3Adapter(array $config)
public function createS3Adapter(array $config): FilesystemAdapter
{
$config['version'] = 'latest';
@ -153,25 +120,21 @@ class BackupManager
$client = new S3Client($config);
return new AwsS3Adapter($client, $config['bucket'], $config['prefix'] ?? '', $config['options'] ?? []);
return new S3Filesystem($client, $config['bucket'], $config['prefix'] ?? '', $config['options'] ?? []);
}
/**
* Returns the configuration associated with a given backup type.
*
* @return array
*/
protected function getConfig(string $name)
protected function getConfig(string $name): array
{
return $this->config->get("backups.disks.{$name}") ?: [];
return $this->config->get("backups.disks.$name") ?: [];
}
/**
* Get the default backup driver name.
*
* @return string
*/
public function getDefaultAdapter()
public function getDefaultAdapter(): string
{
return $this->config->get('backups.default');
}
@ -179,7 +142,7 @@ class BackupManager
/**
* Set the default session driver name.
*/
public function setDefaultAdapter(string $name)
public function setDefaultAdapter(string $name): void
{
$this->config->set('backups.default', $name);
}
@ -188,13 +151,11 @@ class BackupManager
* Unset the given adapter instances.
*
* @param string|string[] $adapter
*
* @return $this
*/
public function forget($adapter)
public function forget(array|string $adapter): self
{
foreach ((array) $adapter as $adapterName) {
unset($this->adapters[$adapter]);
unset($this->adapters[$adapterName]);
}
return $this;
@ -202,10 +163,8 @@ class BackupManager
/**
* Register a custom adapter creator closure.
*
* @return $this
*/
public function extend(string $adapter, Closure $callback)
public function extend(string $adapter, Closure $callback): self
{
$this->customCreators[$adapter] = $callback;

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Extensions;
@ -20,44 +13,22 @@ class DynamicDatabaseConnection
public const DB_COLLATION = 'utf8_unicode_ci';
public const DB_DRIVER = 'mysql';
/**
* @var \Illuminate\Config\Repository
*/
protected $config;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
protected $encrypter;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
*/
protected $repository;
/**
* DynamicDatabaseConnection constructor.
*/
public function __construct(
ConfigRepository $config,
DatabaseHostRepositoryInterface $repository,
Encrypter $encrypter
protected ConfigRepository $config,
protected Encrypter $encrypter,
protected DatabaseHostRepositoryInterface $repository
) {
$this->config = $config;
$this->encrypter = $encrypter;
$this->repository = $repository;
}
/**
* Adds a dynamic database connection entry to the runtime config.
*
* @param string $connection
* @param \Pterodactyl\Models\DatabaseHost|int $host
* @param string $database
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function set($connection, $host, $database = 'mysql')
public function set(string $connection, DatabaseHost|int $host, string $database = 'mysql'): void
{
if (!$host instanceof DatabaseHost) {
$host = $this->repository->find($host);

View File

@ -6,10 +6,7 @@ use Illuminate\Support\Facades\Facade;
class Theme extends Facade
{
/**
* @return string
*/
protected static function getFacadeAccessor()
protected static function getFacadeAccessor(): string
{
return 'extensions.themes';
}

View File

@ -0,0 +1,35 @@
<?php
namespace Pterodactyl\Extensions\Filesystem;
use Aws\S3\S3ClientInterface;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
class S3Filesystem extends AwsS3V3Adapter
{
public function __construct(
private S3ClientInterface $client,
private string $bucket,
string $prefix = '',
array $options = [],
) {
parent::__construct(
$client,
$bucket,
$prefix,
null,
null,
$options,
);
}
public function getClient(): S3ClientInterface
{
return $this->client;
}
public function getBucket(): string
{
return $this->bucket;
}
}

View File

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Extensions;
@ -17,7 +10,7 @@ class Hashids extends VendorHashids implements HashidsInterface
/**
* {@inheritdoc}
*/
public function decodeFirst($encoded, $default = null)
public function decodeFirst(string $encoded, string $default = null): mixed
{
$result = $this->decode($encoded);
if (!is_array($result)) {

View File

@ -8,10 +8,8 @@ class Builder extends EloquentBuilder
{
/**
* Do nothing.
*
* @return $this
*/
public function search()
public function search(): self
{
return $this;
}

View File

@ -2,6 +2,7 @@
namespace Pterodactyl\Extensions\Spatie\Fractalistic;
use League\Fractal\Scope;
use League\Fractal\TransformerAbstract;
use Spatie\Fractal\Fractal as SpatieFractal;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
@ -13,12 +14,10 @@ class Fractal extends SpatieFractal
/**
* Create fractal data.
*
* @return \League\Fractal\Scope
*
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
*/
public function createData()
public function createData(): Scope
{
// Set the serializer by default.
if (is_null($this->serializer)) {

View File

@ -4,17 +4,17 @@ namespace Pterodactyl\Extensions\Themes;
class Theme
{
public function js($path)
public function js($path): string
{
return sprintf('<script src="%s"></script>' . PHP_EOL, $this->getUrl($path));
}
public function css($path)
public function css($path): string
{
return sprintf('<link media="all" type="text/css" rel="stylesheet" href="%s"/>' . PHP_EOL, $this->getUrl($path));
}
protected function getUrl($path)
protected function getUrl($path): string
{
return '/themes/pterodactyl/' . ltrim($path, '/');
}

View File

@ -7,7 +7,7 @@ use Pterodactyl\Services\Activity\ActivityLogService;
class Activity extends Facade
{
protected static function getFacadeAccessor()
protected static function getFacadeAccessor(): string
{
return ActivityLogService::class;
}

Some files were not shown because too many files have changed in this diff Show More