2015-12-09 00:33:33 +01:00
|
|
|
<?php
|
2016-12-07 23:46:38 +01:00
|
|
|
|
2015-12-09 00:33:33 +01:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
2022-10-14 18:59:20 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
2019-09-23 00:30:53 +02:00
|
|
|
/**
|
2021-01-28 05:52:11 +01:00
|
|
|
* @property int $id
|
|
|
|
* @property string $uuid
|
|
|
|
* @property int $nest_id
|
|
|
|
* @property string $author
|
|
|
|
* @property string $name
|
|
|
|
* @property string|null $description
|
|
|
|
* @property array|null $features
|
|
|
|
* @property string $docker_image -- deprecated, use $docker_images
|
2022-05-07 23:45:22 +02:00
|
|
|
* @property array<string, string> $docker_images
|
2022-09-25 21:24:54 +02:00
|
|
|
* @property string $update_url
|
|
|
|
* @property bool $force_outgoing_ip
|
2021-01-28 05:52:11 +01:00
|
|
|
* @property array|null $file_denylist
|
|
|
|
* @property string|null $config_files
|
|
|
|
* @property string|null $config_startup
|
|
|
|
* @property string|null $config_logs
|
|
|
|
* @property string|null $config_stop
|
|
|
|
* @property int|null $config_from
|
|
|
|
* @property string|null $startup
|
|
|
|
* @property bool $script_is_privileged
|
|
|
|
* @property string|null $script_install
|
|
|
|
* @property string $script_entry
|
|
|
|
* @property string $script_container
|
|
|
|
* @property int|null $copy_script_from
|
|
|
|
* @property \Carbon\Carbon $created_at
|
|
|
|
* @property \Carbon\Carbon $updated_at
|
|
|
|
* @property string|null $copy_script_install
|
|
|
|
* @property string $copy_script_entry
|
|
|
|
* @property string $copy_script_container
|
|
|
|
* @property string|null $inherit_config_files
|
|
|
|
* @property string|null $inherit_config_startup
|
|
|
|
* @property string|null $inherit_config_logs
|
|
|
|
* @property string|null $inherit_config_stop
|
|
|
|
* @property string $inherit_file_denylist
|
|
|
|
* @property array|null $inherit_features
|
|
|
|
* @property \Pterodactyl\Models\Nest $nest
|
|
|
|
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Server[] $servers
|
2019-12-28 21:03:19 +01:00
|
|
|
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\EggVariable[] $variables
|
2021-01-28 05:52:11 +01:00
|
|
|
* @property \Pterodactyl\Models\Egg|null $scriptFrom
|
|
|
|
* @property \Pterodactyl\Models\Egg|null $configFrom
|
2019-09-23 00:30:53 +02:00
|
|
|
*/
|
2020-04-04 08:22:35 +02:00
|
|
|
class Egg extends Model
|
2015-12-09 00:33:33 +01:00
|
|
|
{
|
2018-01-26 04:26:06 +01:00
|
|
|
/**
|
|
|
|
* The resource name for this model when it is transformed into an
|
|
|
|
* API representation using fractal.
|
|
|
|
*/
|
2021-01-23 21:33:34 +01:00
|
|
|
public const RESOURCE_NAME = 'egg';
|
2018-01-26 04:26:06 +01:00
|
|
|
|
2022-05-07 23:45:22 +02:00
|
|
|
/**
|
|
|
|
* Defines the current egg export version.
|
|
|
|
*/
|
|
|
|
public const EXPORT_VERSION = 'PTDL_v2';
|
|
|
|
|
2020-11-03 05:20:36 +01:00
|
|
|
/**
|
|
|
|
* Different features that can be enabled on any given egg. These are used internally
|
|
|
|
* to determine which types of frontend functionality should be shown to the user. Eggs
|
|
|
|
* will automatically inherit features from a parent egg if they are already configured
|
|
|
|
* to copy configuration values from said egg.
|
|
|
|
*
|
|
|
|
* To skip copying the features, an empty array value should be passed in ("[]") rather
|
|
|
|
* than leaving it null.
|
|
|
|
*/
|
2021-01-23 21:33:34 +01:00
|
|
|
public const FEATURE_EULA_POPUP = 'eula';
|
|
|
|
public const FEATURE_FASTDL = 'fastdl';
|
2020-11-03 05:20:36 +01:00
|
|
|
|
2015-12-09 00:33:33 +01:00
|
|
|
/**
|
|
|
|
* The table associated with the model.
|
|
|
|
*/
|
2017-10-07 06:57:53 +02:00
|
|
|
protected $table = 'eggs';
|
2015-12-09 00:33:33 +01:00
|
|
|
|
2016-02-15 21:21:28 +01:00
|
|
|
/**
|
|
|
|
* Fields that are not mass assignable.
|
|
|
|
*/
|
2017-10-03 05:51:13 +02:00
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'description',
|
2020-11-03 05:20:36 +01:00
|
|
|
'features',
|
2020-12-13 18:53:17 +01:00
|
|
|
'docker_images',
|
2022-09-25 21:24:54 +02:00
|
|
|
'force_outgoing_ip',
|
2021-01-11 02:02:14 +01:00
|
|
|
'file_denylist',
|
2017-10-03 05:51:13 +02:00
|
|
|
'config_files',
|
|
|
|
'config_startup',
|
|
|
|
'config_logs',
|
|
|
|
'config_stop',
|
|
|
|
'config_from',
|
|
|
|
'startup',
|
|
|
|
'script_is_privileged',
|
|
|
|
'script_install',
|
|
|
|
'script_entry',
|
|
|
|
'script_container',
|
|
|
|
'copy_script_from',
|
|
|
|
];
|
2016-02-15 21:21:28 +01:00
|
|
|
|
2017-08-09 06:24:55 +02:00
|
|
|
/**
|
|
|
|
* Cast values to correct type.
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
2017-10-08 00:21:41 +02:00
|
|
|
'nest_id' => 'integer',
|
2017-10-03 05:51:13 +02:00
|
|
|
'config_from' => 'integer',
|
2017-08-09 06:24:55 +02:00
|
|
|
'script_is_privileged' => 'boolean',
|
2022-09-25 21:24:54 +02:00
|
|
|
'force_outgoing_ip' => 'boolean',
|
2017-10-03 05:51:13 +02:00
|
|
|
'copy_script_from' => 'integer',
|
2020-11-03 05:20:36 +01:00
|
|
|
'features' => 'array',
|
2020-12-13 18:53:17 +01:00
|
|
|
'docker_images' => 'array',
|
2021-01-27 06:08:53 +01:00
|
|
|
'file_denylist' => 'array',
|
2017-08-09 06:24:55 +02:00
|
|
|
];
|
|
|
|
|
2022-10-14 18:59:20 +02:00
|
|
|
public static array $validationRules = [
|
2019-09-05 07:19:57 +02:00
|
|
|
'nest_id' => 'required|bail|numeric|exists:nests,id',
|
|
|
|
'uuid' => 'required|string|size:36',
|
2020-09-27 01:29:26 +02:00
|
|
|
'name' => 'required|string|max:191',
|
2020-04-18 02:52:40 +02:00
|
|
|
'description' => 'string|nullable',
|
2020-11-03 05:24:11 +01:00
|
|
|
'features' => 'array|nullable',
|
2019-09-05 07:19:57 +02:00
|
|
|
'author' => 'required|string|email',
|
2021-01-27 06:08:53 +01:00
|
|
|
'file_denylist' => 'array|nullable',
|
|
|
|
'file_denylist.*' => 'string',
|
2020-12-13 18:53:17 +01:00
|
|
|
'docker_images' => 'required|array|min:1',
|
2024-04-11 01:39:26 +02:00
|
|
|
'docker_images.*' => ['required', 'string', 'max:191', 'regex:/^[\w#\.\/\- ]*\|*[\w\.\/\-:@ ]*$/'],
|
2019-09-05 07:19:57 +02:00
|
|
|
'startup' => 'required|nullable|string',
|
|
|
|
'config_from' => 'sometimes|bail|nullable|numeric|exists:eggs,id',
|
2020-09-27 01:29:26 +02:00
|
|
|
'config_stop' => 'required_without:config_from|nullable|string|max:191',
|
2019-09-05 07:19:57 +02:00
|
|
|
'config_startup' => 'required_without:config_from|nullable|json',
|
|
|
|
'config_logs' => 'required_without:config_from|nullable|json',
|
|
|
|
'config_files' => 'required_without:config_from|nullable|json',
|
2020-12-13 18:53:17 +01:00
|
|
|
'update_url' => 'sometimes|nullable|string',
|
2022-09-25 21:24:54 +02:00
|
|
|
'force_outgoing_ip' => 'sometimes|boolean',
|
2017-08-09 06:24:55 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
protected $attributes = [
|
2020-11-03 05:20:36 +01:00
|
|
|
'features' => null,
|
2021-01-27 06:08:53 +01:00
|
|
|
'file_denylist' => null,
|
2017-08-09 06:24:55 +02:00
|
|
|
'config_stop' => null,
|
|
|
|
'config_startup' => null,
|
|
|
|
'config_logs' => null,
|
|
|
|
'config_files' => null,
|
2020-12-13 18:53:17 +01:00
|
|
|
'update_url' => null,
|
2017-08-09 06:24:55 +02:00
|
|
|
];
|
2016-12-12 20:30:57 +01:00
|
|
|
|
2017-04-27 22:16:57 +02:00
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Returns the install script for the egg; if egg is copying from another
|
2017-04-27 22:16:57 +02:00
|
|
|
* it will return the copied script.
|
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function getCopyScriptInstallAttribute(): ?string
|
2017-04-27 22:16:57 +02:00
|
|
|
{
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!is_null($this->script_install) || is_null($this->copy_script_from)) {
|
2018-03-07 06:07:00 +01:00
|
|
|
return $this->script_install;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->scriptFrom->script_install;
|
2017-04-27 22:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Returns the entry command for the egg; if egg is copying from another
|
2017-04-27 22:16:57 +02:00
|
|
|
* it will return the copied entry command.
|
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function getCopyScriptEntryAttribute(): string
|
2017-04-27 22:16:57 +02:00
|
|
|
{
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!is_null($this->script_entry) || is_null($this->copy_script_from)) {
|
2018-03-07 06:07:00 +01:00
|
|
|
return $this->script_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->scriptFrom->script_entry;
|
2017-04-27 22:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Returns the install container for the egg; if egg is copying from another
|
2017-04-27 22:16:57 +02:00
|
|
|
* it will return the copied install container.
|
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function getCopyScriptContainerAttribute(): string
|
2017-04-27 22:16:57 +02:00
|
|
|
{
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!is_null($this->script_container) || is_null($this->copy_script_from)) {
|
2018-03-07 06:07:00 +01:00
|
|
|
return $this->script_container;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->scriptFrom->script_container;
|
2017-10-04 03:18:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Return the file configuration for an egg.
|
2017-10-04 03:18:27 +02:00
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function getInheritConfigFilesAttribute(): ?string
|
2017-10-04 03:18:27 +02:00
|
|
|
{
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!is_null($this->config_files) || is_null($this->config_from)) {
|
2018-03-07 06:07:00 +01:00
|
|
|
return $this->config_files;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->configFrom->config_files;
|
2017-10-04 03:18:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Return the startup configuration for an egg.
|
2017-10-04 03:18:27 +02:00
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function getInheritConfigStartupAttribute(): ?string
|
2017-10-04 03:18:27 +02:00
|
|
|
{
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!is_null($this->config_startup) || is_null($this->config_from)) {
|
2018-03-07 06:07:00 +01:00
|
|
|
return $this->config_startup;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->configFrom->config_startup;
|
2017-10-04 03:18:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Return the log reading configuration for an egg.
|
2017-10-04 03:18:27 +02:00
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function getInheritConfigLogsAttribute(): ?string
|
2017-10-04 03:18:27 +02:00
|
|
|
{
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!is_null($this->config_logs) || is_null($this->config_from)) {
|
2018-03-07 06:07:00 +01:00
|
|
|
return $this->config_logs;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->configFrom->config_logs;
|
2017-10-04 03:18:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Return the stop command configuration for an egg.
|
2017-10-04 03:18:27 +02:00
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function getInheritConfigStopAttribute(): ?string
|
2017-10-04 03:18:27 +02:00
|
|
|
{
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!is_null($this->config_stop) || is_null($this->config_from)) {
|
2018-03-07 06:07:00 +01:00
|
|
|
return $this->config_stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->configFrom->config_stop;
|
2017-04-27 22:16:57 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 05:20:36 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function getInheritFeaturesAttribute(): ?array
|
2020-11-03 05:20:36 +01:00
|
|
|
{
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!is_null($this->features) || is_null($this->config_from)) {
|
2020-11-03 05:20:36 +01:00
|
|
|
return $this->features;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->configFrom->features;
|
|
|
|
}
|
|
|
|
|
2021-01-11 02:02:14 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function getInheritFileDenylistAttribute(): ?array
|
2021-01-11 02:02:14 +01:00
|
|
|
{
|
|
|
|
if (is_null($this->config_from)) {
|
|
|
|
return $this->file_denylist;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->configFrom->file_denylist;
|
|
|
|
}
|
|
|
|
|
2017-03-20 00:36:50 +01:00
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Gets nest associated with an egg.
|
2017-03-20 00:36:50 +01:00
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function nest(): BelongsTo
|
2017-03-20 00:36:50 +01:00
|
|
|
{
|
2017-10-07 06:57:53 +02:00
|
|
|
return $this->belongsTo(Nest::class);
|
2017-03-20 00:36:50 +01:00
|
|
|
}
|
2017-02-05 23:58:17 +01:00
|
|
|
|
2017-03-20 00:36:50 +01:00
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Gets all servers associated with this egg.
|
2017-03-20 00:36:50 +01:00
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function servers(): HasMany
|
2017-03-20 00:36:50 +01:00
|
|
|
{
|
2017-10-07 06:57:53 +02:00
|
|
|
return $this->hasMany(Server::class, 'egg_id');
|
2017-03-20 00:36:50 +01:00
|
|
|
}
|
2017-02-05 23:58:17 +01:00
|
|
|
|
2017-03-20 00:36:50 +01:00
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Gets all variables associated with this egg.
|
2017-03-20 00:36:50 +01:00
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function variables(): HasMany
|
2017-03-20 00:36:50 +01:00
|
|
|
{
|
2017-10-07 06:57:53 +02:00
|
|
|
return $this->hasMany(EggVariable::class, 'egg_id');
|
2017-03-20 00:36:50 +01:00
|
|
|
}
|
2017-02-02 22:01:18 +01:00
|
|
|
|
2017-08-09 06:24:55 +02:00
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Get the parent egg from which to copy scripts.
|
2017-08-09 06:24:55 +02:00
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function scriptFrom(): BelongsTo
|
2017-04-27 22:16:57 +02:00
|
|
|
{
|
2017-05-02 02:58:36 +02:00
|
|
|
return $this->belongsTo(self::class, 'copy_script_from');
|
2017-04-27 22:16:57 +02:00
|
|
|
}
|
2017-10-04 03:18:27 +02:00
|
|
|
|
|
|
|
/**
|
2017-10-07 06:57:53 +02:00
|
|
|
* Get the parent egg from which to copy configuration settings.
|
2017-10-04 03:18:27 +02:00
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function configFrom(): BelongsTo
|
2017-10-04 03:18:27 +02:00
|
|
|
{
|
|
|
|
return $this->belongsTo(self::class, 'config_from');
|
|
|
|
}
|
2015-12-09 00:33:33 +01:00
|
|
|
}
|