mirror of
https://github.com/pyrohost/pyrodactyl.git
synced 2026-04-05 19:51:59 +02:00
Initial commit
This commit is contained in:
17
.editorconfig
Normal file
17
.editorconfig
Normal file
@@ -0,0 +1,17 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
tab_width = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{md,nix,yml,yaml}]
|
||||
indent_size = 2
|
||||
tab_width = 2
|
||||
6
.eslintignore
Normal file
6
.eslintignore
Normal file
@@ -0,0 +1,6 @@
|
||||
public
|
||||
node_modules
|
||||
resources/views
|
||||
babel.config.js
|
||||
tailwind.config.js
|
||||
webpack.config.js
|
||||
51
.eslintrc.js
Normal file
51
.eslintrc.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/** @type {import('eslint').Linter.Config} */
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
ecmaVersion: 6,
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
},
|
||||
project: './tsconfig.json',
|
||||
tsconfigRootDir: './',
|
||||
},
|
||||
settings: {
|
||||
react: {
|
||||
pragma: 'React',
|
||||
version: 'detect',
|
||||
},
|
||||
linkComponents: [
|
||||
{ name: 'Link', linkAttribute: 'to' },
|
||||
{ name: 'NavLink', linkAttribute: 'to' },
|
||||
],
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
es6: true,
|
||||
},
|
||||
plugins: ['react', 'react-hooks', 'prettier', '@typescript-eslint'],
|
||||
extends: [
|
||||
// 'standard',
|
||||
'eslint:recommended',
|
||||
'plugin:react/recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:jest-dom/recommended',
|
||||
],
|
||||
rules: {
|
||||
eqeqeq: 'error',
|
||||
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
|
||||
// TypeScript can infer this significantly better than eslint ever can.
|
||||
'react/prop-types': 0,
|
||||
'react/display-name': 0,
|
||||
'@typescript-eslint/no-explicit-any': 0,
|
||||
'@typescript-eslint/no-non-null-assertion': 0,
|
||||
// This setup is required to avoid a spam of errors when running eslint about React being
|
||||
// used before it is defined.
|
||||
//
|
||||
// @see https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md#how-to-use
|
||||
'no-use-before-define': 0,
|
||||
'@typescript-eslint/no-use-before-define': 'warn',
|
||||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
|
||||
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-expect-error': 'allow-with-description' }],
|
||||
},
|
||||
};
|
||||
36
.gitignore
vendored
Normal file
36
.gitignore
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/vendor
|
||||
*.DS_Store*
|
||||
!.env.ci
|
||||
!.env.example
|
||||
.env*
|
||||
.vagrant/*
|
||||
.vscode/*
|
||||
storage/framework/*
|
||||
/.idea
|
||||
/nbproject
|
||||
/.direnv
|
||||
|
||||
node_modules
|
||||
*.log
|
||||
_ide_helper.php
|
||||
_ide_helper_models.php
|
||||
.phpstorm.meta.php
|
||||
.yarn
|
||||
public/assets/manifest.json
|
||||
|
||||
# For local development with docker
|
||||
# Remove if we ever put the Dockerfile in the repo
|
||||
.dockerignore
|
||||
docker-compose.yml
|
||||
|
||||
# for image related files
|
||||
misc
|
||||
.php-cs-fixer.cache
|
||||
coverage.xml
|
||||
resources/lang/locales.js
|
||||
.phpunit.result.cache
|
||||
|
||||
/public/build
|
||||
/public/hot
|
||||
result
|
||||
docker-compose.yaml
|
||||
9
.prettierrc.json
Normal file
9
.prettierrc.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 4,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"jsxSingleQuote": true,
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
63
BUILDING.md
Normal file
63
BUILDING.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Local Development
|
||||
Pterodactyl is now powered by React, Typescript, and Tailwindcss using webpack at its core to generate compiled assets.
|
||||
Release versions of Pterodactyl will include pre-compiled, minified, and hashed assets ready-to-go.
|
||||
|
||||
However, if you are interested in running custom themes or making modifications to the React files you'll need a build
|
||||
system in place to generate these compiled assets. To get your environment setup you'll need at minimum:
|
||||
|
||||
* [Node.js](https://nodejs.org/en/) v14.x.x
|
||||
* [Yarn](https://classic.yarnpkg.com/lang/en/) v1.x.x
|
||||
* [Go](https://golang.org/) 1.17.x
|
||||
|
||||
### Install Dependencies
|
||||
```bash
|
||||
yarn install
|
||||
```
|
||||
|
||||
The command above will download all of the dependencies necessary to get Pterodactyl assets building. After that, its as
|
||||
simple as running the command below to generate assets while you're developing. Until you've run this command at least
|
||||
once you'll likely see a 500 error on your Panel about a missing `manifest.json` file. This is generated by the commands
|
||||
below.
|
||||
|
||||
```bash
|
||||
# Build the compiled set of assets for development.
|
||||
yarn run build
|
||||
|
||||
# Build the assets automatically as they are changed. This allows you to refresh
|
||||
# the page and see the changes immediately.
|
||||
yarn run watch
|
||||
```
|
||||
|
||||
### Hot Module Reloading
|
||||
For more advanced users, we also support 'Hot Module Reloading', allowing you to quickly see changes you're making
|
||||
to the Vue template files without having to reload the page you're on. To Get started with this, you just need
|
||||
to run the command below.
|
||||
|
||||
```bash
|
||||
PUBLIC_PATH=http://192.168.1.1:8080 yarn run serve --host 192.168.1.1
|
||||
```
|
||||
|
||||
There are two _very important_ parts of this command to take note of and change for your specific environment. The first
|
||||
is the `--host` flag, which is required and should point to the machine where the `webpack-serve` server will be running.
|
||||
The second is the `PUBLIC_PATH` environment variable which is the URL pointing to the HMR server and is appended to all of
|
||||
the asset URLs used in Pterodactyl.
|
||||
|
||||
#### Development Environment
|
||||
If you're using the [`pterodactyl/development`](https://github.com/pterodactyl/development) environments, which are
|
||||
highly recommended, you can just run `yarn run serve` to run the HMR server, no additional configuration is necessary.
|
||||
|
||||
### Building for Production
|
||||
Once you have your files squared away and ready for the live server, you'll be needing to generate compiled, minified,
|
||||
and hashed assets to push live. To do so, run the command below:
|
||||
|
||||
```bash
|
||||
yarn run build:production
|
||||
```
|
||||
|
||||
This will generate a production JS bundle and associated assets, all located in `public/assets/` which will need to
|
||||
be uploaded to your server or CDN for clients to use.
|
||||
|
||||
### Running Wings
|
||||
To run `wings` in development all you need to do is set up the configuration file as normal when adding a new node, and
|
||||
then you can build and run a local version of Wings by executing `make debug` in the Wings code directory. This must
|
||||
be run on a Linux VM of some sort, you cannot run this locally on macOS or Windows.
|
||||
1769
CHANGELOG.md
Normal file
1769
CHANGELOG.md
Normal file
File diff suppressed because it is too large
Load Diff
41
Dockerfile
Normal file
41
Dockerfile
Normal file
@@ -0,0 +1,41 @@
|
||||
# Stage 0:
|
||||
# Build the assets that are needed for the frontend. This build stage is then discarded
|
||||
# since we won't need NodeJS anymore in the future. This Docker image ships a final production
|
||||
# level distribution of Pterodactyl.
|
||||
FROM --platform=$TARGETOS/$TARGETARCH mhart/alpine-node:14
|
||||
WORKDIR /app
|
||||
COPY . ./
|
||||
RUN yarn install --frozen-lockfile \
|
||||
&& yarn run build:production
|
||||
|
||||
# Stage 1:
|
||||
# Build the actual container with all of the needed PHP dependencies that will run the application.
|
||||
FROM --platform=$TARGETOS/$TARGETARCH php:8.1-fpm-alpine
|
||||
WORKDIR /app
|
||||
COPY . ./
|
||||
COPY --from=0 /app/public/assets ./public/assets
|
||||
RUN apk add --no-cache --update ca-certificates dcron curl git supervisor tar unzip nginx libpng-dev libxml2-dev libzip-dev certbot certbot-nginx \
|
||||
&& docker-php-ext-configure zip \
|
||||
&& docker-php-ext-install bcmath gd pdo_mysql zip \
|
||||
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
|
||||
&& cp .env.example .env \
|
||||
&& mkdir -p bootstrap/cache/ storage/logs storage/framework/sessions storage/framework/views storage/framework/cache \
|
||||
&& chmod 777 -R bootstrap storage \
|
||||
&& composer install --no-dev --optimize-autoloader \
|
||||
&& rm -rf .env bootstrap/cache/*.php \
|
||||
&& mkdir -p /app/storage/logs/ \
|
||||
&& chown -R nginx:nginx .
|
||||
|
||||
RUN rm /usr/local/etc/php-fpm.conf \
|
||||
&& echo "* * * * * /usr/local/bin/php /app/artisan schedule:run >> /dev/null 2>&1" >> /var/spool/cron/crontabs/root \
|
||||
&& echo "0 23 * * * certbot renew --nginx --quiet" >> /var/spool/cron/crontabs/root \
|
||||
&& sed -i s/ssl_session_cache/#ssl_session_cache/g /etc/nginx/nginx.conf \
|
||||
&& mkdir -p /var/run/php /var/run/nginx
|
||||
|
||||
COPY .github/docker/default.conf /etc/nginx/http.d/default.conf
|
||||
COPY .github/docker/www.conf /usr/local/etc/php-fpm.conf
|
||||
COPY .github/docker/supervisord.conf /etc/supervisord.conf
|
||||
|
||||
EXPOSE 80 443
|
||||
ENTRYPOINT [ "/bin/ash", ".github/docker/entrypoint.sh" ]
|
||||
CMD [ "supervisord", "-n", "-c", "/etc/supervisord.conf" ]
|
||||
24
LICENSE.md
Normal file
24
LICENSE.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
```
|
||||
Pterodactyl®
|
||||
Copyright © Dane Everitt <dane@daneeveritt.com> and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
```
|
||||
75
README.md
Normal file
75
README.md
Normal file
@@ -0,0 +1,75 @@
|
||||
[](https://pterodactyl.io)
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
# Pterodactyl Panel
|
||||
|
||||
Pterodactyl® is a free, open-source game server management panel built with PHP, React, and Go. Designed with security
|
||||
in mind, Pterodactyl runs all game servers in isolated Docker containers while exposing a beautiful and intuitive
|
||||
UI to end users.
|
||||
|
||||
Stop settling for less. Make game servers a first class citizen on your platform.
|
||||
|
||||

|
||||
|
||||
## Documentation
|
||||
|
||||
* [Panel Documentation](https://pterodactyl.io/panel/1.0/getting_started.html)
|
||||
* [Wings Documentation](https://pterodactyl.io/wings/1.0/installing.html)
|
||||
* [Community Guides](https://pterodactyl.io/community/about.html)
|
||||
* Or, get additional help [via Discord](https://discord.gg/pterodactyl)
|
||||
|
||||
## Sponsors
|
||||
|
||||
I would like to extend my sincere thanks to the following sponsors for helping fund Pterodactyl's development.
|
||||
[Interested in becoming a sponsor?](https://github.com/sponsors/matthewpi)
|
||||
|
||||
| Company | About |
|
||||
|-----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| [**WISP**](https://wisp.gg) | Extra features. |
|
||||
| [**Aussie Server Hosts**](https://aussieserverhosts.com/) | No frills Australian Owned and operated High Performance Server hosting for some of the most demanding games serving Australia and New Zealand. |
|
||||
| [**WemX**](https://wemx.net/) | WemX helps automate your hosting company or SaaS business by automating billing, user management, authentication, and much more. |
|
||||
| [**BisectHosting**](https://www.bisecthosting.com/) | BisectHosting provides Minecraft, Valheim and other server hosting services with the highest reliability and lightning fast support since 2012. |
|
||||
| [**MineStrator**](https://minestrator.com/) | Looking for the most highend French hosting company for your minecraft server? More than 24,000 members on our discord trust us. Give us a try! |
|
||||
| [**VibeGAMES**](https://vibegames.net/) | VibeGAMES is a game server provider that specializes in DDOS protection for the games we offer. We have multiple locations in the US, Brazil, France, Germany, Singapore, Australia and South Africa. |
|
||||
| [**DutchIS**](https://dutchis.net?ref=pterodactyl) | DutchIS provides instant infrastructure such as pay per use VPS hosting. Start your game hosting journey on DutchIS. |
|
||||
| [**Skoali**](https://skoali.com/) | Skoali is a French company that hosts game servers and other types of services (VPS, WEB, Dedicated servers, ...). We also have a free plan for Minecraft and Garry's Mod. |
|
||||
| [**Rabbit Computing**](https://www.rabbitcomputing.com/link.php?id=5) | Rabbit Computing offers powerful VPS servers, highly available game hosting, and fully unlimited web hosting. Use code README for 20% off your first three months! |
|
||||
|
||||
### Supported Games
|
||||
|
||||
Pterodactyl supports a wide variety of games by utilizing Docker containers to isolate each instance. This gives
|
||||
you the power to run game servers without bloating machines with a host of additional dependencies.
|
||||
|
||||
Some of our core supported games include:
|
||||
|
||||
* Minecraft — including Paper, Sponge, Bungeecord, Waterfall, and more
|
||||
* Rust
|
||||
* Terraria
|
||||
* Teamspeak
|
||||
* Mumble
|
||||
* Team Fortress 2
|
||||
* Counter Strike: Global Offensive
|
||||
* Garry's Mod
|
||||
* ARK: Survival Evolved
|
||||
|
||||
In addition to our standard nest of supported games, our community is constantly pushing the limits of this software
|
||||
and there are plenty more games available provided by the community. Some of these games include:
|
||||
|
||||
* Factorio
|
||||
* San Andreas: MP
|
||||
* Pocketmine MP
|
||||
* Squad
|
||||
* Xonotic
|
||||
* Starmade
|
||||
* Discord ATLBot, and most other Node.js/Python discord bots
|
||||
* [and many more...](https://github.com/parkervcp/eggs)
|
||||
|
||||
## License
|
||||
|
||||
Pterodactyl® Copyright © 2015 - 2022 Dane Everitt and contributors.
|
||||
|
||||
Code released under the [MIT License](./LICENSE.md).
|
||||
20
SECURITY.md
Normal file
20
SECURITY.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
The following versions of Pterodactyl are receiving active support and maintenance. Any security vulnerabilities discovered must be reproducible in supported versions.
|
||||
|
||||
| Panel | Daemon | Supported |
|
||||
|--------|--------------|--------------------|
|
||||
| 1.10.x | wings@1.7.x | :white_check_mark: |
|
||||
| 1.11.x | wings@1.11.x | :white_check_mark: |
|
||||
| 0.7.x | daemon@0.6.x | :x: |
|
||||
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please reach out directly to any project team member on Discord when reporting a security vulnerability, or you can email `matthew@pterodactyl.io`.
|
||||
|
||||
We make every effort to respond as soon as possible, although it may take a day or two for us to sync internally and determine the severity of the report and its impact. Please, _do not_ use a public facing channel or GitHub issues to report sensitive security issues.
|
||||
|
||||
As part of our process, we will create a security advisory for the affected versions and disclose it publicly, usually two to four weeks after a releasing a version that addresses it.
|
||||
183
app/Console/Commands/Environment/AppSettingsCommand.php
Normal file
183
app/Console/Commands/Environment/AppSettingsCommand.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Environment;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
|
||||
|
||||
class AppSettingsCommand extends Command
|
||||
{
|
||||
use EnvironmentWriterTrait;
|
||||
|
||||
public const CACHE_DRIVERS = [
|
||||
'redis' => 'Redis (recommended)',
|
||||
'memcached' => 'Memcached',
|
||||
'file' => 'Filesystem',
|
||||
];
|
||||
|
||||
public const SESSION_DRIVERS = [
|
||||
'redis' => 'Redis (recommended)',
|
||||
'memcached' => 'Memcached',
|
||||
'database' => 'MySQL Database',
|
||||
'file' => 'Filesystem',
|
||||
'cookie' => 'Cookie',
|
||||
];
|
||||
|
||||
public const QUEUE_DRIVERS = [
|
||||
'redis' => 'Redis (recommended)',
|
||||
'database' => 'MySQL Database',
|
||||
'sync' => 'Sync',
|
||||
];
|
||||
|
||||
protected $description = 'Configure basic environment settings for the Panel.';
|
||||
|
||||
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.}
|
||||
{--url= : The URL that this Panel is running on.}
|
||||
{--timezone= : The timezone to use for Panel times.}
|
||||
{--cache= : The cache driver backend to use.}
|
||||
{--session= : The session driver backend to use.}
|
||||
{--queue= : The queue driver backend to use.}
|
||||
{--redis-host= : Redis host to use for connections.}
|
||||
{--redis-pass= : Password used to connect to redis.}
|
||||
{--redis-port= : Port to connect to redis over.}
|
||||
{--settings-ui= : Enable or disable the settings UI.}
|
||||
{--telemetry= : Enable or disable anonymous telemetry.}';
|
||||
|
||||
protected array $variables = [];
|
||||
|
||||
/**
|
||||
* AppSettingsCommand constructor.
|
||||
*/
|
||||
public function __construct(private Kernel $console)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle command execution.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\PterodactylException
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
if (empty(config('hashids.salt')) || $this->option('new-salt')) {
|
||||
$this->variables['HASHIDS_SALT'] = str_random(20);
|
||||
}
|
||||
|
||||
$this->output->comment('Provide the email address that eggs exported by this Panel should be from. This should be a valid email address.');
|
||||
$this->variables['APP_SERVICE_AUTHOR'] = $this->option('author') ?? $this->ask(
|
||||
'Egg Author Email',
|
||||
config('pterodactyl.service.author', 'unknown@unknown.com')
|
||||
);
|
||||
|
||||
if (!filter_var($this->variables['APP_SERVICE_AUTHOR'], FILTER_VALIDATE_EMAIL)) {
|
||||
$this->output->error('The service author email provided is invalid.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$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', 'https://example.com')
|
||||
);
|
||||
|
||||
$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(),
|
||||
config('app.timezone')
|
||||
);
|
||||
|
||||
$selected = config('cache.default', 'redis');
|
||||
$this->variables['CACHE_DRIVER'] = $this->option('cache') ?? $this->choice(
|
||||
'Cache Driver',
|
||||
self::CACHE_DRIVERS,
|
||||
array_key_exists($selected, self::CACHE_DRIVERS) ? $selected : null
|
||||
);
|
||||
|
||||
$selected = config('session.driver', 'redis');
|
||||
$this->variables['SESSION_DRIVER'] = $this->option('session') ?? $this->choice(
|
||||
'Session Driver',
|
||||
self::SESSION_DRIVERS,
|
||||
array_key_exists($selected, self::SESSION_DRIVERS) ? $selected : null
|
||||
);
|
||||
|
||||
$selected = config('queue.default', 'redis');
|
||||
$this->variables['QUEUE_CONNECTION'] = $this->option('queue') ?? $this->choice(
|
||||
'Queue Driver',
|
||||
self::QUEUE_DRIVERS,
|
||||
array_key_exists($selected, self::QUEUE_DRIVERS) ? $selected : null
|
||||
);
|
||||
|
||||
if (!is_null($this->option('settings-ui'))) {
|
||||
$this->variables['APP_ENVIRONMENT_ONLY'] = $this->option('settings-ui') == 'true' ? 'false' : 'true';
|
||||
} else {
|
||||
$this->variables['APP_ENVIRONMENT_ONLY'] = $this->confirm('Enable UI based settings editor?', true) ? 'false' : 'true';
|
||||
}
|
||||
|
||||
$this->output->comment('Please reference https://pterodactyl.io/panel/1.0/additional_configuration.html#telemetry for more detailed information regarding telemetry data and collection.');
|
||||
$this->variables['PTERODACTYL_TELEMETRY_ENABLED'] = $this->option('telemetry') ?? $this->confirm(
|
||||
'Enable sending anonymous telemetry data?',
|
||||
config('pterodactyl.telemetry.enabled', true)
|
||||
) ? 'true' : 'false';
|
||||
|
||||
// Make sure session cookies are set as "secure" when using HTTPS
|
||||
if (str_starts_with($this->variables['APP_URL'], 'https://')) {
|
||||
$this->variables['SESSION_SECURE_COOKIE'] = 'true';
|
||||
}
|
||||
|
||||
$this->checkForRedis();
|
||||
$this->writeToEnvironment($this->variables);
|
||||
|
||||
$this->info($this->console->output());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if redis is selected, if so, request connection details and verify them.
|
||||
*/
|
||||
private function checkForRedis()
|
||||
{
|
||||
$items = collect($this->variables)->filter(function ($item) {
|
||||
return $item === 'redis';
|
||||
});
|
||||
|
||||
// Redis was not selected, no need to continue.
|
||||
if (count($items) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->output->note('You\'ve selected the Redis driver for one or more options, please provide valid connection information below. In most cases you can use the defaults provided unless you have modified your setup.');
|
||||
$this->variables['REDIS_HOST'] = $this->option('redis-host') ?? $this->ask(
|
||||
'Redis Host',
|
||||
config('database.redis.default.host')
|
||||
);
|
||||
|
||||
$askForRedisPassword = true;
|
||||
if (!empty(config('database.redis.default.password'))) {
|
||||
$this->variables['REDIS_PASSWORD'] = config('database.redis.default.password');
|
||||
$askForRedisPassword = $this->confirm('It seems a password is already defined for Redis, would you like to change it?');
|
||||
}
|
||||
|
||||
if ($askForRedisPassword) {
|
||||
$this->output->comment('By default a Redis server instance has no password as it is running locally and inaccessible to the outside world. If this is the case, simply hit enter without entering a value.');
|
||||
$this->variables['REDIS_PASSWORD'] = $this->option('redis-pass') ?? $this->output->askHidden(
|
||||
'Redis Password'
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($this->variables['REDIS_PASSWORD'])) {
|
||||
$this->variables['REDIS_PASSWORD'] = 'null';
|
||||
}
|
||||
|
||||
$this->variables['REDIS_PORT'] = $this->option('redis-port') ?? $this->ask(
|
||||
'Redis Port',
|
||||
config('database.redis.default.port')
|
||||
);
|
||||
}
|
||||
}
|
||||
113
app/Console/Commands/Environment/DatabaseSettingsCommand.php
Normal file
113
app/Console/Commands/Environment/DatabaseSettingsCommand.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Environment;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
|
||||
|
||||
class DatabaseSettingsCommand extends Command
|
||||
{
|
||||
use EnvironmentWriterTrait;
|
||||
|
||||
protected $description = 'Configure database settings for the Panel.';
|
||||
|
||||
protected $signature = 'p:environment:database
|
||||
{--host= : The connection address for the MySQL server.}
|
||||
{--port= : The connection port for the MySQL server.}
|
||||
{--database= : The database to use.}
|
||||
{--username= : Username to use when connecting.}
|
||||
{--password= : Password to use for this database.}';
|
||||
|
||||
protected array $variables = [];
|
||||
|
||||
/**
|
||||
* DatabaseSettingsCommand constructor.
|
||||
*/
|
||||
public function __construct(private DatabaseManager $database, private Kernel $console)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle command execution.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\PterodactylException
|
||||
*/
|
||||
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(
|
||||
'Database Host',
|
||||
config('database.connections.mysql.host', '127.0.0.1')
|
||||
);
|
||||
|
||||
$this->variables['DB_PORT'] = $this->option('port') ?? $this->ask(
|
||||
'Database Port',
|
||||
config('database.connections.mysql.port', 3306)
|
||||
);
|
||||
|
||||
$this->variables['DB_DATABASE'] = $this->option('database') ?? $this->ask(
|
||||
'Database Name',
|
||||
config('database.connections.mysql.database', 'panel')
|
||||
);
|
||||
|
||||
$this->output->note('Using the "root" account for MySQL connections is not only highly frowned upon, it is also not allowed by this application. You\'ll need to have created a MySQL user for this software.');
|
||||
$this->variables['DB_USERNAME'] = $this->option('username') ?? $this->ask(
|
||||
'Database Username',
|
||||
config('database.connections.mysql.username', 'pterodactyl')
|
||||
);
|
||||
|
||||
$askForMySQLPassword = true;
|
||||
if (!empty(config('database.connections.mysql.password')) && $this->input->isInteractive()) {
|
||||
$this->variables['DB_PASSWORD'] = config('database.connections.mysql.password');
|
||||
$askForMySQLPassword = $this->confirm('It appears you already have a MySQL connection password defined, would you like to change it?');
|
||||
}
|
||||
|
||||
if ($askForMySQLPassword) {
|
||||
$this->variables['DB_PASSWORD'] = $this->option('password') ?? $this->secret('Database Password');
|
||||
}
|
||||
|
||||
try {
|
||||
$this->testMySQLConnection();
|
||||
} catch (\PDOException $exception) {
|
||||
$this->output->error(sprintf('Unable to connect to the MySQL server using the provided credentials. The error returned was "%s".', $exception->getMessage()));
|
||||
$this->output->error('Your connection credentials have NOT been saved. You will need to provide valid connection information before proceeding.');
|
||||
|
||||
if ($this->confirm('Go back and try again?')) {
|
||||
$this->database->disconnect('_pterodactyl_command_test');
|
||||
|
||||
return $this->handle();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->writeToEnvironment($this->variables);
|
||||
|
||||
$this->info($this->console->output());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we can connect to the provided MySQL instance and perform a selection.
|
||||
*/
|
||||
private function testMySQLConnection()
|
||||
{
|
||||
config()->set('database.connections._pterodactyl_command_test', [
|
||||
'driver' => 'mysql',
|
||||
'host' => $this->variables['DB_HOST'],
|
||||
'port' => $this->variables['DB_PORT'],
|
||||
'database' => $this->variables['DB_DATABASE'],
|
||||
'username' => $this->variables['DB_USERNAME'],
|
||||
'password' => $this->variables['DB_PASSWORD'],
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'strict' => true,
|
||||
]);
|
||||
|
||||
$this->database->connection('_pterodactyl_command_test')->getPdo();
|
||||
}
|
||||
}
|
||||
152
app/Console/Commands/Environment/EmailSettingsCommand.php
Normal file
152
app/Console/Commands/Environment/EmailSettingsCommand.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Environment;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
|
||||
class EmailSettingsCommand extends Command
|
||||
{
|
||||
use EnvironmentWriterTrait;
|
||||
|
||||
protected $description = 'Set or update the email sending configuration for the Panel.';
|
||||
|
||||
protected $signature = 'p:environment:mail
|
||||
{--driver= : The mail driver to use.}
|
||||
{--email= : Email address that messages from the Panel will originate from.}
|
||||
{--from= : The name emails from the Panel will appear to be from.}
|
||||
{--encryption=}
|
||||
{--host=}
|
||||
{--port=}
|
||||
{--endpoint=}
|
||||
{--username=}
|
||||
{--password=}';
|
||||
|
||||
protected array $variables = [];
|
||||
|
||||
/**
|
||||
* EmailSettingsCommand constructor.
|
||||
*/
|
||||
public function __construct(private ConfigRepository $config)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle command execution.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\PterodactylException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->variables['MAIL_DRIVER'] = $this->option('driver') ?? $this->choice(
|
||||
trans('command/messages.environment.mail.ask_driver'),
|
||||
[
|
||||
'smtp' => 'SMTP Server',
|
||||
'sendmail' => 'sendmail Binary',
|
||||
'mailgun' => 'Mailgun Transactional Email',
|
||||
'mandrill' => 'Mandrill Transactional Email',
|
||||
'postmark' => 'Postmark Transactional Email',
|
||||
],
|
||||
$this->config->get('mail.default', 'smtp')
|
||||
);
|
||||
|
||||
$method = 'setup' . studly_case($this->variables['MAIL_DRIVER']) . 'DriverVariables';
|
||||
if (method_exists($this, $method)) {
|
||||
$this->{$method}();
|
||||
}
|
||||
|
||||
$this->variables['MAIL_FROM_ADDRESS'] = $this->option('email') ?? $this->ask(
|
||||
trans('command/messages.environment.mail.ask_mail_from'),
|
||||
$this->config->get('mail.from.address')
|
||||
);
|
||||
|
||||
$this->variables['MAIL_FROM_NAME'] = $this->option('from') ?? $this->ask(
|
||||
trans('command/messages.environment.mail.ask_mail_name'),
|
||||
$this->config->get('mail.from.name')
|
||||
);
|
||||
|
||||
$this->writeToEnvironment($this->variables);
|
||||
|
||||
$this->line('Updating stored environment configuration file.');
|
||||
$this->line('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle variables for SMTP driver.
|
||||
*/
|
||||
private function setupSmtpDriverVariables()
|
||||
{
|
||||
$this->variables['MAIL_HOST'] = $this->option('host') ?? $this->ask(
|
||||
trans('command/messages.environment.mail.ask_smtp_host'),
|
||||
$this->config->get('mail.mailers.smtp.host')
|
||||
);
|
||||
|
||||
$this->variables['MAIL_PORT'] = $this->option('port') ?? $this->ask(
|
||||
trans('command/messages.environment.mail.ask_smtp_port'),
|
||||
$this->config->get('mail.mailers.smtp.port')
|
||||
);
|
||||
|
||||
$this->variables['MAIL_USERNAME'] = $this->option('username') ?? $this->ask(
|
||||
trans('command/messages.environment.mail.ask_smtp_username'),
|
||||
$this->config->get('mail.mailers.smtp.username')
|
||||
);
|
||||
|
||||
$this->variables['MAIL_PASSWORD'] = $this->option('password') ?? $this->secret(
|
||||
trans('command/messages.environment.mail.ask_smtp_password')
|
||||
);
|
||||
|
||||
$this->variables['MAIL_ENCRYPTION'] = $this->option('encryption') ?? $this->choice(
|
||||
trans('command/messages.environment.mail.ask_encryption'),
|
||||
['tls' => 'TLS', 'ssl' => 'SSL', '' => 'None'],
|
||||
$this->config->get('mail.mailers.smtp.encryption', 'tls')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle variables for mailgun driver.
|
||||
*/
|
||||
private function setupMailgunDriverVariables()
|
||||
{
|
||||
$this->variables['MAILGUN_DOMAIN'] = $this->option('host') ?? $this->ask(
|
||||
trans('command/messages.environment.mail.ask_mailgun_domain'),
|
||||
$this->config->get('services.mailgun.domain')
|
||||
);
|
||||
|
||||
$this->variables['MAILGUN_SECRET'] = $this->option('password') ?? $this->ask(
|
||||
trans('command/messages.environment.mail.ask_mailgun_secret'),
|
||||
$this->config->get('services.mailgun.secret')
|
||||
);
|
||||
|
||||
$this->variables['MAILGUN_ENDPOINT'] = $this->option('endpoint') ?? $this->ask(
|
||||
trans('command/messages.environment.mail.ask_mailgun_endpoint'),
|
||||
$this->config->get('services.mailgun.endpoint')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle variables for mandrill driver.
|
||||
*/
|
||||
private function setupMandrillDriverVariables()
|
||||
{
|
||||
$this->variables['MANDRILL_SECRET'] = $this->option('password') ?? $this->ask(
|
||||
trans('command/messages.environment.mail.ask_mandrill_secret'),
|
||||
$this->config->get('services.mandrill.secret')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle variables for postmark driver.
|
||||
*/
|
||||
private function setupPostmarkDriverVariables()
|
||||
{
|
||||
$this->variables['MAIL_DRIVER'] = 'smtp';
|
||||
$this->variables['MAIL_HOST'] = 'smtp.postmarkapp.com';
|
||||
$this->variables['MAIL_PORT'] = 587;
|
||||
$this->variables['MAIL_USERNAME'] = $this->variables['MAIL_PASSWORD'] = $this->option('username') ?? $this->ask(
|
||||
trans('command/messages.environment.mail.ask_postmark_username'),
|
||||
$this->config->get('mail.username')
|
||||
);
|
||||
}
|
||||
}
|
||||
81
app/Console/Commands/InfoCommand.php
Normal file
81
app/Console/Commands/InfoCommand.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Pterodactyl\Services\Helpers\SoftwareVersionService;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
|
||||
class InfoCommand extends Command
|
||||
{
|
||||
protected $description = 'Displays the application, database, and email configurations along with the panel version.';
|
||||
|
||||
protected $signature = 'p:info';
|
||||
|
||||
/**
|
||||
* VersionCommand constructor.
|
||||
*/
|
||||
public function __construct(private ConfigRepository $config, private SoftwareVersionService $versionService)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle execution of command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->output->title('Version Information');
|
||||
$this->table([], [
|
||||
['Panel Version', $this->config->get('app.version')],
|
||||
['Latest Version', $this->versionService->getPanel()],
|
||||
['Up-to-Date', $this->versionService->isLatestPanel() ? 'Yes' : $this->formatText('No', 'bg=red')],
|
||||
['Unique Identifier', $this->config->get('pterodactyl.service.author')],
|
||||
], 'compact');
|
||||
|
||||
$this->output->title('Application Configuration');
|
||||
$this->table([], [
|
||||
['Environment', $this->formatText($this->config->get('app.env'), $this->config->get('app.env') === 'production' ?: 'bg=red')],
|
||||
['Debug Mode', $this->formatText($this->config->get('app.debug') ? 'Yes' : 'No', !$this->config->get('app.debug') ?: 'bg=red')],
|
||||
['Installation URL', $this->config->get('app.url')],
|
||||
['Installation Directory', base_path()],
|
||||
['Timezone', $this->config->get('app.timezone')],
|
||||
['Cache Driver', $this->config->get('cache.default')],
|
||||
['Queue Driver', $this->config->get('queue.default')],
|
||||
['Session Driver', $this->config->get('session.driver')],
|
||||
['Filesystem Driver', $this->config->get('filesystems.default')],
|
||||
['Default Theme', $this->config->get('themes.active')],
|
||||
['Proxies', $this->config->get('trustedproxies.proxies')],
|
||||
], 'compact');
|
||||
|
||||
$this->output->title('Database Configuration');
|
||||
$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")],
|
||||
], 'compact');
|
||||
|
||||
// TODO: Update this to handle other mail drivers
|
||||
$this->output->title('Email Configuration');
|
||||
$this->table([], [
|
||||
['Driver', $this->config->get('mail.default')],
|
||||
['Host', $this->config->get('mail.mailers.smtp.host')],
|
||||
['Port', $this->config->get('mail.mailers.smtp.port')],
|
||||
['Username', $this->config->get('mail.mailers.smtp.username')],
|
||||
['From Address', $this->config->get('mail.from.address')],
|
||||
['From Name', $this->config->get('mail.from.name')],
|
||||
['Encryption', $this->config->get('mail.mailers.smtp.encryption')],
|
||||
], 'compact');
|
||||
}
|
||||
|
||||
/**
|
||||
* Format output in a Name: Value manner.
|
||||
*/
|
||||
private function formatText(string $value, string $opts = ''): string
|
||||
{
|
||||
return sprintf('<%s>%s</>', $opts, $value);
|
||||
}
|
||||
}
|
||||
55
app/Console/Commands/Location/DeleteLocationCommand.php
Normal file
55
app/Console/Commands/Location/DeleteLocationCommand.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
protected $description = 'Deletes a location from the Panel.';
|
||||
|
||||
protected $signature = 'p:location:delete {--short= : The short code of the location to delete.}';
|
||||
|
||||
protected Collection $locations;
|
||||
|
||||
/**
|
||||
* DeleteLocationCommand constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
private LocationDeletionService $deletionService,
|
||||
private LocationRepositoryInterface $repository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to the command request.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->locations = $this->locations ?? $this->repository->all();
|
||||
$short = $this->option('short') ?? $this->anticipate(
|
||||
trans('command/messages.location.ask_short'),
|
||||
$this->locations->pluck('short')->toArray()
|
||||
);
|
||||
|
||||
$location = $this->locations->where('short', $short)->first();
|
||||
if (is_null($location)) {
|
||||
$this->error(trans('command/messages.location.no_location_found'));
|
||||
if ($this->input->isInteractive()) {
|
||||
$this->handle();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->deletionService->handle($location->id);
|
||||
$this->line(trans('command/messages.location.deleted'));
|
||||
}
|
||||
}
|
||||
40
app/Console/Commands/Location/MakeLocationCommand.php
Normal file
40
app/Console/Commands/Location/MakeLocationCommand.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Location;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Pterodactyl\Services\Locations\LocationCreationService;
|
||||
|
||||
class MakeLocationCommand extends Command
|
||||
{
|
||||
protected $signature = 'p:location:make
|
||||
{--short= : The shortcode name of this location (ex. us1).}
|
||||
{--long= : A longer description of this location.}';
|
||||
|
||||
protected $description = 'Creates a new location on the system via the CLI.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct(private LocationCreationService $creationService)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the command execution process.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$short = $this->option('short') ?? $this->ask(trans('command/messages.location.ask_short'));
|
||||
$long = $this->option('long') ?? $this->ask(trans('command/messages.location.ask_long'));
|
||||
|
||||
$location = $this->creationService->handle(compact('short', 'long'));
|
||||
$this->line(trans('command/messages.location.created', [
|
||||
'name' => $location->short,
|
||||
'id' => $location->id,
|
||||
]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Maintenance;
|
||||
|
||||
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;
|
||||
|
||||
protected $description = 'Clean orphaned .bak files created when modifying services.';
|
||||
|
||||
protected $signature = 'p:maintenance:clean-service-backups';
|
||||
|
||||
protected Filesystem $disk;
|
||||
|
||||
/**
|
||||
* CleanServiceBackupFilesCommand constructor.
|
||||
*/
|
||||
public function __construct(FilesystemFactory $filesystem)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->disk = $filesystem->disk();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle command execution.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$files = $this->disk->files('services/.bak');
|
||||
|
||||
collect($files)->each(function (\SplFileInfo $file) {
|
||||
$lastModified = Carbon::createFromTimestamp($this->disk->lastModified($file->getPath()));
|
||||
if ($lastModified->diffInMinutes(Carbon::now()) > self::BACKUP_THRESHOLD_MINUTES) {
|
||||
$this->disk->delete($file->getPath());
|
||||
$this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file->getFilename()]));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Maintenance;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Console\Command;
|
||||
use Pterodactyl\Repositories\Eloquent\BackupRepository;
|
||||
|
||||
class PruneOrphanedBackupsCommand extends Command
|
||||
{
|
||||
protected $signature = 'p:maintenance:prune-backups {--prune-age=}';
|
||||
|
||||
protected $description = 'Marks all backups older than "n" minutes that have not yet completed as being failed.';
|
||||
|
||||
/**
|
||||
* 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 = $this->backupRepository->getBuilder()
|
||||
->whereNull('completed_at')
|
||||
->where('created_at', '<=', CarbonImmutable::now()->subMinutes($since)->toDateTimeString());
|
||||
|
||||
$count = $query->count();
|
||||
if (!$count) {
|
||||
$this->info('There are no orphaned backups to be marked as failed.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->warn("Marking $count uncompleted backups that are older than $since minutes as failed.");
|
||||
|
||||
$query->update([
|
||||
'is_successful' => false,
|
||||
'completed_at' => CarbonImmutable::now(),
|
||||
'updated_at' => CarbonImmutable::now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
69
app/Console/Commands/Node/MakeNodeCommand.php
Normal file
69
app/Console/Commands/Node/MakeNodeCommand.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Node;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Pterodactyl\Services\Nodes\NodeCreationService;
|
||||
|
||||
class MakeNodeCommand extends Command
|
||||
{
|
||||
protected $signature = 'p:node:make
|
||||
{--name= : A name to identify the node.}
|
||||
{--description= : A description to identify the node.}
|
||||
{--locationId= : A valid locationId.}
|
||||
{--fqdn= : The domain name (e.g node.example.com) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node.}
|
||||
{--public= : Should the node be public or private? (public=1 / private=0).}
|
||||
{--scheme= : Which scheme should be used? (Enable SSL=https / Disable SSL=http).}
|
||||
{--proxy= : Is the daemon behind a proxy? (Yes=1 / No=0).}
|
||||
{--maintenance= : Should maintenance mode be enabled? (Enable Maintenance mode=1 / Disable Maintenance mode=0).}
|
||||
{--maxMemory= : Set the max memory amount.}
|
||||
{--overallocateMemory= : Enter the amount of ram to overallocate (% or -1 to overallocate the maximum).}
|
||||
{--maxDisk= : Set the max disk amount.}
|
||||
{--overallocateDisk= : Enter the amount of disk to overallocate (% or -1 to overallocate the maximum).}
|
||||
{--uploadSize= : Enter the maximum upload filesize.}
|
||||
{--daemonListeningPort= : Enter the wings listening port.}
|
||||
{--daemonSFTPPort= : Enter the wings SFTP listening port.}
|
||||
{--daemonBase= : Enter the base folder.}';
|
||||
|
||||
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()
|
||||
{
|
||||
$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');
|
||||
$data['scheme'] = $this->option('scheme') ?? $this->anticipate(
|
||||
'Please either enter https for SSL or http for a non-ssl connection',
|
||||
['https', 'http'],
|
||||
'https'
|
||||
);
|
||||
$data['fqdn'] = $this->option('fqdn') ?? $this->ask('Enter a domain name (e.g node.example.com) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node');
|
||||
$data['public'] = $this->option('public') ?? $this->confirm('Should this node be public? As a note, setting a node to private you will be denying the ability to auto-deploy to this node.', true);
|
||||
$data['behind_proxy'] = $this->option('proxy') ?? $this->confirm('Is your FQDN behind a proxy?');
|
||||
$data['maintenance_mode'] = $this->option('maintenance') ?? $this->confirm('Should maintenance mode be enabled?');
|
||||
$data['memory'] = $this->option('maxMemory') ?? $this->ask('Enter the maximum amount of memory');
|
||||
$data['memory_overallocate'] = $this->option('overallocateMemory') ?? $this->ask('Enter the amount of memory to over allocate by, -1 will disable checking and 0 will prevent creating new servers');
|
||||
$data['disk'] = $this->option('maxDisk') ?? $this->ask('Enter the maximum amount of disk space');
|
||||
$data['disk_overallocate'] = $this->option('overallocateDisk') ?? $this->ask('Enter the amount of memory to over allocate by, -1 will disable checking and 0 will prevent creating new server');
|
||||
$data['upload_size'] = $this->option('uploadSize') ?? $this->ask('Enter the maximum filesize upload', '100');
|
||||
$data['daemonListen'] = $this->option('daemonListeningPort') ?? $this->ask('Enter the wings listening port', '8080');
|
||||
$data['daemonSFTP'] = $this->option('daemonSFTPPort') ?? $this->ask('Enter the wings SFTP listening port', '2022');
|
||||
$data['daemonBase'] = $this->option('daemonBase') ?? $this->ask('Enter the base folder', '/var/lib/pterodactyl/volumes');
|
||||
|
||||
$node = $this->creationService->handle($data);
|
||||
$this->line('Successfully created a new node on the location ' . $data['location_id'] . ' with the name ' . $data['name'] . ' and has an id of ' . $node->id . '.');
|
||||
}
|
||||
}
|
||||
44
app/Console/Commands/Node/NodeConfigurationCommand.php
Normal file
44
app/Console/Commands/Node/NodeConfigurationCommand.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Node;
|
||||
|
||||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class NodeConfigurationCommand extends Command
|
||||
{
|
||||
protected $signature = 'p:node:configuration
|
||||
{node : The ID or UUID of the node to return the configuration for.}
|
||||
{--format=yaml : The output format. Options are "yaml" and "json".}';
|
||||
|
||||
protected $description = 'Displays the configuration for the specified node.';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$column = ctype_digit((string) $this->argument('node')) ? 'id' : 'uuid';
|
||||
|
||||
/** @var \Pterodactyl\Models\Node $node */
|
||||
$node = Node::query()->where($column, $this->argument('node'))->firstOr(function () {
|
||||
$this->error('The selected node does not exist.');
|
||||
|
||||
exit(1);
|
||||
});
|
||||
|
||||
$format = $this->option('format');
|
||||
if (!in_array($format, ['yaml', 'yml', 'json'])) {
|
||||
$this->error('Invalid format specified. Valid options are "yaml" and "json".');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($format === 'json') {
|
||||
$this->output->write($node->getJsonConfiguration(true));
|
||||
} else {
|
||||
$this->output->write($node->getYamlConfiguration());
|
||||
}
|
||||
|
||||
$this->output->newLine();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
34
app/Console/Commands/Node/NodeListCommand.php
Normal file
34
app/Console/Commands/Node/NodeListCommand.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Node;
|
||||
|
||||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class NodeListCommand extends Command
|
||||
{
|
||||
protected $signature = 'p:node:list {--format=text : The output format: "text" or "json". }';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$nodes = Node::query()->with('location')->get()->map(function (Node $node) {
|
||||
return [
|
||||
'id' => $node->id,
|
||||
'uuid' => $node->uuid,
|
||||
'name' => $node->name,
|
||||
'location' => $node->location->short,
|
||||
'host' => $node->getConnectionAddress(),
|
||||
];
|
||||
});
|
||||
|
||||
if ($this->option('format') === 'json') {
|
||||
$this->output->write($nodes->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
} else {
|
||||
$this->table(['ID', 'UUID', 'Name', 'Location', 'Host'], $nodes->toArray());
|
||||
}
|
||||
|
||||
$this->output->newLine();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
28
app/Console/Commands/Overrides/KeyGenerateCommand.php
Normal file
28
app/Console/Commands/Overrides/KeyGenerateCommand.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Overrides;
|
||||
|
||||
use Illuminate\Foundation\Console\KeyGenerateCommand as BaseKeyGenerateCommand;
|
||||
|
||||
class KeyGenerateCommand extends BaseKeyGenerateCommand
|
||||
{
|
||||
/**
|
||||
* Override the default Laravel key generation command to throw a warning to the user
|
||||
* if it appears that they have already generated an application encryption key.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (!empty(config('app.key')) && $this->input->isInteractive()) {
|
||||
$this->output->warning('It appears you have already configured an application encryption key. Continuing with this process with overwrite that key and cause data corruption for any existing encrypted data. DO NOT CONTINUE UNLESS YOU KNOW WHAT YOU ARE DOING.');
|
||||
if (!$this->confirm('I understand the consequences of performing this command and accept all responsibility for the loss of encrypted data.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->confirm('Are you sure you wish to continue? Changing the application encryption key WILL CAUSE DATA LOSS.')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
parent::handle();
|
||||
}
|
||||
}
|
||||
26
app/Console/Commands/Overrides/SeedCommand.php
Normal file
26
app/Console/Commands/Overrides/SeedCommand.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Overrides;
|
||||
|
||||
use Pterodactyl\Console\RequiresDatabaseMigrations;
|
||||
use Illuminate\Database\Console\Seeds\SeedCommand as BaseSeedCommand;
|
||||
|
||||
class SeedCommand extends BaseSeedCommand
|
||||
{
|
||||
use RequiresDatabaseMigrations;
|
||||
|
||||
/**
|
||||
* Block someone from running this seed command if they have not completed
|
||||
* the migration process.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
if (!$this->hasCompletedMigrations()) {
|
||||
$this->showMigrationWarning();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return parent::handle();
|
||||
}
|
||||
}
|
||||
26
app/Console/Commands/Overrides/UpCommand.php
Normal file
26
app/Console/Commands/Overrides/UpCommand.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Overrides;
|
||||
|
||||
use Pterodactyl\Console\RequiresDatabaseMigrations;
|
||||
use Illuminate\Foundation\Console\UpCommand as BaseUpCommand;
|
||||
|
||||
class UpCommand extends BaseUpCommand
|
||||
{
|
||||
use RequiresDatabaseMigrations;
|
||||
|
||||
/**
|
||||
* Block someone from running this up command if they have not completed
|
||||
* the migration process.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
if (!$this->hasCompletedMigrations()) {
|
||||
$this->showMigrationWarning();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return parent::handle() ?? 0;
|
||||
}
|
||||
}
|
||||
76
app/Console/Commands/Schedule/ProcessRunnableCommand.php
Normal file
76
app/Console/Commands/Schedule/ProcessRunnableCommand.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\Schedule;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Pterodactyl\Services\Schedules\ProcessScheduleService;
|
||||
|
||||
class ProcessRunnableCommand extends Command
|
||||
{
|
||||
protected $signature = 'p:schedule:process';
|
||||
|
||||
protected $description = 'Process schedules in the database and determine which are ready to run.';
|
||||
|
||||
/**
|
||||
* Handle command execution.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$schedules = Schedule::query()
|
||||
->with('tasks')
|
||||
->whereRelation('server', fn (Builder $builder) => $builder->whereNull('status'))
|
||||
->where('is_active', true)
|
||||
->where('is_processing', false)
|
||||
->whereRaw('next_run_at <= NOW()')
|
||||
->get();
|
||||
|
||||
if ($schedules->count() < 1) {
|
||||
$this->line('There are no scheduled tasks for servers that need to be run.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$bar = $this->output->createProgressBar(count($schedules));
|
||||
foreach ($schedules as $schedule) {
|
||||
$bar->clear();
|
||||
$this->processSchedule($schedule);
|
||||
$bar->advance();
|
||||
$bar->display();
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a given schedule and logs and errors encountered the console output. This should
|
||||
* never throw an exception out, otherwise you'll end up killing the entire run group causing
|
||||
* any other schedules to not process correctly.
|
||||
*
|
||||
* @see https://github.com/pterodactyl/panel/issues/2609
|
||||
*/
|
||||
protected function processSchedule(Schedule $schedule)
|
||||
{
|
||||
if ($schedule->tasks->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->getLaravel()->make(ProcessScheduleService::class)->handle($schedule);
|
||||
|
||||
$this->line(trans('command/messages.schedule.output_line', [
|
||||
'schedule' => $schedule->name,
|
||||
'hash' => $schedule->hashid,
|
||||
]));
|
||||
} catch (\Throwable|\Exception $exception) {
|
||||
Log::error($exception, ['schedule_id' => $schedule->id]);
|
||||
|
||||
$this->error("An error was encountered while processing Schedule #$schedule->id: " . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
106
app/Console/Commands/Server/BulkPowerActionCommand.php
Normal file
106
app/Console/Commands/Server/BulkPowerActionCommand.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
|
||||
class BulkPowerActionCommand extends Command
|
||||
{
|
||||
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.}';
|
||||
|
||||
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()
|
||||
{
|
||||
$action = $this->argument('action');
|
||||
$nodes = empty($this->option('nodes')) ? [] : explode(',', $this->option('nodes'));
|
||||
$servers = empty($this->option('servers')) ? [] : explode(',', $this->option('servers'));
|
||||
|
||||
$validator = $this->validator->make([
|
||||
'action' => $action,
|
||||
'nodes' => $nodes,
|
||||
'servers' => $servers,
|
||||
], [
|
||||
'action' => 'string|in:start,stop,kill,restart',
|
||||
'nodes' => 'array',
|
||||
'nodes.*' => 'integer|min:1',
|
||||
'servers' => 'array',
|
||||
'servers.*' => 'integer|min:1',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
foreach ($validator->getMessageBag()->all() as $message) {
|
||||
$this->output->error($message);
|
||||
}
|
||||
|
||||
throw new ValidationException($validator);
|
||||
}
|
||||
|
||||
$count = $this->getQueryBuilder($servers, $nodes)->count();
|
||||
if (!$this->confirm(trans('command/messages.server.power.confirm', ['action' => $action, 'count' => $count])) && $this->input->isInteractive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$bar = $this->output->createProgressBar($count);
|
||||
$powerRepository = $this->powerRepository;
|
||||
$this->getQueryBuilder($servers, $nodes)->each(function (Server $server) use ($action, $powerRepository, &$bar) {
|
||||
$bar->clear();
|
||||
|
||||
try {
|
||||
$powerRepository->setServer($server)->send($action);
|
||||
} catch (DaemonConnectionException $exception) {
|
||||
$this->output->error(trans('command/messages.server.power.action_failed', [
|
||||
'name' => $server->name,
|
||||
'id' => $server->id,
|
||||
'node' => $server->node->name,
|
||||
'message' => $exception->getMessage(),
|
||||
]));
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
$bar->display();
|
||||
});
|
||||
|
||||
$this->line('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query builder instance that will return the servers that should be affected.
|
||||
*/
|
||||
protected function getQueryBuilder(array $servers, array $nodes): Builder
|
||||
{
|
||||
$instance = Server::query()->whereNull('status');
|
||||
|
||||
if (!empty($nodes) && !empty($servers)) {
|
||||
$instance->whereIn('id', $servers)->orWhereIn('node_id', $nodes);
|
||||
} elseif (empty($nodes) && !empty($servers)) {
|
||||
$instance->whereIn('id', $servers);
|
||||
} elseif (!empty($nodes) && empty($servers)) {
|
||||
$instance->whereIn('node_id', $nodes);
|
||||
}
|
||||
|
||||
return $instance->with('node');
|
||||
}
|
||||
}
|
||||
34
app/Console/Commands/TelemetryCommand.php
Normal file
34
app/Console/Commands/TelemetryCommand.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\VarDumper\VarDumper;
|
||||
use Pterodactyl\Services\Telemetry\TelemetryCollectionService;
|
||||
|
||||
class TelemetryCommand extends Command
|
||||
{
|
||||
protected $description = 'Displays all the data that would be sent to the Pterodactyl Telemetry Service if telemetry collection is enabled.';
|
||||
|
||||
protected $signature = 'p:telemetry';
|
||||
|
||||
/**
|
||||
* TelemetryCommand constructor.
|
||||
*/
|
||||
public function __construct(private TelemetryCollectionService $telemetryCollectionService)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle execution of command.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->output->info('Collecting telemetry data, this may take a while...');
|
||||
|
||||
VarDumper::dump($this->telemetryCollectionService->collect());
|
||||
}
|
||||
}
|
||||
195
app/Console/Commands/UpgradeCommand.php
Normal file
195
app/Console/Commands/UpgradeCommand.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Pterodactyl\Console\Kernel;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
|
||||
class UpgradeCommand extends Command
|
||||
{
|
||||
protected const DEFAULT_URL = 'https://github.com/pterodactyl/panel/releases/%s/panel.tar.gz';
|
||||
|
||||
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.}
|
||||
{--url= : The specific archive to download.}
|
||||
{--release= : A specific Pterodactyl version to download from GitHub. Leave blank to use latest.}
|
||||
{--skip-download : If set no archive will be downloaded.}';
|
||||
|
||||
protected $description = 'Downloads a new archive for Pterodactyl from GitHub and then executes the normal upgrade commands.';
|
||||
|
||||
/**
|
||||
* Executes an upgrade command which will run through all of our standard
|
||||
* commands for Pterodactyl and enable users to basically just download
|
||||
* the archive and execute this and be done.
|
||||
*
|
||||
* This places the application in maintenance mode as well while the commands
|
||||
* are being executed.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$skipDownload = $this->option('skip-download');
|
||||
if (!$skipDownload) {
|
||||
$this->output->warning('This command does not verify the integrity of downloaded assets. Please ensure that you trust the download source before continuing. If you do not wish to download an archive, please indicate that using the --skip-download flag, or answering "no" to the question below.');
|
||||
$this->output->comment('Download Source (set with --url=):');
|
||||
$this->line($this->getUrl());
|
||||
}
|
||||
|
||||
if (version_compare(PHP_VERSION, '7.4.0') < 0) {
|
||||
$this->error('Cannot execute self-upgrade process. The minimum required PHP version required is 7.4.0, you have [' . PHP_VERSION . '].');
|
||||
}
|
||||
|
||||
$user = 'www-data';
|
||||
$group = 'www-data';
|
||||
if ($this->input->isInteractive()) {
|
||||
if (!$skipDownload) {
|
||||
$skipDownload = !$this->confirm('Would you like to download and unpack the archive files for the latest version?', true);
|
||||
}
|
||||
|
||||
if (is_null($this->option('user'))) {
|
||||
$userDetails = posix_getpwuid(fileowner('public'));
|
||||
$user = $userDetails['name'] ?? 'www-data';
|
||||
|
||||
if (!$this->confirm("Your webserver user has been detected as <fg=blue>[{$user}]:</> is this correct?", true)) {
|
||||
$user = $this->anticipate(
|
||||
'Please enter the name of the user running your webserver process. This varies from system to system, but is generally "www-data", "nginx", or "apache".',
|
||||
[
|
||||
'www-data',
|
||||
'nginx',
|
||||
'apache',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($this->option('group'))) {
|
||||
$groupDetails = posix_getgrgid(filegroup('public'));
|
||||
$group = $groupDetails['name'] ?? 'www-data';
|
||||
|
||||
if (!$this->confirm("Your webserver group has been detected as <fg=blue>[{$group}]:</> is this correct?", true)) {
|
||||
$group = $this->anticipate(
|
||||
'Please enter the name of the group running your webserver process. Normally this is the same as your user.',
|
||||
[
|
||||
'www-data',
|
||||
'nginx',
|
||||
'apache',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->confirm('Are you sure you want to run the upgrade process for your Panel?')) {
|
||||
$this->warn('Upgrade process terminated by user.');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ini_set('output_buffering', '0');
|
||||
$bar = $this->output->createProgressBar($skipDownload ? 9 : 10);
|
||||
$bar->start();
|
||||
|
||||
if (!$skipDownload) {
|
||||
$this->withProgress($bar, function () {
|
||||
$this->line("\$upgrader> curl -L \"{$this->getUrl()}\" | tar -xzv");
|
||||
$process = Process::fromShellCommandline("curl -L \"{$this->getUrl()}\" | tar -xzv");
|
||||
$process->run(function ($type, $buffer) {
|
||||
$this->{$type === Process::ERR ? 'error' : 'line'}($buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$this->withProgress($bar, function () {
|
||||
$this->line('$upgrader> php artisan down');
|
||||
$this->call('down');
|
||||
});
|
||||
|
||||
$this->withProgress($bar, function () {
|
||||
$this->line('$upgrader> chmod -R 755 storage bootstrap/cache');
|
||||
$process = new Process(['chmod', '-R', '755', 'storage', 'bootstrap/cache']);
|
||||
$process->run(function ($type, $buffer) {
|
||||
$this->{$type === Process::ERR ? 'error' : 'line'}($buffer);
|
||||
});
|
||||
});
|
||||
|
||||
$this->withProgress($bar, function () {
|
||||
$command = ['composer', 'install', '--no-ansi'];
|
||||
if (config('app.env') === 'production' && !config('app.debug')) {
|
||||
$command[] = '--optimize-autoloader';
|
||||
$command[] = '--no-dev';
|
||||
}
|
||||
|
||||
$this->line('$upgrader> ' . implode(' ', $command));
|
||||
$process = new Process($command);
|
||||
$process->setTimeout(10 * 60);
|
||||
$process->run(function ($type, $buffer) {
|
||||
$this->line($buffer);
|
||||
});
|
||||
});
|
||||
|
||||
/** @var \Illuminate\Foundation\Application $app */
|
||||
$app = require __DIR__ . '/../../../bootstrap/app.php';
|
||||
/** @var \Pterodactyl\Console\Kernel $kernel */
|
||||
$kernel = $app->make(Kernel::class);
|
||||
$kernel->bootstrap();
|
||||
$this->setLaravel($app);
|
||||
|
||||
$this->withProgress($bar, function () {
|
||||
$this->line('$upgrader> php artisan view:clear');
|
||||
$this->call('view:clear');
|
||||
});
|
||||
|
||||
$this->withProgress($bar, function () {
|
||||
$this->line('$upgrader> php artisan config:clear');
|
||||
$this->call('config:clear');
|
||||
});
|
||||
|
||||
$this->withProgress($bar, function () {
|
||||
$this->line('$upgrader> php artisan migrate --force --seed');
|
||||
$this->call('migrate', ['--force' => true, '--seed' => true]);
|
||||
});
|
||||
|
||||
$this->withProgress($bar, function () use ($user, $group) {
|
||||
$this->line("\$upgrader> chown -R {$user}:{$group} *");
|
||||
$process = Process::fromShellCommandline("chown -R {$user}:{$group} *", $this->getLaravel()->basePath());
|
||||
$process->setTimeout(10 * 60);
|
||||
$process->run(function ($type, $buffer) {
|
||||
$this->{$type === Process::ERR ? 'error' : 'line'}($buffer);
|
||||
});
|
||||
});
|
||||
|
||||
$this->withProgress($bar, function () {
|
||||
$this->line('$upgrader> php artisan queue:restart');
|
||||
$this->call('queue:restart');
|
||||
});
|
||||
|
||||
$this->withProgress($bar, function () {
|
||||
$this->line('$upgrader> php artisan up');
|
||||
$this->call('up');
|
||||
});
|
||||
|
||||
$this->newLine(2);
|
||||
$this->info('Panel has been successfully upgraded. Please ensure you also update any Wings instances: https://pterodactyl.io/wings/1.0/upgrading.html');
|
||||
}
|
||||
|
||||
protected function withProgress(ProgressBar $bar, \Closure $callback)
|
||||
{
|
||||
$bar->clear();
|
||||
$callback();
|
||||
$bar->advance();
|
||||
$bar->display();
|
||||
}
|
||||
|
||||
protected function getUrl(): string
|
||||
{
|
||||
if ($this->option('url')) {
|
||||
return $this->option('url');
|
||||
}
|
||||
|
||||
return sprintf(self::DEFAULT_URL, $this->option('release') ? 'download/v' . $this->option('release') : 'latest/download');
|
||||
}
|
||||
}
|
||||
71
app/Console/Commands/User/DeleteUserCommand.php
Normal file
71
app/Console/Commands/User/DeleteUserCommand.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\User;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Webmozart\Assert\Assert;
|
||||
use Illuminate\Console\Command;
|
||||
use Pterodactyl\Services\Users\UserDeletionService;
|
||||
|
||||
class DeleteUserCommand extends Command
|
||||
{
|
||||
protected $description = 'Deletes a user from the Panel if no servers are attached to their account.';
|
||||
|
||||
protected $signature = 'p:user:delete {--user=}';
|
||||
|
||||
/**
|
||||
* DeleteUserCommand constructor.
|
||||
*/
|
||||
public function __construct(private UserDeletionService $deletionService)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
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.');
|
||||
|
||||
$results = User::query()
|
||||
->where('id', 'LIKE', "$search%")
|
||||
->orWhere('username', 'LIKE', "$search%")
|
||||
->orWhere('email', 'LIKE', "$search%")
|
||||
->get();
|
||||
|
||||
if (count($results) < 1) {
|
||||
$this->error(trans('command/messages.user.no_users_found'));
|
||||
if ($this->input->isInteractive()) {
|
||||
return $this->handle();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($this->input->isInteractive()) {
|
||||
$tableValues = [];
|
||||
foreach ($results as $user) {
|
||||
$tableValues[] = [$user->id, $user->email, $user->name];
|
||||
}
|
||||
|
||||
$this->table(['User ID', 'Email', 'Name'], $tableValues);
|
||||
if (!$deleteUser = $this->ask(trans('command/messages.user.select_search_user'))) {
|
||||
return $this->handle();
|
||||
}
|
||||
} else {
|
||||
if (count($results) > 1) {
|
||||
$this->error(trans('command/messages.user.multiple_found'));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$deleteUser = $results->first();
|
||||
}
|
||||
|
||||
if ($this->confirm(trans('command/messages.user.confirm_delete')) || !$this->input->isInteractive()) {
|
||||
$this->deletionService->handle($deleteUser);
|
||||
$this->info(trans('command/messages.user.deleted'));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
43
app/Console/Commands/User/DisableTwoFactorCommand.php
Normal file
43
app/Console/Commands/User/DisableTwoFactorCommand.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\User;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
|
||||
class DisableTwoFactorCommand extends Command
|
||||
{
|
||||
protected $description = 'Disable two-factor authentication for a specific user in the Panel.';
|
||||
|
||||
protected $signature = 'p:user:disable2fa {--email= : The email of the user to disable 2-Factor for.}';
|
||||
|
||||
/**
|
||||
* DisableTwoFactorCommand constructor.
|
||||
*/
|
||||
public function __construct(private UserRepositoryInterface $repository)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle command execution process.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->input->isInteractive()) {
|
||||
$this->output->warning(trans('command/messages.user.2fa_help_text'));
|
||||
}
|
||||
|
||||
$email = $this->option('email') ?? $this->ask(trans('command/messages.user.ask_email'));
|
||||
$user = $this->repository->setColumns(['id', 'email'])->findFirstWhere([['email', '=', $email]]);
|
||||
|
||||
$this->repository->withoutFreshModel()->update($user->id, [
|
||||
'use_totp' => false,
|
||||
'totp_secret' => null,
|
||||
]);
|
||||
$this->info(trans('command/messages.user.2fa_disabled', ['email' => $user->email]));
|
||||
}
|
||||
}
|
||||
51
app/Console/Commands/User/MakeUserCommand.php
Normal file
51
app/Console/Commands/User/MakeUserCommand.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console\Commands\User;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Pterodactyl\Services\Users\UserCreationService;
|
||||
|
||||
class MakeUserCommand extends Command
|
||||
{
|
||||
protected $description = 'Creates a user on the system via the CLI.';
|
||||
|
||||
protected $signature = 'p:user:make {--email=} {--username=} {--name-first=} {--name-last=} {--password=} {--admin=} {--no-password}';
|
||||
|
||||
/**
|
||||
* MakeUserCommand constructor.
|
||||
*/
|
||||
public function __construct(private UserCreationService $creationService)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle command request to create a new user.
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$root_admin = $this->option('admin') ?? $this->confirm(trans('command/messages.user.ask_admin'));
|
||||
$email = $this->option('email') ?? $this->ask(trans('command/messages.user.ask_email'));
|
||||
$username = $this->option('username') ?? $this->ask(trans('command/messages.user.ask_username'));
|
||||
$name_first = $this->option('name-first') ?? $this->ask(trans('command/messages.user.ask_name_first'));
|
||||
$name_last = $this->option('name-last') ?? $this->ask(trans('command/messages.user.ask_name_last'));
|
||||
|
||||
if (is_null($password = $this->option('password')) && !$this->option('no-password')) {
|
||||
$this->warn(trans('command/messages.user.ask_password_help'));
|
||||
$this->line(trans('command/messages.user.ask_password_tip'));
|
||||
$password = $this->secret(trans('command/messages.user.ask_password'));
|
||||
}
|
||||
|
||||
$user = $this->creationService->handle(compact('email', 'username', 'name_first', 'name_last', 'password', 'root_admin'));
|
||||
$this->table(['Field', 'Value'], [
|
||||
['UUID', $user->uuid],
|
||||
['Email', $user->email],
|
||||
['Username', $user->username],
|
||||
['Name', $user->name],
|
||||
['Admin', $user->root_admin ? 'Yes' : 'No'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
76
app/Console/Kernel.php
Normal file
76
app/Console/Kernel.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Pterodactyl\Models\ActivityLog;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Database\Console\PruneCommand;
|
||||
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use Pterodactyl\Services\Telemetry\TelemetryCollectionService;
|
||||
use Pterodactyl\Console\Commands\Schedule\ProcessRunnableCommand;
|
||||
use Pterodactyl\Console\Commands\Maintenance\PruneOrphanedBackupsCommand;
|
||||
use Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*/
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__ . '/Commands');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// https://laravel.com/docs/10.x/upgrade#redis-cache-tags
|
||||
$schedule->command('cache:prune-stale-tags')->hourly();
|
||||
|
||||
// Execute scheduled commands for servers every minute, as if there was a normal cron running.
|
||||
$schedule->command(ProcessRunnableCommand::class)->everyMinute()->withoutOverlapping();
|
||||
$schedule->command(CleanServiceBackupFilesCommand::class)->daily();
|
||||
|
||||
if (config('backups.prune_age')) {
|
||||
// Every 30 minutes, run the backup pruning command so that any abandoned backups can be deleted.
|
||||
$schedule->command(PruneOrphanedBackupsCommand::class)->everyThirtyMinutes();
|
||||
}
|
||||
|
||||
if (config('activity.prune_days')) {
|
||||
$schedule->command(PruneCommand::class, ['--model' => [ActivityLog::class]])->daily();
|
||||
}
|
||||
|
||||
if (config('pterodactyl.telemetry.enabled')) {
|
||||
$this->registerTelemetry($schedule);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* I wonder what this does.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
private function registerTelemetry(Schedule $schedule): void
|
||||
{
|
||||
$settingsRepository = app()->make(SettingsRepository::class);
|
||||
|
||||
$uuid = $settingsRepository->get('app:telemetry:uuid');
|
||||
if (is_null($uuid)) {
|
||||
$uuid = Uuid::uuid4()->toString();
|
||||
$settingsRepository->set('app:telemetry:uuid', $uuid);
|
||||
}
|
||||
|
||||
// Calculate a fixed time to run the data push at, this will be the same time every day.
|
||||
$time = hexdec(str_replace('-', '', substr($uuid, 27))) % 1440;
|
||||
$hour = floor($time / 60);
|
||||
$minute = $time % 60;
|
||||
|
||||
// Run the telemetry collector.
|
||||
$schedule->call(app()->make(TelemetryCollectionService::class))->description('Collect Telemetry')->dailyAt("$hour:$minute");
|
||||
}
|
||||
}
|
||||
55
app/Console/RequiresDatabaseMigrations.php
Normal file
55
app/Console/RequiresDatabaseMigrations.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Console;
|
||||
|
||||
/**
|
||||
* @mixin \Illuminate\Console\Command
|
||||
*/
|
||||
trait RequiresDatabaseMigrations
|
||||
{
|
||||
/**
|
||||
* Checks if the migrations have finished running by comparing the last migration file.
|
||||
*/
|
||||
protected function hasCompletedMigrations(): bool
|
||||
{
|
||||
/** @var \Illuminate\Database\Migrations\Migrator $migrator */
|
||||
$migrator = $this->getLaravel()->make('migrator');
|
||||
|
||||
$files = $migrator->getMigrationFiles(database_path('migrations'));
|
||||
|
||||
if (!$migrator->repositoryExists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (array_diff(array_keys($files), $migrator->getRepository()->getRan())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a massive error into the console to hopefully catch the users attention and get
|
||||
* them to properly run the migrations rather than ignoring all of the other previous
|
||||
* errors...
|
||||
*/
|
||||
protected function showMigrationWarning(): void
|
||||
{
|
||||
$this->getOutput()->writeln('<options=bold>
|
||||
| @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
|
||||
| |
|
||||
| Your database has not been properly migrated! |
|
||||
| |
|
||||
| @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |</>
|
||||
|
||||
You must run the following command to finish migrating your database:
|
||||
|
||||
<fg=green;options=bold>php artisan migrate --step --force</>
|
||||
|
||||
You will not be able to use Pterodactyl Panel as expected without fixing your
|
||||
database state by running the command above.
|
||||
');
|
||||
|
||||
$this->getOutput()->error('You must correct the error above before continuing.');
|
||||
}
|
||||
}
|
||||
13
app/Contracts/Core/ReceivesEvents.php
Normal file
13
app/Contracts/Core/ReceivesEvents.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Core;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
|
||||
interface ReceivesEvents
|
||||
{
|
||||
/**
|
||||
* Handles receiving an event from the application.
|
||||
*/
|
||||
public function handle(Event $notification): void;
|
||||
}
|
||||
14
app/Contracts/Criteria/CriteriaInterface.php
Normal file
14
app/Contracts/Criteria/CriteriaInterface.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Criteria;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Pterodactyl\Repositories\Repository;
|
||||
|
||||
interface CriteriaInterface
|
||||
{
|
||||
/**
|
||||
* Apply selected criteria to a repository call.
|
||||
*/
|
||||
public function apply(Model $model, Repository $repository): mixed;
|
||||
}
|
||||
15
app/Contracts/Extensions/HashidsInterface.php
Normal file
15
app/Contracts/Extensions/HashidsInterface.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Extensions;
|
||||
|
||||
use Hashids\HashidsInterface as VendorHashidsInterface;
|
||||
|
||||
interface HashidsInterface extends VendorHashidsInterface
|
||||
{
|
||||
/**
|
||||
* Decode an encoded hashid and return the first result.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function decodeFirst(string $encoded, string $default = null): mixed;
|
||||
}
|
||||
13
app/Contracts/Http/ClientPermissionsRequest.php
Normal file
13
app/Contracts/Http/ClientPermissionsRequest.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Http;
|
||||
|
||||
interface ClientPermissionsRequest
|
||||
{
|
||||
/**
|
||||
* Returns the permissions string indicating which permission should be used to
|
||||
* validate that the authenticated user has permission to perform this action against
|
||||
* the given resource (server).
|
||||
*/
|
||||
public function permission(): string;
|
||||
}
|
||||
19
app/Contracts/Repository/AllocationRepositoryInterface.php
Normal file
19
app/Contracts/Repository/AllocationRepositoryInterface.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Models\Allocation;
|
||||
|
||||
interface AllocationRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function getRandomAllocation(array $nodes, array $ports, bool $dedicated = false): ?Allocation;
|
||||
}
|
||||
29
app/Contracts/Repository/ApiKeyRepositoryInterface.php
Normal file
29
app/Contracts/Repository/ApiKeyRepositoryInterface.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
interface ApiKeyRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get all the account API keys that exist for a specific user.
|
||||
*/
|
||||
public function getAccountKeys(User $user): Collection;
|
||||
|
||||
/**
|
||||
* Get all the application API keys that exist for a specific user.
|
||||
*/
|
||||
public function getApplicationKeys(User $user): Collection;
|
||||
|
||||
/**
|
||||
* Delete an account API key from the panel for a specific user.
|
||||
*/
|
||||
public function deleteAccountKey(User $user, string $identifier): int;
|
||||
|
||||
/**
|
||||
* Delete an application API key from the panel for a specific user.
|
||||
*/
|
||||
public function deleteApplicationKey(User $user, string $identifier): int;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
interface ApiPermissionRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
}
|
||||
14
app/Contracts/Repository/DatabaseHostRepositoryInterface.php
Normal file
14
app/Contracts/Repository/DatabaseHostRepositoryInterface.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
interface DatabaseHostRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Return database hosts with a count of databases and the node
|
||||
* information for which it is attached.
|
||||
*/
|
||||
public function getWithViewDetails(): Collection;
|
||||
}
|
||||
61
app/Contracts/Repository/DatabaseRepositoryInterface.php
Normal file
61
app/Contracts/Repository/DatabaseRepositoryInterface.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface DatabaseRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
public const DEFAULT_CONNECTION_NAME = 'dynamic';
|
||||
|
||||
/**
|
||||
* Set the connection name to execute statements against.
|
||||
*/
|
||||
public function setConnection(string $connection): self;
|
||||
|
||||
/**
|
||||
* Return the connection to execute statements against.
|
||||
*/
|
||||
public function getConnection(): string;
|
||||
|
||||
/**
|
||||
* Return all the databases belonging to a server.
|
||||
*/
|
||||
public function getDatabasesForServer(int $server): Collection;
|
||||
|
||||
/**
|
||||
* Return all the databases for a given host with the server relationship loaded.
|
||||
*/
|
||||
public function getDatabasesForHost(int $host, int $count = 25): LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* Create a new database on a given connection.
|
||||
*/
|
||||
public function createDatabase(string $database): bool;
|
||||
|
||||
/**
|
||||
* Create a new database user on a given connection.
|
||||
*/
|
||||
public function createUser(string $username, string $remote, string $password, ?int $max_connections): bool;
|
||||
|
||||
/**
|
||||
* Give a specific user access to a given database.
|
||||
*/
|
||||
public function assignUserToDatabase(string $database, string $username, string $remote): bool;
|
||||
|
||||
/**
|
||||
* Flush the privileges for a given connection.
|
||||
*/
|
||||
public function flush(): bool;
|
||||
|
||||
/**
|
||||
* Drop a given database on a specific connection.
|
||||
*/
|
||||
public function dropDatabase(string $database): bool;
|
||||
|
||||
/**
|
||||
* Drop a given user on a specific connection.
|
||||
*/
|
||||
public function dropUser(string $username, string $remote): bool;
|
||||
}
|
||||
38
app/Contracts/Repository/EggRepositoryInterface.php
Normal file
38
app/Contracts/Repository/EggRepositoryInterface.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
interface EggRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Return an egg with the variables relation attached.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithVariables(int $id): Egg;
|
||||
|
||||
/**
|
||||
* Return all eggs and their relations to be used in the daemon API.
|
||||
*/
|
||||
public function getAllWithCopyAttributes(): Collection;
|
||||
|
||||
/**
|
||||
* Return an egg with the scriptFrom and configFrom relations loaded onto the model.
|
||||
*/
|
||||
public function getWithCopyAttributes(int|string $value, string $column = 'id'): Egg;
|
||||
|
||||
/**
|
||||
* Return all the data needed to export a service.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithExportAttributes(int $id): Egg;
|
||||
|
||||
/**
|
||||
* Confirm a copy script belongs to the same nest as the item trying to use it.
|
||||
*/
|
||||
public function isCopyableScript(int $copyFromId, int $service): bool;
|
||||
}
|
||||
14
app/Contracts/Repository/EggVariableRepositoryInterface.php
Normal file
14
app/Contracts/Repository/EggVariableRepositoryInterface.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
interface EggVariableRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Return editable variables for a given egg. Editable variables must be set to
|
||||
* user viewable in order to be picked up by this function.
|
||||
*/
|
||||
public function getEditableVariables(int $egg): Collection;
|
||||
}
|
||||
33
app/Contracts/Repository/LocationRepositoryInterface.php
Normal file
33
app/Contracts/Repository/LocationRepositoryInterface.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Models\Location;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
interface LocationRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Return locations with a count of nodes and servers attached to it.
|
||||
*/
|
||||
public function getAllWithDetails(): Collection;
|
||||
|
||||
/**
|
||||
* Return all the available locations with the nodes as a relationship.
|
||||
*/
|
||||
public function getAllWithNodes(): Collection;
|
||||
|
||||
/**
|
||||
* Return all the nodes and their respective count of servers for a location.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithNodes(int $id): Location;
|
||||
|
||||
/**
|
||||
* Return a location and the count of nodes in that location.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithNodeCount(int $id): Location;
|
||||
}
|
||||
30
app/Contracts/Repository/NestRepositoryInterface.php
Normal file
30
app/Contracts/Repository/NestRepositoryInterface.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
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.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithEggs(int $id = null): Collection|Nest;
|
||||
|
||||
/**
|
||||
* Return a nest or all nests and the count of eggs and servers for that nest.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithCounts(int $id = null): Collection|Nest;
|
||||
|
||||
/**
|
||||
* Return a nest along with its associated eggs and the servers relation on those eggs.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithEggServers(int $id): Nest;
|
||||
}
|
||||
38
app/Contracts/Repository/NodeRepositoryInterface.php
Normal file
38
app/Contracts/Repository/NodeRepositoryInterface.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
interface NodeRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
public const THRESHOLD_PERCENTAGE_LOW = 75;
|
||||
public const THRESHOLD_PERCENTAGE_MEDIUM = 90;
|
||||
|
||||
/**
|
||||
* Return the usage stats for a single node.
|
||||
*/
|
||||
public function getUsageStats(Node $node): array;
|
||||
|
||||
/**
|
||||
* Return the usage stats for a single node.
|
||||
*/
|
||||
public function getUsageStatsRaw(Node $node): array;
|
||||
|
||||
/**
|
||||
* Return a single node with location and server information.
|
||||
*/
|
||||
public function loadLocationAndServerCount(Node $node, bool $refresh = false): Node;
|
||||
|
||||
/**
|
||||
* Attach a paginated set of allocations to a node mode including
|
||||
* any servers that are also attached to those allocations.
|
||||
*/
|
||||
public function loadNodeAllocations(Node $node, bool $refresh = false): Node;
|
||||
|
||||
/**
|
||||
* Return a collection of nodes for all locations to use in server creation UI.
|
||||
*/
|
||||
public function getNodesForServerCreation(): Collection;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
interface PermissionRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
}
|
||||
141
app/Contracts/Repository/RepositoryInterface.php
Normal file
141
app/Contracts/Repository/RepositoryInterface.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
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.
|
||||
*/
|
||||
public function model(): string;
|
||||
|
||||
/**
|
||||
* Return the model being used for this repository instance.
|
||||
*/
|
||||
public function getModel(): Model;
|
||||
|
||||
/**
|
||||
* Returns an instance of a query builder.
|
||||
*/
|
||||
public function getBuilder(): Builder;
|
||||
|
||||
/**
|
||||
* Returns the columns to be selected or returned by the query.
|
||||
*/
|
||||
public function getColumns(): array;
|
||||
|
||||
/**
|
||||
* An array of columns to filter the response by.
|
||||
*/
|
||||
public function setColumns(array|string $columns = ['*']): self;
|
||||
|
||||
/**
|
||||
* Stop repository update functions from returning a fresh
|
||||
* model when changes are committed.
|
||||
*/
|
||||
public function withoutFreshModel(): self;
|
||||
|
||||
/**
|
||||
* Return a fresh model with a repository updates a model.
|
||||
*/
|
||||
public function withFreshModel(): self;
|
||||
|
||||
/**
|
||||
* Set whether the repository should return a fresh model
|
||||
* when changes are committed.
|
||||
*/
|
||||
public function setFreshModel(bool $fresh = true): self;
|
||||
|
||||
/**
|
||||
* Create a new model instance and persist it to the database.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function create(array $fields, bool $validate = true, bool $force = false): mixed;
|
||||
|
||||
/**
|
||||
* Find a model that has the specific ID passed.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function find(int $id): mixed;
|
||||
|
||||
/**
|
||||
* Find a model matching an array of where clauses.
|
||||
*/
|
||||
public function findWhere(array $fields): Collection;
|
||||
|
||||
/**
|
||||
* Find and return the first matching instance for the given fields.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function findFirstWhere(array $fields): mixed;
|
||||
|
||||
/**
|
||||
* Return a count of records matching the passed arguments.
|
||||
*/
|
||||
public function findCountWhere(array $fields): int;
|
||||
|
||||
/**
|
||||
* Delete a given record from the database.
|
||||
*/
|
||||
public function delete(int $id): int;
|
||||
|
||||
/**
|
||||
* Delete records matching the given attributes.
|
||||
*/
|
||||
public function deleteWhere(array $attributes): int;
|
||||
|
||||
/**
|
||||
* Update a given ID with the passed array of fields.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
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.
|
||||
* This does not perform any model data validation.
|
||||
*/
|
||||
public function updateWhereIn(string $column, array $values, array $fields): int;
|
||||
|
||||
/**
|
||||
* Update a record if it exists in the database, otherwise create it.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function updateOrCreate(array $where, array $fields, bool $validate = true, bool $force = false): mixed;
|
||||
|
||||
/**
|
||||
* Return all records associated with the given model.
|
||||
*/
|
||||
public function all(): Collection;
|
||||
|
||||
/**
|
||||
* Return a paginated result set using a search term if set on the repository.
|
||||
*/
|
||||
public function paginated(int $perPage): LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* Insert a single or multiple records into the database at once skipping
|
||||
* validation and mass assignment checking.
|
||||
*/
|
||||
public function insert(array $data): bool;
|
||||
|
||||
/**
|
||||
* Insert multiple records into the database and ignore duplicates.
|
||||
*/
|
||||
public function insertIgnore(array $values): bool;
|
||||
|
||||
/**
|
||||
* Get the amount of entries in the database.
|
||||
*/
|
||||
public function count(): int;
|
||||
}
|
||||
21
app/Contracts/Repository/ScheduleRepositoryInterface.php
Normal file
21
app/Contracts/Repository/ScheduleRepositoryInterface.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
interface ScheduleRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Return all the schedules for a given server.
|
||||
*/
|
||||
public function findServerSchedules(int $server): Collection;
|
||||
|
||||
/**
|
||||
* Return a schedule model with all the associated tasks as a relationship.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getScheduleWithTasks(int $schedule): Schedule;
|
||||
}
|
||||
73
app/Contracts/Repository/ServerRepositoryInterface.php
Normal file
73
app/Contracts/Repository/ServerRepositoryInterface.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface ServerRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Load the egg relations onto the server model.
|
||||
*/
|
||||
public function loadEggRelations(Server $server, bool $refresh = false): Server;
|
||||
|
||||
/**
|
||||
* Return a collection of servers with their associated data for rebuild operations.
|
||||
*/
|
||||
public function getDataForRebuild(int $server = null, int $node = null): Collection;
|
||||
|
||||
/**
|
||||
* Return a collection of servers with their associated data for reinstall operations.
|
||||
*/
|
||||
public function getDataForReinstall(int $server = null, int $node = null): Collection;
|
||||
|
||||
/**
|
||||
* Return a server model and all variables associated with the server.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function findWithVariables(int $id): Server;
|
||||
|
||||
/**
|
||||
* Get the primary allocation for a given server. If a model is passed into
|
||||
* the function, load the allocation relationship onto it. Otherwise, find and
|
||||
* return the server from the database.
|
||||
*/
|
||||
public function getPrimaryAllocation(Server $server, bool $refresh = false): Server;
|
||||
|
||||
/**
|
||||
* Return enough data to be used for the creation of a server via the daemon.
|
||||
*/
|
||||
public function getDataForCreation(Server $server, bool $refresh = false): Server;
|
||||
|
||||
/**
|
||||
* Load associated databases onto the server model.
|
||||
*/
|
||||
public function loadDatabaseRelations(Server $server, bool $refresh = false): Server;
|
||||
|
||||
/**
|
||||
* Get data for use when updating a server on the Daemon. Returns an array of
|
||||
* the egg which is used for build and rebuild. Only loads relations
|
||||
* if they are missing, or refresh is set to true.
|
||||
*/
|
||||
public function getDaemonServiceData(Server $server, bool $refresh = false): array;
|
||||
|
||||
/**
|
||||
* Return a server by UUID.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getByUuid(string $uuid): Server;
|
||||
|
||||
/**
|
||||
* Check if a given UUID and UUID-Short string are unique to a server.
|
||||
*/
|
||||
public function isUniqueUuidCombo(string $uuid, string $short): bool;
|
||||
|
||||
/**
|
||||
* Returns all the servers that exist for a given node in a paginated response.
|
||||
*/
|
||||
public function loadAllServersForNode(int $node, int $limit): LengthAwarePaginator;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
interface ServerVariableRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
}
|
||||
18
app/Contracts/Repository/SessionRepositoryInterface.php
Normal file
18
app/Contracts/Repository/SessionRepositoryInterface.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
interface SessionRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Return all the active sessions for a user.
|
||||
*/
|
||||
public function getUserSessions(int $user): Collection;
|
||||
|
||||
/**
|
||||
* Delete a session for a given user.
|
||||
*/
|
||||
public function deleteUserSession(int $user, string $session): ?int;
|
||||
}
|
||||
24
app/Contracts/Repository/SettingsRepositoryInterface.php
Normal file
24
app/Contracts/Repository/SettingsRepositoryInterface.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
interface SettingsRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Store a new persistent setting in the database.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function set(string $key, string $value = null);
|
||||
|
||||
/**
|
||||
* Retrieve a persistent setting from the database.
|
||||
*/
|
||||
public function get(string $key, mixed $default): mixed;
|
||||
|
||||
/**
|
||||
* Remove a key from the database cache.
|
||||
*/
|
||||
public function forget(string $key);
|
||||
}
|
||||
25
app/Contracts/Repository/SubuserRepositoryInterface.php
Normal file
25
app/Contracts/Repository/SubuserRepositoryInterface.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Models\Subuser;
|
||||
|
||||
interface SubuserRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Return a subuser with the associated server relationship.
|
||||
*/
|
||||
public function loadServerAndUserRelations(Subuser $subuser, bool $refresh = false): Subuser;
|
||||
|
||||
/**
|
||||
* Return a subuser with the associated permissions relationship.
|
||||
*/
|
||||
public function getWithPermissions(Subuser $subuser, bool $refresh = false): Subuser;
|
||||
|
||||
/**
|
||||
* Return a subuser and associated permissions given a user_id and server_id.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithPermissionsUsingUserAndServer(int $user, int $server): Subuser;
|
||||
}
|
||||
20
app/Contracts/Repository/TaskRepositoryInterface.php
Normal file
20
app/Contracts/Repository/TaskRepositoryInterface.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Models\Task;
|
||||
|
||||
interface TaskRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get a task and the server relationship for that task.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getTaskForJobProcess(int $id): Task;
|
||||
|
||||
/**
|
||||
* Returns the next task in a schedule.
|
||||
*/
|
||||
public function getNextTask(int $schedule, int $index): ?Task;
|
||||
}
|
||||
7
app/Contracts/Repository/UserRepositoryInterface.php
Normal file
7
app/Contracts/Repository/UserRepositoryInterface.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
interface UserRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
}
|
||||
34
app/Events/ActivityLogged.php
Normal file
34
app/Events/ActivityLogged.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Pterodactyl\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ActivityLogged extends Event
|
||||
{
|
||||
public function __construct(public ActivityLog $model)
|
||||
{
|
||||
}
|
||||
|
||||
public function is(string $event): bool
|
||||
{
|
||||
return $this->model->event === $event;
|
||||
}
|
||||
|
||||
public function actor(): ?Model
|
||||
{
|
||||
return $this->isSystem() ? null : $this->model->actor;
|
||||
}
|
||||
|
||||
public function isServerEvent(): bool
|
||||
{
|
||||
return Str::startsWith($this->model->event, 'server:');
|
||||
}
|
||||
|
||||
public function isSystem(): bool
|
||||
{
|
||||
return is_null($this->model->actor_id);
|
||||
}
|
||||
}
|
||||
13
app/Events/Auth/DirectLogin.php
Normal file
13
app/Events/Auth/DirectLogin.php
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
18
app/Events/Auth/FailedCaptcha.php
Normal file
18
app/Events/Auth/FailedCaptcha.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Auth;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class FailedCaptcha extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public string $ip, public string $domain)
|
||||
{
|
||||
}
|
||||
}
|
||||
18
app/Events/Auth/FailedPasswordReset.php
Normal file
18
app/Events/Auth/FailedPasswordReset.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Auth;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class FailedPasswordReset extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public string $ip, public string $email)
|
||||
{
|
||||
}
|
||||
}
|
||||
13
app/Events/Auth/ProvidedAuthenticationToken.php
Normal file
13
app/Events/Auth/ProvidedAuthenticationToken.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Auth;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Events\Event;
|
||||
|
||||
class ProvidedAuthenticationToken extends Event
|
||||
{
|
||||
public function __construct(public User $user, public bool $recovery = false)
|
||||
{
|
||||
}
|
||||
}
|
||||
7
app/Events/Event.php
Normal file
7
app/Events/Event.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events;
|
||||
|
||||
abstract class Event
|
||||
{
|
||||
}
|
||||
19
app/Events/Server/Created.php
Normal file
19
app/Events/Server/Created.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Server;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Created extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Server $server)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Server/Creating.php
Normal file
19
app/Events/Server/Creating.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Server;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Creating extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Server $server)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Server/Deleted.php
Normal file
19
app/Events/Server/Deleted.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Server;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Deleted extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Server $server)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Server/Deleting.php
Normal file
19
app/Events/Server/Deleting.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Server;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Deleting extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Server $server)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Server/Installed.php
Normal file
19
app/Events/Server/Installed.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Server;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Installed extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Server $server)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Server/Saved.php
Normal file
19
app/Events/Server/Saved.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Server;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Saved extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Server $server)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Server/Saving.php
Normal file
19
app/Events/Server/Saving.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Server;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Saving extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Server $server)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Server/Updated.php
Normal file
19
app/Events/Server/Updated.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Server;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Updated extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Server $server)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Server/Updating.php
Normal file
19
app/Events/Server/Updating.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Server;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Updating extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Server $server)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Subuser/Created.php
Normal file
19
app/Events/Subuser/Created.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Subuser;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Subuser;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Created extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Subuser $subuser)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Subuser/Creating.php
Normal file
19
app/Events/Subuser/Creating.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Subuser;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Subuser;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Creating extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Subuser $subuser)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Subuser/Deleted.php
Normal file
19
app/Events/Subuser/Deleted.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Subuser;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Subuser;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Deleted extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Subuser $subuser)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/Subuser/Deleting.php
Normal file
19
app/Events/Subuser/Deleting.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\Subuser;
|
||||
|
||||
use Pterodactyl\Events\Event;
|
||||
use Pterodactyl\Models\Subuser;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Deleting extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Subuser $subuser)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/User/Created.php
Normal file
19
app/Events/User/Created.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\User;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Events\Event;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Created extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public User $user)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/User/Creating.php
Normal file
19
app/Events/User/Creating.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\User;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Events\Event;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Creating extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public User $user)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/User/Deleted.php
Normal file
19
app/Events/User/Deleted.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\User;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Events\Event;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Deleted extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public User $user)
|
||||
{
|
||||
}
|
||||
}
|
||||
19
app/Events/User/Deleting.php
Normal file
19
app/Events/User/Deleting.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Events\User;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Events\Event;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Deleting extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public User $user)
|
||||
{
|
||||
}
|
||||
}
|
||||
7
app/Exceptions/AccountNotFoundException.php
Normal file
7
app/Exceptions/AccountNotFoundException.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions;
|
||||
|
||||
class AccountNotFoundException extends \Exception
|
||||
{
|
||||
}
|
||||
7
app/Exceptions/AutoDeploymentException.php
Normal file
7
app/Exceptions/AutoDeploymentException.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions;
|
||||
|
||||
class AutoDeploymentException extends \Exception
|
||||
{
|
||||
}
|
||||
81
app/Exceptions/DisplayException.php
Normal file
81
app/Exceptions/DisplayException.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions;
|
||||
|
||||
use Exception;
|
||||
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;
|
||||
|
||||
class DisplayException extends PterodactylException implements HttpExceptionInterface
|
||||
{
|
||||
public const LEVEL_DEBUG = 'debug';
|
||||
public const LEVEL_INFO = 'info';
|
||||
public const LEVEL_WARNING = 'warning';
|
||||
public const LEVEL_ERROR = 'error';
|
||||
|
||||
/**
|
||||
* DisplayException constructor.
|
||||
*/
|
||||
public function __construct(string $message, ?\Throwable $previous = null, protected string $level = self::LEVEL_ERROR, int $code = 0)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getErrorLevel(): string
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
public function getStatusCode(): int
|
||||
{
|
||||
return Response::HTTP_BAD_REQUEST;
|
||||
}
|
||||
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function render(Request $request): JsonResponse|RedirectResponse
|
||||
{
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json(Handler::toArray($this), $this->getStatusCode(), $this->getHeaders());
|
||||
}
|
||||
|
||||
app(AlertsMessageBag::class)->danger($this->getMessage())->flash();
|
||||
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the exception to the logs using the defined error level only if the previous
|
||||
* exception is set.
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function report()
|
||||
{
|
||||
if (!$this->getPrevious() instanceof \Exception || !Handler::isReportable($this->getPrevious())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$logger = Container::getInstance()->make(LoggerInterface::class);
|
||||
} catch (Exception) {
|
||||
throw $this->getPrevious();
|
||||
}
|
||||
|
||||
return $logger->{$this->getErrorLevel()}($this->getPrevious());
|
||||
}
|
||||
}
|
||||
283
app/Exceptions/Handler.php
Normal file
283
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
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;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
private const PTERODACTYL_RULE_STRING = 'pterodactyl\_rules\_';
|
||||
|
||||
/**
|
||||
* A list of the exception types that should not be reported.
|
||||
*/
|
||||
protected $dontReport = [
|
||||
AuthenticationException::class,
|
||||
AuthorizationException::class,
|
||||
HttpException::class,
|
||||
ModelNotFoundException::class,
|
||||
RecordNotFoundException::class,
|
||||
TokenMismatchException::class,
|
||||
ValidationException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Maps exceptions to a specific response code. This handles special exception
|
||||
* types that don't have a defined response code.
|
||||
*/
|
||||
protected static array $exceptionResponseCodes = [
|
||||
AuthenticationException::class => 401,
|
||||
AuthorizationException::class => 403,
|
||||
ValidationException::class => 422,
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'token',
|
||||
'secret',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Registers the exception handling callbacks for the application. This
|
||||
* will capture specific exception types that we do not want to include
|
||||
* the detailed stack traces for since they could reveal credentials to
|
||||
* whoever can read the logs.
|
||||
*
|
||||
* @noinspection PhpUnusedLocalVariableInspection
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
if (config('app.exceptions.report_all', false)) {
|
||||
$this->dontReport = [];
|
||||
}
|
||||
|
||||
$this->reportable(function (\PDOException $ex) {
|
||||
$ex = $this->generateCleanedExceptionStack($ex);
|
||||
});
|
||||
|
||||
$this->reportable(function (TransportException $ex) {
|
||||
$ex = $this->generateCleanedExceptionStack($ex);
|
||||
});
|
||||
}
|
||||
|
||||
private function generateCleanedExceptionStack(\Throwable $exception): string
|
||||
{
|
||||
$cleanedStack = '';
|
||||
foreach ($exception->getTrace() as $index => $item) {
|
||||
$cleanedStack .= sprintf(
|
||||
"#%d %s(%d): %s%s%s\n",
|
||||
$index,
|
||||
Arr::get($item, 'file'),
|
||||
Arr::get($item, 'line'),
|
||||
Arr::get($item, 'class'),
|
||||
Arr::get($item, 'type'),
|
||||
Arr::get($item, 'function')
|
||||
);
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
'%s: %s in %s:%d',
|
||||
class_basename($exception),
|
||||
$exception->getMessage(),
|
||||
$exception->getFile(),
|
||||
$exception->getLine()
|
||||
);
|
||||
|
||||
return $message . "\nStack trace:\n" . trim($cleanedStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function render($request, \Throwable $e): Response
|
||||
{
|
||||
$connections = $this->container->make(Connection::class);
|
||||
|
||||
// If we are currently wrapped up inside a transaction, we will roll all the way
|
||||
// back to the beginning. This needs to happen, otherwise session data does not
|
||||
// get properly persisted.
|
||||
//
|
||||
// This is kind of a hack, and ideally things like this should be handled as
|
||||
// much as possible at the code level, but there are a lot of spots that do a
|
||||
// ton of actions and were written before this bug discovery was made.
|
||||
//
|
||||
// @see https://github.com/pterodactyl/panel/pull/1468
|
||||
if ($connections->transactionLevel()) {
|
||||
$connections->rollBack(0);
|
||||
}
|
||||
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a validation exception into a consistent format to be returned for
|
||||
* calls to the API.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*/
|
||||
public function invalidJson($request, ValidationException $exception): JsonResponse
|
||||
{
|
||||
$codes = Collection::make($exception->validator->failed())->mapWithKeys(function ($reasons, $field) {
|
||||
$cleaned = [];
|
||||
foreach ($reasons as $reason => $attrs) {
|
||||
$cleaned[] = Str::snake($reason);
|
||||
}
|
||||
|
||||
return [str_replace('.', '_', $field) => $cleaned];
|
||||
})->toArray();
|
||||
|
||||
$errors = Collection::make($exception->errors())->map(function ($errors, $field) use ($codes, $exception) {
|
||||
$response = [];
|
||||
foreach ($errors as $key => $error) {
|
||||
$meta = [
|
||||
'source_field' => $field,
|
||||
'rule' => str_replace(self::PTERODACTYL_RULE_STRING, 'p_', Arr::get(
|
||||
$codes,
|
||||
str_replace('.', '_', $field) . '.' . $key
|
||||
)),
|
||||
];
|
||||
|
||||
$converted = $this->convertExceptionToArray($exception)['errors'][0];
|
||||
$converted['detail'] = $error;
|
||||
$converted['meta'] = array_merge($converted['meta'] ?? [], $meta);
|
||||
|
||||
$response[] = $converted;
|
||||
}
|
||||
|
||||
return $response;
|
||||
})->flatMap(function ($errors) {
|
||||
return $errors;
|
||||
})->toArray();
|
||||
|
||||
return response()->json(['errors' => $errors], $exception->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the exception as a JSONAPI representation for use on API requests.
|
||||
*/
|
||||
protected function convertExceptionToArray(\Throwable $e, array $override = []): array
|
||||
{
|
||||
$match = self::$exceptionResponseCodes[get_class($e)] ?? null;
|
||||
|
||||
$error = [
|
||||
'code' => class_basename($e),
|
||||
'status' => method_exists($e, 'getStatusCode')
|
||||
? strval($e->getStatusCode())
|
||||
: strval($match ?? '500'),
|
||||
'detail' => $e instanceof HttpExceptionInterface || !is_null($match)
|
||||
? $e->getMessage()
|
||||
: 'An unexpected error was encountered while processing this request, please try again.',
|
||||
];
|
||||
|
||||
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.
|
||||
$error['detail'] = 'The requested resource could not be found on the server.';
|
||||
}
|
||||
|
||||
if (config('app.debug')) {
|
||||
$error = array_merge($error, [
|
||||
'detail' => $e->getMessage(),
|
||||
'source' => [
|
||||
'line' => $e->getLine(),
|
||||
'file' => str_replace(Application::getInstance()->basePath(), '', $e->getFile()),
|
||||
],
|
||||
'meta' => [
|
||||
'trace' => Collection::make($e->getTrace())
|
||||
->map(fn ($trace) => Arr::except($trace, ['args']))
|
||||
->all(),
|
||||
'previous' => Collection::make($this->extractPrevious($e))
|
||||
->map(fn ($exception) => $e->getTrace())
|
||||
->map(fn ($trace) => Arr::except($trace, ['args']))
|
||||
->all(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
return ['errors' => [array_merge($error, $override)]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of exceptions that should not be reported.
|
||||
*/
|
||||
public static function isReportable(\Exception $exception): bool
|
||||
{
|
||||
return (new static(Container::getInstance()))->shouldReport($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an authentication exception into an unauthenticated response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*/
|
||||
protected function unauthenticated($request, AuthenticationException $exception): JsonResponse|RedirectResponse
|
||||
{
|
||||
if ($request->expectsJson()) {
|
||||
return new JsonResponse($this->convertExceptionToArray($exception), JsonResponse::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
return redirect()->guest('/auth/login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts all the previous exceptions that lead to the one passed into this
|
||||
* function being thrown.
|
||||
*
|
||||
* @return \Throwable[]
|
||||
*/
|
||||
protected function extractPrevious(\Throwable $e): array
|
||||
{
|
||||
$previous = [];
|
||||
while ($value = $e->getPrevious()) {
|
||||
if (!$value instanceof \Throwable) {
|
||||
break;
|
||||
}
|
||||
$previous[] = $value;
|
||||
$e = $value;
|
||||
}
|
||||
|
||||
return $previous;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to allow reaching into the handler to convert an exception
|
||||
* into the expected array response type.
|
||||
*/
|
||||
public static function toArray(\Throwable $e): array
|
||||
{
|
||||
return (new self(app()))->convertExceptionToArray($e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Http\Base;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
class InvalidPasswordProvidedException extends DisplayException
|
||||
{
|
||||
}
|
||||
90
app/Exceptions/Http/Connection/DaemonConnectionException.php
Normal file
90
app/Exceptions/Http/Connection/DaemonConnectionException.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Http\Connection;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
/**
|
||||
* @method \GuzzleHttp\Exception\GuzzleException getPrevious()
|
||||
*/
|
||||
class DaemonConnectionException extends DisplayException
|
||||
{
|
||||
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.
|
||||
*/
|
||||
private ?string $requestId;
|
||||
|
||||
/**
|
||||
* Throw a displayable exception caused by a daemon connection error.
|
||||
*/
|
||||
public function __construct(GuzzleException $previous, bool $useStatusCode = true)
|
||||
{
|
||||
/** @var \GuzzleHttp\Psr7\Response|null $response */
|
||||
$response = method_exists($previous, 'getResponse') ? $previous->getResponse() : null;
|
||||
$this->requestId = $response?->getHeaderLine('X-Request-Id');
|
||||
|
||||
if ($useStatusCode) {
|
||||
$this->statusCode = is_null($response) ? $this->statusCode : $response->getStatusCode();
|
||||
// There are rare conditions where wings encounters a panic condition and crashes the
|
||||
// request being made after content has already been sent over the wire. In these cases
|
||||
// you can end up with a "successful" response code that is actual an error.
|
||||
//
|
||||
// Handle those better here since we shouldn't ever end up in this exception state and
|
||||
// be returning a 2XX level response.
|
||||
if ($this->statusCode < 400) {
|
||||
$this->statusCode = Response::HTTP_BAD_GATEWAY;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($response)) {
|
||||
$message = 'Could not establish a connection to the machine running this server. Please try again.';
|
||||
} else {
|
||||
$message = sprintf('There was an error while communicating with the machine running this server. This error has been logged, please try again. (code: %s) (request_id: %s)', $response->getStatusCode(), $this->requestId ?? '<nil>');
|
||||
}
|
||||
|
||||
// Attempt to pull the actual error message off the response and return that if it is not
|
||||
// a 500 level error.
|
||||
if ($this->statusCode < 500 && !is_null($response)) {
|
||||
$body = json_decode($response->getBody()->__toString(), true);
|
||||
$message = sprintf('An error occurred on the remote host: %s. (request id: %s)', $body['error'] ?? $message, $this->requestId ?? '<nil>');
|
||||
}
|
||||
|
||||
$level = $this->statusCode >= 500 && $this->statusCode !== 504
|
||||
? DisplayException::LEVEL_ERROR
|
||||
: DisplayException::LEVEL_WARNING;
|
||||
|
||||
parent::__construct($message, $previous, $level);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function report()
|
||||
{
|
||||
Log::{$this->getErrorLevel()}($this->getPrevious(), [
|
||||
'request_id' => $this->requestId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTTP status code for this exception.
|
||||
*/
|
||||
public function getStatusCode(): int
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
|
||||
public function getRequestId(): ?string
|
||||
{
|
||||
return $this->requestId;
|
||||
}
|
||||
}
|
||||
17
app/Exceptions/Http/HttpForbiddenException.php
Normal file
17
app/Exceptions/Http/HttpForbiddenException.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Http;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class HttpForbiddenException extends HttpException
|
||||
{
|
||||
/**
|
||||
* HttpForbiddenException constructor.
|
||||
*/
|
||||
public function __construct(string $message = null, \Throwable $previous = null)
|
||||
{
|
||||
parent::__construct(Response::HTTP_FORBIDDEN, $message, $previous);
|
||||
}
|
||||
}
|
||||
16
app/Exceptions/Http/Server/FileSizeTooLargeException.php
Normal file
16
app/Exceptions/Http/Server/FileSizeTooLargeException.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Http\Server;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
class FileSizeTooLargeException extends DisplayException
|
||||
{
|
||||
/**
|
||||
* FileSizeTooLargeException constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('The file you are attempting to open is too large to view in the file editor.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Http\Server;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
class FileTypeNotEditableException extends DisplayException
|
||||
{
|
||||
}
|
||||
31
app/Exceptions/Http/Server/ServerStateConflictException.php
Normal file
31
app/Exceptions/Http/Server/ServerStateConflictException.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Http\Server;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||
|
||||
class ServerStateConflictException extends ConflictHttpException
|
||||
{
|
||||
/**
|
||||
* Exception thrown when the server is in an unsupported state for API access or
|
||||
* certain operations within the codebase.
|
||||
*/
|
||||
public function __construct(Server $server, \Throwable $previous = null)
|
||||
{
|
||||
$message = 'This server is currently in an unsupported state, please try again later.';
|
||||
if ($server->isSuspended()) {
|
||||
$message = 'This server is currently suspended and the functionality requested is unavailable.';
|
||||
} elseif ($server->node->isUnderMaintenance()) {
|
||||
$message = 'The node of this server is currently under maintenance and the functionality requested is unavailable.';
|
||||
} elseif (!$server->isInstalled()) {
|
||||
$message = 'This server has not yet completed its installation process, please try again later.';
|
||||
} elseif ($server->status === Server::STATUS_RESTORING_BACKUP) {
|
||||
$message = 'This server is currently restoring from a backup, please try again later.';
|
||||
} elseif (!is_null($server->transfer)) {
|
||||
$message = 'This server is currently being transferred to a new machine, please try again later.';
|
||||
}
|
||||
|
||||
parent::__construct($message, $previous);
|
||||
}
|
||||
}
|
||||
18
app/Exceptions/Http/TwoFactorAuthRequiredException.php
Normal file
18
app/Exceptions/Http/TwoFactorAuthRequiredException.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Http;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
|
||||
class TwoFactorAuthRequiredException extends HttpException implements HttpExceptionInterface
|
||||
{
|
||||
/**
|
||||
* TwoFactorAuthRequiredException constructor.
|
||||
*/
|
||||
public function __construct(\Throwable $previous = null)
|
||||
{
|
||||
parent::__construct(Response::HTTP_BAD_REQUEST, 'Two-factor authentication is required on this account in order to access this endpoint.', $previous);
|
||||
}
|
||||
}
|
||||
14
app/Exceptions/ManifestDoesNotExistException.php
Normal file
14
app/Exceptions/ManifestDoesNotExistException.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions;
|
||||
|
||||
use Spatie\Ignition\Contracts\Solution;
|
||||
use Spatie\Ignition\Contracts\ProvidesSolution;
|
||||
|
||||
class ManifestDoesNotExistException extends \Exception implements ProvidesSolution
|
||||
{
|
||||
public function getSolution(): Solution
|
||||
{
|
||||
return new Solutions\ManifestDoesNotExistSolution();
|
||||
}
|
||||
}
|
||||
59
app/Exceptions/Model/DataValidationException.php
Normal file
59
app/Exceptions/Model/DataValidationException.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Model;
|
||||
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Pterodactyl\Exceptions\PterodactylException;
|
||||
use Illuminate\Contracts\Support\MessageProvider;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
|
||||
class DataValidationException extends PterodactylException implements HttpExceptionInterface, MessageProvider
|
||||
{
|
||||
/**
|
||||
* DataValidationException constructor.
|
||||
*/
|
||||
public function __construct(protected Validator $validator, protected Model $model)
|
||||
{
|
||||
$message = sprintf(
|
||||
'Could not save %s[%s]: failed to validate data: %s',
|
||||
get_class($model),
|
||||
$model->getKey(),
|
||||
$validator->errors()->toJson()
|
||||
);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the validator message bag.
|
||||
*/
|
||||
public function getMessageBag(): MessageBag
|
||||
{
|
||||
return $this->validator->errors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the status code for this request.
|
||||
*/
|
||||
public function getStatusCode(): int
|
||||
{
|
||||
return 500;
|
||||
}
|
||||
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getValidator(): Validator
|
||||
{
|
||||
return $this->validator;
|
||||
}
|
||||
|
||||
public function getModel(): Model
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
7
app/Exceptions/PterodactylException.php
Normal file
7
app/Exceptions/PterodactylException.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions;
|
||||
|
||||
class PterodactylException extends \Exception
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Repository\Daemon;
|
||||
|
||||
use Pterodactyl\Exceptions\Repository\RepositoryException;
|
||||
|
||||
class InvalidPowerSignalException extends RepositoryException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Repository;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
class DuplicateDatabaseNameException extends DisplayException
|
||||
{
|
||||
}
|
||||
25
app/Exceptions/Repository/RecordNotFoundException.php
Normal file
25
app/Exceptions/Repository/RecordNotFoundException.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Repository;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
|
||||
class RecordNotFoundException extends RepositoryException implements HttpExceptionInterface
|
||||
{
|
||||
/**
|
||||
* Returns the status code.
|
||||
*/
|
||||
public function getStatusCode(): int
|
||||
{
|
||||
return Response::HTTP_NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns response headers.
|
||||
*/
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
9
app/Exceptions/Repository/RepositoryException.php
Normal file
9
app/Exceptions/Repository/RepositoryException.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Repository;
|
||||
|
||||
use Pterodactyl\Exceptions\PterodactylException;
|
||||
|
||||
class RepositoryException extends PterodactylException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Service\Allocation;
|
||||
|
||||
use Pterodactyl\Exceptions\PterodactylException;
|
||||
|
||||
class AllocationDoesNotBelongToServerException extends PterodactylException
|
||||
{
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user