Files
pterodactyl-panel/app/Models/Mount.php
T

123 lines
3.1 KiB
PHP
Raw Normal View History

2020-05-20 17:29:03 -06:00
<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2020-05-20 17:29:03 -06:00
namespace Pterodactyl\Models;
2026-10-05 18:10:18 -04:00
use Database\Factories\MountFactory;
use Illuminate\Database\Eloquent\Attributes\Guarded;
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Attributes\WithoutTimestamps;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Pterodactyl\Contracts\Models\Identifiable;
use Pterodactyl\Models\Traits\HasRealtimeIdentifier;
2020-10-17 14:42:08 -06:00
2020-05-20 17:29:03 -06: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
2026-10-05 18:10:18 -04:00
* @property Egg[]|Collection $eggs
* @property Node[]|Collection $nodes
* @property Server[]|Collection $servers
2020-05-20 17:29:03 -06:00
*/
#[Attributes\Identifiable('moun')]
2026-10-05 18:10:18 -04:00
#[Guarded(['id', 'uuid'])]
#[WithoutTimestamps]
class Mount extends Model implements Identifiable
2020-05-20 17:29:03 -06:00
{
2026-10-05 18:10:18 -04:00
/** @use HasFactory<MountFactory> */
use HasFactory;
use HasRealtimeIdentifier;
2020-05-20 17:29:03 -06:00
/**
* The resource name for this model when it is transformed into an
* API representation using fractal.
*/
2026-10-05 18:10:18 -04:00
public const string RESOURCE_NAME = 'mount';
2020-05-20 18:55:59 -06:00
2020-10-17 14:37:18 -06:00
/**
2021-01-23 12:09:16 -08:00
* Blacklisted source paths.
2026-10-05 18:10:18 -04:00
*
* @var list<string>
2020-10-17 14:37:18 -06:00
*/
2026-10-05 18:10:18 -04:00
public static array $invalidSourcePaths = [
2020-10-17 14:37:18 -06:00
'/etc/pterodactyl',
'/var/lib/pterodactyl/volumes',
'/srv/daemon-data',
];
/**
2021-01-23 12:09:16 -08:00
* Blacklisted target paths.
2026-10-05 18:10:18 -04:00
*
* @var list<string>
2020-10-17 14:37:18 -06:00
*/
2026-10-05 18:10:18 -04:00
public static array $invalidTargetPaths = [
2020-10-17 14:37:18 -06:00
'/home/container',
];
2026-10-05 18:10:18 -04:00
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'id' => 'int',
'read_only' => 'bool',
'user_mountable' => 'bool',
];
}
/**
* Returns all eggs that have this mount assigned.
*
2026-10-05 18:10:18 -04:00
* @return BelongsToMany<Egg, $this>
*/
2022-10-14 10:59:20 -06:00
public function eggs(): BelongsToMany
{
return $this->belongsToMany(Egg::class);
}
/**
* Returns all nodes that have this mount assigned.
*
2026-10-05 18:10:18 -04:00
* @return BelongsToMany<Node, $this>
*/
2022-10-14 10:59:20 -06:00
public function nodes(): BelongsToMany
{
2020-08-25 21:54:41 -07:00
return $this->belongsToMany(Node::class);
}
/**
2020-08-25 21:54:41 -07:00
* Returns all servers that have this mount assigned.
*
2026-10-05 18:10:18 -04:00
* @return BelongsToMany<Server, $this>
*/
2022-10-14 10:59:20 -06:00
public function servers(): BelongsToMany
{
2020-08-25 21:54:41 -07:00
return $this->belongsToMany(Server::class);
}
2026-10-05 18:10:18 -04:00
/**
* Mounts attached to both the server's egg and its node, whether or not the
* server currently has them mounted.
*
* @param Builder<self> $query
*/
#[Scope]
protected function availableToServer(Builder $query, Server $server): void
{
$query
->whereHas('eggs', fn (Builder $eggs) => $eggs->whereKey($server->egg_id))
->whereHas('nodes', fn (Builder $nodes) => $nodes->whereKey($server->node_id));
}
2020-05-20 17:29:03 -06:00
}