2015-12-08 23:33:33 +00:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2015-12-08 23:33:33 +00:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
2022-10-24 16:01:26 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
2019-09-22 22:30:53 +00:00
|
|
|
/**
|
2021-01-28 04:52:11 +00: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 21:45:22 +00:00
|
|
|
* @property array<string, string> $docker_images
|
2022-09-25 19:24:54 +00:00
|
|
|
* @property string $update_url
|
|
|
|
* @property bool $force_outgoing_ip
|
2021-01-28 04:52:11 +00: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 20:03:19 +00:00
|
|
|
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\EggVariable[] $variables
|
2021-01-28 04:52:11 +00:00
|
|
|
* @property \Pterodactyl\Models\Egg|null $scriptFrom
|
|
|
|
* @property \Pterodactyl\Models\Egg|null $configFrom
|
2019-09-22 22:30:53 +00:00
|
|
|
*/
|
2020-04-04 06:22:35 +00:00
|
|
|
class Egg extends Model
|
2015-12-08 23:33:33 +00:00
|
|
|
{
|
2018-01-26 03:26:06 +00:00
|
|
|
/**
|
|
|
|
* The resource name for this model when it is transformed into an
|
|
|
|
* API representation using fractal.
|
|
|
|
*/
|
2021-01-23 20:33:34 +00:00
|
|
|
public const RESOURCE_NAME = 'egg';
|
2018-01-26 03:26:06 +00:00
|
|
|
|
2022-05-07 21:45:22 +00:00
|
|
|
/**
|
|
|
|
* Defines the current egg export version.
|
|
|
|
*/
|
|
|
|
public const EXPORT_VERSION = 'PTDL_v2';
|
|
|
|
|
2020-11-03 04:20:36 +00: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 20:33:34 +00:00
|
|
|
public const FEATURE_EULA_POPUP = 'eula';
|
|
|
|
public const FEATURE_FASTDL = 'fastdl';
|
2020-11-03 04:20:36 +00:00
|
|
|
|
2015-12-08 23:33:33 +00:00
|
|
|
/**
|
|
|
|
* The table associated with the model.
|
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
protected $table = 'eggs';
|
2015-12-08 23:33:33 +00:00
|
|
|
|
2016-02-15 20:21:28 +00:00
|
|
|
/**
|
|
|
|
* Fields that are not mass assignable.
|
|
|
|
*/
|
2017-10-03 03:51:13 +00:00
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'description',
|
2020-11-03 04:20:36 +00:00
|
|
|
'features',
|
2020-12-13 17:53:17 +00:00
|
|
|
'docker_images',
|
2022-09-25 19:24:54 +00:00
|
|
|
'force_outgoing_ip',
|
2021-01-11 01:02:14 +00:00
|
|
|
'file_denylist',
|
2017-10-03 03:51:13 +00: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 20:21:28 +00:00
|
|
|
|
2017-08-09 04:24:55 +00:00
|
|
|
/**
|
|
|
|
* Cast values to correct type.
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
2017-10-07 22:21:41 +00:00
|
|
|
'nest_id' => 'integer',
|
2017-10-03 03:51:13 +00:00
|
|
|
'config_from' => 'integer',
|
2017-08-09 04:24:55 +00:00
|
|
|
'script_is_privileged' => 'boolean',
|
2022-09-25 19:24:54 +00:00
|
|
|
'force_outgoing_ip' => 'boolean',
|
2017-10-03 03:51:13 +00:00
|
|
|
'copy_script_from' => 'integer',
|
2020-11-03 04:20:36 +00:00
|
|
|
'features' => 'array',
|
2020-12-13 17:53:17 +00:00
|
|
|
'docker_images' => 'array',
|
2021-01-27 05:08:53 +00:00
|
|
|
'file_denylist' => 'array',
|
2017-08-09 04:24:55 +00:00
|
|
|
];
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
public static array $validationRules = [
|
2019-09-05 05:19:57 +00:00
|
|
|
'nest_id' => 'required|bail|numeric|exists:nests,id',
|
|
|
|
'uuid' => 'required|string|size:36',
|
2020-09-26 23:29:26 +00:00
|
|
|
'name' => 'required|string|max:191',
|
2020-04-18 00:52:40 +00:00
|
|
|
'description' => 'string|nullable',
|
2020-11-03 04:24:11 +00:00
|
|
|
'features' => 'array|nullable',
|
2019-09-05 05:19:57 +00:00
|
|
|
'author' => 'required|string|email',
|
2021-01-27 05:08:53 +00:00
|
|
|
'file_denylist' => 'array|nullable',
|
|
|
|
'file_denylist.*' => 'string',
|
2020-12-13 17:53:17 +00:00
|
|
|
'docker_images' => 'required|array|min:1',
|
|
|
|
'docker_images.*' => 'required|string',
|
2019-09-05 05:19:57 +00:00
|
|
|
'startup' => 'required|nullable|string',
|
|
|
|
'config_from' => 'sometimes|bail|nullable|numeric|exists:eggs,id',
|
2020-09-26 23:29:26 +00:00
|
|
|
'config_stop' => 'required_without:config_from|nullable|string|max:191',
|
2019-09-05 05:19:57 +00: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 17:53:17 +00:00
|
|
|
'update_url' => 'sometimes|nullable|string',
|
2022-09-25 19:24:54 +00:00
|
|
|
'force_outgoing_ip' => 'sometimes|boolean',
|
2017-08-09 04:24:55 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
protected $attributes = [
|
2020-11-03 04:20:36 +00:00
|
|
|
'features' => null,
|
2021-01-27 05:08:53 +00:00
|
|
|
'file_denylist' => null,
|
2017-08-09 04:24:55 +00:00
|
|
|
'config_stop' => null,
|
|
|
|
'config_startup' => null,
|
|
|
|
'config_logs' => null,
|
|
|
|
'config_files' => null,
|
2020-12-13 17:53:17 +00:00
|
|
|
'update_url' => null,
|
2017-08-09 04:24:55 +00:00
|
|
|
];
|
2016-12-12 19:30:57 +00:00
|
|
|
|
2017-04-27 20:16:57 +00:00
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Returns the install script for the egg; if egg is copying from another
|
2017-04-27 20:16:57 +00:00
|
|
|
* it will return the copied script.
|
|
|
|
*/
|
2022-10-24 16:01:26 +00:00
|
|
|
public function copyScriptInstall(): Attribute
|
2017-04-27 20:16:57 +00:00
|
|
|
{
|
2022-10-24 16:01:26 +00:00
|
|
|
return new Attribute(
|
|
|
|
get: fn () => (!is_null($this->script_install) || is_null($this->copy_script_from))
|
|
|
|
? $this->script_install : $this->scriptFrom->script_install,
|
|
|
|
);
|
2017-04-27 20:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Returns the entry command for the egg; if egg is copying from another
|
2017-04-27 20:16:57 +00:00
|
|
|
* it will return the copied entry command.
|
|
|
|
*/
|
2022-10-24 16:01:26 +00:00
|
|
|
public function copyScriptEntry(): Attribute
|
2017-04-27 20:16:57 +00:00
|
|
|
{
|
2022-10-24 16:01:26 +00:00
|
|
|
return new Attribute(
|
|
|
|
get: fn () => (!is_null($this->script_entry) || is_null($this->copy_script_from))
|
|
|
|
? $this->script_entry : $this->scriptFrom->script_entry,
|
|
|
|
);
|
2017-04-27 20:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Returns the install container for the egg; if egg is copying from another
|
2017-04-27 20:16:57 +00:00
|
|
|
* it will return the copied install container.
|
|
|
|
*/
|
2022-10-24 16:01:26 +00:00
|
|
|
public function copyScriptContainer(): Attribute
|
2017-04-27 20:16:57 +00:00
|
|
|
{
|
2022-10-24 16:01:26 +00:00
|
|
|
return new Attribute(
|
|
|
|
get: fn () => (!is_null($this->script_container) || is_null($this->copy_script_from))
|
|
|
|
? $this->script_container : $this->scriptFrom->script_container,
|
|
|
|
);
|
2017-10-04 01:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Return the file configuration for an egg.
|
2017-10-04 01:18:27 +00:00
|
|
|
*/
|
2022-10-24 16:01:26 +00:00
|
|
|
public function inheritConfigFiles(): Attribute
|
2017-10-04 01:18:27 +00:00
|
|
|
{
|
2022-10-24 16:01:26 +00:00
|
|
|
return new Attribute(
|
|
|
|
get: fn () => (!is_null($this->config_files) || is_null($this->config_from))
|
|
|
|
? $this->config_files : $this->configFrom->config_files,
|
|
|
|
);
|
2017-10-04 01:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Return the startup configuration for an egg.
|
2017-10-04 01:18:27 +00:00
|
|
|
*/
|
2022-10-24 16:01:26 +00:00
|
|
|
public function inheritConfigStartup(): Attribute
|
2017-10-04 01:18:27 +00:00
|
|
|
{
|
2022-10-24 16:01:26 +00:00
|
|
|
return new Attribute(
|
|
|
|
get: fn () => (!is_null($this->config_startup) || is_null($this->config_from))
|
|
|
|
? $this->config_startup : $this->configFrom->config_startup,
|
|
|
|
);
|
2017-10-04 01:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Return the log reading configuration for an egg.
|
2017-10-04 01:18:27 +00:00
|
|
|
*/
|
2022-10-24 16:01:26 +00:00
|
|
|
public function inheritConfigLogs(): Attribute
|
2017-10-04 01:18:27 +00:00
|
|
|
{
|
2022-10-24 16:01:26 +00:00
|
|
|
return new Attribute(
|
|
|
|
get: fn () => (!is_null($this->config_logs) || is_null($this->config_from))
|
|
|
|
? $this->config_logs : $this->configFrom->config_logs,
|
|
|
|
);
|
2017-10-04 01:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Return the stop command configuration for an egg.
|
2017-10-04 01:18:27 +00:00
|
|
|
*/
|
2022-10-24 16:01:26 +00:00
|
|
|
public function inheritConfigStop(): Attribute
|
2017-10-04 01:18:27 +00:00
|
|
|
{
|
2022-10-24 16:01:26 +00:00
|
|
|
return new Attribute(
|
|
|
|
get: fn () => (!is_null($this->config_stop) || is_null($this->config_from))
|
|
|
|
? $this->config_stop : $this->configFrom->config_stop,
|
|
|
|
);
|
2017-04-27 20:16:57 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 04:20:36 +00: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-24 16:01:26 +00:00
|
|
|
public function inheritFeatures(): Attribute
|
2020-11-03 04:20:36 +00:00
|
|
|
{
|
2022-10-24 16:01:26 +00:00
|
|
|
return new Attribute(
|
|
|
|
get: fn () => (!is_null($this->features) || is_null($this->config_from))
|
|
|
|
? $this->features : $this->configFrom->features,
|
|
|
|
);
|
2020-11-03 04:20:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 01:02:14 +00: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-24 16:01:26 +00:00
|
|
|
public function inheritFileDenylist(): Attribute
|
2021-01-11 01:02:14 +00:00
|
|
|
{
|
2022-10-24 16:01:26 +00:00
|
|
|
return new Attribute(
|
|
|
|
get: fn () => is_null($this->config_from)
|
|
|
|
? $this->file_denylist : $this->configFrom->file_denylist,
|
|
|
|
);
|
2021-01-11 01:02:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Gets nest associated with an egg.
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function nest(): BelongsTo
|
2017-03-19 23:36:50 +00:00
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
return $this->belongsTo(Nest::class);
|
2017-03-19 23:36:50 +00:00
|
|
|
}
|
2017-02-05 22:58:17 +00:00
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Gets all servers associated with this egg.
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function servers(): HasMany
|
2017-03-19 23:36:50 +00:00
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
return $this->hasMany(Server::class, 'egg_id');
|
2017-03-19 23:36:50 +00:00
|
|
|
}
|
2017-02-05 22:58:17 +00:00
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Gets all variables associated with this egg.
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function variables(): HasMany
|
2017-03-19 23:36:50 +00:00
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
return $this->hasMany(EggVariable::class, 'egg_id');
|
2017-03-19 23:36:50 +00:00
|
|
|
}
|
2017-02-02 21:01:18 +00:00
|
|
|
|
2017-08-09 04:24:55 +00:00
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Get the parent egg from which to copy scripts.
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function scriptFrom(): BelongsTo
|
2017-04-27 20:16:57 +00:00
|
|
|
{
|
2017-05-02 00:58:36 +00:00
|
|
|
return $this->belongsTo(self::class, 'copy_script_from');
|
2017-04-27 20:16:57 +00:00
|
|
|
}
|
2017-10-04 01:18:27 +00:00
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Get the parent egg from which to copy configuration settings.
|
2017-10-04 01:18:27 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function configFrom(): BelongsTo
|
2017-10-04 01:18:27 +00:00
|
|
|
{
|
|
|
|
return $this->belongsTo(self::class, 'config_from');
|
|
|
|
}
|
2015-12-08 23:33:33 +00:00
|
|
|
}
|