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