mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 20:14:46 +02:00
Various improvements
This commit is contained in:
parent
4f5e9a6c30
commit
a2108c3d91
@ -46,8 +46,11 @@ class CreateServer extends CreateRecord
|
||||
protected static bool $canCreateAnother = false;
|
||||
|
||||
public ?Node $node = null;
|
||||
|
||||
public ?Egg $egg = null;
|
||||
|
||||
public array $ports = [];
|
||||
|
||||
public array $eggDefaultPorts = [];
|
||||
|
||||
private ServerCreationService $serverCreationService;
|
||||
@ -769,7 +772,7 @@ class CreateServer extends CreateRecord
|
||||
->all();
|
||||
}
|
||||
|
||||
public function ports($state, Forms\Set $set)
|
||||
public function ports(array $state, Forms\Set $set): void
|
||||
{
|
||||
$ports = collect();
|
||||
foreach ($state as $portEntry) {
|
||||
@ -804,7 +807,7 @@ class CreateServer extends CreateRecord
|
||||
$this->ports = $ports->all();
|
||||
}
|
||||
|
||||
public function resetEggVariables(Forms\Set $set, Forms\Get $get)
|
||||
public function resetEggVariables(Forms\Set $set, Forms\Get $get): void
|
||||
{
|
||||
$set('assignments', []);
|
||||
|
||||
|
@ -47,8 +47,11 @@ use Webbingbrasil\FilamentCopyActions\Forms\Actions\CopyAction;
|
||||
class EditServer extends EditRecord
|
||||
{
|
||||
public ?Node $node = null;
|
||||
|
||||
public ?Egg $egg = null;
|
||||
|
||||
public array $ports = [];
|
||||
|
||||
public array $eggDefaultPorts = [];
|
||||
|
||||
protected static string $resource = ServerResource::class;
|
||||
@ -901,7 +904,7 @@ class EditServer extends EditRecord
|
||||
->all();
|
||||
}
|
||||
|
||||
public function ports($state, Forms\Set $set)
|
||||
public function ports(array $state, Forms\Set $set): void
|
||||
{
|
||||
$ports = collect();
|
||||
|
||||
@ -949,7 +952,7 @@ class EditServer extends EditRecord
|
||||
$this->ports = $ports->all();
|
||||
}
|
||||
|
||||
public function portOptions(Egg $egg, string $startup = null): array
|
||||
public function portOptions(Egg $egg, ?string $startup = null): array
|
||||
{
|
||||
if (empty($startup)) {
|
||||
$startup = $egg->startup;
|
||||
|
@ -289,7 +289,7 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile
|
||||
|
||||
if ($token = $data['2facode'] ?? null) {
|
||||
$tokens = $this->toggleTwoFactorService->handle($record, $token, true);
|
||||
cache()->set("users.$record->id.2fa.tokens", implode("\n", $tokens), now()->addSeconds(15));
|
||||
cache()->set("users.$record->id.2fa.tokens", implode("\n", $tokens), 15);
|
||||
|
||||
$this->redirectRoute('filament.admin.auth.profile', ['tab' => '-2fa-tab']);
|
||||
}
|
||||
|
@ -4,22 +4,23 @@ namespace App\Livewire;
|
||||
|
||||
use App\Models\Objects\Endpoint;
|
||||
use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth;
|
||||
use Stringable;
|
||||
|
||||
class EndpointSynth extends Synth
|
||||
{
|
||||
public static $key = 'endpoint';
|
||||
public static string $key = 'endpoint';
|
||||
|
||||
public static function match($target)
|
||||
public static function match(mixed $target): bool
|
||||
{
|
||||
return $target instanceof Endpoint;
|
||||
}
|
||||
|
||||
public function dehydrate($target)
|
||||
public function dehydrate(Stringable $target): string
|
||||
{
|
||||
return (string) $target;
|
||||
}
|
||||
|
||||
public function hydrate($value)
|
||||
public function hydrate(mixed $value): ?Endpoint
|
||||
{
|
||||
if (!is_string($value) && !is_int($value)) {
|
||||
return null;
|
||||
|
@ -53,6 +53,7 @@ class Node extends Model
|
||||
public const RESOURCE_NAME = 'node';
|
||||
|
||||
public const DAEMON_TOKEN_ID_LENGTH = 16;
|
||||
|
||||
public const DAEMON_TOKEN_LENGTH = 64;
|
||||
|
||||
/**
|
||||
@ -135,7 +136,9 @@ class Node extends Model
|
||||
}
|
||||
|
||||
public int $servers_sum_memory = 0;
|
||||
|
||||
public int $servers_sum_disk = 0;
|
||||
|
||||
public int $servers_sum_cpu = 0;
|
||||
|
||||
public function getRouteKeyName(): string
|
||||
@ -264,6 +267,7 @@ class Node extends Model
|
||||
{
|
||||
return once(function () {
|
||||
try {
|
||||
// @phpstan-ignore-next-line
|
||||
return resolve(DaemonConfigurationRepository::class)
|
||||
->setNode($this)
|
||||
->getSystemInformation(connectTimeout: 3);
|
||||
@ -299,7 +303,7 @@ class Node extends Model
|
||||
return $statuses;
|
||||
}
|
||||
|
||||
public function statistics()
|
||||
public function statistics(): array
|
||||
{
|
||||
$default = [
|
||||
'memory_total' => 0,
|
||||
|
@ -8,18 +8,26 @@ use InvalidArgumentException;
|
||||
class Endpoint implements Jsonable
|
||||
{
|
||||
public const CIDR_MAX_BITS = 27;
|
||||
|
||||
public const CIDR_MIN_BITS = 32;
|
||||
|
||||
public const PORT_FLOOR = 1024;
|
||||
|
||||
public const PORT_CEIL = 65535;
|
||||
|
||||
public const PORT_RANGE_LIMIT = 1000;
|
||||
|
||||
public const PORT_RANGE_REGEX = '/^(\d{4,5})-(\d{4,5})$/';
|
||||
|
||||
public const INADDR_ANY = '0.0.0.0';
|
||||
|
||||
public const INADDR_LOOPBACK = '127.0.0.1';
|
||||
|
||||
public int $port;
|
||||
|
||||
public string $ip;
|
||||
|
||||
public function __construct(string|int $port, string $ip = null)
|
||||
public function __construct(string|int $port, ?string $ip = null)
|
||||
{
|
||||
$this->ip = $ip ?? self::INADDR_ANY;
|
||||
$this->port = (int) $port;
|
||||
|
@ -433,6 +433,7 @@ class Server extends Model
|
||||
|
||||
return $this->status->color();
|
||||
}
|
||||
|
||||
public function getPrimaryEndpoint(): ?Endpoint
|
||||
{
|
||||
$endpoint = $this->ports->first();
|
||||
|
@ -18,9 +18,6 @@ use App\Models\Egg;
|
||||
|
||||
class ServerCreationService
|
||||
{
|
||||
/**
|
||||
* ServerCreationService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
private ConnectionInterface $connection,
|
||||
private DaemonServerRepository $daemonServerRepository,
|
||||
@ -32,19 +29,13 @@ class ServerCreationService
|
||||
/**
|
||||
* Create a server on the Panel and trigger a request to the Daemon to begin the server creation process.
|
||||
* This function will attempt to set as many additional values as possible given the input data.
|
||||
*
|
||||
* @throws \Throwable
|
||||
* @throws \App\Exceptions\DisplayException
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
* @throws \App\Exceptions\Service\Deployment\NoViableAllocationException
|
||||
*/
|
||||
public function handle(array $data, ?DeploymentObject $deployment = null, $validateVariables = true): Server
|
||||
public function handle(array $data, ?DeploymentObject $deployment = null, bool $validateVariables = true): Server
|
||||
{
|
||||
if (!isset($data['oom_killer']) && isset($data['oom_disabled'])) {
|
||||
$data['oom_killer'] = !$data['oom_disabled'];
|
||||
}
|
||||
|
||||
/** @var Egg $egg */
|
||||
$egg = Egg::query()->findOrFail($data['egg_id']);
|
||||
|
||||
// Fill missing fields from egg
|
||||
@ -62,7 +53,7 @@ class ServerCreationService
|
||||
//
|
||||
// If that connection fails out we will attempt to perform a cleanup by just
|
||||
// deleting the server itself from the system.
|
||||
/** @var \App\Models\Server $server */
|
||||
/** @var Server $server */
|
||||
$server = $this->connection->transaction(function () use ($data, $eggVariableData) {
|
||||
// Create the server and assign any additional allocations to it.
|
||||
$server = $this->createModel($data);
|
||||
|
@ -25,7 +25,7 @@ class VariableValidatorService
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function handle(int $egg, array $fields = [], $validate = true): Collection
|
||||
public function handle(int $egg, array $fields = [], bool $validate = true): Collection
|
||||
{
|
||||
$query = EggVariable::query()->where('egg_id', $egg);
|
||||
if (!$this->isUserLevel(User::USER_LEVEL_ADMIN)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user