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