diff --git a/app/Filament/Admin/Resources/NodeResource/Pages/CreateNode.php b/app/Filament/Admin/Resources/NodeResource/Pages/CreateNode.php index 302ac18cb..2af83bf70 100644 --- a/app/Filament/Admin/Resources/NodeResource/Pages/CreateNode.php +++ b/app/Filament/Admin/Resources/NodeResource/Pages/CreateNode.php @@ -3,19 +3,26 @@ namespace App\Filament\Admin\Resources\NodeResource\Pages; use App\Filament\Admin\Resources\NodeResource; +use App\Models\ApiKey; use App\Models\Node; +use App\Services\Acl\Api\AdminAcl; +use App\Services\Api\KeyCreationService; use Filament\Forms; use Filament\Forms\Components\Actions\Action; use Filament\Forms\Components\Grid; use Filament\Forms\Components\TagsInput; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\ToggleButtons; +use Filament\Forms\Components\View; use Filament\Forms\Components\Wizard; use Filament\Forms\Components\Wizard\Step; use Filament\Forms\Get; use Filament\Forms\Set; +use Filament\Notifications\Notification; use Filament\Resources\Pages\CreateRecord; use Illuminate\Support\Facades\Blade; +use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Request; use Illuminate\Support\HtmlString; class CreateNode extends CreateRecord @@ -24,11 +31,83 @@ class CreateNode extends CreateRecord protected static bool $canCreateAnother = false; + private KeyCreationService $keyCreationService; + + public function boot(KeyCreationService $keyCreationService): void + { + $this->keyCreationService = $keyCreationService; + } + + public function local(): void + { + $wizard = null; + foreach ($this->form->getComponents() as $component) { + if ($component instanceof Wizard) { + $wizard = $component; + } + } + + $wizard->dispatchEvent('wizard::nextStep', $wizard->getStatePath(), 0); + } + + public function cloud(): void + { + $key = ApiKey::query() + ->where('key_type', ApiKey::TYPE_APPLICATION) + ->whereJsonContains('permissions->' . Node::RESOURCE_NAME, AdminAcl::READ|AdminAcl::WRITE) + ->first(); + + if (!$key) { + $key = $this->keyCreationService->setKeyType(ApiKey::TYPE_APPLICATION)->handle([ + 'memo' => 'Automatically generated node cloud key.', + 'user_id' => auth()->user()->id, + 'permissions' => [Node::RESOURCE_NAME => AdminAcl::READ|AdminAcl::WRITE], + ]); + } + + $vars = [ + 'url' => Request::root(), + 'token' => $key->identifier . $key->token, + ]; + + $domain = config('PELICAN_CLOUD_DOMAIN', 'https://hub.pelican.dev'); + + $response = Http::post("$domain/api/cloud/start", $vars); + + if ($response->json('error')) { + $code = $response->json('code'); + Notification::make() + ->danger() + ->persistent() + ->title('Pelican Cloud Error')->body(new HtmlString(" + It looks like there was a problem communicating with Pelican Cloud! + Please make a ticket by clicking here. + ")) + ->send() + ; + + return; + } + + $uuid = $response->json('uuid'); + + $this->redirect("$domain/cloud/$uuid"); + } + public function form(Forms\Form $form): Forms\Form { return $form ->schema([ Wizard::make([ + Step::make('select') + ->label(trans('admin/node.tabs.select_type')) + ->icon('tabler-cloud') + ->columns(2) + ->schema([ + View::make('filament.admin.nodes.config.left'), + View::make('filament.admin.nodes.config.right'), + ]) + , Step::make('basic') ->label(trans('admin/node.tabs.basic_settings')) ->icon('tabler-server') @@ -374,16 +453,25 @@ class CreateNode extends CreateRecord ->required(), ]), ]), - ])->columnSpanFull() - ->nextAction(fn (Action $action) => $action->label(trans('admin/node.next_step'))) - ->submitAction(new HtmlString(Blade::render(<<<'BLADE' - - Create Node - - BLADE))), + ]) + ->columnSpanFull() + ->nextAction(function (Action $action, Wizard $wizard) { + if ($wizard->getCurrentStepIndex() === 0) { + return $action->label(trans('admin/node.next_step'))->view('filament.admin.nodes.config.empty'); + } + + return $action->label(trans('admin/node.next_step')); + }) + ->submitAction(new HtmlString(Blade::render( + <<<'BLADE' + + Create Node + + BLADE + ))), ]); } diff --git a/app/Filament/App/Resources/ServerResource/Pages/ListServers.php b/app/Filament/App/Resources/ServerResource/Pages/ListServers.php index a961d5036..1ddfbf8a8 100644 --- a/app/Filament/App/Resources/ServerResource/Pages/ListServers.php +++ b/app/Filament/App/Resources/ServerResource/Pages/ListServers.php @@ -55,19 +55,19 @@ class ListServers extends ListRecords $viewThree = [ TextColumn::make('cpuUsage') - ->label('') + ->label('CPU') ->icon('tabler-cpu') ->tooltip(fn (Server $server) => 'Usage Limit: ' . $server->formatResource('cpu', limit: true, type: ServerResourceType::Percentage, precision: 0)) ->state(fn (Server $server) => $server->formatResource('cpu_absolute', type: ServerResourceType::Percentage)) ->color(fn (Server $server) => $this->getResourceColor($server, 'cpu')), TextColumn::make('memoryUsage') - ->label('') + ->label('Memory') ->icon('tabler-memory') ->tooltip(fn (Server $server) => 'Usage Limit: ' . $server->formatResource('memory', limit: true)) ->state(fn (Server $server) => $server->formatResource('memory_bytes')) ->color(fn (Server $server) => $this->getResourceColor($server, 'memory')), TextColumn::make('diskUsage') - ->label('') + ->label('Disk') ->icon('tabler-device-floppy') ->tooltip(fn (Server $server) => 'Usage Limit: ' . $server->formatResource('disk', limit: true)) ->state(fn (Server $server) => $server->formatResource('disk_bytes')) diff --git a/app/Repositories/Daemon/DaemonConfigurationRepository.php b/app/Repositories/Daemon/DaemonConfigurationRepository.php index 48d2b35c4..73d5bf021 100644 --- a/app/Repositories/Daemon/DaemonConfigurationRepository.php +++ b/app/Repositories/Daemon/DaemonConfigurationRepository.php @@ -18,7 +18,8 @@ class DaemonConfigurationRepository extends DaemonRepository public function getSystemInformation(): array { return $this->getHttpClient() - ->connectTimeout(3) + ->connectTimeout(1) + ->timeout(1) ->get('/api/system') ->throwIf(function ($result) { $header = $result->header('User-Agent'); diff --git a/lang/en/admin/node.php b/lang/en/admin/node.php index 582d3a808..4a1d3dc7d 100644 --- a/lang/en/admin/node.php +++ b/lang/en/admin/node.php @@ -9,6 +9,7 @@ return [ 'basic_settings' => 'Basic Settings', 'advanced_settings' => 'Advanced Settings', 'config_file' => 'Configuration File', + 'select_type' => 'Node Type', ], 'table' => [ 'health' => 'Health', diff --git a/public/images/cloud.png b/public/images/cloud.png new file mode 100644 index 000000000..ca3c4da8d Binary files /dev/null and b/public/images/cloud.png differ diff --git a/public/images/local.png b/public/images/local.png new file mode 100644 index 000000000..0c655cf30 Binary files /dev/null and b/public/images/local.png differ diff --git a/resources/views/filament/admin/nodes/config/empty.blade.php b/resources/views/filament/admin/nodes/config/empty.blade.php new file mode 100644 index 000000000..e69de29bb diff --git a/resources/views/filament/admin/nodes/config/left.blade.php b/resources/views/filament/admin/nodes/config/left.blade.php new file mode 100644 index 000000000..09fccd768 --- /dev/null +++ b/resources/views/filament/admin/nodes/config/left.blade.php @@ -0,0 +1,16 @@ +
+ + Pelican Cloud + +
+ +
+

Very easily and quickly set up a powerful game server on our cloud!

+ pelican cloud +
diff --git a/resources/views/filament/admin/nodes/config/right.blade.php b/resources/views/filament/admin/nodes/config/right.blade.php new file mode 100644 index 000000000..62c2cc7be --- /dev/null +++ b/resources/views/filament/admin/nodes/config/right.blade.php @@ -0,0 +1,16 @@ +
+ + Self Host + +
+ +
+

Use your own hardware either in your home or somewhere else.

+ pelican cloud +