Skip to content

Commit

Permalink
Merge branch 'pelican-dev:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultjunin authored Dec 4, 2024
2 parents 628481b + efc37dd commit 9790094
Show file tree
Hide file tree
Showing 109 changed files with 6,047 additions and 452 deletions.
98 changes: 98 additions & 0 deletions app/Enums/EditorLanguages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace App\Enums;

use Filament\Support\Contracts\HasLabel;

enum EditorLanguages: string implements HasLabel
{
case plaintext = 'plaintext';
case abap = 'abap';
case apex = 'apex';
case azcali = 'azcali';
case bat = 'bat';
case bicep = 'bicep';
case cameligo = 'cameligo';
case coljure = 'coljure';
case coffeescript = 'coffeescript';
case c = 'c';
case cpp = 'cpp';
case csharp = 'csharp';
case csp = 'csp';
case css = 'css';
case cypher = 'cypher';
case dart = 'dart';
case dockerfile = 'dockerfile';
case ecl = 'ecl';
case elixir = 'elixir';
case flow9 = 'flow9';
case fsharp = 'fsharp';
case go = 'go';
case graphql = 'graphql';
case handlebars = 'handlebars';
case hcl = 'hcl';
case html = 'html';
case ini = 'ini';
case java = 'java';
case javascript = 'javascript';
case julia = 'julia';
case kotlin = 'kotlin';
case less = 'less';
case lexon = 'lexon';
case lua = 'lua';
case liquid = 'liquid';
case m3 = 'm3';
case markdown = 'markdown';
case mdx = 'mdx';
case mips = 'mips';
case msdax = 'msdax';
case mysql = 'mysql';
case objectivec = 'objective-c';
case pascal = 'pascal';
case pascaligo = 'pascaligo';
case perl = 'perl';
case pgsql = 'pgsql';
case php = 'php';
case pla = 'pla';
case postiats = 'postiats';
case powerquery = 'powerquery';
case powershell = 'powershell';
case proto = 'proto';
case pug = 'pug';
case python = 'python';
case qsharp = 'qsharp';
case r = 'r';
case razor = 'razor';
case redis = 'redis';
case redshift = 'redshift';
case restructuredtext = 'restructuredtext';
case ruby = 'ruby';
case rust = 'rust';
case sb = 'sb';
case scala = 'scala';
case scheme = 'scheme';
case scss = 'scss';
case shell = 'shell';
case sol = 'sol';
case aes = 'aes';
case sparql = 'sparql';
case sql = 'sql';
case st = 'st';
case swift = 'swift';
case systemverilog = 'systemverilog';
case verilog = 'verilog';
case tcl = 'tcl';
case twig = 'twig';
case typescript = 'typescript';
case typespec = 'typespec';
case vb = 'vb';
case wgsl = 'wgsl';
case xml = 'xml';
case yaml = 'yaml';
case json = 'json';

public function getLabel(): ?string
{
return $this->name;
}
}
1 change: 1 addition & 0 deletions app/Enums/RolePermissionModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ enum RolePermissionModels: string
case Role = 'role';
case Server = 'server';
case User = 'user';
case Webhook = 'webhook';
}
28 changes: 28 additions & 0 deletions app/Filament/App/Resources/ServerResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Filament\App\Resources;

use App\Filament\App\Resources\ServerResource\Pages;
use App\Models\Server;
use Filament\Resources\Resource;

class ServerResource extends Resource
{
protected static ?string $model = Server::class;

protected static ?string $slug = '/';

protected static bool $shouldRegisterNavigation = false;

public static function canAccess(): bool
{
return true;
}

public static function getPages(): array
{
return [
'index' => Pages\ListServers::route('/'),
];
}
}
101 changes: 101 additions & 0 deletions app/Filament/App/Resources/ServerResource/Pages/ListServers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace App\Filament\App\Resources\ServerResource\Pages;

use App\Filament\App\Resources\ServerResource;
use App\Filament\Server\Pages\Console;
use App\Models\Server;
use App\Tables\Columns\ServerEntryColumn;
use Carbon\CarbonInterface;
use Filament\Resources\Pages\ListRecords;
use Filament\Tables\Columns\Layout\Stack;
use Filament\Tables\Table;
use Illuminate\Support\Arr;
use Illuminate\Support\Number;

class ListServers extends ListRecords
{
protected static string $resource = ServerResource::class;

public function table(Table $table): Table
{
return $table
->paginated(false)
->query(fn () => auth()->user()->can('viewList server') ? Server::query() : auth()->user()->accessibleServers())
->poll('15s')
->columns([
Stack::make([
ServerEntryColumn::make('server_entry')
->searchable(['name']),
]),
])
->contentGrid([
'default' => 1,
'xl' => 2,
])
->recordUrl(fn (Server $server) => Console::getUrl(panel: 'server', tenant: $server))
->emptyStateIcon('tabler-brand-docker')
->emptyStateDescription('')
->emptyStateHeading('You don\'t have access to any servers!');
}

// @phpstan-ignore-next-line
private function uptime(Server $server): string
{
$uptime = Arr::get($server->resources(), 'uptime', 0);

if ($uptime === 0) {
return 'Offline';
}

return now()->subMillis($uptime)->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, short: true, parts: 2);
}

// @phpstan-ignore-next-line
private function cpu(Server $server): string
{
$cpu = Number::format(Arr::get($server->resources(), 'cpu_absolute', 0), maxPrecision: 2, locale: auth()->user()->language) . '%';
$max = Number::format($server->cpu, locale: auth()->user()->language) . '%';

return $cpu . ($server->cpu > 0 ? ' Of ' . $max : '');
}

// @phpstan-ignore-next-line
private function memory(Server $server): string
{
$latestMemoryUsed = Arr::get($server->resources(), 'memory_bytes', 0);
$totalMemory = Arr::get($server->resources(), 'memory_limit_bytes', 0);

$used = config('panel.use_binary_prefix')
? Number::format($latestMemoryUsed / 1024 / 1024 / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB'
: Number::format($latestMemoryUsed / 1000 / 1000 / 1000, maxPrecision: 2, locale: auth()->user()->language) . ' GB';

if ($totalMemory === 0) {
$total = config('panel.use_binary_prefix')
? Number::format($server->memory / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB'
: Number::format($server->memory / 1000, maxPrecision: 2, locale: auth()->user()->language) . ' GB';
} else {
$total = config('panel.use_binary_prefix')
? Number::format($totalMemory / 1024 / 1024 / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB'
: Number::format($totalMemory / 1000 / 1000 / 1000, maxPrecision: 2, locale: auth()->user()->language) . ' GB';
}

return $used . ($server->memory > 0 ? ' Of ' . $total : '');
}

// @phpstan-ignore-next-line
private function disk(Server $server): string
{
$usedDisk = Arr::get($server->resources(), 'disk_bytes', 0);

$used = config('panel.use_binary_prefix')
? Number::format($usedDisk / 1024 / 1024 / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB'
: Number::format($usedDisk / 1000 / 1000 / 1000, maxPrecision: 2, locale: auth()->user()->language) . ' GB';

$total = config('panel.use_binary_prefix')
? Number::format($server->disk / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB'
: Number::format($server->disk / 1000, maxPrecision: 2, locale: auth()->user()->language) . ' GB';

return $used . ($server->disk > 0 ? ' Of ' . $total : '');
}
}
23 changes: 23 additions & 0 deletions app/Filament/Pages/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace App\Filament\Pages\Auth;

use Coderflex\FilamentTurnstile\Forms\Components\Turnstile;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\TextInput;
use Filament\Pages\Auth\Login as BaseLogin;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;

class Login extends BaseLogin
Expand All @@ -19,6 +22,7 @@ protected function getForms(): array
$this->getLoginFormComponent(),
$this->getPasswordFormComponent(),
$this->getRememberFormComponent(),
$this->getOAuthFormComponent(),
Turnstile::make('captcha')
->hidden(!config('turnstile.turnstile_enabled'))
->validationMessages([
Expand Down Expand Up @@ -49,6 +53,25 @@ protected function getLoginFormComponent(): Component
->extraInputAttributes(['tabindex' => 1]);
}

protected function getOAuthFormComponent(): Component
{
$actions = [];

foreach (config('auth.oauth') as $name => $data) {
if (!$data['enabled']) {
continue;
}

$actions[] = Action::make("oauth_$name")
->label(Str::title($name))
->icon($data['icon'])
->color($data['color'])
->url(route('auth.oauth.redirect', ['driver' => $name], false));
}

return Actions::make($actions);
}

protected function getCredentialsFromFormData(array $data): array
{
$loginType = filter_var($data['login'], FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
Expand Down
31 changes: 17 additions & 14 deletions app/Filament/Pages/Installer/PanelInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
use Filament\Pages\SimplePage;
use Filament\Support\Enums\MaxWidth;
use Filament\Support\Exceptions\Halt;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\HtmlString;
Expand Down Expand Up @@ -91,20 +89,26 @@ protected function getFormStatePath(): ?string
return 'data';
}

public function submit(UserCreationService $userCreationService): Redirector|RedirectResponse
public function submit(UserCreationService $userCreationService): void
{
// Disable installer
$this->writeToEnvironment(['APP_INSTALLED' => 'true']);
try {
// Disable installer
$this->writeToEnvironment(['APP_INSTALLED' => 'true']);

// Run migrations
$this->runMigrations();

// Create admin user & login
$user = $this->createAdminUser($userCreationService);
auth()->guard()->login($user, true);
// Create admin user & login
$user = $this->createAdminUser($userCreationService);
auth()->guard()->login($user, true);

// Write session data at the very end to avoid "page expired" errors
$this->writeToEnv('env_session');
// Write session data at the very end to avoid "page expired" errors
$this->writeToEnv('env_session');

// Redirect to admin panel
return redirect(Dashboard::getUrl());
// Redirect to admin panel
$this->redirect(Dashboard::getUrl());
} catch (Halt) {
}
}

public function writeToEnv(string $key): void
Expand All @@ -129,13 +133,12 @@ public function writeToEnv(string $key): void
Artisan::call('config:clear');
}

public function runMigrations(string $driver): void
public function runMigrations(): void
{
try {
Artisan::call('migrate', [
'--force' => true,
'--seed' => true,
'--database' => $driver,
]);
} catch (Exception $exception) {
report($exception);
Expand Down
2 changes: 0 additions & 2 deletions app/Filament/Pages/Installer/Steps/DatabaseStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ public static function make(PanelInstaller $installer): Step
}

$installer->writeToEnv('env_database');

$installer->runMigrations($driver);
});
}

Expand Down
4 changes: 1 addition & 3 deletions app/Filament/Pages/Installer/Steps/QueueStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public static function make(PanelInstaller $installer): Step
->hidden(fn () => file_exists('/.dockerenv'))
->columnSpanFull(),
])
->afterValidation(function () use ($installer) {
$installer->writeToEnv('env_queue');
});
->afterValidation(fn () => $installer->writeToEnv('env_queue'));
}
}
Loading

0 comments on commit 9790094

Please sign in to comment.