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