Admin panel v1

This commit is contained in:
Ralph J. Smit
2022-08-05 18:11:23 +02:00
parent d89482c4aa
commit 9d1b12b0a3
62 changed files with 2010 additions and 577 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Actions\Provider;
use App\Models\Provider;
use App\Services\Ploi\Ploi;
class SynchronizeProviderAction
{
public function execute(int $ploiProviderId): Provider
{
$ploiProvider = Ploi::make()->user()->serverProviders($ploiProviderId)->getData();
$provider = Provider::updateOrCreate([
'ploi_id' => $ploiProvider->id,
], [
'label' => $ploiProvider->label,
'name' => $ploiProvider->name,
]);
foreach ($ploiProvider->provider->plans as $plan) {
$provider->plans()->updateOrCreate([
'plan_id' => $plan->id,
], [
'label' => $plan->name,
]);
}
foreach ($ploiProvider->provider->regions as $region) {
$provider->regions()->updateOrCreate([
'region_id' => $region->id,
], [
'label' => $region->name,
]);
}
return $provider;
}
}

View File

@@ -0,0 +1,175 @@
<?php
namespace App\Filament\Pages;
use App\Models\Package;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
class Settings extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-cog';
protected static string $view = 'filament.pages.settings';
protected static ?string $navigationGroup = 'Settings';
protected static ?int $navigationSort = 1;
public array $data = [];
public function mount(): void
{
cache()->forget('core.settings');
$this->form->fill([
'logo' => setting('logo'),
'name' => setting('name'),
'email' => setting('email'),
'support_emails' => setting('support_emails'),
'default_package' => setting('default_package'),
'default_language' => setting('default_language'),
'rotate_logs_after' => setting('rotate_logs_after'),
'trial' => (bool) setting('trial'),
'support' => (bool) setting('support'),
'documentation' => (bool) setting('documentation'),
'allow_registration' => (bool) setting('allow_registration'),
'receive_email_on_server_creation' => (bool) setting('receive_email_on_server_creation'),
'receive_email_on_site_creation' => (bool) setting('receive_email_on_site_creation'),
'enable_api' => (bool) setting('enable_api'),
'api_token' => setting('api_token'),
'isolate_per_site_per_user' => (bool) setting('isolate_per_site_per_user'),
]);
}
public function getFormSchema(): array
{
return [
Grid::make(2)
->schema([
FileUpload::make('logo')
->label(__('Logo'))
->disk('logos'),
Grid::make(1)
->schema([
TextInput::make('name')
->label(__('Company name'))
->required(),
TextInput::make('email')
->label(__('E-mail address'))
->email(),
TextInput::make('support_emails')
->label(__('Support email address'))
->helperText('Separate by comma to allow more email addresses'),
])
->columnSpan(1),
Select::make('default_package')
->options(fn () => Package::orderBy('name')->get()->mapWithKeys(fn (Package $package) => [$package->id => $package->name]))
->label(__('Select default package'))
->helperText(__('Select the default package a user should get when you create or they register')),
Select::make('default_language')
->options(collect(languages())->mapWithKeys(fn (string $language) => [$language => $language]))
->label('Select default language')
->helperText('Select the default language a user should get when you create or they register'),
Select::make('rotate_logs_after')
->label(__('This will rotate any logs older than selected, this helps cleanup your database'))
->options([
null => __("Don't rotate logs"),
'weeks-1' => __('Older than 1 week'),
'months-1' => __('Older than 1 month'),
'months-3' => __('Older than 3 months'),
'months-6' => __('Older than 6 months'),
'years-1' => __('Older than 1 year'),
'years-2' => __('Older than 2 years'),
'years-3' => __('Older than 3 years'),
'years-4' => __('Older than 4 years'),
])
->columnSpan(2),
Toggle::make('trial')
->label(__('Enable trial'))
->helperText(__('This will allow you to have users with trials.')),
Toggle::make('allow_registration')
->label(__('Allow registration'))
->helperText(__('This will allow your customers to make support requests to you.')),
Toggle::make('support')
->label(__('Enable support platform'))
->helperText(__('This will allow your customers to make support requests to you.')),
Toggle::make('documentation')
->label(__('Enable documentation platform'))
->helperText(__('This will allow you to create articles for your users to look at.')),
Toggle::make('receive_email_on_server_creation')
->label(__('Receive email when customers create server'))
->helperText(__('This will send an email to all admins notifying them about a new server installation.')),
Toggle::make('receive_email_on_site_creation')
->label(__('Receive email when customers create site'))
->helperText(__('This will send an email to all admins notifying them about a new site installation.')),
Toggle::make('enable_api')
->label(__('Enable API'))
->helperText(new HtmlString(__('This will allow you to interact with your system via the API. ') . '<a href="https://docs.ploi-core.io/core-api/introduction" target="_blank" class="text-primary-600">' . __('More information') . '</a>')),
TextInput::make('api_token')
->label(__('API token'))
->afterStateHydrated(function (?string $state, TextInput $component) {
$state = filled($state) ? decrypt($state) : null;
$component->state($state);
})
->dehydrateStateUsing(function (?string $state) {
return filled($state) ? encrypt($state) : null;
})
->registerActions([
'generate' => $generateAction = Action::make('generate')
->label(__('Generate'))
->icon('heroicon-o-key')
->action(function (TextInput $component) {
$component->state(Str::random(20));
})
->tooltip('Generate'),
])
->suffixAction($generateAction),
Toggle::make('isolate_per_site_per_user')
->label(__('Enable site isolation per site & user'))
->helperText(__('This will make sure each site created by one user is always isolated from another.')),
]),
];
}
public function getFormStatePath(): ?string
{
return 'data';
}
public function save(): void
{
$state = $this->form->getState();
$oldLogo = setting('logo');
if ( $state['logo'] === null && $oldLogo ) {
Storage::disk('logos')->delete($oldLogo);
}
foreach ($state as $key => $value) {
setting([$key => $value]);
}
cache()->forget('core.settings');
Notification::make()
->success()
->body(__('Settings saved.'))
->send();
if ( $state['logo'] !== $oldLogo ) {
$this->redirectRoute('filament.pages.settings');
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Filament\Pages;
use App\Services\VersionChecker;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
class System extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-adjustments';
protected static string $view = 'filament.pages.system';
protected static ?string $navigationGroup = 'Settings';
protected static ?int $navigationSort = 2;
public function getCurrentVersion(): string
{
return app(VersionChecker::class)->getVersions()->currentVersion;
}
public function getRemoteVersion(): string
{
return app(VersionChecker::class)->getVersions()->remoteVersion;
}
public function refreshRemoteVersion(): void
{
app(VersionChecker::class)->flushVersionData();
Notification::make()
->success()
->body(__('Refreshed versions'))
->send();
}
public function getHorizonWorkerStatus(): bool
{
return (bool) app(MasterSupervisorRepository::class)->all();
}
public function hasAvailableUpdate(): bool
{
return app(VersionChecker::class)->getVersions()->isOutOfDate();
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Filament\Pages;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Pages\Actions\Action;
use Filament\Pages\Page;
use Illuminate\Support\Str;
class Terms extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.terms';
protected static ?string $navigationGroup = 'Settings';
protected static ?int $navigationSort = 3;
public array $data = [];
public function mount(): void
{
cache()->forget('core.settings');
$this->form->fill([
'accept_terms_required' => (bool) setting('accept_terms_required'),
'terms' => setting('terms'),
'privacy' => setting('privacy'),
]);
}
protected function getFormSchema(): array
{
return [
Toggle::make('accept_terms_required')
->label(__(' Require users to accept terms of service on registration'))
->helperText(__('This will require newly registered users to accept the terms of service.')),
MarkdownEditor::make('terms')
->label(__('Content Terms Of Service')),
MarkdownEditor::make('privacy')
->label(__('Content Privacy Policy')),
];
}
protected function getActions(): array
{
return [
Action::make('load_terms_template')
->label(__('Load Terms Of Service Template'))
->action(function (self $livewire) {
$template = Str::of(file_get_contents(storage_path('templates/terms-of-service.md')))
->replace([
'{NAME}',
'{WEBSITE}',
'{DATE}',
], [
setting('name'),
config('app.url'),
date('Y-m-d'),
])
->value();
$livewire->data['terms'] = $template;
Notification::make()
->success()
->body(__('Loaded Terms Of Service Template'))
->send();
}),
];
}
protected function getFormStatePath(): ?string
{
return 'data';
}
public function save(): void
{
$state = $this->form->getState();
foreach ($state as $key => $value) {
setting([$key => $value]);
}
cache()->forget('core.settings');
Notification::make()
->success()
->body(__('Terms saved.'))
->send();
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\AlertResource\Pages;
use App\Models\Alert;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Select;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables\Columns\BadgeColumn;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
class AlertResource extends Resource
{
protected static ?string $model = Alert::class;
protected static ?string $navigationIcon = 'heroicon-o-bell';
protected static ?string $navigationGroup = 'Settings';
protected static ?int $navigationSort = 4;
public static function form(Form $form): Form
{
return $form
->schema([
MarkdownEditor::make('message')
->label(__('Content'))
->columnSpan(2)
->required(),
Select::make('type')
->label(__('Type'))
->options([
Alert::TYPE_INFO => __('Informational'),
Alert::TYPE_WARNING => __('Warning'),
Alert::TYPE_DANGER => __('Danger'),
])
->required(),
DateTimePicker::make('expires_at')
->label(__('Expires at'))
->withoutSeconds(),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('message')
->label(__('Content'))
->formatStateUsing(fn (?string $state) => new HtmlString(Str::markdown($state))),
BadgeColumn::make('type')
->label(__('Type'))
->enum([
Alert::TYPE_INFO => __('Informational'),
Alert::TYPE_WARNING => __('Warning'),
Alert::TYPE_DANGER => __('Danger'),
])
->colors([
'success' => Alert::TYPE_INFO,
'warning' => Alert::TYPE_WARNING,
'danger' => Alert::TYPE_DANGER,
]),
TextColumn::make('expires_at')
->label('Expires Date')
->formatStateUsing(fn (?string $state) => filled($state) ? $state : '-'),
]);
}
public static function getPages(): array
{
return [
'index' => Pages\ListAlerts::route('/'),
'create' => Pages\CreateAlert::route('/create'),
'edit' => Pages\EditAlert::route('/{record}/edit'),
];
}
public static function getGloballySearchableAttributes(): array
{
return [];
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\AlertResource\Pages;
use App\Filament\Resources\AlertResource;
use Filament\Resources\Pages\CreateRecord;
class CreateAlert extends CreateRecord
{
protected static string $resource = AlertResource::class;
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\AlertResource\Pages;
use App\Filament\Resources\AlertResource;
use Filament\Pages\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
class EditAlert extends EditRecord
{
protected static string $resource = AlertResource::class;
protected function getActions(): array
{
return [
DeleteAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\AlertResource\Pages;
use App\Filament\Resources\AlertResource;
use Filament\Pages\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListAlerts extends ListRecords
{
protected static string $resource = AlertResource::class;
protected function getActions(): array
{
return [
CreateAction::make(),
];
}
}

View File

@@ -10,12 +10,13 @@ use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
class CertificateResource extends Resource
{
protected static ?string $model = Certificate::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationIcon = 'heroicon-o-annotation';
protected static ?string $navigationGroup = 'Site management';
@@ -25,7 +26,7 @@ class CertificateResource extends Resource
{
return $form
->schema([
Forms\Components\TextInput::make('site_id'),
Forms\Components\TextInput::make('site.name'),
Forms\Components\TextInput::make('server_id'),
Forms\Components\TextInput::make('status')
->maxLength(255),
@@ -43,17 +44,26 @@ class CertificateResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('site_id'),
Tables\Columns\TextColumn::make('server_id'),
Tables\Columns\TextColumn::make('status'),
Tables\Columns\TextColumn::make('ploi_id'),
Tables\Columns\TextColumn::make('domain'),
Tables\Columns\TextColumn::make('certificate'),
Tables\Columns\TextColumn::make('private'),
Tables\Columns\TextColumn::make('type'),
Tables\Columns\TextColumn::make('server.name')
->label(__('Server')),
Tables\Columns\TextColumn::make('site.domain')
->label(__('Main domain')),
Tables\Columns\TextColumn::make('type')
->label('Type'),
Tables\Columns\BadgeColumn::make('status')
->enum([
Certificate::STATUS_BUSY => __('Busy'),
Certificate::STATUS_ACTIVE => __('Active'),
])
->colors([
'warning' => Certificate::STATUS_BUSY,
'success' => Certificate::STATUS_ACTIVE,
])
->label(__('Status')),
Tables\Columns\TextColumn::make('domain')
->label('Domains & aliases'),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->label(__('Date'))
->dateTime(),
])
->filters([
@@ -67,6 +77,12 @@ class CertificateResource extends Resource
]);
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->orderBy('domain');
}
public static function getRelations(): array
{
return [
@@ -78,8 +94,6 @@ class CertificateResource extends Resource
{
return [
'index' => Pages\ListCertificates::route('/'),
'create' => Pages\CreateCertificate::route('/create'),
'edit' => Pages\EditCertificate::route('/{record}/edit'),
];
}
}

View File

@@ -1,12 +0,0 @@
<?php
namespace App\Filament\Resources\CertificateResource\Pages;
use App\Filament\Resources\CertificateResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateCertificate extends CreateRecord
{
protected static string $resource = CertificateResource::class;
}

View File

@@ -1,19 +0,0 @@
<?php
namespace App\Filament\Resources\CertificateResource\Pages;
use App\Filament\Resources\CertificateResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;
class EditCertificate extends EditRecord
{
protected static string $resource = CertificateResource::class;
protected function getActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Resources\CronjobResource\Pages;
use App\Filament\Resources\CronjobResource\RelationManagers;
use App\Models\Cronjob;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
@@ -15,7 +14,7 @@ class CronjobResource extends Resource
{
protected static ?string $model = Cronjob::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationIcon = 'heroicon-o-clock';
protected static ?string $navigationGroup = 'Site management';
@@ -25,18 +24,7 @@ class CronjobResource extends Resource
{
return $form
->schema([
Forms\Components\TextInput::make('site_id'),
Forms\Components\TextInput::make('server_id'),
Forms\Components\TextInput::make('status')
->maxLength(255),
Forms\Components\TextInput::make('ploi_id'),
Forms\Components\TextInput::make('command')
->maxLength(255),
Forms\Components\TextInput::make('user')
->maxLength(255),
Forms\Components\TextInput::make('frequency')
->required()
->maxLength(255),
//
]);
}
@@ -44,26 +32,36 @@ class CronjobResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('site_id'),
Tables\Columns\TextColumn::make('server_id'),
Tables\Columns\TextColumn::make('status'),
Tables\Columns\TextColumn::make('ploi_id'),
Tables\Columns\TextColumn::make('command'),
Tables\Columns\TextColumn::make('user'),
Tables\Columns\TextColumn::make('frequency'),
Tables\Columns\TextColumn::make('site.domain')
->label(__('Site')),
Tables\Columns\BadgeColumn::make('status')
->enum([
Cronjob::STATUS_BUSY => __('Busy'),
Cronjob::STATUS_ACTIVE => __('Active'),
])
->colors([
'warning' => Cronjob::STATUS_BUSY,
'success' => Cronjob::STATUS_ACTIVE,
])
->label(__('Status')),
Tables\Columns\TextColumn::make('server.name')
->label(__('Server')),
Tables\Columns\TextColumn::make('command')
->label(__('Command')),
Tables\Columns\TextColumn::make('frequency')
->label(__('Frequency')),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->label(__('Date'))
->dateTime(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
//
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
//
]);
}
@@ -78,8 +76,6 @@ class CronjobResource extends Resource
{
return [
'index' => Pages\ListCronjobs::route('/'),
'create' => Pages\CreateCronjob::route('/create'),
'edit' => Pages\EditCronjob::route('/{record}/edit'),
];
}
}

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Resources\DatabaseResource\Pages;
use App\Filament\Resources\DatabaseResource\RelationManagers;
use App\Models\Database;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
@@ -15,7 +14,7 @@ class DatabaseResource extends Resource
{
protected static ?string $model = Database::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationIcon = 'heroicon-o-database';
protected static ?string $navigationGroup = 'Site management';
@@ -25,13 +24,7 @@ class DatabaseResource extends Resource
{
return $form
->schema([
Forms\Components\TextInput::make('site_id'),
Forms\Components\TextInput::make('server_id'),
Forms\Components\TextInput::make('status')
->maxLength(255),
Forms\Components\TextInput::make('ploi_id'),
Forms\Components\TextInput::make('name')
->maxLength(255),
//
]);
}
@@ -39,24 +32,34 @@ class DatabaseResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('site_id'),
Tables\Columns\TextColumn::make('server_id'),
Tables\Columns\TextColumn::make('status'),
Tables\Columns\TextColumn::make('ploi_id'),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('server.name')
->label(__('Server')),
Tables\Columns\TextColumn::make('site.domain')
->label(__('Site')),
Tables\Columns\BadgeColumn::make('status')
->enum([
Database::STATUS_BUSY => __('Busy'),
Database::STATUS_ACTIVE => __('Active'),
])
->colors([
'warning' => Database::STATUS_BUSY,
'success' => Database::STATUS_ACTIVE,
])
->label(__('Status')),
Tables\Columns\TextColumn::make('name')
->label(__('Name')),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->label(__('Date'))
->dateTime(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
//
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
//
]);
}
@@ -71,8 +74,6 @@ class DatabaseResource extends Resource
{
return [
'index' => Pages\ListDatabases::route('/'),
'create' => Pages\CreateDatabase::route('/create'),
'edit' => Pages\EditDatabase::route('/{record}/edit'),
];
}
}

View File

@@ -1,12 +0,0 @@
<?php
namespace App\Filament\Resources\DatabaseResource\Pages;
use App\Filament\Resources\DatabaseResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateDatabase extends CreateRecord
{
protected static string $resource = DatabaseResource::class;
}

View File

@@ -1,19 +0,0 @@
<?php
namespace App\Filament\Resources\DatabaseResource\Pages;
use App\Filament\Resources\DatabaseResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;
class EditDatabase extends EditRecord
{
protected static string $resource = DatabaseResource::class;
protected function getActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View File

@@ -19,7 +19,7 @@ class PackageResource extends Resource
{
protected static ?string $model = Package::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationIcon = 'heroicon-o-color-swatch';
protected static ?int $navigationSort = 3;
@@ -135,7 +135,7 @@ class PackageResource extends Resource
public static function getRelations(): array
{
return [
//
RelationManagers\UsersRelationManager::class,
];
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Filament\Resources\PackageResource\RelationManagers;
use App\Filament\Resources\UserResource;
use App\Models\User;
use Filament\Forms\Components\Select;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables\Actions\Action;
class UsersRelationManager extends RelationManager
{
protected static string $relationship = 'users';
protected static ?string $recordTitleAttribute = 'name';
public static function form(Form $form): Form
{
return UserResource::form($form);
}
public static function table(Table $table): Table
{
return UserResource::table($table)
->appendHeaderActions([
Action::make('add_user')
->label(__('Add user'))
->form(fn (self $livewire) => [
Select::make('user_id')
->options(User::orderBy('name')->get()->mapWithKeys(fn (User $user) => [$user->id => $user->name]))
->required(),
])
->action(function (array $data, self $livewire) {
$user = User::find($data['user_id']);
$user->update([
'package_id' => $livewire->ownerRecord->id,
]);
})
->button(),
]);
}
}

View File

@@ -4,8 +4,8 @@ namespace App\Filament\Resources;
use App\Filament\Resources\ProviderPlanResource\Pages;
use App\Filament\Resources\ProviderPlanResource\RelationManagers;
use App\Models\Provider;
use App\Models\ProviderPlan;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
@@ -15,7 +15,7 @@ class ProviderPlanResource extends Resource
{
protected static ?string $model = ProviderPlan::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationIcon = 'heroicon-o-cube';
protected static ?string $navigationGroup = 'Providers';
@@ -25,11 +25,7 @@ class ProviderPlanResource extends Resource
{
return $form
->schema([
Forms\Components\TextInput::make('provider_id'),
Forms\Components\TextInput::make('plan_id')
->maxLength(255),
Forms\Components\TextInput::make('label')
->maxLength(255),
//
]);
}
@@ -37,22 +33,25 @@ class ProviderPlanResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('provider_id'),
Tables\Columns\TextColumn::make('plan_id'),
Tables\Columns\TextColumn::make('label'),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->dateTime(),
Tables\Columns\TextColumn::make('provider.name')
->label(__('Provider')),
Tables\Columns\TextColumn::make('plan_id')
->label(__('Plan ID'))
->searchable(),
Tables\Columns\TextColumn::make('label')
->label(__('Label'))
->searchable(),
])
->filters([
//
Tables\Filters\SelectFilter::make('provider_id')
->label(__('Provider'))
->options(fn () => Provider::orderBy('name')->get()->mapWithKeys(fn (Provider $provider) => [$provider->id => $provider->name])),
])
->actions([
Tables\Actions\EditAction::make(),
//
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
//
]);
}

View File

@@ -3,7 +3,6 @@
namespace App\Filament\Resources\ProviderPlanResource\Pages;
use App\Filament\Resources\ProviderPlanResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;
class ListProviderPlans extends ListRecords
@@ -13,11 +12,7 @@ class ListProviderPlans extends ListRecords
protected function getActions(): array
{
return [
Actions\Action::make('synchronize_providers')
->label(__('Synchronize providers'))
->action(function () {
//
}),
//
];
}
}

View File

@@ -4,8 +4,8 @@ namespace App\Filament\Resources;
use App\Filament\Resources\ProviderRegionResource\Pages;
use App\Filament\Resources\ProviderRegionResource\RelationManagers;
use App\Models\Provider;
use App\Models\ProviderRegion;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
@@ -15,7 +15,7 @@ class ProviderRegionResource extends Resource
{
protected static ?string $model = ProviderRegion::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationIcon = 'heroicon-o-globe';
protected static ?string $navigationGroup = 'Providers';
@@ -25,11 +25,7 @@ class ProviderRegionResource extends Resource
{
return $form
->schema([
Forms\Components\TextInput::make('provider_id'),
Forms\Components\TextInput::make('region_id')
->maxLength(255),
Forms\Components\TextInput::make('label')
->maxLength(255),
//
]);
}
@@ -37,22 +33,25 @@ class ProviderRegionResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('provider_id'),
Tables\Columns\TextColumn::make('region_id'),
Tables\Columns\TextColumn::make('label'),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->dateTime(),
Tables\Columns\TextColumn::make('provider.name')
->label(__('Provider')),
Tables\Columns\TextColumn::make('region_id')
->searchable()
->label(__('Region')),
Tables\Columns\TextColumn::make('label')
->searchable()
->label(__('Label')),
])
->filters([
//
Tables\Filters\SelectFilter::make('provider_id')
->label(__('Provider'))
->options(fn () => Provider::orderBy('name')->get()->mapWithKeys(fn (Provider $provider) => [$provider->id => $provider->name])),
])
->actions([
Tables\Actions\EditAction::make(),
//
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
//
]);
}

View File

@@ -2,20 +2,24 @@
namespace App\Filament\Resources;
use App\Actions\Provider\SynchronizeProviderAction;
use App\Filament\Resources\ProviderResource\Pages;
use App\Filament\Resources\ProviderResource\RelationManagers;
use App\Filament\Resources\ProviderResource\Widgets\AvailableProvidersOverview;
use App\Models\Provider;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
class ProviderResource extends Resource
{
protected static ?string $model = Provider::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationIcon = 'heroicon-o-cloud-upload';
protected static ?string $navigationGroup = 'Providers';
@@ -39,27 +43,41 @@ class ProviderResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('ploi_id'),
Tables\Columns\TextColumn::make('label'),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('allowed_plans'),
Tables\Columns\TextColumn::make('allowed_regions'),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->dateTime(),
Tables\Columns\TextColumn::make('name')
->description(function (Provider $record) {
return "{$record->plans_count} plan(s) · {$record->regions_count} region(s)";
})
->label(__('Name')),
Tables\Columns\TextColumn::make('label')
->label(__('Label')),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('synchronize_provider')
->label(__('Synchronize'))
->icon('heroicon-o-refresh')
->action(function (Provider $record) {
$provider = app(SynchronizeProviderAction::class)->execute($record->ploi_id);
Notification::make()
->body(__('Provider :provider synchronized successfully.', ['provider' => $provider->name]))
->success()
->send();
}),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
//
]);
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withCount(['plans', 'regions']);
}
public static function getRelations(): array
{
return [
@@ -67,6 +85,13 @@ class ProviderResource extends Resource
];
}
public static function getWidgets(): array
{
return [
AvailableProvidersOverview::class,
];
}
public static function getPages(): array
{
return [

View File

@@ -3,17 +3,27 @@
namespace App\Filament\Resources\ProviderResource\Pages;
use App\Filament\Resources\ProviderResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;
class ListProviders extends ListRecords
{
protected $listeners = [
'$refresh',
];
protected static string $resource = ProviderResource::class;
protected function getActions(): array
{
return [
Actions\CreateAction::make(),
//
];
}
protected function getHeaderWidgets(): array
{
return [
ProviderResource\Widgets\AvailableProvidersOverview::class,
];
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Filament\Resources\ProviderResource\Widgets;
use App\Actions\Provider\SynchronizeProviderAction;
use App\Models\AvailableProvider;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
use Filament\Widgets\TableWidget;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
class AvailableProvidersOverview extends TableWidget
{
protected $listeners = [
'$refresh'
];
protected int|string|array $columnSpan = 'full';
protected static ?string $heading = 'Available Providers';
protected function getTableQuery(): Builder|Relation
{
return AvailableProvider::query();
}
protected function getTableColumns(): array
{
return [
TextColumn::make('name')
->label(__('Name')),
TextColumn::make('label')
->label(__('Label')),
];
}
protected function getTableActions(): array
{
return [
Action::make('synchronize_provider')
->label(__('Synchronize'))
->icon('heroicon-o-refresh')
->action(function (AvailableProvider $record, self $livewire) {
$provider = app(SynchronizeProviderAction::class)->execute($record->id);
$livewire->emit('$refresh');
Notification::make()
->body(__('Provider :provider synchronized successfully.', ['provider' => $provider->name]))
->success()
->send();
}),
];
}
public static function canView(): bool
{
return AvailableProvider::exists();
}
}

View File

@@ -15,7 +15,7 @@ class RedirectResource extends Resource
{
protected static ?string $model = Redirect::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationIcon = 'heroicon-o-external-link';
protected static ?string $navigationGroup = 'Site management';
@@ -43,26 +43,38 @@ class RedirectResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('site_id'),
Tables\Columns\TextColumn::make('server_id'),
Tables\Columns\TextColumn::make('status'),
Tables\Columns\TextColumn::make('ploi_id'),
Tables\Columns\TextColumn::make('redirect_from'),
Tables\Columns\TextColumn::make('redirect_to'),
Tables\Columns\TextColumn::make('type'),
Tables\Columns\TextColumn::make('server.name')
->label(__('Server')),
Tables\Columns\TextColumn::make('site.domain')
->label(__('Site')),
Tables\Columns\TextColumn::make('type')
->label(__('Type')),
Tables\Columns\BadgeColumn::make('status')
->enum([
Redirect::STATUS_BUSY => __('Busy'),
Redirect::STATUS_ACTIVE => __('Active'),
])
->colors([
'warning' => Redirect::STATUS_BUSY,
'success' => Redirect::STATUS_ACTIVE,
])
->label(__('Status')),
Tables\Columns\TextColumn::make('redirect_from')
->label(__('Redirect from')),
Tables\Columns\TextColumn::make('redirect_to')
->label(__('Redirect to')),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->label(__('Date'))
->dateTime(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
//
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
//
]);
}
@@ -77,8 +89,6 @@ class RedirectResource extends Resource
{
return [
'index' => Pages\ListRedirects::route('/'),
'create' => Pages\CreateRedirect::route('/create'),
'edit' => Pages\EditRedirect::route('/{record}/edit'),
];
}
}

View File

@@ -1,12 +0,0 @@
<?php
namespace App\Filament\Resources\RedirectResource\Pages;
use App\Filament\Resources\RedirectResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateRedirect extends CreateRecord
{
protected static string $resource = RedirectResource::class;
}

View File

@@ -1,19 +0,0 @@
<?php
namespace App\Filament\Resources\RedirectResource\Pages;
use App\Filament\Resources\RedirectResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;
class EditRedirect extends EditRecord
{
protected static string $resource = RedirectResource::class;
protected function getActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View File

@@ -119,7 +119,7 @@ class ServerResource extends Resource
{
return parent::getEloquentQuery()
->with(['users'])
->withCount('sites');
->withCount(['sites']);
}
public static function getRelations(): array

View File

@@ -21,7 +21,7 @@ class SiteResource extends Resource
{
protected static ?string $model = Site::class;
protected static ?string $navigationIcon = 'heroicon-o-globe';
protected static ?string $navigationIcon = 'heroicon-o-code';
protected static ?string $navigationGroup = 'Site management';

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Resources\SiteSystemUserResource\Pages;
use App\Filament\Resources\SiteSystemUserResource\RelationManagers;
use App\Models\SiteSystemUser;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
@@ -15,7 +14,7 @@ class SiteSystemUserResource extends Resource
{
protected static ?string $model = SiteSystemUser::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationIcon = 'heroicon-o-user-group';
protected static ?string $navigationGroup = 'Site management';
@@ -25,10 +24,7 @@ class SiteSystemUserResource extends Resource
{
return $form
->schema([
Forms\Components\TextInput::make('user_name')
->maxLength(255),
Forms\Components\Textarea::make('ftp_password')
->maxLength(65535),
//
]);
}
@@ -36,20 +32,22 @@ class SiteSystemUserResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('user_name'),
Tables\Columns\TextColumn::make('site.domain')
->label(__('Site')),
Tables\Columns\TextColumn::make('user_name')
->label(__('Username')),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->label(__('Date'))
->dateTime(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
//
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
//
]);
}
@@ -64,8 +62,6 @@ class SiteSystemUserResource extends Resource
{
return [
'index' => Pages\ListSiteSystemUsers::route('/'),
'create' => Pages\CreateSiteSystemUser::route('/create'),
'edit' => Pages\EditSiteSystemUser::route('/{record}/edit'),
];
}
}

View File

@@ -1,12 +0,0 @@
<?php
namespace App\Filament\Resources\SiteSystemUserResource\Pages;
use App\Filament\Resources\SiteSystemUserResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateSiteSystemUser extends CreateRecord
{
protected static string $resource = SiteSystemUserResource::class;
}

View File

@@ -1,19 +0,0 @@
<?php
namespace App\Filament\Resources\SiteSystemUserResource\Pages;
use App\Filament\Resources\SiteSystemUserResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;
class EditSiteSystemUser extends EditRecord
{
protected static string $resource = SiteSystemUserResource::class;
protected function getActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View File

@@ -45,6 +45,10 @@ class UserResource extends Resource
Forms\Components\Select::make('language')
->label(__('Language'))
->options(collect(languages())->mapWithKeys(fn (string $language) => [$language => $language])),
Forms\Components\TextInput::make('stripe_id')
->label(__('Customer payment ID'))
->disabled()
->columnSpan(2),
Forms\Components\Textarea::make('notes')
->label(__('Notes'))
->maxLength(65535),

View File

@@ -2,13 +2,12 @@
namespace App\Filament\Resources\UserResource\RelationManagers;
use Filament\Forms;
use App\Filament\Resources\ServerResource;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Database\Eloquent\Relations\Relation;
class ServersRelationManager extends RelationManager
{
@@ -18,32 +17,17 @@ class ServersRelationManager extends RelationManager
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
]);
return ServerResource::form($form);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}
return ServerResource::table($table);
}
protected function getTableQuery(): Builder|Relation
{
return parent::getTableQuery()
->withCount('sites');
}
}

View File

@@ -2,7 +2,6 @@
namespace App\Filament\Resources\UserResource\RelationManagers;
use App\Filament\Resources\ServerResource;
use App\Filament\Resources\SiteResource;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
@@ -21,6 +20,6 @@ class SitesRelationManager extends RelationManager
public static function table(Table $table): Table
{
return ServerResource::table($table);
return SiteResource::table($table);
}
}

View File

@@ -4,7 +4,7 @@ use App\Models\Setting;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Arr;
if (!function_exists('setting')) {
if ( ! function_exists('setting') ) {
/**
* @param null $key
* @param null $default
@@ -12,11 +12,21 @@ if (!function_exists('setting')) {
*/
function setting($key = null, $default = null)
{
if (is_array($key)) {
if ( is_array($key) ) {
$value = Arr::first($key);
if ( $value === true ) {
$value = '1';
}
if ( $value === false ) {
$value = '0';
}
Setting::updateOrCreate([
'key' => key($key)
], [
'value' => Arr::first($key)
'value' => $value,
]);
try {
@@ -31,7 +41,7 @@ if (!function_exists('setting')) {
$value = Arr::get(app('settings'), $key, $default);
// Boolean casting
if ($value === "0" || $value === "1" && $key !== 'trial_package') {
if ( $value === "0" || $value === "1" && $key !== 'trial_package' ) {
return (bool) $value;
}

View File

@@ -8,6 +8,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Storage;
use Inertia\Middleware;
class HandleInertiaRequests extends Middleware
@@ -47,7 +48,7 @@ class HandleInertiaRequests extends Middleware
'create' => Arr::get($package->site_permissions, 'create', false),
'update' => Arr::get($package->site_permissions, 'update', false),
'delete' => Arr::get($package->site_permissions, 'delete', false),
]
],
] : [];
return [
@@ -66,17 +67,19 @@ class HandleInertiaRequests extends Middleware
'zip' => Auth::user()->zip,
'city' => Auth::user()->city,
] : null,
'package' => auth()->user() && auth()->user()->package ? [
'name' => auth()->user()->package->name,
'maximum_sites' => auth()->user()->package->maximum_sites,
'trial' => auth()->user()->onTrial()
] : [
'name' => __('None')
],
'package' => auth()->user() && auth()->user()->package
? [
'name' => auth()->user()->package->name,
'maximum_sites' => auth()->user()->package->maximum_sites,
'trial' => auth()->user()->onTrial(),
]
: [
'name' => __('None'),
],
'can' => $can,
'integrations' => [
'cloudflare' => (bool) auth()->user() ? auth()->user()->providers()->where('type', UserProvider::TYPE_CLOUDFLARE)->count() : false,
]
],
];
},
@@ -86,12 +89,12 @@ class HandleInertiaRequests extends Middleware
'name' => setting('name', 'Company'),
'support' => setting('support', false),
'documentation' => setting('documentation', false),
'logo' => setting('logo'),
'logo' => Storage::disk('logos')->url(setting('logo')),
'allow_registration' => setting('allow_registration'),
'billing' => config('cashier.key') && config('cashier.secret'),
'has_terms' => (bool)setting('terms'),
'has_privacy' => (bool)setting('privacy'),
'accept_terms_required' => (bool)setting('accept_terms_required')
'has_terms' => (bool) setting('terms'),
'has_privacy' => (bool) setting('privacy'),
'accept_terms_required' => (bool) setting('accept_terms_required'),
];
},
'flash' => function () {
@@ -104,7 +107,7 @@ class HandleInertiaRequests extends Middleware
'errors' => function () {
return Session::get('errors')
? Session::get('errors')->getBag('default')->getMessages()
: (object)[];
: (object) [];
},
'errors_count' => function () {
return Session::get('errors')
@@ -120,15 +123,15 @@ class HandleInertiaRequests extends Middleware
})
->first(['message', 'expires_at', 'type']);
if (!$alert) {
if ( ! $alert ) {
return null;
}
return [
'message_html' => $alert->messageHtml,
'type' => $alert->type
'type' => $alert->type,
];
}
},
]);
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Models;
use App\Services\Ploi\Ploi;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use stdClass;
use Sushi\Sushi;
class AvailableProvider extends Model
{
use Sushi;
public function getRows(): array
{
$availableProviders = Ploi::make()
->user()
->serverProviders()
->getData();
$currentProviders = Provider::pluck('ploi_id');
return collect($availableProviders)
->map(fn (stdClass $provider): array => Arr::only((array) $provider, ['id', 'label', 'name']))
->filter(fn (array $provider): bool => $currentProviders->doesntContain($provider['id']))
->all();
}
}

View File

@@ -4,10 +4,16 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ProviderPlan extends Model
{
use HasFactory;
protected $guarded = [];
public function provider(): BelongsTo
{
return $this->belongsTo(Provider::class);
}
}

View File

@@ -4,10 +4,16 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ProviderRegion extends Model
{
use HasFactory;
protected $guarded = [];
public function provider(): BelongsTo
{
return $this->belongsTo(Provider::class);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Policies;
use App\Models\Certificate;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class CertificatePolicy
{
use HandlesAuthorization;
public function viewAny(User $user): bool
{
return $user->isAdmin();
}
public function view(User $user, Certificate $certificate): bool
{
return $user->isAdmin();
}
public function create(User $user): bool
{
return false;
}
public function update(User $user, Certificate $certificate): bool
{
return false;
}
public function delete(User $user, Certificate $certificate): bool
{
return false;
}
public function restore(User $user, Certificate $certificate): bool
{
return false;
}
public function forceDelete(User $user, Certificate $certificate): bool
{
return false;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Policies;
use App\Models\Cronjob;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class CronjobPolicy
{
use HandlesAuthorization;
public function viewAny(User $user): bool
{
return $user->isAdmin();
}
public function view(User $user, Cronjob $cronjob): bool
{
return $user->isAdmin();
}
public function create(User $user): bool
{
return false;
}
public function update(User $user, Cronjob $cronjob): bool
{
return false;
}
public function delete(User $user, Cronjob $cronjob): bool
{
return false;
}
public function restore(User $user, Cronjob $cronjob): bool
{
return false;
}
public function forceDelete(User $user, Cronjob $cronjob): bool
{
return false;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Policies;
use App\Models\Database;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class DatabasePolicy
{
use HandlesAuthorization;
public function viewAny(User $user): bool
{
return $user->isAdmin();
}
public function view(User $user, Database $database): bool
{
return $user->isAdmin();
}
public function create(User $user): bool
{
return false;
}
public function update(User $user, Database $database): bool
{
return false;
}
public function delete(User $user, Database $database): bool
{
return false;
}
public function restore(User $user, Database $database): bool
{
return false;
}
public function forceDelete(User $user, Database $database): bool
{
return false;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Policies;
use App\Models\Redirect;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class RedirectPolicy
{
use HandlesAuthorization;
public function viewAny(User $user): bool
{
return $user->isAdmin();
}
public function view(User $user, Redirect $redirect): bool
{
return $user->isAdmin();
}
public function create(User $user): bool
{
return false;
}
public function update(User $user, Redirect $redirect): bool
{
return false;
}
public function delete(User $user, Redirect $redirect): bool
{
return false;
}
public function restore(User $user, Redirect $redirect): bool
{
return false;
}
public function forceDelete(User $user, Redirect $redirect): bool
{
return false;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Policies;
use App\Models\SiteSystemUser;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class SiteSystemUserPolicy
{
use HandlesAuthorization;
public function viewAny(User $user): bool
{
return $user->isAdmin();
}
public function view(User $user, SiteSystemUser $siteSystemUser): bool
{
return $user->isAdmin();
}
public function create(User $user): bool
{
return false;
}
public function update(User $user, SiteSystemUser $siteSystemUser): bool
{
return false;
}
public function delete(User $user, SiteSystemUser $siteSystemUser): bool
{
return false;
}
public function restore(User $user, SiteSystemUser $siteSystemUser): bool
{
return false;
}
public function forceDelete(User $user, SiteSystemUser $siteSystemUser): bool
{
return false;
}
}

View File

@@ -7,6 +7,7 @@ use Filament\Facades\Filament;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\PluginServiceProvider;
use Illuminate\Foundation\Vite;
class FilamentServiceProvider extends PluginServiceProvider
{
@@ -27,6 +28,17 @@ class FilamentServiceProvider extends PluginServiceProvider
public function boot(): void
{
Filament::serving(function () {
Filament::registerTheme(
app(Vite::class)('resources/css/filament.css', 'build/filament'),
);
Filament::registerNavigationGroups([
'Server management',
'Site management',
'Providers',
'Settings'
]);
TextInput::macro('hostname', function () {
return $this->rule(new Hostname());
});

View File

@@ -12,9 +12,10 @@
"php": "^8.0.2",
"ext-json": "*",
"aws/aws-sdk-php": "^3.224",
"calebporzio/sushi": "^2.4",
"cloudflare/sdk": "^1.3",
"doctrine/dbal": "^3.3",
"filament/filament": "^2.0",
"filament/filament": "^2.15.13",
"guzzlehttp/guzzle": "^7.4.1",
"inertiajs/inertia-laravel": "^0.6.3",
"laragear/two-factor": "^1.1",
@@ -27,6 +28,7 @@
"predis/predis": "^1.1",
"spatie/laravel-data": "^1.5.1",
"spiral/roadrunner": "^2.8.2",
"stechstudio/filament-impersonate": "^2.5",
"symfony/http-client": "^6.0",
"symfony/mailgun-mailer": "^6.0",
"symfony/postmark-mailer": "^6.0",
@@ -90,5 +92,6 @@
"@php artisan horizon:publish",
"@php artisan filament:upgrade"
]
}
},
"repositories": []
}

858
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -51,7 +51,14 @@ return [
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
'logos' => [
'driver' => 'local',
'root' => storage_path('app/public/logos'),
'url' => env('APP_URL') . '/storage/logos',
'visibility' => 'public',
],

View File

@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
return new class extends Migration
{
public function up()
{
$currentLogoPath = setting('logo');
if ( ! $currentLogoPath ) {
return;
}
$currentFileName = Str::of($currentLogoPath)->after('/storage/logo/')->ltrim('/');
Storage::disk('logos')->put($currentFileName, file_get_contents(Storage::path("public/logo/" . $currentFileName)));
// Storage::delete($currentLogoPath);
setting(['logo' => $currentFileName]);
}
public function down()
{
$currentFileName = setting('logo');
if ( ! $currentFileName ) {
return;
}
Storage::put($path = "logo/{$currentFileName}", Storage::disk('logos')->path($currentFileName));
Storage::disk('logos')->delete($currentFileName);
setting(['logo' => "/storage/{$path}"]);
}
};

55
package-lock.json generated
View File

@@ -11,11 +11,11 @@
"@inertiajs/inertia-vue": "^0.7.1",
"@inertiajs/progress": "^0.2.6",
"@rollup/plugin-commonjs": "^21.0",
"@tailwindcss/forms": "^0.4.0",
"@tailwindcss/typography": "^0.5.0",
"@tailwindcss/forms": "^0.4.1",
"@tailwindcss/typography": "^0.5.4",
"@types/node": "^18.0.6",
"@vitejs/plugin-vue2": "^1.1.2",
"autoprefixer": "^10.4.7",
"autoprefixer": "^10.4.8",
"axios": "^0.21.1",
"balloon-css": "^1.2.0",
"cross-env": "^7.0.3",
@@ -27,7 +27,8 @@
"resolve-url-loader": "^3.1.0",
"sass": "^1.53.0",
"sass-loader": "^8.0.0",
"tailwindcss": "^3.1.6",
"tailwindcss": "^3.1.8",
"tippy.js": "^6.3.7",
"v-click-outside": "^3.1.2",
"vite": "^3.0.2",
"vue": "^2.7",
@@ -535,6 +536,16 @@
"node": ">= 8"
}
},
"node_modules/@popperjs/core": {
"version": "2.11.5",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz",
"integrity": "sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw==",
"dev": true,
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/popperjs"
}
},
"node_modules/@rollup/plugin-commonjs": {
"version": "21.1.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-21.1.0.tgz",
@@ -3597,9 +3608,9 @@
}
},
"node_modules/tailwindcss": {
"version": "3.1.7",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.1.7.tgz",
"integrity": "sha512-r7mgumZ3k0InfVPpGWcX8X/Ut4xBfv+1O/+C73ar/m01LxGVzWvPxF/w6xIUPEztrCoz7axfx0SMdh8FH8ZvRQ==",
"version": "3.1.8",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.1.8.tgz",
"integrity": "sha512-YSneUCZSFDYMwk+TGq8qYFdCA3yfBRdBlS7txSq0LUmzyeqRe3a8fBQzbz9M3WS/iFT4BNf/nmw9mEzrnSaC0g==",
"dev": true,
"dependencies": {
"arg": "^5.0.2",
@@ -3756,6 +3767,15 @@
"integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==",
"dev": true
},
"node_modules/tippy.js": {
"version": "6.3.7",
"resolved": "https://registry.npmjs.org/tippy.js/-/tippy.js-6.3.7.tgz",
"integrity": "sha512-E1d3oP2emgJ9dRQZdf3Kkn0qJgI6ZLpyS5z6ZkY1DF3kaQaBsGZsndEpHwx+eC+tYM41HaSNvNtLx8tU57FzTQ==",
"dev": true,
"dependencies": {
"@popperjs/core": "^2.9.0"
}
},
"node_modules/to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
@@ -4548,6 +4568,12 @@
"fastq": "^1.6.0"
}
},
"@popperjs/core": {
"version": "2.11.5",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz",
"integrity": "sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw==",
"dev": true
},
"@rollup/plugin-commonjs": {
"version": "21.1.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-21.1.0.tgz",
@@ -6771,9 +6797,9 @@
"dev": true
},
"tailwindcss": {
"version": "3.1.7",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.1.7.tgz",
"integrity": "sha512-r7mgumZ3k0InfVPpGWcX8X/Ut4xBfv+1O/+C73ar/m01LxGVzWvPxF/w6xIUPEztrCoz7axfx0SMdh8FH8ZvRQ==",
"version": "3.1.8",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.1.8.tgz",
"integrity": "sha512-YSneUCZSFDYMwk+TGq8qYFdCA3yfBRdBlS7txSq0LUmzyeqRe3a8fBQzbz9M3WS/iFT4BNf/nmw9mEzrnSaC0g==",
"dev": true,
"requires": {
"arg": "^5.0.2",
@@ -6880,6 +6906,15 @@
"integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==",
"dev": true
},
"tippy.js": {
"version": "6.3.7",
"resolved": "https://registry.npmjs.org/tippy.js/-/tippy.js-6.3.7.tgz",
"integrity": "sha512-E1d3oP2emgJ9dRQZdf3Kkn0qJgI6ZLpyS5z6ZkY1DF3kaQaBsGZsndEpHwx+eC+tYM41HaSNvNtLx8tU57FzTQ==",
"dev": true,
"requires": {
"@popperjs/core": "^2.9.0"
}
},
"to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",

View File

@@ -3,22 +3,25 @@
"private": true,
"scripts": {
"watch": "npm run development",
"watch:filament": "npm run dev:filament",
"dev": "npm run development",
"development": "vite",
"dev:filament": "TAILWIND_CONFIG=filament vite",
"prod": "npm run production",
"production": "vite build"
"production": "vite build",
"prod:filament": "TAILWIND_CONFIG=filament vite build"
},
"devDependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@inertiajs/inertia": "^0.10.0",
"@inertiajs/inertia-vue": "^0.7.1",
"@inertiajs/progress": "^0.2.6",
"@tailwindcss/forms": "^0.4.0",
"@tailwindcss/typography": "^0.5.0",
"@rollup/plugin-commonjs": "^21.0",
"@tailwindcss/forms": "^0.4.1",
"@tailwindcss/typography": "^0.5.4",
"@types/node": "^18.0.6",
"@vitejs/plugin-vue2": "^1.1.2",
"@rollup/plugin-commonjs": "^21.0",
"autoprefixer": "^10.4.7",
"autoprefixer": "^10.4.8",
"axios": "^0.21.1",
"balloon-css": "^1.2.0",
"cross-env": "^7.0.3",
@@ -30,7 +33,8 @@
"resolve-url-loader": "^3.1.0",
"sass": "^1.53.0",
"sass-loader": "^8.0.0",
"tailwindcss": "^3.1.6",
"tailwindcss": "^3.1.8",
"tippy.js": "^6.3.7",
"v-click-outside": "^3.1.2",
"vite": "^3.0.2",
"vue": "^2.7",
@@ -39,8 +43,5 @@
"vue-meta": "^2.4.0",
"vue-template-compiler": "^2.6.11",
"vuex": "^3.6.2"
},
"dependencies": {
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
{
"resources/css/filament.css": {
"file": "assets/filament.e3675133.css",
"src": "resources/css/filament.css",
"isEntry": true
}
}

9
resources/css/filament.css vendored Normal file
View File

@@ -0,0 +1,9 @@
@import "../../vendor/filament/filament/resources/css/app.css";
@import "../../node_modules/tippy.js/dist/tippy.css";
@import "../../node_modules/tippy.js/themes/light.css";
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap');
@tailwind base;
@tailwind components;
@tailwind utilities;

View File

@@ -19,7 +19,7 @@
@endif
@if($logo = setting('logo'))
<link rel="icon" type="image/x-icon" href="{{ $logo }}">
<link rel="icon" type="image/x-icon" href="{{ \Illuminate\Support\Facades\Storage::disk('logos')->url($logo) }}">
@endif
@if(view()->exists('header'))

View File

@@ -0,0 +1,11 @@
<x-filament::page>
<x-filament::form wire:submit.prevent="save">
{{ $this->form }}
<div class="mt-4">
<x-filament-support::button type="submit">
{{ __('Save') }}
</x-filament-support::button>
</div>
</x-filament::form>
</x-filament::page>

View File

@@ -0,0 +1,29 @@
<x-filament::page>
<div class="px-4 py-3 rounded-md border border-gray-400">
<p>{{ __("Check your system's version here. If there's an update available you'll be able to press the update button to update your system.") }}</p>
<ul class="mt-4">
<li>{{ __("Current version") }}: {{ $this->getCurrentVersion() }}</li>
<li>{{ __("Remote version") }}: {{ $this->getRemoteVersion() }} <span class="text-primary-500" wire:click="refreshRemoteVersion">{{ __('Refresh') }}</span></li>
<li>{{ __('Horizon worker status') }}: <span @class(['text-red-600' => ! $this->getHorizonWorkerStatus(), 'text-green-600' => $this->getHorizonWorkerStatus()])> {{ $this->getHorizonWorkerStatus() ? __('Active') : __('Inactive') }}</span></li>
</ul>
@if($this->hasAvailableUpdate())
<div class="mt-8 bg-primary-600 text-white rounded px-4 py-3">
<h2 class="text-lg">{{ __('Update available') }}</h2>
<p>{{ __('An update is available for your system, please upgrade.') }}</p>
<a href="https://docs.ploi-core.io/digging-deeper/manual-update" target="_blank" class="block mt-4 underline font-bold">{{ __('Find out how to upgrade here') }}</a>
</div>
@endif
</div>
<div class="mt-8 pl-4 px-4 py-4 rounded-md border border-gray-400">
<ul class="list-disc ml-4">
<li><a class="text-primary-600" href="https://docs.ploi-core.io/">Ploi Core Docs</a></li>
<li><a class="text-primary-600" href="https://ploi.io/">Ploi Website</a></li>
<li><a class="text-primary-600" href="https://ploi.io/login">Ploi Panel</a></li>
<li><a class="text-primary-600" href="https://github.com/ploi-deploy/ploi-core">Ploi GitHub repository </a></li>
</ul>
</div>
</x-filament::page>

View File

@@ -0,0 +1,11 @@
<x-filament::page>
<form wire:submit.prevent="save">
{{ $this->form }}
<div class="mt-4">
<x-filament-support::button type="submit">
{{ __('Save') }}
</x-filament-support::button>
</div>
</form>
</x-filament::page>

View File

@@ -0,0 +1,5 @@
<x-filament::widget>
<x-filament::card>
{{-- Widget content --}}
</x-filament::card>
</x-filament::widget>

View File

@@ -0,0 +1,10 @@
@if($logo = setting('logo'))
<img src="{{ Storage::disk('logos')->url($logo) }}" class="h-8" alt="{{ setting('name') }}" />
@elseif (filled($brand = config('filament.brand')))
<div @class([
'text-xl font-bold tracking-tight filament-brand',
'dark:text-white' => config('filament.dark_mode'),
])>
{{ $brand }}
</div>
@endif

28
tailwind-filament.config.js vendored Normal file
View File

@@ -0,0 +1,28 @@
const colors = require('tailwindcss/colors')
const defaultTheme = require('tailwindcss/defaultTheme')
module.exports = {
content: [
'./resources/views/filament/**/*.blade.php',
'./vendor/filament/**/*.blade.php',
],
darkMode: 'class',
theme: {
extend: {
colors: {
danger: colors.rose,
primary: colors.sky,
success: colors.green,
warning: colors.yellow,
},
},
fontFamily: {
'sans': ['"DM Sans"', 'system-ui'],
...defaultTheme
},
},
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
],
}

36
vite.config.js vendored
View File

@@ -2,12 +2,23 @@ import {defineConfig} from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue2';
let inputs = [];
if (process.env.TAILWIND_CONFIG) {
inputs = [`resources/css/${process.env.TAILWIND_CONFIG}.css`];
} else {
inputs = [
/** CSS is dynamically imported in the app.js file. */
'resources/js/app.js',
];
}
export default defineConfig({
plugins: [
laravel([
/** CSS is dynamically imported in the app.js file. */
'resources/js/app.js',
]),
laravel({
input: inputs,
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
@@ -20,6 +31,23 @@ export default defineConfig({
},
}),
],
css: {
postcss: {
plugins: [
require("tailwindcss")({
config: process.env?.TAILWIND_CONFIG
? `tailwind-${process.env.TAILWIND_CONFIG}.config.js`
: "./tailwind.config.js",
}),
require("autoprefixer"),
]
}
},
build: {
outDir: process.env?.TAILWIND_CONFIG
? `./public/build/${process.env.TAILWIND_CONFIG}`
: "./public/build/frontend",
},
resolve: {
alias: {
"@": '/resources/js'