1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-23 09:32:29 +01:00
Pterodactyl-Panel/app/Models/Mount.php

138 lines
3.7 KiB
PHP
Raw Normal View History

2020-05-21 01:29:03 +02:00
<?php
namespace Pterodactyl\Models;
use Illuminate\Validation\Rules\NotIn;
2020-05-21 01:29:03 +02:00
/**
2021-01-23 21:33:34 +01:00
* @property int $id
* @property string $uuid
* @property string $name
* @property string $description
* @property string $source
* @property string $target
* @property bool $read_only
* @property bool $user_mountable
* @property \Pterodactyl\Models\Egg[]|\Illuminate\Database\Eloquent\Collection $eggs
* @property \Pterodactyl\Models\Node[]|\Illuminate\Database\Eloquent\Collection $nodes
* @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
2020-05-21 01:29:03 +02:00
*/
class Mount extends Model
{
/**
* The resource name for this model when it is transformed into an
* API representation using fractal.
*/
2021-01-23 21:33:34 +01:00
public const RESOURCE_NAME = 'mount';
2020-05-21 01:29:03 +02:00
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'mounts';
/**
* Fields that are not mass assignable.
*
* @var array
*/
protected $guarded = ['id', 'uuid'];
/**
* Default values for specific fields in the database.
*
* @var array
*/
2020-09-13 19:04:30 +02:00
protected $casts = [
'id' => 'int',
'read_only' => 'bool',
'user_mountable' => 'bool',
];
/**
* Rules verifying that the data being stored matches the expectations of the database.
*
* @var string
*/
public static $validationRules = [
'name' => 'required|string|min:2|max:64|unique:mounts,name',
'description' => 'nullable|string|max:191',
'source' => 'required|string',
'target' => 'required|string',
'read_only' => 'sometimes|boolean',
'user_mountable' => 'sometimes|boolean',
];
/**
* Implement language verification by overriding Eloquence's gather
* rules function.
*/
public static function getRules()
{
$rules = parent::getRules();
$rules['source'][] = new NotIn(Mount::$invalidSourcePaths);
2020-10-17 22:43:07 +02:00
$rules['target'][] = new NotIn(Mount::$invalidTargetPaths);
return $rules;
}
2020-05-21 02:55:59 +02:00
/**
* Disable timestamps on this model.
2020-05-21 02:57:30 +02:00
*
2020-05-21 02:55:59 +02:00
* @var bool
*/
public $timestamps = false;
2020-10-17 22:37:18 +02:00
/**
* Blacklisted source paths.
2020-10-17 22:37:18 +02:00
*
* @var string[]
*/
public static $invalidSourcePaths = [
'/etc/pterodactyl',
'/var/lib/pterodactyl/volumes',
'/srv/daemon-data',
];
/**
* Blacklisted target paths.
2020-10-17 22:37:18 +02:00
*
* @var string[]
*/
public static $invalidTargetPaths = [
'/home/container',
];
/**
* Returns all eggs that have this mount assigned.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function eggs()
{
return $this->belongsToMany(Egg::class);
}
/**
* Returns all nodes that have this mount assigned.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function nodes()
{
return $this->belongsToMany(Node::class);
}
/**
* Returns all servers that have this mount assigned.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function servers()
{
return $this->belongsToMany(Server::class);
}
2020-05-21 01:29:03 +02:00
}