Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Models/Mount.php
7432 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
public function eggs(): BelongsToMany
99
{
100
return $this->belongsToMany(Egg::class);
101
}
102
103
/**
104
* Returns all nodes that have this mount assigned.
105
*/
106
public function nodes(): BelongsToMany
107
{
108
return $this->belongsToMany(Node::class);
109
}
110
111
/**
112
* Returns all servers that have this mount assigned.
113
*/
114
public function servers(): BelongsToMany
115
{
116
return $this->belongsToMany(Server::class);
117
}
118
}
119
120