Merge branch 'develop' into dane/restore-backups

This commit is contained in:
Dane Everitt 2021-01-30 10:10:29 -08:00
commit be26921fcc
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
41 changed files with 440 additions and 362 deletions

View file

@ -34,7 +34,7 @@ jobs:
- name: Create release archive
run: |
rm -rf node_modules/ test/ codecov.yml CODE_OF_CONDUCT.md CONTRIBUTING.md phpunit.dusk.xml phpunit.xml Vagrantfile
tar -czf panel.tar.gz * .env.example
tar -czf panel.tar.gz * .env.example .babel-plugin-macrosrc.js
- name: Extract changelog
id: extract_changelog

View file

@ -23,6 +23,17 @@ return (new Config())
'ordered_imports' => [
'sortAlgorithm' => 'length',
],
'phpdoc_align' => [
'align' => 'left',
'tags' => [
'param',
'property',
'return',
'throws',
'type',
'var',
],
],
'random_api_migration' => true,
'ternary_to_null_coalescing' => true,
'yoda_style' => [

View file

@ -22,7 +22,7 @@ class EggFormRequest extends AdminFormRequest
'name' => 'required|string|max:191',
'description' => 'nullable|string',
'docker_images' => 'required|string',
'file_denylist' => 'string',
'file_denylist' => 'array',
'startup' => 'required|string',
'config_from' => 'sometimes|bail|nullable|numeric',
'config_stop' => 'required_without:config_from|nullable|string|max:191',

View file

@ -13,7 +13,7 @@ namespace Pterodactyl\Models;
* @property string $docker_image -- deprecated, use $docker_images
* @property string $update_url
* @property array $docker_images
* @property string $file_denylist
* @property array|null $file_denylist
* @property string|null $config_files
* @property string|null $config_startup
* @property string|null $config_logs
@ -105,6 +105,7 @@ class Egg extends Model
'copy_script_from' => 'integer',
'features' => 'array',
'docker_images' => 'array',
'file_denylist' => 'array',
];
/**
@ -117,6 +118,8 @@ class Egg extends Model
'description' => 'string|nullable',
'features' => 'array|nullable',
'author' => 'required|string|email',
'file_denylist' => 'array|nullable',
'file_denylist.*' => 'string',
'docker_images' => 'required|array|min:1',
'docker_images.*' => 'required|string',
'startup' => 'required|nullable|string',
@ -133,6 +136,7 @@ class Egg extends Model
*/
protected $attributes = [
'features' => null,
'file_denylist' => null,
'config_stop' => null,
'config_startup' => null,
'config_logs' => null,
@ -260,7 +264,7 @@ class Egg extends Model
* Returns the features available to this egg from the parent configuration if there are
* no features defined for this egg specifically and there is a parent egg configured.
*
* @return string
* @return string[]|null
*/
public function getInheritFileDenylistAttribute()
{

View file

@ -2,8 +2,16 @@
namespace Pterodactyl\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $server_id
* @property int $variable_id
* @property string $variable_value
* @property \Carbon\CarbonImmutable|null $created_at
* @property \Carbon\CarbonImmutable|null $updated_at
* @property \Pterodactyl\Models\EggVariable $variable
* @property \Pterodactyl\Models\Server $server
*/
class ServerVariable extends Model
{
/**
@ -12,58 +20,36 @@ class ServerVariable extends Model
*/
public const RESOURCE_NAME = 'server_variable';
/**
* The table associated with the model.
*
* @var string
*/
/** @var bool */
protected $immutableDates = true;
/** @var string */
protected $table = 'server_variables';
/**
* Fields that are not mass assignable.
*
* @var array
*/
/** @var string[] */
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Cast values to correct type.
*
* @var array
*/
/** @var string[] */
protected $casts = [
'server_id' => 'integer',
'variable_id' => 'integer',
];
/**
* Determine if variable is viewable by users.
*
* @return bool
*/
public function getUserCanViewAttribute()
{
return (bool) $this->variable->user_viewable;
}
/** @var string[] */
public static $validationRules = [
'server_id' => 'required|int',
'variable_id' => 'required|int',
'variable_value' => 'string',
];
/**
* Determine if variable is editable by users.
* Returns the server this variable is associated with.
*
* @return bool
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function getUserCanEditAttribute()
public function server()
{
return (bool) $this->variable->user_editable;
}
/**
* Determine if variable is required.
*
* @return bool
*/
public function getRequiredAttribute()
{
return $this->variable->required;
return $this->belongsTo(Server::class);
}
/**

View file

@ -3,6 +3,8 @@
namespace Pterodactyl\Services\Eggs\Sharing;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
class EggExporterService
@ -41,7 +43,9 @@ class EggExporterService
'description' => $egg->description,
'features' => $egg->features,
'images' => $egg->docker_images,
'file_denylist' => $egg->inherit_file_denylist,
'file_denylist' => Collection::make($egg->inherit_file_denylist)->filter(function ($value) {
return !empty($value);
}),
'startup' => $egg->startup,
'config' => [
'files' => $egg->inherit_config_files,
@ -56,10 +60,10 @@ class EggExporterService
'entrypoint' => $egg->copy_script_entry,
],
],
'variables' => $egg->variables->transform(function ($item) {
return collect($item->toArray())->except([
'id', 'egg_id', 'created_at', 'updated_at',
])->toArray();
'variables' => $egg->variables->transform(function (EggVariable $item) {
return Collection::make($item->toArray())
->except(['id', 'egg_id', 'created_at', 'updated_at'])
->toArray();
}),
];

View file

@ -3,8 +3,10 @@
namespace Pterodactyl\Services\Eggs\Sharing;
use Ramsey\Uuid\Uuid;
use Illuminate\Support\Arr;
use Pterodactyl\Models\Egg;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Collection;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
@ -63,43 +65,47 @@ class EggImporterService
throw new InvalidFileUploadException(sprintf('The selected file ["%s"] was not in a valid format to import. (is_file: %s is_valid: %s err_code: %s err: %s)', $file->getFilename(), $file->isFile() ? 'true' : 'false', $file->isValid() ? 'true' : 'false', $file->getError(), $file->getErrorMessage()));
}
$parsed = json_decode($file->openFile()->fread($file->getSize()));
/** @var array $parsed */
$parsed = json_decode($file->openFile()->fread($file->getSize()), true);
if (json_last_error() !== 0) {
throw new BadJsonFormatException(trans('exceptions.nest.importer.json_error', ['error' => json_last_error_msg()]));
}
if (object_get($parsed, 'meta.version') !== 'PTDL_v1') {
if (Arr::get($parsed, 'meta.version') !== 'PTDL_v1') {
throw new InvalidFileUploadException(trans('exceptions.nest.importer.invalid_json_provided'));
}
$nest = $this->nestRepository->getWithEggs($nest);
$this->connection->beginTransaction();
/** @var \Pterodactyl\Models\Egg $egg */
$egg = $this->repository->create([
'uuid' => Uuid::uuid4()->toString(),
'nest_id' => $nest->id,
'author' => object_get($parsed, 'author'),
'name' => object_get($parsed, 'name'),
'description' => object_get($parsed, 'description'),
'features' => object_get($parsed, 'features'),
'author' => Arr::get($parsed, 'author'),
'name' => Arr::get($parsed, 'name'),
'description' => Arr::get($parsed, 'description'),
'features' => Arr::get($parsed, 'features'),
// Maintain backwards compatability for eggs that are still using the old single image
// string format. New eggs can provide an array of Docker images that can be used.
'docker_images' => object_get($parsed, 'images') ?? [object_get($parsed, 'image')],
'file_denylist' => implode(PHP_EOL, object_get($parsed, 'file_denylist') ?? []),
'update_url' => object_get($parsed, 'meta.update_url'),
'config_files' => object_get($parsed, 'config.files'),
'config_startup' => object_get($parsed, 'config.startup'),
'config_logs' => object_get($parsed, 'config.logs'),
'config_stop' => object_get($parsed, 'config.stop'),
'startup' => object_get($parsed, 'startup'),
'script_install' => object_get($parsed, 'scripts.installation.script'),
'script_entry' => object_get($parsed, 'scripts.installation.entrypoint'),
'script_container' => object_get($parsed, 'scripts.installation.container'),
'docker_images' => Arr::get($parsed, 'images') ?? [Arr::get($parsed, 'image')],
'file_denylist' => Collection::make(Arr::get($parsed, 'file_denylist'))->filter(function ($value) {
return !empty($value);
}),
'update_url' => Arr::get($parsed, 'meta.update_url'),
'config_files' => Arr::get($parsed, 'config.files'),
'config_startup' => Arr::get($parsed, 'config.startup'),
'config_logs' => Arr::get($parsed, 'config.logs'),
'config_stop' => Arr::get($parsed, 'config.stop'),
'startup' => Arr::get($parsed, 'startup'),
'script_install' => Arr::get($parsed, 'scripts.installation.script'),
'script_entry' => Arr::get($parsed, 'scripts.installation.entrypoint'),
'script_container' => Arr::get($parsed, 'scripts.installation.container'),
'copy_script_from' => null,
], true, true);
collect($parsed->variables)->each(function ($variable) use ($egg) {
$this->eggVariableRepository->create(array_merge((array) $variable, [
Collection::make($parsed['variables'] ?? [])->each(function (array $variable) use ($egg) {
$this->eggVariableRepository->create(array_merge($variable, [
'egg_id' => $egg->id,
]));
});

View file

@ -80,7 +80,7 @@ class ServerConfigurationStructureService
}),
'egg' => [
'id' => $server->egg->uuid,
'file_denylist' => explode(PHP_EOL, $server->egg->inherit_file_denylist),
'file_denylist' => $server->egg->inherit_file_denylist,
],
];
}

View file

@ -258,7 +258,7 @@ class ServerCreationService
return [
'server_id' => $server->id,
'variable_id' => $result->id,
'variable_value' => $result->value,
'variable_value' => $result->value ?? '',
];
})->toArray();

View file

@ -16,7 +16,11 @@ class EggTransformer extends BaseTransformer
* @var array
*/
protected $availableIncludes = [
'nest', 'servers', 'config', 'script', 'variables',
'nest',
'servers',
'config',
'script',
'variables',
];
/**
@ -52,7 +56,7 @@ class EggTransformer extends BaseTransformer
'startup' => json_decode($model->config_startup, true),
'stop' => $model->config_stop,
'logs' => json_decode($model->config_logs, true),
'file_denylist' => explode(PHP_EOL, $model->file_denylist),
'file_denylist' => $model->file_denylist,
'extends' => $model->config_from,
],
'startup' => $model->startup,

View file

@ -68,7 +68,7 @@
}
},
"scripts": {
"php-cs-fixer": "php-cs-fixer fix --diff --diff-format=udiff --config=./.php_cs.dist --rules=psr_autoloading",
"php-cs-fixer": "php-cs-fixer fix --diff --diff-format=udiff --config=./.php_cs.dist",
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],

View file

@ -3,12 +3,13 @@
"meta": {
"version": "PTDL_v1"
},
"exported_at": "2020-10-20T00:03:09+00:00",
"exported_at": "2021-01-25T07:42:35+02:00",
"name": "Rust",
"author": "support@pterodactyl.io",
"description": "The only aim in Rust is to survive. To do this you will need to overcome struggles such as hunger, thirst and cold. Build a fire. Build a shelter. Kill animals for meat. Protect yourself from other players, and kill them for meat. Create alliances with other players and form a town. Do whatever it takes to survive.",
"features": null,
"image": "quay.io\/pterodactyl\/core:rust",
"startup": ".\/RustDedicated -batchmode +server.port {{SERVER_PORT}} +server.identity \"rust\" +rcon.port {{RCON_PORT}} +rcon.web true +server.hostname \\\"{{HOSTNAME}}\\\" +server.level \\\"{{LEVEL}}\\\" +server.description \\\"{{DESCRIPTION}}\\\" +server.url \\\"{{SERVER_URL}}\\\" +server.headerimage \\\"{{SERVER_IMG}}\\\" +server.worldsize \\\"{{WORLD_SIZE}}\\\" +server.seed \\\"{{WORLD_SEED}}\\\" +server.maxplayers {{MAX_PLAYERS}} +rcon.password \\\"{{RCON_PASS}}\\\" +server.saveinterval {{SAVEINTERVAL}} {{ADDITIONAL_ARGS}}",
"startup": ".\/RustDedicated -batchmode +server.port {{SERVER_PORT}} +server.identity \"rust\" +rcon.port {{RCON_PORT}} +rcon.web true +server.hostname \\\"{{HOSTNAME}}\\\" +server.level \\\"{{LEVEL}}\\\" +server.description \\\"{{DESCRIPTION}}\\\" +server.url \\\"{{SERVER_URL}}\\\" +server.headerimage \\\"{{SERVER_IMG}}\\\" +server.logoimage \\\"{{SERVER_LOGO}}\\\" +server.worldsize \\\"{{WORLD_SIZE}}\\\" +server.seed \\\"{{WORLD_SEED}}\\\" +server.maxplayers {{MAX_PLAYERS}} +rcon.password \\\"{{RCON_PASS}}\\\" +server.saveinterval {{SAVEINTERVAL}} +app.port {{APP_PORT}} {{ADDITIONAL_ARGS}}",
"config": {
"files": "{}",
"startup": "{\r\n \"done\": \"Server startup complete\",\r\n \"userInteraction\": []\r\n}",
@ -139,6 +140,24 @@
"user_viewable": true,
"user_editable": true,
"rules": "nullable|string"
},
{
"name": "App Port",
"description": "Port for the Rust+ App. -1 to disable.",
"env_variable": "APP_PORT",
"default_value": "28082",
"user_viewable": true,
"user_editable": false,
"rules": "required|integer"
},
{
"name": "Server Logo",
"description": "The circular server logo for the Rust+ app.",
"env_variable": "SERVER_LOGO",
"default_value": "",
"user_viewable": true,
"user_editable": true,
"rules": "nullable|url"
}
]
}

View file

@ -0,0 +1,40 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UpdateFileDenylistToJson extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('eggs', function (Blueprint $table) {
$table->dropColumn('file_denylist');
});
Schema::table('eggs', function (Blueprint $table) {
$table->json('file_denylist')->nullable()->after('docker_images');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('eggs', function (Blueprint $table) {
$table->dropColumn('file_denylist');
});
Schema::table('eggs', function (Blueprint $table) {
$table->text('file_denylist')->after('docker_images');
});
}
}

View file

@ -29,6 +29,6 @@ return [
'node_required' => 'You must have at least one node configured before you can add a server to this panel.',
'transfer_nodes_required' => 'You must have at least two nodes configured before you can transfer servers.',
'transfer_started' => 'Server transfer has been started.',
'transfer_not_viable' => 'The node you selected is not viable for this transfer.',
'transfer_not_viable' => 'The node you selected does not have the required disk space or memory available to accommodate this server.',
],
];

View file

@ -30,19 +30,23 @@ export default () => {
<TitledGreyBox title={'SFTP Details'} css={tw`mb-6 md:mb-10`}>
<div>
<Label>Server Address</Label>
<CopyOnClick text={`sftp://${sftp.ip}:${sftp.port}`}>
<Input
type={'text'}
value={`sftp://${sftp.ip}:${sftp.port}`}
readOnly
/>
</CopyOnClick>
</div>
<div css={tw`mt-6`}>
<Label>Username</Label>
<CopyOnClick text={`${username}.${id}`}>
<Input
type={'text'}
value={`${username}.${id}`}
readOnly
/>
</CopyOnClick>
</div>
<div css={tw`mt-6 flex items-center`}>
<div css={tw`flex-1`}>