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