Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Models/Mount.php
14039 views
1
<?php
2
3
namespace Pterodactyl\Models;
4
5
use Illuminate\Validation\Rules\NotIn;
6
use Pterodactyl\Contracts\Models\Identifiable;
7
use Pterodactyl\Models\Traits\HasRealtimeIdentifier;
8
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
9
10
/**
11
* @property int $id
12
* @property string $uuid
13
* @property string $name
14
* @property string $description
15
* @property string $source
16
* @property string $target
17
* @property bool $read_only
18
* @property bool $user_mountable
19
* @property \Pterodactyl\Models\Egg[]|\Illuminate\Database\Eloquent\Collection $eggs
20
* @property \Pterodactyl\Models\Node[]|\Illuminate\Database\Eloquent\Collection $nodes
21
* @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
22
*/
23
#[Attributes\Identifiable('moun')]
24
class Mount extends Model implements Identifiable
25
{
26
use HasRealtimeIdentifier;
27
28
/**
29
* The resource name for this model when it is transformed into an
30
* API representation using fractal.
31
*/
32
public const RESOURCE_NAME = 'mount';
33
34
/**
35
* The table associated with the model.
36
*/
37
protected $table = 'mounts';
38
39
/**
40
* Fields that are not mass assignable.
41
*/
42
protected $guarded = ['id', 'uuid'];
43
44
/**
45
* Default values for specific fields in the database.
46
*/
47
protected $casts = [
48
'id' => 'int',
49
'read_only' => 'bool',
50
'user_mountable' => 'bool',
51
];
52
53
/**
54
* Rules verifying that the data being stored matches the expectations of the database.
55
*/
56
public static array $validationRules = [
57
'name' => 'required|string|min:2|max:64|unique:mounts,name',
58
'description' => 'nullable|string|max:191',
59
'source' => 'required|string',
60
'target' => 'required|string',
61
'read_only' => 'sometimes|boolean',
62
'user_mountable' => 'sometimes|boolean',
63
];
64
65
/**
66
* Implement language verification by overriding Eloquence's gather
67
* rules function.
68
*/
69
public static function getRules(): array
70
{
71
$rules = parent::getRules();
72
73
$rules['source'][] = new NotIn(Mount::$invalidSourcePaths);
74
$rules['target'][] = new NotIn(Mount::$invalidTargetPaths);
75
76
return $rules;
77
}
78
79
/**
80
* Disable timestamps on this model.
81
*/
82
public $timestamps = false;
83
84
/**
85
* Blacklisted source paths.
86
*/
87
public static $invalidSourcePaths = [
88
'/etc/pterodactyl',
89
'/var/lib/pterodactyl/volumes',
90
'/srv/daemon-data',
91
];
92
93
/**
94
* Blacklisted target paths.
95
*/
96
public static $invalidTargetPaths = [
97
'/home/container',
98
];
99
100
/**
101
* Returns all eggs that have this mount assigned.
102
*
103
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\Pterodactyl\Models\Egg, $this>
104
*/
105
public function eggs(): BelongsToMany
106
{
107
return $this->belongsToMany(Egg::class);
108
}
109
110
/**
111
* Returns all nodes that have this mount assigned.
112
*
113
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\Pterodactyl\Models\Node, $this>
114
*/
115
public function nodes(): BelongsToMany
116
{
117
return $this->belongsToMany(Node::class);
118
}
119
120
/**
121
* Returns all servers that have this mount assigned.
122
*
123
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\Pterodactyl\Models\Server, $this>
124
*/
125
public function servers(): BelongsToMany
126
{
127
return $this->belongsToMany(Server::class);
128
}
129
}
130
131