Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Models/Egg.php
7432 views
1
<?php
2
3
namespace Pterodactyl\Models;
4
5
use Illuminate\Database\Eloquent\Relations\HasMany;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
use Illuminate\Database\Eloquent\Factories\HasFactory;
8
9
/**
10
* @property int $id
11
* @property string $uuid
12
* @property int $nest_id
13
* @property string $author
14
* @property string $name
15
* @property string|null $description
16
* @property array|null $features
17
* @property string $docker_image -- deprecated, use $docker_images
18
* @property array<string, string> $docker_images
19
* @property string $update_url
20
* @property bool $force_outgoing_ip
21
* @property array|null $file_denylist
22
* @property string|null $config_files
23
* @property string|null $config_startup
24
* @property string|null $config_logs
25
* @property string|null $config_stop
26
* @property int|null $config_from
27
* @property string|null $startup
28
* @property bool $script_is_privileged
29
* @property string|null $script_install
30
* @property string $script_entry
31
* @property string $script_container
32
* @property int|null $copy_script_from
33
* @property \Carbon\Carbon $created_at
34
* @property \Carbon\Carbon $updated_at
35
* @property string|null $copy_script_install
36
* @property string $copy_script_entry
37
* @property string $copy_script_container
38
* @property string|null $inherit_config_files
39
* @property string|null $inherit_config_startup
40
* @property string|null $inherit_config_logs
41
* @property string|null $inherit_config_stop
42
* @property string $inherit_file_denylist
43
* @property array|null $inherit_features
44
* @property Nest $nest
45
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Server[] $servers
46
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\EggVariable[] $variables
47
* @property Egg|null $scriptFrom
48
* @property Egg|null $configFrom
49
*/
50
class Egg extends Model
51
{
52
/** @use HasFactory<\Database\Factories\EggFactory> */
53
use HasFactory;
54
55
/**
56
* The resource name for this model when it is transformed into an
57
* API representation using fractal.
58
*/
59
public const RESOURCE_NAME = 'egg';
60
61
/**
62
* Defines the current egg export version.
63
*/
64
public const EXPORT_VERSION = 'PTDL_v2';
65
66
/**
67
* Different features that can be enabled on any given egg. These are used internally
68
* to determine which types of frontend functionality should be shown to the user. Eggs
69
* will automatically inherit features from a parent egg if they are already configured
70
* to copy configuration values from said egg.
71
*
72
* To skip copying the features, an empty array value should be passed in ("[]") rather
73
* than leaving it null.
74
*/
75
public const FEATURE_EULA_POPUP = 'eula';
76
public const FEATURE_FASTDL = 'fastdl';
77
78
/**
79
* The table associated with the model.
80
*/
81
protected $table = 'eggs';
82
83
/**
84
* Fields that are not mass assignable.
85
*/
86
protected $fillable = [
87
'name',
88
'description',
89
'features',
90
'docker_images',
91
'force_outgoing_ip',
92
'file_denylist',
93
'config_files',
94
'config_startup',
95
'config_logs',
96
'config_stop',
97
'config_from',
98
'startup',
99
'script_is_privileged',
100
'script_install',
101
'script_entry',
102
'script_container',
103
'copy_script_from',
104
];
105
106
/**
107
* Cast values to correct type.
108
*/
109
protected $casts = [
110
'nest_id' => 'integer',
111
'config_from' => 'integer',
112
'script_is_privileged' => 'boolean',
113
'force_outgoing_ip' => 'boolean',
114
'copy_script_from' => 'integer',
115
'features' => 'array',
116
'docker_images' => 'array',
117
'file_denylist' => 'array',
118
];
119
120
public static array $validationRules = [
121
'nest_id' => 'required|bail|numeric|exists:nests,id',
122
'uuid' => 'required|string|size:36',
123
'name' => 'required|string|max:191',
124
'description' => 'string|nullable',
125
'features' => 'array|nullable',
126
'author' => 'required|string|email',
127
'file_denylist' => 'array|nullable',
128
'file_denylist.*' => 'string',
129
'docker_images' => 'required|array|min:1',
130
'docker_images.*' => ['required', 'string', 'max:191', 'regex:/^[\w#\.\/\- ]*\|?~?[\w\.\/\-:@ ]*$/'],
131
'startup' => 'required|nullable|string',
132
'config_from' => 'sometimes|bail|nullable|numeric|exists:eggs,id',
133
'config_stop' => 'required_without:config_from|nullable|string|max:191',
134
'config_startup' => 'required_without:config_from|nullable|json',
135
'config_logs' => 'required_without:config_from|nullable|json',
136
'config_files' => 'required_without:config_from|nullable|json',
137
'update_url' => 'sometimes|nullable|string',
138
'force_outgoing_ip' => 'sometimes|boolean',
139
];
140
141
protected $attributes = [
142
'features' => null,
143
'file_denylist' => null,
144
'config_stop' => null,
145
'config_startup' => null,
146
'config_logs' => null,
147
'config_files' => null,
148
'update_url' => null,
149
];
150
151
/**
152
* Returns the install script for the egg; if egg is copying from another
153
* it will return the copied script.
154
*/
155
public function getCopyScriptInstallAttribute(): ?string
156
{
157
if (!is_null($this->script_install) || is_null($this->copy_script_from)) {
158
return $this->script_install;
159
}
160
161
return $this->scriptFrom->script_install;
162
}
163
164
/**
165
* Returns the entry command for the egg; if egg is copying from another
166
* it will return the copied entry command.
167
*/
168
public function getCopyScriptEntryAttribute(): string
169
{
170
if (!is_null($this->script_entry) || is_null($this->copy_script_from)) {
171
return $this->script_entry;
172
}
173
174
return $this->scriptFrom->script_entry;
175
}
176
177
/**
178
* Returns the install container for the egg; if egg is copying from another
179
* it will return the copied install container.
180
*/
181
public function getCopyScriptContainerAttribute(): string
182
{
183
if (!is_null($this->script_container) || is_null($this->copy_script_from)) {
184
return $this->script_container;
185
}
186
187
return $this->scriptFrom->script_container;
188
}
189
190
/**
191
* Return the file configuration for an egg.
192
*/
193
public function getInheritConfigFilesAttribute(): ?string
194
{
195
if (!is_null($this->config_files) || is_null($this->config_from)) {
196
return $this->config_files;
197
}
198
199
return $this->configFrom->config_files;
200
}
201
202
/**
203
* Return the startup configuration for an egg.
204
*/
205
public function getInheritConfigStartupAttribute(): ?string
206
{
207
if (!is_null($this->config_startup) || is_null($this->config_from)) {
208
return $this->config_startup;
209
}
210
211
return $this->configFrom->config_startup;
212
}
213
214
/**
215
* Return the log reading configuration for an egg.
216
*/
217
public function getInheritConfigLogsAttribute(): ?string
218
{
219
if (!is_null($this->config_logs) || is_null($this->config_from)) {
220
return $this->config_logs;
221
}
222
223
return $this->configFrom->config_logs;
224
}
225
226
/**
227
* Return the stop command configuration for an egg.
228
*/
229
public function getInheritConfigStopAttribute(): ?string
230
{
231
if (!is_null($this->config_stop) || is_null($this->config_from)) {
232
return $this->config_stop;
233
}
234
235
return $this->configFrom->config_stop;
236
}
237
238
/**
239
* Returns the features available to this egg from the parent configuration if there are
240
* no features defined for this egg specifically and there is a parent egg configured.
241
*/
242
public function getInheritFeaturesAttribute(): ?array
243
{
244
if (!is_null($this->features) || is_null($this->config_from)) {
245
return $this->features;
246
}
247
248
return $this->configFrom->features;
249
}
250
251
/**
252
* Returns the features available to this egg from the parent configuration if there are
253
* no features defined for this egg specifically and there is a parent egg configured.
254
*/
255
public function getInheritFileDenylistAttribute(): ?array
256
{
257
if (is_null($this->config_from)) {
258
return $this->file_denylist;
259
}
260
261
return $this->configFrom->file_denylist;
262
}
263
264
/**
265
* Gets nest associated with an egg.
266
*/
267
public function nest(): BelongsTo
268
{
269
return $this->belongsTo(Nest::class);
270
}
271
272
/**
273
* Gets all servers associated with this egg.
274
*/
275
public function servers(): HasMany
276
{
277
return $this->hasMany(Server::class, 'egg_id');
278
}
279
280
/**
281
* Gets all variables associated with this egg.
282
*/
283
public function variables(): HasMany
284
{
285
return $this->hasMany(EggVariable::class, 'egg_id');
286
}
287
288
/**
289
* Get the parent egg from which to copy scripts.
290
*/
291
public function scriptFrom(): BelongsTo
292
{
293
return $this->belongsTo(self::class, 'copy_script_from');
294
}
295
296
/**
297
* Get the parent egg from which to copy configuration settings.
298
*/
299
public function configFrom(): BelongsTo
300
{
301
return $this->belongsTo(self::class, 'config_from');
302
}
303
}
304
305