Skip to content

Commit 239984f

Browse files
committed
Add internal support for file denylist on eggs; closes pterodactyl#569
1 parent ff21d83 commit 239984f

File tree

7 files changed

+64
-2
lines changed

7 files changed

+64
-2
lines changed

app/Http/Requests/Admin/Egg/EggFormRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function rules()
2222
'name' => 'required|string|max:191',
2323
'description' => 'nullable|string',
2424
'docker_images' => 'required|string',
25+
'file_denylist' => 'string',
2526
'startup' => 'required|string',
2627
'config_from' => 'sometimes|bail|nullable|numeric',
2728
'config_stop' => 'required_without:config_from|nullable|string|max:191',
@@ -43,7 +44,7 @@ public function rules()
4344
public function withValidator($validator)
4445
{
4546
$validator->sometimes('config_from', 'exists:eggs,id', function () {
46-
return (int) $this->input('config_from') !== 0;
47+
return (int)$this->input('config_from') !== 0;
4748
});
4849
}
4950
}

app/Models/Egg.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @property string $docker_image -- deprecated, use $docker_images
1414
* @property string $update_url
1515
* @property array $docker_images
16+
* @property string $file_denylist
1617
* @property string|null $config_files
1718
* @property string|null $config_startup
1819
* @property string|null $config_logs
@@ -34,6 +35,7 @@
3435
* @property string|null $inherit_config_startup
3536
* @property string|null $inherit_config_logs
3637
* @property string|null $inherit_config_stop
38+
* @property string $inherit_file_denylist
3739
* @property array|null $inherit_features
3840
*
3941
* @property \Pterodactyl\Models\Nest $nest
@@ -79,6 +81,7 @@ class Egg extends Model
7981
'description',
8082
'features',
8183
'docker_images',
84+
'file_denylist',
8285
'config_files',
8386
'config_startup',
8487
'config_logs',
@@ -255,6 +258,21 @@ public function getInheritFeaturesAttribute()
255258
return $this->configFrom->features;
256259
}
257260

261+
/**
262+
* Returns the features available to this egg from the parent configuration if there are
263+
* no features defined for this egg specifically and there is a parent egg configured.
264+
*
265+
* @return string
266+
*/
267+
public function getInheritFileDenylistAttribute()
268+
{
269+
if (is_null($this->config_from)) {
270+
return $this->file_denylist;
271+
}
272+
273+
return $this->configFrom->file_denylist;
274+
}
275+
258276
/**
259277
* Gets nest associated with an egg.
260278
*

app/Services/Eggs/Sharing/EggExporterService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function handle(int $egg): string
4646
'description' => $egg->description,
4747
'features' => $egg->features,
4848
'images' => $egg->docker_images,
49+
'file_denylist' => $egg->inherit_file_denylist,
4950
'startup' => $egg->startup,
5051
'config' => [
5152
'files' => $egg->inherit_config_files,

app/Services/Eggs/Sharing/EggImporterService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function handle(UploadedFile $file, int $nest): Egg
105105
// Maintain backwards compatability for eggs that are still using the old single image
106106
// string format. New eggs can provide an array of Docker images that can be used.
107107
'docker_images' => object_get($parsed, 'images') ?? [object_get($parsed, 'image')],
108+
'file_denylist' => implode(PHP_EOL, object_get($parsed, 'file_denylist') ?? []),
108109
'update_url' => object_get($parsed, 'meta.update_url'),
109110
'config_files' => object_get($parsed, 'config.files'),
110111
'config_startup' => object_get($parsed, 'config.startup'),
@@ -118,7 +119,7 @@ public function handle(UploadedFile $file, int $nest): Egg
118119
], true, true);
119120

120121
collect($parsed->variables)->each(function ($variable) use ($egg) {
121-
$this->eggVariableRepository->create(array_merge((array) $variable, [
122+
$this->eggVariableRepository->create(array_merge((array)$variable, [
122123
'egg_id' => $egg->id,
123124
]));
124125
});

app/Services/Servers/ServerConfigurationStructureService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ protected function returnCurrentFormat(Server $server)
9191
'read_only' => $mount->read_only,
9292
];
9393
}),
94+
'egg' => [
95+
'id' => $server->egg->uuid,
96+
'file_denylist' => [
97+
'config.yml',
98+
'**/*.json'
99+
]
100+
// 'file_denylist' => explode(PHP_EOL, $server->egg->inherit_file_denylist),
101+
]
94102
];
95103
}
96104

app/Transformers/Api/Application/EggTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function transform(Egg $model)
5555
'startup' => json_decode($model->config_startup, true),
5656
'stop' => $model->config_stop,
5757
'logs' => json_decode($model->config_logs, true),
58+
'file_denylist' => explode(PHP_EOL, $model->file_denylist),
5859
'extends' => $model->config_from,
5960
],
6061
'startup' => $model->startup,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddFileDenylistToEggConfigs extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('eggs', function (Blueprint $table) {
17+
$table->text('file_denylist')->after('docker_images');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('eggs', function (Blueprint $table) {
29+
$table->dropColumn('file_denylist');
30+
});
31+
}
32+
}

0 commit comments

Comments
 (0)