Compare commits
141 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f927f9ec1 | ||
|
|
33692960ff | ||
|
|
1f79a4e790 | ||
|
|
903e1cccc6 | ||
|
|
3f7f6206bd | ||
|
|
be00824f59 | ||
|
|
eb4220adc9 | ||
|
|
3562a60461 | ||
|
|
4d80f26519 | ||
|
|
29dc893806 | ||
|
|
35abe4cfd7 | ||
|
|
275b359b53 | ||
|
|
0be4f4cd94 | ||
|
|
2ffd09877e | ||
|
|
a5d2445e3f | ||
|
|
92631cdee9 | ||
|
|
0f63b8153a | ||
|
|
b6983d5377 | ||
|
|
78899bef61 | ||
|
|
9397651515 | ||
|
|
f692fb681a | ||
|
|
6de17d3e3c | ||
|
|
b2b24db2e6 | ||
|
|
2af546643e | ||
|
|
e63b13e5fd | ||
|
|
36385c2242 | ||
|
|
ed67a44f5f | ||
|
|
fb8b2fa935 | ||
|
|
6e1b7613e4 | ||
|
|
175b104ebc | ||
|
|
a72a2466ef | ||
|
|
9952e2226d | ||
|
|
5fa9c334ee | ||
|
|
d1f50c8dd9 | ||
|
|
557cff5e05 | ||
|
|
fd1d31d347 | ||
|
|
71d5521ca8 | ||
|
|
489d39099f | ||
|
|
cbd6a227ee | ||
|
|
b3d2b2ec7a | ||
|
|
2889e46685 | ||
|
|
761878e1b6 | ||
|
|
4169b07b39 | ||
|
|
8c001cf984 | ||
|
|
a73adb9acf | ||
|
|
6ed9867f6b | ||
|
|
b1667ff445 | ||
|
|
db4a25fb5c | ||
|
|
ee21924253 | ||
|
|
37ea8aa6b0 | ||
|
|
d4c495eaee | ||
|
|
434046cd3e | ||
|
|
eee61494d0 | ||
|
|
053864a589 | ||
|
|
dc87d0d415 | ||
|
|
ae1b41e068 | ||
|
|
277aae4bca | ||
|
|
f727c4cddb | ||
|
|
58c91fe7bc | ||
|
|
cc29f729d3 | ||
|
|
ff8982c2ee | ||
|
|
aab1e86eee | ||
|
|
3388b4fdec | ||
|
|
8ef6e2b64c | ||
|
|
dd5c074976 | ||
|
|
9861ff3a9b | ||
|
|
b4607d8e01 | ||
|
|
7a98295853 | ||
|
|
95e7682cc2 | ||
|
|
251c29b4bd | ||
|
|
96587db6a2 | ||
|
|
06aecba93d | ||
|
|
bcadd716fe | ||
|
|
b2e1ee9e24 | ||
|
|
e3612ebf23 | ||
|
|
25d5a9617d | ||
|
|
b6e25806ea | ||
|
|
f0a8e5e318 | ||
|
|
c5dbfa2c4b | ||
|
|
93273b5a45 | ||
|
|
751449de5e | ||
|
|
e601222b4f | ||
|
|
30685c4595 | ||
|
|
60c951a1f8 | ||
|
|
ccc09f0967 | ||
|
|
de9834d6a7 | ||
|
|
09dd3db506 | ||
|
|
560100e592 | ||
|
|
0f5ef71936 | ||
|
|
84b2f36440 | ||
|
|
92c605d9df | ||
|
|
0fddf4f348 | ||
|
|
ef64bdd7b3 | ||
|
|
465b2a524b | ||
|
|
f2c47ba2f3 | ||
|
|
eab8c45f57 | ||
|
|
2215e12717 | ||
|
|
f76e5b4d7b | ||
|
|
9d1b12b0a3 | ||
|
|
d89482c4aa | ||
|
|
488808a7a2 | ||
|
|
8e788dfd8e | ||
|
|
200d2bc44d | ||
|
|
f9424781c0 | ||
|
|
f2441990cd | ||
|
|
369d205d6a | ||
|
|
b63d4e753b | ||
|
|
fbe7641cb7 | ||
|
|
1ebcf75806 | ||
|
|
88b324b47a | ||
|
|
50768d5648 | ||
|
|
7cfe8d64c4 | ||
|
|
f6f5385751 | ||
|
|
4294377160 | ||
|
|
1ae9519594 | ||
|
|
c0f7d572cb | ||
|
|
247fd27368 | ||
|
|
39e5d20444 | ||
|
|
8900e5088a | ||
|
|
e52cc6205a | ||
|
|
a85be2d666 | ||
|
|
bffaadec1b | ||
|
|
0c7398c7ac | ||
|
|
a44ce140fc | ||
|
|
8afe483cee | ||
|
|
9bd3107303 | ||
|
|
5b124cc433 | ||
|
|
661426668e | ||
|
|
2df37131d1 | ||
|
|
c55b2f1f85 | ||
|
|
705739d2d3 | ||
|
|
35bf27097a | ||
|
|
59d60a5b03 | ||
|
|
0cd7c7e4f6 | ||
|
|
254dbaf2ec | ||
|
|
705104524e | ||
|
|
a7da48a5dd | ||
|
|
df87d541cd | ||
|
|
07ba298c5e | ||
|
|
8936e4c2d5 | ||
|
|
92bb321a68 |
@@ -4,10 +4,13 @@ APP_KEY=
|
||||
APP_DEBUG=false
|
||||
APP_URL=http://localhost
|
||||
APP_DEMO=false
|
||||
APP_DATE_TIME_FORMAT="Y-m-d H:i:s"
|
||||
|
||||
PLOI_TOKEN=
|
||||
PLOI_CORE_TOKEN=
|
||||
|
||||
IMPERSONATION=false
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
@@ -51,5 +54,5 @@ PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
|
||||
6
.github/workflows/master.yml
vendored
6
.github/workflows/master.yml
vendored
@@ -28,14 +28,14 @@ jobs:
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '12.x'
|
||||
node-version: '16.x'
|
||||
- run: npm install
|
||||
- run: npm run production
|
||||
- run: npm run production:all
|
||||
|
||||
- name: Commit build assets
|
||||
run: |
|
||||
git config --local user.email "actions@github.com"
|
||||
git config --local user.name "GitHub Actions"
|
||||
git add .
|
||||
git commit -m "Run Laravel Mix en build front-end assets"
|
||||
git commit -m "Updated build assets"
|
||||
git push origin
|
||||
|
||||
2
.github/workflows/run-tests.yml
vendored
2
.github/workflows/run-tests.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
php: [8.0, 8.1]
|
||||
php: [8.1]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -20,3 +20,4 @@ yarn-error.log
|
||||
/storage/views/footer.blade.php
|
||||
rr
|
||||
.rr.yaml
|
||||
.DS_Store
|
||||
|
||||
@@ -9,5 +9,5 @@ php:
|
||||
js:
|
||||
finder:
|
||||
not-name:
|
||||
- webpack.mix.js
|
||||
- vite.config.js
|
||||
css: true
|
||||
|
||||
39
app/Actions/Provider/SynchronizeProviderAction.php
Normal file
39
app/Actions/Provider/SynchronizeProviderAction.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Actions\Server;
|
||||
|
||||
use App\DataTransferObjects\ServerData;
|
||||
use App\Jobs\Servers\CreateServer;
|
||||
use App\Mail\Admin\Server\AdminServerCreatedEmail;
|
||||
use App\Models\Server;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Jobs\Servers\CreateServer;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\DataTransferObjects\ServerData;
|
||||
use App\Mail\Admin\Server\AdminServerCreatedEmail;
|
||||
|
||||
class CreateServerAction
|
||||
{
|
||||
@@ -18,6 +18,7 @@ class CreateServerAction
|
||||
$server = $serverData->getUser()->servers()->create([
|
||||
'name' => $serverData->name,
|
||||
'database_type' => $serverData->database_type,
|
||||
'os' => setting('default_os', Server::OS_UBUNTU_22)
|
||||
]);
|
||||
|
||||
$server->provider()->associate($provider);
|
||||
|
||||
52
app/Actions/Server/SynchronizeServerAction.php
Normal file
52
app/Actions/Server/SynchronizeServerAction.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Server;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class SynchronizeServerAction
|
||||
{
|
||||
public function execute(int $ploiServerId): Server|null
|
||||
{
|
||||
try {
|
||||
$serverData = Ploi::make()->server()->get($ploiServerId)->getData();
|
||||
} catch (\Throwable $exception) {
|
||||
Notification::make()
|
||||
->body('An error has occurred: ' . $exception->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$server = Server::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $serverData->id,
|
||||
], [
|
||||
'status' => $serverData->status,
|
||||
'name' => $serverData->name,
|
||||
'ip' => $serverData->ip_address,
|
||||
'ssh_port' => $serverData->ssh_port,
|
||||
'internal_ip' => $serverData->internal_ip,
|
||||
'available_php_versions' => $serverData->installed_php_versions,
|
||||
]);
|
||||
} catch (\Throwable $exception) {
|
||||
Notification::make()
|
||||
->body('An error has occurred: ' . $exception->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->body(__('Server :server synchronized successfully.', ['server' => $server->name]))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
return $server;
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Actions\Site;
|
||||
|
||||
use App\DataTransferObjects\SiteData;
|
||||
use App\Jobs\Sites\CreateSite;
|
||||
use App\Mail\Admin\Site\AdminSiteCreatedEmail;
|
||||
use App\Models\Server;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\Server;
|
||||
use App\Jobs\Sites\CreateSite;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\DataTransferObjects\SiteData;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Mail\Admin\Site\AdminSiteCreatedEmail;
|
||||
|
||||
class CreateSiteAction
|
||||
{
|
||||
@@ -17,7 +17,7 @@ class CreateSiteAction
|
||||
{
|
||||
$server = $this->determineServer($siteData);
|
||||
|
||||
if ( ! $server ) {
|
||||
if (! $server) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class CreateSiteAction
|
||||
|
||||
protected function determineServer(SiteData $siteData): ?Server
|
||||
{
|
||||
if ( $siteData->server_id ) {
|
||||
if ($siteData->server_id) {
|
||||
return $siteData->getUser()->servers()->findOrFail($siteData->server_id);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class CreateSiteAction
|
||||
|
||||
protected function sendAdminSiteCreatedEmails(Server $server, Model|Site $site, User $user): void
|
||||
{
|
||||
if ( ! setting('receive_email_on_site_creation') ) {
|
||||
if (! setting('receive_email_on_site_creation')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
55
app/Actions/Site/SynchronizeSiteAction.php
Normal file
55
app/Actions/Site/SynchronizeSiteAction.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Site;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class SynchronizeSiteAction
|
||||
{
|
||||
public function execute(int $ploiServerId, int $ploiSiteId): Site
|
||||
{
|
||||
$siteData = Ploi::make()->server($ploiServerId)->sites()->get($ploiSiteId)->getData();
|
||||
|
||||
$server = Server::query()
|
||||
->where('ploi_id', $siteData->server_id)
|
||||
->firstOrFail();
|
||||
|
||||
$site = Site::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $siteData->id,
|
||||
], [
|
||||
'domain' => $siteData->domain,
|
||||
'php_version' => $siteData->php_version,
|
||||
'project' => $siteData->project_type,
|
||||
]);
|
||||
|
||||
$site->status = $siteData->status;
|
||||
$site->server_id = $server->id;
|
||||
$site->save();
|
||||
|
||||
$certificates = Ploi::make()->server($siteData->server_id)->sites($siteData->id)->certificates()->get()->getData();
|
||||
|
||||
if ($certificates) {
|
||||
foreach ($certificates as $certificate) {
|
||||
$site->certificates()->updateOrCreate([
|
||||
'ploi_id' => $certificate->id,
|
||||
], [
|
||||
'status' => $certificate->status,
|
||||
'ploi_id' => $certificate->id,
|
||||
'domain' => $certificate->domain,
|
||||
'type' => $certificate->type,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->body(__('Site :site synchronized successfully.', ['site' => $site->domain]))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
return $site;
|
||||
}
|
||||
}
|
||||
50
app/Actions/User/DeleteUserAction.php
Normal file
50
app/Actions/User/DeleteUserAction.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\User;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Jobs\Sites\DeleteSite;
|
||||
use App\Jobs\Servers\DeleteServer;
|
||||
|
||||
class DeleteUserAction
|
||||
{
|
||||
public function execute(User $user, bool $removeAllData): void
|
||||
{
|
||||
if ($removeAllData) {
|
||||
$this->removeAllData($user);
|
||||
}
|
||||
|
||||
// The next items are already being deleted by the "deleting" event:
|
||||
// systemLogs, servers detached, sites detached, supportTickets, supportTicketReplies, userProviders
|
||||
$user->delete();
|
||||
}
|
||||
|
||||
protected function removeAllData(User $user): void
|
||||
{
|
||||
$user
|
||||
->sites()
|
||||
->withCount('users')
|
||||
->get()
|
||||
->filter(fn (Site $site) => $site->users_count === 1)
|
||||
->each(function (Site $site) {
|
||||
dispatch(new DeleteSite($site->server->ploi_id, $site->ploi_id));
|
||||
|
||||
// Deletes databases, redirects, cronjobs, certificates.
|
||||
$site->delete();
|
||||
});
|
||||
|
||||
$user
|
||||
->servers()
|
||||
->withCount('users')
|
||||
->get()
|
||||
->filter(fn (Server $server) => $server->users_count === 1)
|
||||
->each(function (Server $server) {
|
||||
dispatch(new DeleteServer($server->ploi_id));
|
||||
|
||||
// Deletes databases, redirects, cronjobs, certificates.
|
||||
$server->delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Console\Commands\Core\Trial;
|
||||
use App\Jobs\Core\Ping;
|
||||
use App\Console\Commands\Core\Css;
|
||||
use App\Console\Commands\Core\Trial;
|
||||
use App\Console\Commands\Core\Cleanup;
|
||||
use App\Console\Commands\Core\Install;
|
||||
use App\Console\Commands\Core\CssBackup;
|
||||
|
||||
26
app/DataTransferObjects/PackageData.php
Normal file
26
app/DataTransferObjects/PackageData.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
|
||||
class PackageData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
// Add validation attributes to this class if we add additional API-endpoints.
|
||||
public int $id,
|
||||
public ?string $name,
|
||||
public ?int $maximum_servers,
|
||||
public ?int $maximum_sites,
|
||||
public float $price_hourly,
|
||||
public float $price_monthly,
|
||||
public float $price_yearly,
|
||||
public ?string $stripe_plan_id,
|
||||
public string $currency,
|
||||
public array $server_permissions,
|
||||
public array $site_permissions,
|
||||
public Carbon $created_at,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -2,36 +2,55 @@
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use App\DataTransferObjects\Support\Concerns\BelongsToUser;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Models\Provider;
|
||||
use App\Models\ProviderPlan;
|
||||
use App\Models\ProviderRegion;
|
||||
use App\Models\User;
|
||||
use Spatie\LaravelData\Attributes\Validation\AlphaDash;
|
||||
use Spatie\LaravelData\Attributes\Validation\Exists;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use Spatie\LaravelData\Attributes\Validation\In;
|
||||
use Spatie\LaravelData\Attributes\Validation\IntegerType;
|
||||
use Spatie\LaravelData\Attributes\Validation\Max;
|
||||
use Spatie\LaravelData\Attributes\Validation\NotIn;
|
||||
use Spatie\LaravelData\Attributes\Validation\Exists;
|
||||
use Spatie\LaravelData\Attributes\Validation\AlphaDash;
|
||||
use Spatie\LaravelData\Attributes\Validation\StringType;
|
||||
use Spatie\LaravelData\Attributes\Validation\IntegerType;
|
||||
use App\DataTransferObjects\Support\Concerns\BelongsToUser;
|
||||
|
||||
class ServerData extends Data
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
public function __construct(
|
||||
#[StringType, AlphaDash, Max( 40 )]
|
||||
public ?int $id = null,
|
||||
#[StringType]
|
||||
public ?string $status = null,
|
||||
#[StringType,
|
||||
AlphaDash,
|
||||
Max(40)]
|
||||
public string $name,
|
||||
#[NotIn( 0 ), Exists( Provider::class, 'id' )]
|
||||
#[NotIn(0),
|
||||
Exists(Provider::class, 'id')]
|
||||
public int $provider_id,
|
||||
#[NotIn( 0 ), Exists( ProviderRegion::class, 'id' )]
|
||||
#[NotIn(0),
|
||||
Exists(ProviderRegion::class, 'id')]
|
||||
public int $provider_region_id,
|
||||
#[NotIn( 0 ), Exists( ProviderPlan::class, 'id' )]
|
||||
#[NotIn(0),
|
||||
Exists(ProviderPlan::class, 'id')]
|
||||
public int $provider_plan_id,
|
||||
#[StringType, In( ['mysql', 'mariadb', 'postgresql', 'postgresql13'] )]
|
||||
#[StringType,
|
||||
In(['mysql', 'mariadb', 'postgresql', 'postgresql13'])]
|
||||
public string $database_type,
|
||||
#[Exists( User::class, 'id' ), IntegerType]
|
||||
#[Exists(User::class, 'id'),
|
||||
IntegerType]
|
||||
public ?int $user_id = null,
|
||||
) {}
|
||||
public ?Carbon $created_at = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function fromModel(Server $server): static
|
||||
{
|
||||
return static::from(array_merge($server->toArray(), ['user_id' => $server->user->id]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use App\DataTransferObjects\Support\Concerns\BelongsToUser;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use App\DataTransferObjects\Support\Rules\CustomRule;
|
||||
use App\DataTransferObjects\Support\WithUser;
|
||||
use App\Models\Server;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Rules\Hostname;
|
||||
use App\Rules\ValidateMaximumSites;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Rules\ValidateMaximumSites;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use Spatie\LaravelData\Attributes\Validation\Exists;
|
||||
use Spatie\LaravelData\Attributes\Validation\IntegerType;
|
||||
use App\DataTransferObjects\Support\Rules\CustomRule;
|
||||
use Spatie\LaravelData\Attributes\Validation\StringType;
|
||||
use Spatie\LaravelData\Attributes\Validation\IntegerType;
|
||||
use App\DataTransferObjects\Support\Concerns\BelongsToUser;
|
||||
|
||||
class SiteData extends Data
|
||||
{
|
||||
@@ -23,23 +23,33 @@ class SiteData extends Data
|
||||
public function __construct(
|
||||
public ?int $id = null,
|
||||
public ?string $status = null,
|
||||
#[Exists( Server::class, 'id' ), IntegerType]
|
||||
#[Exists(Server::class, 'id'),
|
||||
IntegerType]
|
||||
public ?int $server_id = null,
|
||||
#[StringType, CustomRule(Hostname::class, ValidateMaximumSites::class)]
|
||||
#[StringType,
|
||||
CustomRule(Hostname::class, ValidateMaximumSites::class)]
|
||||
public ?string $domain = null,
|
||||
#[Exists(User::class, 'id'), IntegerType]
|
||||
#[Exists(User::class, 'id'),
|
||||
IntegerType]
|
||||
public ?int $user_id = null,
|
||||
) {}
|
||||
public ?Carbon $created_at = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function authorize(): bool
|
||||
{
|
||||
if ( auth()->guest() ) {
|
||||
if (auth()->guest()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return auth()->user()->can('create', Site::class);
|
||||
}
|
||||
|
||||
public static function fromModel(Site $site): static
|
||||
{
|
||||
return static::from(array_merge($site->toArray(), ['user_id' => $site->user->id]));
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return Arr::only(parent::toArray(), [
|
||||
@@ -47,6 +57,8 @@ class SiteData extends Data
|
||||
'status',
|
||||
'server_id',
|
||||
'domain',
|
||||
'user_id',
|
||||
'created_at',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Pagination\AbstractCursorPaginator;
|
||||
use Illuminate\Pagination\AbstractPaginator;
|
||||
use Illuminate\Support\Enumerable;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
use Illuminate\Pagination\AbstractPaginator;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Pagination\AbstractCursorPaginator;
|
||||
|
||||
class Data extends \Spatie\LaravelData\Data
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\DataTransferObjects\Support\Rules;
|
||||
use Attribute;
|
||||
use Spatie\LaravelData\Attributes\Validation\ValidationAttribute;
|
||||
|
||||
#[Attribute( Attribute::TARGET_PROPERTY )]
|
||||
#[Attribute(Attribute::TARGET_PROPERTY)]
|
||||
class CustomRule extends ValidationAttribute
|
||||
{
|
||||
protected array $rules = [];
|
||||
|
||||
@@ -2,30 +2,41 @@
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use App\Models\Package;
|
||||
use App\Models\User;
|
||||
use App\Models\Package;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use Spatie\LaravelData\Attributes\Validation\Max;
|
||||
use Spatie\LaravelData\Attributes\Validation\Email;
|
||||
use Spatie\LaravelData\Attributes\Validation\Exists;
|
||||
use Spatie\LaravelData\Attributes\Validation\IntegerType;
|
||||
use Spatie\LaravelData\Attributes\Validation\Max;
|
||||
use Spatie\LaravelData\Attributes\Validation\StringType;
|
||||
use Spatie\LaravelData\Attributes\Validation\Unique;
|
||||
use Spatie\LaravelData\Attributes\Validation\StringType;
|
||||
use Spatie\LaravelData\Attributes\Validation\BooleanType;
|
||||
use Spatie\LaravelData\Attributes\Validation\IntegerType;
|
||||
|
||||
class UserData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public ?int $id = null,
|
||||
public ?string $avatar = null,
|
||||
#[StringType, Max(255)]
|
||||
#[StringType,
|
||||
Max(255)]
|
||||
public ?string $name = null,
|
||||
#[StringType, Email, Max(255), Unique(User::class)]
|
||||
#[StringType,
|
||||
Email,
|
||||
Max(255),
|
||||
Unique(User::class)]
|
||||
public ?string $email = null,
|
||||
#[Exists( Package::class, 'id'), IntegerType]
|
||||
#[Exists(Package::class, 'id'),
|
||||
IntegerType]
|
||||
public ?int $package_id = null,
|
||||
#[StringType]
|
||||
public ?string $blocked = null,
|
||||
#[StringType]
|
||||
public ?string $language = 'en',
|
||||
#[BooleanType]
|
||||
public ?bool $requires_password_for_ftp = true,
|
||||
public ?Carbon $created_at = null,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Exceptions;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Middleware\SetLocale;
|
||||
use App\Http\Middleware\HandleInertiaRequests;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
@@ -58,6 +59,10 @@ class Handler extends ExceptionHandler
|
||||
|
||||
// Only return an Inertia-response when there are special Vue-templates (403 and 404) and when it isn't an API request.
|
||||
if (in_array($response->status(), [403, 404]) && ! $request->routeIs('api.*')) {
|
||||
inertia()->share([
|
||||
'translations' => SetLocale::getTranslations()
|
||||
]);
|
||||
|
||||
return app(HandleInertiaRequests::class)
|
||||
->handle($request, fn () => inertia()->render('Errors/' . $response->status(), ['status' => $response->status()])
|
||||
->toResponse($request));
|
||||
|
||||
188
app/Filament/Pages/Settings.php
Normal file
188
app/Filament/Pages/Settings.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\Package;
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
|
||||
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'),
|
||||
'default_os' => setting('default_os', Server::OS_UBUNTU_22),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormSchema(): array
|
||||
{
|
||||
return [
|
||||
Grid::make(2)
|
||||
->schema([
|
||||
|
||||
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(2),
|
||||
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'),
|
||||
FileUpload::make('logo')
|
||||
->label(__('Logo'))
|
||||
->disk('logos')
|
||||
->columnSpan(2),
|
||||
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(1),
|
||||
Select::make('default_os')
|
||||
->label(__('Select the default OS that should be used when users create a server'))
|
||||
->default(Server::OS_UBUNTU_22)
|
||||
->options([
|
||||
Server::OS_UBUNTU_18 => __('Ubuntu 18'),
|
||||
Server::OS_UBUNTU_20 => __('Ubuntu 20'),
|
||||
Server::OS_UBUNTU_22 => __('Ubuntu 22'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
Toggle::make('trial')
|
||||
->label(__('Enable trial'))
|
||||
->helperText(__('This will allow you to have users with trials.')),
|
||||
Toggle::make('allow_registration')
|
||||
->label(__('Allow registration'))
|
||||
->helperText(__('Allow customer registration')),
|
||||
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');
|
||||
$oldDocumentation = setting('documentation');
|
||||
$oldSupport = setting('support');
|
||||
|
||||
if ($state['logo'] === null && $oldLogo) {
|
||||
Storage::disk('logos')->delete($oldLogo);
|
||||
}
|
||||
|
||||
setting($state);
|
||||
|
||||
cache()->forget('core.settings');
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->body(__('Settings saved.'))
|
||||
->send();
|
||||
|
||||
if ($state['logo'] !== $oldLogo || $state['documentation'] !== $oldDocumentation || $state['support'] !== $oldSupport) {
|
||||
$this->redirectRoute('filament.pages.settings');
|
||||
}
|
||||
}
|
||||
}
|
||||
60
app/Filament/Pages/System.php
Normal file
60
app/Filament/Pages/System.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Pages\Page;
|
||||
use App\Services\VersionChecker;
|
||||
use Filament\Notifications\Notification;
|
||||
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 rescue(fn () => (bool) app(MasterSupervisorRepository::class)->all(), false, false);
|
||||
}
|
||||
|
||||
public function hasAvailableUpdate(): bool
|
||||
{
|
||||
return app(VersionChecker::class)->getVersions()->isOutOfDate();
|
||||
}
|
||||
|
||||
protected static function getNavigationBadge(): ?string
|
||||
{
|
||||
$systemChecker = app(VersionChecker::class);
|
||||
|
||||
if ($systemChecker->isOutOfDate()) {
|
||||
return 'Update available';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
94
app/Filament/Pages/Terms.php
Normal file
94
app/Filament/Pages/Terms.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
|
||||
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();
|
||||
|
||||
setting($state);
|
||||
|
||||
cache()->forget('core.settings');
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->body(__('Terms saved.'))
|
||||
->send();
|
||||
}
|
||||
}
|
||||
90
app/Filament/Resources/AlertResource.php
Normal file
90
app/Filament/Resources/AlertResource.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Models\Alert;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\BadgeColumn;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use App\Filament\Resources\AlertResource\Pages;
|
||||
|
||||
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;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'message';
|
||||
|
||||
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([
|
||||
'primary' => 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 [];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/AlertResource/Pages/CreateAlert.php
Normal file
11
app/Filament/Resources/AlertResource/Pages/CreateAlert.php
Normal 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;
|
||||
}
|
||||
19
app/Filament/Resources/AlertResource/Pages/EditAlert.php
Normal file
19
app/Filament/Resources/AlertResource/Pages/EditAlert.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AlertResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\AlertResource;
|
||||
|
||||
class EditAlert extends EditRecord
|
||||
{
|
||||
protected static string $resource = AlertResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/AlertResource/Pages/ListAlerts.php
Normal file
19
app/Filament/Resources/AlertResource/Pages/ListAlerts.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AlertResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\CreateAction;
|
||||
use App\Filament\Resources\AlertResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAlerts extends ListRecords
|
||||
{
|
||||
protected static string $resource = AlertResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
110
app/Filament/Resources/CertificateResource.php
Normal file
110
app/Filament/Resources/CertificateResource.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Certificate;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Filament\Resources\CertificateResource\Pages;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class CertificateResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Certificate::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-annotation';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('site.name'),
|
||||
Forms\Components\TextInput::make('server_id'),
|
||||
Forms\Components\TextInput::make('status')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('ploi_id'),
|
||||
Forms\Components\TextInput::make('domain')
|
||||
->maxLength(255),
|
||||
Forms\Components\Textarea::make('certificate'),
|
||||
Forms\Components\Textarea::make('private'),
|
||||
Forms\Components\TextInput::make('type')
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('server.name')
|
||||
->searchable()
|
||||
->label(__('Server')),
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->searchable()
|
||||
->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')
|
||||
->searchable()
|
||||
->wrap()
|
||||
->getStateUsing(function (Certificate $record) {
|
||||
$state = str($record->domain)->explode(',')->implode(', ');
|
||||
|
||||
return new HtmlString($state);
|
||||
})
|
||||
->label('Domains & aliases'),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->orderBy('domain');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListCertificates::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CertificateResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\CertificateResource;
|
||||
|
||||
class ListCertificates extends ListRecords
|
||||
{
|
||||
protected static string $resource = CertificateResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
85
app/Filament/Resources/CronjobResource.php
Normal file
85
app/Filament/Resources/CronjobResource.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Cronjob;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
class CronjobResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Cronjob::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-clock';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->searchable()
|
||||
->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')
|
||||
->searchable()
|
||||
->label(__('Server')),
|
||||
Tables\Columns\TextColumn::make('command')
|
||||
->searchable()
|
||||
->label(__('Command')),
|
||||
Tables\Columns\TextColumn::make('frequency')
|
||||
->label(__('Frequency')),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
//
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListCronjobs::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
|
||||
class CreateCronjob extends CreateRecord
|
||||
{
|
||||
protected static string $resource = CronjobResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/CronjobResource/Pages/EditCronjob.php
Normal file
19
app/Filament/Resources/CronjobResource/Pages/EditCronjob.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
|
||||
class EditCronjob extends EditRecord
|
||||
{
|
||||
protected static string $resource = CronjobResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
|
||||
class ListCronjobs extends ListRecords
|
||||
{
|
||||
protected static string $resource = CronjobResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
85
app/Filament/Resources/DatabaseResource.php
Normal file
85
app/Filament/Resources/DatabaseResource.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Database;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\DatabaseResource\Pages;
|
||||
|
||||
class DatabaseResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Database::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-database';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('server.name')
|
||||
->label(__('Server'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->label(__('Site'))
|
||||
->searchable(),
|
||||
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('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListDatabases::route('/'),
|
||||
'edit' => Pages\EditDatabase::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DatabaseResource\Pages;
|
||||
|
||||
use App\Models\Database;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use App\Mail\Database\PasswordReset;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use App\Filament\Resources\DatabaseResource;
|
||||
|
||||
class EditDatabase extends Page
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
protected static string $resource = DatabaseResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.database-resource.pages.edit-database';
|
||||
|
||||
public Database $record;
|
||||
|
||||
protected ?string $recentlyUpdatedPassword = null;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->resetDatabasePasswordForm->fill();
|
||||
}
|
||||
|
||||
public function getForms(): array
|
||||
{
|
||||
return [
|
||||
'resetDatabasePasswordForm' => $this->makeForm()
|
||||
->schema([
|
||||
Toggle::make('send_new_password_to_user')
|
||||
->label(__('Email new password to user')),
|
||||
])
|
||||
->model($this->record),
|
||||
];
|
||||
}
|
||||
|
||||
public function resetDatabasePassword(): void
|
||||
{
|
||||
$state = $this->resetDatabasePasswordForm->getState();
|
||||
|
||||
$data = Ploi::make()
|
||||
->server($this->record->server->ploi_id)
|
||||
->databases($this->record->ploi_id)
|
||||
->users($this->record->users->first()->ploi_id)
|
||||
->resetPassword()
|
||||
->getData();
|
||||
|
||||
$this->recentlyUpdatedPassword = $data->new_password;
|
||||
|
||||
Notification::make()
|
||||
->body(__('Successfully reset database password.'))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
if ($state['send_new_password_to_user']) {
|
||||
Mail::to($this->record->site->users)->send(new PasswordReset($this->record, $this->recentlyUpdatedPassword));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DatabaseResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\DatabaseResource;
|
||||
|
||||
class ListDatabases extends ListRecords
|
||||
{
|
||||
protected static string $resource = DatabaseResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
86
app/Filament/Resources/DocumentationCategoryResource.php
Normal file
86
app/Filament/Resources/DocumentationCategoryResource.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use App\Models\DocumentationCategory;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
use App\Filament\Resources\DocumentationCategoryResource\RelationManagers\DocumentationItemsRelationManager;
|
||||
|
||||
class DocumentationCategoryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = DocumentationCategory::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-tag';
|
||||
|
||||
protected static ?string $navigationGroup = 'Documentation';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
protected static ?string $pluralLabel = 'Categories';
|
||||
|
||||
protected static ?string $label = 'Category';
|
||||
|
||||
protected static function shouldRegisterNavigation(): bool
|
||||
{
|
||||
return (bool) setting('documentation');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->label(__('Title'))
|
||||
->unique(table: DocumentationCategory::class, column: 'title', ignoreRecord: true)
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
MarkdownEditor::make('description')
|
||||
->label(__('Description'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->label(__('Title')),
|
||||
TextColumn::make('description')
|
||||
->label(__('Description'))
|
||||
->formatStateUsing(fn (string $state) => new HtmlString(Str::markdown($state))),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
DocumentationItemsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListDocumentationCategories::route('/'),
|
||||
'create' => Pages\CreateDocumentationCategory::route('/create'),
|
||||
'edit' => Pages\EditDocumentationCategory::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['title'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\DocumentationCategoryResource;
|
||||
|
||||
class CreateDocumentationCategory extends CreateRecord
|
||||
{
|
||||
protected static string $resource = DocumentationCategoryResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\DocumentationCategoryResource;
|
||||
|
||||
class EditDocumentationCategory extends EditRecord
|
||||
{
|
||||
protected static string $resource = DocumentationCategoryResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\DocumentationCategoryResource;
|
||||
|
||||
class ListDocumentationCategories extends ListRecords
|
||||
{
|
||||
protected static string $resource = DocumentationCategoryResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationCategoryResource\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class DocumentationItemsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'items';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'title';
|
||||
|
||||
protected static ?string $label = 'Article';
|
||||
|
||||
protected static ?string $pluralLabel = 'Articles';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('title')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
74
app/Filament/Resources/DocumentationItemResource.php
Normal file
74
app/Filament/Resources/DocumentationItemResource.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Models\DocumentationItem;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
class DocumentationItemResource extends Resource
|
||||
{
|
||||
protected static ?string $model = DocumentationItem::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-duplicate';
|
||||
|
||||
protected static ?string $navigationGroup = 'Documentation';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $pluralLabel = 'Articles';
|
||||
|
||||
protected static ?string $label = 'Article';
|
||||
|
||||
protected static function shouldRegisterNavigation(): bool
|
||||
{
|
||||
return (bool) setting('documentation');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->label(__('Title'))
|
||||
->required(),
|
||||
Select::make('documentation_category_id')
|
||||
->relationship('category', 'title')
|
||||
->searchable()
|
||||
->preload(),
|
||||
MarkdownEditor::make('content')
|
||||
->label(__('Content'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('category.title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListDocumentationItems::route('/'),
|
||||
'create' => Pages\CreateDocumentationItem::route('/create'),
|
||||
'edit' => Pages\EditDocumentationItem::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\DocumentationItemResource;
|
||||
|
||||
class CreateDocumentationItem extends CreateRecord
|
||||
{
|
||||
protected static string $resource = DocumentationItemResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\DocumentationItemResource;
|
||||
|
||||
class EditDocumentationItem extends EditRecord
|
||||
{
|
||||
protected static string $resource = DocumentationItemResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\DocumentationItemResource;
|
||||
|
||||
class ListDocumentationItems extends ListRecords
|
||||
{
|
||||
protected static string $resource = DocumentationItemResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
165
app/Filament/Resources/PackageResource.php
Normal file
165
app/Filament/Resources/PackageResource.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Package;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use App\Filament\Resources\PackageResource\Pages;
|
||||
use App\Filament\Resources\PackageResource\RelationManagers;
|
||||
|
||||
class PackageResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Package::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-color-swatch';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label(__('Name'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
TextInput::make('maximum_sites')
|
||||
->helperText(__('Set to 0 for unlimited'))
|
||||
->integer()
|
||||
->required(),
|
||||
TextInput::make('maximum_servers')
|
||||
->helperText(__('Set to 0 for unlimited'))
|
||||
->integer()
|
||||
->required(),
|
||||
TextInput::make('stripe_plan_id')
|
||||
->helperText(__('Enter the pricing ID from Stripe here') . ' - <a href="https://docs.ploi-core.io/digging-deeper/using-stripe" target="ploi-docs-stripe" class="text-primary-500">How does this work?</a>')
|
||||
->label(__('Stripe ID'))
|
||||
->columnSpan(2),
|
||||
TextInput::make('price_monthly')
|
||||
->label(__('Monthly price'))
|
||||
->helperText(__('Fill this in if you want it to be monthly payments'))
|
||||
->required(),
|
||||
TextInput::make('price_yearly')
|
||||
->label(__('Yearly price'))
|
||||
->helperText(__('Fill this in if you want it to be yearly payments'))
|
||||
->required(),
|
||||
Select::make('currency')
|
||||
->label(__('Currency'))
|
||||
->options([
|
||||
'usd' => 'USD $',
|
||||
'eur' => 'Euro €',
|
||||
'gbp' => 'GBP £',
|
||||
'nok' => 'NOK (Norwegian Krone)',
|
||||
'aud' => 'AUD (Australian dollar)',
|
||||
'cad' => 'CAD (Canadian dollar)',
|
||||
'inr' => 'INR (Indian ₹ rupee)',
|
||||
'thb' => 'THB (Thai Baht)',
|
||||
'brl' => 'BRL R$ (Brazilian Real)',
|
||||
])
|
||||
->required(),
|
||||
Grid::make()
|
||||
->schema([
|
||||
Section::make(__('Server permissions'))
|
||||
->schema([
|
||||
Checkbox::make('server_permissions.create')
|
||||
->reactive()
|
||||
->label('Allow server creation')
|
||||
->helperText('This will allow users to create servers'),
|
||||
Checkbox::make('server_permissions.update')
|
||||
->label('Allow server updates')
|
||||
->helperText('This will allow users to update servers'),
|
||||
Checkbox::make('server_permissions.delete')
|
||||
->label('Allow server deletion')
|
||||
->helperText('This will allow users to delete servers'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
Section::make(__('Site permissions'))
|
||||
->schema([
|
||||
Checkbox::make('site_permissions.create')
|
||||
->label('Allow site creation')
|
||||
->helperText('This will allow users to create sites'),
|
||||
Checkbox::make('site_permissions.update')
|
||||
->label('Allow site updates')
|
||||
->helperText('This will allow users to update sites'),
|
||||
Checkbox::make('site_permissions.delete')
|
||||
->label('Allow site deletion')
|
||||
->helperText('This will allow users to delete sites'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
]),
|
||||
|
||||
Grid::make()
|
||||
->schema([
|
||||
Section::make(__('Available server providers'))
|
||||
->description(__('These server providers will be available for users that are attached to this package.'))
|
||||
->schema([
|
||||
CheckboxList::make('providers')
|
||||
->relationship('providers', 'name')
|
||||
])
|
||||
->columnSpan(1)
|
||||
])
|
||||
->visible(function ($get) {
|
||||
return $get('server_permissions')['create'];
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('ID')->searchable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->description(function (Package $record) {
|
||||
if (!$record->stripe_plan_id) {
|
||||
return __('Not attached to Stripe.');
|
||||
}
|
||||
|
||||
return "Attached to stripe - {$record->price_monthly} {$record->currency}";
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('maximum_sites')
|
||||
->formatStateUsing(fn (int $state) => $state === 0 ? __('Unlimited') : $state)
|
||||
->label(__('Maximum sites')),
|
||||
Tables\Columns\TextColumn::make('maximum_servers')
|
||||
->formatStateUsing(fn (int $state) => $state === 0 ? __('Unlimited') : $state)
|
||||
->label(__('Maximum servers')),
|
||||
Tables\Columns\TextColumn::make('users_count')
|
||||
->counts('users'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\UsersRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListPackages::route('/'),
|
||||
'create' => Pages\CreatePackage::route('/create'),
|
||||
'edit' => Pages\EditPackage::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PackageResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\PackageResource;
|
||||
|
||||
class CreatePackage extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PackageResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/PackageResource/Pages/EditPackage.php
Normal file
19
app/Filament/Resources/PackageResource/Pages/EditPackage.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PackageResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\PackageResource;
|
||||
|
||||
class EditPackage extends EditRecord
|
||||
{
|
||||
protected static string $resource = PackageResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PackageResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\PackageResource;
|
||||
|
||||
class ListPackages extends ListRecords
|
||||
{
|
||||
protected static string $resource = PackageResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PackageResource\RelationManagers;
|
||||
|
||||
use App\Models\User;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
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')
|
||||
->label('User')
|
||||
->options(User::orderBy('name')->get()->mapWithKeys(fn (User $user) => [$user->id => $user->name]))
|
||||
->preload()
|
||||
->searchable()
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data, self $livewire) {
|
||||
$user = User::find($data['user_id']);
|
||||
|
||||
$user->update([
|
||||
'package_id' => $livewire->ownerRecord->id,
|
||||
]);
|
||||
})
|
||||
->button(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
78
app/Filament/Resources/ProviderPlanResource.php
Normal file
78
app/Filament/Resources/ProviderPlanResource.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Provider;
|
||||
use App\Models\ProviderPlan;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use App\Filament\Resources\ProviderPlanResource\Pages;
|
||||
|
||||
class ProviderPlanResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ProviderPlan::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cube';
|
||||
|
||||
protected static ?string $navigationGroup = 'Providers';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('label'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('ID')->searchable(),
|
||||
Tables\Columns\TextColumn::make('provider.name')
|
||||
->label(__('Provider'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('plan_id')
|
||||
->label(__('Plan ID'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('label')
|
||||
->label(__('Label'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->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([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListProviderPlans::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderPlanResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\ProviderPlanResource;
|
||||
|
||||
class ListProviderPlans extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProviderPlanResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
72
app/Filament/Resources/ProviderRegionResource.php
Normal file
72
app/Filament/Resources/ProviderRegionResource.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Provider;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Models\ProviderRegion;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\ProviderRegionResource\Pages;
|
||||
|
||||
class ProviderRegionResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ProviderRegion::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-globe';
|
||||
|
||||
protected static ?string $navigationGroup = 'Providers';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('ID')->searchable(),
|
||||
Tables\Columns\TextColumn::make('provider.name')
|
||||
->label(__('Provider'))
|
||||
->searchable(),
|
||||
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([
|
||||
//
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListProviderRegions::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderRegionResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\ProviderRegionResource;
|
||||
|
||||
class ListProviderRegions extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProviderRegionResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
118
app/Filament/Resources/ProviderResource.php
Normal file
118
app/Filament/Resources/ProviderResource.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Provider;
|
||||
use App\Models\ProviderPlan;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Filament\Resources\ProviderResource\Pages;
|
||||
use App\Actions\Provider\SynchronizeProviderAction;
|
||||
use App\Filament\Resources\ProviderResource\Widgets\AvailableProvidersOverview;
|
||||
|
||||
class ProviderResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Provider::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cloud-upload';
|
||||
|
||||
protected static ?string $navigationGroup = 'Providers';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label(__('Name'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
Forms\Components\CheckboxList::make('allowed_plans')
|
||||
->options(function (Provider $record) {
|
||||
return $record->plans->mapWithKeys(fn (ProviderPlan $plan) => [$plan->id => $plan->label ?? $plan->plan_id]);
|
||||
})
|
||||
->label(__('Allowed Plans')),
|
||||
Forms\Components\CheckboxList::make('allowed_regions')
|
||||
->options(fn (Provider $record) => $record->regions->pluck('label', 'id'))
|
||||
->label(__('Allowed Regions')),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('ID')->searchable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->description(function (Provider $record) {
|
||||
return "{$record->plans_count} plan(s) · {$record->regions_count} region(s)";
|
||||
})
|
||||
->label(__('Name'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('label')
|
||||
->label(__('Label'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\Action::make('synchronize_provider')
|
||||
->label(__('Synchronize'))
|
||||
->tooltip(__('This will synchronize the latest data from this provider to your Ploi Core installation'))
|
||||
->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([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withCount(['plans', 'regions']);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
AvailableProvidersOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListProviders::route('/'),
|
||||
'synchronize' => Pages\SynchronizeProviders::route('/synchronize'),
|
||||
'edit' => Pages\EditProvider::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\ProviderResource;
|
||||
|
||||
class EditProvider extends EditRecord
|
||||
{
|
||||
protected static string $resource = ProviderResource::class;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\ProviderResource;
|
||||
|
||||
class ListProviders extends ListRecords
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
protected static string $resource = ProviderResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_providers')
|
||||
->label(__('Synchronize providers'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->color('secondary')
|
||||
->url(route('filament.resources.providers.synchronize')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\Page;
|
||||
use App\Filament\Resources\ProviderResource;
|
||||
|
||||
class SynchronizeProviders extends Page
|
||||
{
|
||||
protected static string $resource = ProviderResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.provider-resource.pages.synchronize-providers';
|
||||
|
||||
protected static ?string $title = 'Synchronize providers';
|
||||
|
||||
protected function getHeaderWidgets(): array
|
||||
{
|
||||
return [
|
||||
ProviderResource\Widgets\AvailableProvidersOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderResource\Widgets;
|
||||
|
||||
use App\Models\AvailableProvider;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Provider\SynchronizeProviderAction;
|
||||
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 getTableDescription(): ?string
|
||||
{
|
||||
return 'These are all the providers available from your ploi.io account which you can synchronize to your Ploi Core installation.';
|
||||
}
|
||||
|
||||
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();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
101
app/Filament/Resources/RedirectResource.php
Normal file
101
app/Filament/Resources/RedirectResource.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Redirect;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\RedirectResource\Pages;
|
||||
|
||||
class RedirectResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Redirect::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-external-link';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
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('redirect_from')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('redirect_to')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('type')
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('redirect_from')
|
||||
->wrap()
|
||||
->label(__('Redirect from'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('redirect_to')
|
||||
->wrap()
|
||||
->label(__('Redirect to'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('server.name')
|
||||
->label(__('Server'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->label(__('Site'))
|
||||
->searchable(),
|
||||
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('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
//
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListRedirects::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\RedirectResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\RedirectResource;
|
||||
|
||||
class ListRedirects extends ListRecords
|
||||
{
|
||||
protected static string $resource = RedirectResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
136
app/Filament/Resources/ServerResource.php
Normal file
136
app/Filament/Resources/ServerResource.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use App\Models\User;
|
||||
use Filament\Tables;
|
||||
use App\Models\Server;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Server\SynchronizeServerAction;
|
||||
use App\Filament\Resources\ServerResource\Pages;
|
||||
use App\Filament\Resources\ServerResource\RelationManagers;
|
||||
|
||||
class ServerResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Server::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-server';
|
||||
|
||||
protected static ?string $navigationGroup = 'Server management';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['name', 'ip', 'internal_ip', 'id'];
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->label(__('Name'))
|
||||
->columnSpan(2),
|
||||
Forms\Components\TextInput::make('ip')
|
||||
->required()
|
||||
->label('IP address')
|
||||
->columnSpan(2),
|
||||
Forms\Components\TextInput::make('internal_ip')
|
||||
->required()
|
||||
->label('Internal IP address')
|
||||
->columnSpan(2),
|
||||
Forms\Components\TextInput::make('maximum_sites')
|
||||
->label(__('Maximum sites'))
|
||||
->integer()
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->searchable(),
|
||||
Tables\Columns\BadgeColumn::make('status')
|
||||
->label(__('Status'))
|
||||
->enum([
|
||||
Server::STATUS_BUSY => __('Busy'),
|
||||
Server::STATUS_ACTIVE => __('Active'),
|
||||
])
|
||||
->colors([
|
||||
'warning' => Server::STATUS_BUSY,
|
||||
'success' => Server::STATUS_ACTIVE,
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('users')
|
||||
->label(__('Users'))
|
||||
->wrap()
|
||||
->getStateUsing(function (Server $record) {
|
||||
$state = $record
|
||||
->users
|
||||
->map(function (User $user) {
|
||||
return '<a href="' . route('filament.resources.users.edit', ['record' => $user]) . '" class="text-primary-600">' . $user->name . '</a>';
|
||||
})
|
||||
->implode(', ') ?: '-';
|
||||
|
||||
return new HtmlString($state);
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('maximum_sites')
|
||||
->label(__('Max sites'))
|
||||
->formatStateUsing(fn (Server $record) => $record->maximum_sites . " (Current: {$record->sites_count})"),
|
||||
Tables\Columns\TextColumn::make('ip')
|
||||
->label(__('IP')),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\Action::make('synchronize_server')
|
||||
->label(__('Synchronize'))
|
||||
->tooltip(__('This will synchronize the latest data from this provider to your Ploi Core installation'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->action(fn (Server $record) => app(SynchronizeServerAction::class)->execute($record->ploi_id))
|
||||
->visible(fn (Server $record) => $record->status === Server::STATUS_ACTIVE),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->with(['users:id,name'])
|
||||
->withCount(['sites']);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\UsersRelationManager::class,
|
||||
RelationManagers\SitesRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListServers::route('/'),
|
||||
'edit' => Pages\EditServer::route('/{record}/edit'),
|
||||
'synchronize' => Pages\SynchronizeServers::route('/synchronize'),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/ServerResource/Pages/CreateServer.php
Normal file
11
app/Filament/Resources/ServerResource/Pages/CreateServer.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ServerResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateServer extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ServerResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/ServerResource/Pages/EditServer.php
Normal file
19
app/Filament/Resources/ServerResource/Pages/EditServer.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
|
||||
class EditServer extends EditRecord
|
||||
{
|
||||
protected static string $resource = ServerResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
37
app/Filament/Resources/ServerResource/Pages/ListServers.php
Normal file
37
app/Filament/Resources/ServerResource/Pages/ListServers.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
|
||||
class ListServers extends ListRecords
|
||||
{
|
||||
protected static string $resource = ServerResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_servers')
|
||||
->label(__('Synchronize servers'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->color('secondary')
|
||||
->url(route('filament.resources.servers.synchronize')),
|
||||
...parent::getActions(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function applySearchToTableQuery(Builder $query): Builder
|
||||
{
|
||||
if (filled($searchTerm = $this->getTableSearchQuery())) {
|
||||
$query
|
||||
->where('domain', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhereHas('users', fn (Builder $query) => $query->where('name', 'LIKE', "%{$searchTerm}%"))
|
||||
->orWhereHas('users', fn (Builder $query) => $query->where('email', 'LIKE', "%{$searchTerm}%"));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use Filament\Notifications\Notification;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
|
||||
class SynchronizeServers extends Page
|
||||
{
|
||||
protected static string $resource = ServerResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.server-resource.pages.synchronize-servers';
|
||||
|
||||
protected static ?string $title = 'Synchronize servers';
|
||||
|
||||
protected function getHeaderWidgets(): array
|
||||
{
|
||||
return [
|
||||
ServerResource\Widgets\AvailableServersOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_servers')
|
||||
->label(__('Synchronize all servers'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Synchronize servers')
|
||||
->modalSubheading('This will synchronize all the servers that are listed in the table, to your Ploi Core installation.')
|
||||
->action(function () {
|
||||
$availableServers = Ploi::make()->synchronize()->servers()->getData();
|
||||
|
||||
foreach ($availableServers as $availableServer) {
|
||||
Server::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $availableServer->id,
|
||||
], [
|
||||
'status' => $availableServer->status,
|
||||
'name' => $availableServer->name,
|
||||
'ip' => $availableServer->ip_address,
|
||||
'ssh_port' => $availableServer->ssh_port,
|
||||
'internal_ip' => $availableServer->internal_ip,
|
||||
'available_php_versions' => $availableServer->installed_php_versions,
|
||||
]);
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->body(__('Servers synchronized successfully.'))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class SitesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'sites';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'domain';
|
||||
|
||||
public static function getLabel(): ?string
|
||||
{
|
||||
return __('Site');
|
||||
}
|
||||
|
||||
protected static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('Sites');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return SiteResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return SiteResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\RelationManagers;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class UsersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'users';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getLabel(): ?string
|
||||
{
|
||||
return __('User');
|
||||
}
|
||||
|
||||
protected static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('Users');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return UserResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return UserResource::table($table)
|
||||
->appendHeaderActions([
|
||||
Tables\Actions\AttachAction::make()->preloadRecordSelect(),
|
||||
])
|
||||
->appendActions([
|
||||
Tables\Actions\DetachAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Widgets;
|
||||
|
||||
use App\Models\AvailableServer;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Server\SynchronizeServerAction;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
class AvailableServersOverview extends TableWidget
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected static ?string $heading = 'Available servers';
|
||||
|
||||
protected function getTableQuery(): Builder|Relation
|
||||
{
|
||||
return AvailableServer::query();
|
||||
}
|
||||
|
||||
protected function getTableDescription(): ?string
|
||||
{
|
||||
return 'These are all the servers available from your ploi.io account which you can synchronize to your Ploi Core installation.';
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('name')->label(__('Name')),
|
||||
TextColumn::make('ip_address')->label(__('IP address')),
|
||||
TextColumn::make('sites_count')->label(__('Sites')),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTableActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_server')
|
||||
->label(__('Synchronize'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->action(function (AvailableServer $record) {
|
||||
app(SynchronizeServerAction::class)->execute($record->id);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
142
app/Filament/Resources/SiteResource.php
Normal file
142
app/Filament/Resources/SiteResource.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use App\Actions\Site\SynchronizeSiteAction;
|
||||
use App\Filament\Resources\SiteResource\Pages;
|
||||
use App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
class SiteResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Site::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-code';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 0;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'domain';
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getLabel(): ?string
|
||||
{
|
||||
return __('Site');
|
||||
}
|
||||
|
||||
public static function getPluralLabel(): ?string
|
||||
{
|
||||
return __('Sites');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('domain')
|
||||
->label(__('Domain'))
|
||||
->required()
|
||||
->hostname()
|
||||
->unique(Site::class, column: 'domain', ignoreRecord: true)
|
||||
->columnSpan(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('domain')
|
||||
->description(function (Site $record) {
|
||||
return "PHP $record->php_version";
|
||||
})
|
||||
->label(__('Name'))
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('server.name')
|
||||
->label(__('Server'))
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\BadgeColumn::make('status')
|
||||
->enum([
|
||||
Site::STATUS_BUSY => __('Busy'),
|
||||
Site::STATUS_ACTIVE => __('Active'),
|
||||
])
|
||||
->colors([
|
||||
'warning' => Site::STATUS_BUSY,
|
||||
'success' => Site::STATUS_ACTIVE,
|
||||
])
|
||||
->label(__('Status')),
|
||||
Tables\Columns\TextColumn::make('users')
|
||||
->label(__('Users'))
|
||||
->getStateUsing(function (Site $record) {
|
||||
$state = $record
|
||||
->users
|
||||
->map(function (User $user) {
|
||||
return '<a href="' . route('filament.resources.users.edit', ['record' => $user]) . '" class="text-primary-600">' . $user->name . '</a>';
|
||||
})
|
||||
->implode(', ') ?: '-';
|
||||
|
||||
return new HtmlString($state);
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\Action::make('synchronize_site')
|
||||
->label(__('Synchronize'))
|
||||
->tooltip(__('This will synchronize the latest data from this provider to your Ploi Core installation'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->action(function (Site $record) {
|
||||
app(SynchronizeSiteAction::class)->execute($record->server->ploi_id, $record->ploi_id);
|
||||
})
|
||||
->visible(fn (Site $record) => $record->status === Site::STATUS_ACTIVE),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
])
|
||||
->defaultSort('sites.created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): \Illuminate\Database\Eloquent\Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->with(['users', 'server']);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\UsersRelationManager::class,
|
||||
RelationManagers\CertificatesRelationManager::class,
|
||||
RelationManagers\CronjobsRelationManager::class,
|
||||
RelationManagers\RedirectsRelationManager::class,
|
||||
RelationManagers\SystemUsersRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSites::route('/'),
|
||||
'edit' => Pages\EditSite::route('/{record}/edit'),
|
||||
'synchronize' => Pages\SynchronizeSites::route('/synchronize'),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/SiteResource/Pages/CreateSite.php
Normal file
11
app/Filament/Resources/SiteResource/Pages/CreateSite.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateSite extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SiteResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/SiteResource/Pages/EditSite.php
Normal file
19
app/Filament/Resources/SiteResource/Pages/EditSite.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSite extends EditRecord
|
||||
{
|
||||
protected static string $resource = SiteResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
41
app/Filament/Resources/SiteResource/Pages/ListSites.php
Normal file
41
app/Filament/Resources/SiteResource/Pages/ListSites.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use App\Traits\HasPloi;
|
||||
use Filament\Pages\Actions\Action;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListSites extends ListRecords
|
||||
{
|
||||
use HasPloi;
|
||||
|
||||
protected static string $resource = SiteResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_sites')
|
||||
->label(__('Synchronize sites'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->color('secondary')
|
||||
->url(route('filament.resources.sites.synchronize')),
|
||||
|
||||
...parent::getActions()
|
||||
];
|
||||
}
|
||||
|
||||
protected function applySearchToTableQuery(Builder $query): Builder
|
||||
{
|
||||
if (filled($searchTerm = $this->getTableSearchQuery())) {
|
||||
$query
|
||||
->where('domain', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhereHas('users', fn (Builder $query) => $query->where('name', 'LIKE', "%{$searchTerm}%"))
|
||||
->orWhereHas('users', fn (Builder $query) => $query->where('email', 'LIKE', "%{$searchTerm}%"));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class SynchronizeSites extends Page
|
||||
{
|
||||
protected static string $resource = SiteResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.site-resource.pages.synchronize-sites';
|
||||
|
||||
public function getHeaderWidgets(): array
|
||||
{
|
||||
return [
|
||||
SiteResource\Widgets\AvailableSitesOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_sites')
|
||||
->label(__('Synchronize all sites'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Synchronize sites')
|
||||
->modalSubheading('This will synchronize all the sites that are listed in the table, to your Ploi Core installation.')
|
||||
->action(function () {
|
||||
$availableSites = Ploi::make()->synchronize()->sites()->getData();
|
||||
|
||||
foreach ($availableSites as $availableSite) {
|
||||
$server = Server::query()->where('ploi_id', $availableSite->server_id)->firstOrFail();
|
||||
|
||||
$site = Site::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $availableSite->id,
|
||||
], [
|
||||
'domain' => $availableSite->domain,
|
||||
'php_version' => $availableSite->php_version,
|
||||
]);
|
||||
|
||||
$site->status = $availableSite->status;
|
||||
$site->server_id = $server->id;
|
||||
$site->save();
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->body(__('Sites synchronized successfully.'))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Filament\Resources\CertificateResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class CertificatesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'certificates';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'domain';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return CertificateResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return CertificateResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class CronjobsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'cronjobs';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'command';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return CronjobResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return CronjobResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Filament\Resources\DatabaseResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class DatabasesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'databases';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return DatabaseResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return DatabaseResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Filament\Resources\RedirectResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class RedirectsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'redirects';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'from';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return RedirectResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return RedirectResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Filament\Resources\SiteSystemUserResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class SystemUsersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'systemUsers';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'user_name';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return SiteSystemUserResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return SiteSystemUserResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Tables\Actions\AttachAction;
|
||||
use Filament\Tables\Actions\DetachAction;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class UsersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'users';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getLabel(): ?string
|
||||
{
|
||||
return __('User');
|
||||
}
|
||||
|
||||
protected static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('Users');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return UserResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return UserResource::table($table)
|
||||
->headerActions([
|
||||
AttachAction::make()
|
||||
->preloadRecordSelect(),
|
||||
])
|
||||
->appendActions([
|
||||
DetachAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Widgets;
|
||||
|
||||
use App\Models\AvailableSite;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Site\SynchronizeSiteAction;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
class AvailableSitesOverview extends TableWidget
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected static ?string $heading = 'Available sites';
|
||||
|
||||
protected function getTableDescription(): ?string
|
||||
{
|
||||
return 'These are all the sites available from your ploi.io account which you can synchronize to your Ploi Core installation.';
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder|Relation
|
||||
{
|
||||
return AvailableSite::query();
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('domain')->label(__('Site')),
|
||||
TextColumn::make('system_user')->label(__('System user')),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTableActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_site')
|
||||
->label(__('Synchronize'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->action(function (AvailableSite $record) {
|
||||
app(SynchronizeSiteAction::class)->execute(ploiServerId: $record->server_id, ploiSiteId: $record->id);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
70
app/Filament/Resources/SiteSystemUserResource.php
Normal file
70
app/Filament/Resources/SiteSystemUserResource.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Models\SiteSystemUser;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\SiteSystemUserResource\Pages;
|
||||
|
||||
class SiteSystemUserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = SiteSystemUser::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-user-group';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('user_name')
|
||||
->label(__('Username'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->label(__('Site'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
//
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSiteSystemUsers::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteSystemUserResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\SiteSystemUserResource;
|
||||
|
||||
class ListSiteSystemUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = SiteSystemUserResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
80
app/Filament/Resources/SubscriptionResource.php
Normal file
80
app/Filament/Resources/SubscriptionResource.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Laravel\Cashier\Subscription;
|
||||
use App\Filament\Resources\SubscriptionResource\Pages;
|
||||
|
||||
class SubscriptionResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Subscription::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cash';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public static function getSlug(): string
|
||||
{
|
||||
return 'subscriptions';
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('user.name')
|
||||
->searchable()
|
||||
->url(fn ($record) => UserResource::getUrl('edit', ['record' => $record])),
|
||||
Tables\Columns\TextColumn::make('stripe_id')->searchable(),
|
||||
Tables\Columns\TextColumn::make('stripe_plan')->searchable(),
|
||||
Tables\Columns\BadgeColumn::make('stripe_status')
|
||||
->label('Status')
|
||||
->colors([
|
||||
'success' => \Stripe\Subscription::STATUS_ACTIVE,
|
||||
'warning' => \Stripe\Subscription::STATUS_PAST_DUE,
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->sortable()
|
||||
->dateTime()
|
||||
->label(__('Date'))
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
// Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSubscriptions::route('/'),
|
||||
// 'create' => Pages\CreateSubscription::route('/create'),
|
||||
// 'edit' => Pages\EditSubscription::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SubscriptionResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\SubscriptionResource;
|
||||
|
||||
class CreateSubscription extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SubscriptionResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SubscriptionResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\SubscriptionResource;
|
||||
|
||||
class EditSubscription extends EditRecord
|
||||
{
|
||||
protected static string $resource = SubscriptionResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SubscriptionResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\SubscriptionResource;
|
||||
|
||||
class ListSubscriptions extends ListRecords
|
||||
{
|
||||
protected static string $resource = SubscriptionResource::class;
|
||||
}
|
||||
102
app/Filament/Resources/SupportTicketResource.php
Normal file
102
app/Filament/Resources/SupportTicketResource.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use App\Models\SupportTicket;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\BadgeColumn;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Filament\Tables\Filters\MultiSelectFilter;
|
||||
use App\Filament\Resources\SupportTicketResource\Pages;
|
||||
|
||||
class SupportTicketResource extends Resource
|
||||
{
|
||||
protected static ?string $model = SupportTicket::class;
|
||||
|
||||
protected static ?string $navigationGroup = 'Support';
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-support';
|
||||
|
||||
protected static ?string $label = 'Ticker';
|
||||
|
||||
protected static ?string $pluralLabel = 'Tickets';
|
||||
|
||||
protected static function shouldRegisterNavigation(): bool
|
||||
{
|
||||
return (bool) setting('support');
|
||||
}
|
||||
|
||||
protected static function getNavigationBadge(): ?string
|
||||
{
|
||||
return static::getEloquentQuery()->count();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
BadgeColumn::make('status')
|
||||
->label(__('Status'))
|
||||
->enum([
|
||||
SupportTicket::STATUS_OPEN => __('Open'),
|
||||
SupportTicket::STATUS_CLOSED => __('Closed'),
|
||||
SupportTicket::STATUS_CUSTOMER_REPLY => __('Customer Reply'),
|
||||
SupportTicket::STATUS_SUPPORT_REPLY => __('Support Reply'),
|
||||
])
|
||||
->colors([
|
||||
'primary' => [SupportTicket::STATUS_OPEN, SupportTicket::STATUS_SUPPORT_REPLY, SupportTicket::STATUS_CUSTOMER_REPLY],
|
||||
'danger' => SupportTicket::STATUS_CLOSED,
|
||||
])
|
||||
->wrap(false),
|
||||
TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('replies_count')
|
||||
->label(__('Replies'))
|
||||
->getStateUsing(fn (SupportTicket $record) => $record->replies->count()),
|
||||
TextColumn::make('user.name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
MultiSelectFilter::make('status')
|
||||
->label(__('Status'))
|
||||
->options([
|
||||
SupportTicket::STATUS_OPEN => __('Open'),
|
||||
SupportTicket::STATUS_CLOSED => __('Closed'),
|
||||
SupportTicket::STATUS_CUSTOMER_REPLY => __('Customer Reply'),
|
||||
SupportTicket::STATUS_SUPPORT_REPLY => __('Support Reply'),
|
||||
])
|
||||
->default([
|
||||
SupportTicket::STATUS_CUSTOMER_REPLY,
|
||||
SupportTicket::STATUS_OPEN,
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->with(['user', 'replies'])
|
||||
->orderByDesc('updated_at');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSupportTickets::route('/'),
|
||||
'view' => Pages\ViewSupportTicket::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SupportTicketResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\SupportTicketResource;
|
||||
|
||||
class ListSupportTickets extends ListRecords
|
||||
{
|
||||
protected static string $resource = SupportTicketResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SupportTicketResource\Pages;
|
||||
|
||||
use App\Models\SupportTicket;
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Filament\Notifications\Notification;
|
||||
use App\Mail\Support\TicketRepliedToEmail;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use App\Filament\Resources\SupportTicketResource;
|
||||
|
||||
class ViewSupportTicket extends Page
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
protected static string $resource = SupportTicketResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.support-ticket-resource.pages.view-support-ticket';
|
||||
|
||||
public SupportTicket $record;
|
||||
|
||||
public array $data = [];
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return __('View ticket') . ': ' . $this->record->title;
|
||||
}
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('close')
|
||||
->label(__('Close'))
|
||||
->action(function (self $livewire) {
|
||||
$livewire->record->status = SupportTicket::STATUS_CLOSED;
|
||||
$livewire->record->save();
|
||||
|
||||
Notification::make()
|
||||
->body(__('Ticket closed'))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$livewire->redirectRoute('filament.resources.support-tickets.view', $livewire->record);
|
||||
})
|
||||
->visible(fn (self $livewire) => $livewire->record->status !== SupportTicket::STATUS_CLOSED)
|
||||
->color('danger'),
|
||||
Action::make('reopen')
|
||||
->label(__('Reopen'))
|
||||
->action(function (self $livewire) {
|
||||
$livewire->record->status = SupportTicket::STATUS_OPEN;
|
||||
$livewire->record->save();
|
||||
|
||||
Notification::make()
|
||||
->body(__('Ticket reopened'))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$livewire->redirectRoute('filament.resources.support-tickets.view', $livewire->record);
|
||||
})
|
||||
->visible(fn (self $livewire) => $livewire->record->status === SupportTicket::STATUS_CLOSED)
|
||||
->color('primary'),
|
||||
];
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->form->fill();
|
||||
}
|
||||
|
||||
protected function getFormSchema(): array
|
||||
{
|
||||
return [
|
||||
MarkdownEditor::make('content')
|
||||
->label(__('Reply'))
|
||||
->required(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getFormStatePath(): ?string
|
||||
{
|
||||
return 'data';
|
||||
}
|
||||
|
||||
public function reply(): void
|
||||
{
|
||||
$state = $this->form->getStateOnly(['content']);
|
||||
|
||||
$this->record->status = SupportTicket::STATUS_SUPPORT_REPLY;
|
||||
$this->record->save();
|
||||
|
||||
$reply = $this->record->replies()->create($state);
|
||||
$reply->user_id = Auth::id();
|
||||
$reply->save();
|
||||
|
||||
Mail::to($this->record->user)->send(new TicketRepliedToEmail($this->record));
|
||||
|
||||
$this->form->fill();
|
||||
$this->emit('$refresh');
|
||||
|
||||
Notification::make()
|
||||
->body(__('Reply sent'))
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
public function close(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
140
app/Filament/Resources/UserResource.php
Normal file
140
app/Filament/Resources/UserResource.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use App\Models\User;
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use STS\FilamentImpersonate\Impersonate;
|
||||
use App\Filament\Resources\UserResource\Pages;
|
||||
use App\Filament\Resources\UserResource\RelationManagers;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = User::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-users';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['user_name', 'name', 'email'];
|
||||
}
|
||||
|
||||
public static function getLabel(): ?string
|
||||
{
|
||||
return __('User');
|
||||
}
|
||||
|
||||
public static function getPluralLabel(): ?string
|
||||
{
|
||||
return __('Users');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label(__('Name'))
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('email')
|
||||
->label(__('E-mail address'))
|
||||
->email()
|
||||
->unique(table: User::class, column: 'email', ignoreRecord: true)
|
||||
->required(),
|
||||
Forms\Components\Select::make('role')
|
||||
->options([
|
||||
User::ADMIN => __('Administrator'),
|
||||
User::USER => __('User'),
|
||||
])
|
||||
->default(User::USER)
|
||||
->columnSpan(2)
|
||||
->required(),
|
||||
Forms\Components\Select::make('package_id')
|
||||
->label(__('Package'))
|
||||
->relationship('package', 'name'),
|
||||
Forms\Components\Select::make('language')
|
||||
->label(__('Language'))
|
||||
->default('en')
|
||||
->options(collect(languages())->mapWithKeys(fn(string $language) => [$language => $language])),
|
||||
Forms\Components\Textarea::make('notes')
|
||||
->label(__('Notes'))
|
||||
->maxLength(65535),
|
||||
Forms\Components\Textarea::make('blocked')
|
||||
->helperText('Entering a reason here will block the user from accessing your panel. It will also display the typed message to the user.')
|
||||
->label(__('Blocked')),
|
||||
Forms\Components\Checkbox::make('requires_password_for_ftp')
|
||||
->default(true)
|
||||
->label(__('Require password to show FTP password'))
|
||||
->helperText(__('Disabling this will allow this user to get the FTP password without entering their password.')),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
$actions = [];
|
||||
|
||||
if (config('core.impersonation')) {
|
||||
$actions[] = Impersonate::make('impersonate')->tooltip('Login as this user (impersonate)');
|
||||
}
|
||||
|
||||
$actions[] = Tables\Actions\EditAction::make();
|
||||
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('user_name')
|
||||
->label(__('User name'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('email')
|
||||
->label(__('E-mail address'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('servers_count')
|
||||
->label(__('Servers'))
|
||||
->counts('servers')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('sites_count')
|
||||
->label(__('Sites'))
|
||||
->counts('sites')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('role')
|
||||
->label(__('Role')),
|
||||
Tables\Columns\TextColumn::make('package.name')
|
||||
->label(__('Package')),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions($actions)
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
])
|
||||
->defaultSort('users.created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\SitesRelationManager::class,
|
||||
RelationManagers\ServersRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListUsers::route('/'),
|
||||
'create' => Pages\CreateUser::route('/create'),
|
||||
'edit' => Pages\EditUser::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/UserResource/Pages/CreateUser.php
Normal file
11
app/Filament/Resources/UserResource/Pages/CreateUser.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateUser extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
}
|
||||
53
app/Filament/Resources/UserResource/Pages/EditUser.php
Normal file
53
app/Filament/Resources/UserResource/Pages/EditUser.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use App\Actions\User\DeleteUserAction;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditUser extends EditRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('two_factor_authentication')
|
||||
->label(__('Disable two-factor authentication'))
|
||||
->color('secondary')
|
||||
->action(function () {
|
||||
$this->record->disableTwoFactorAuth();
|
||||
|
||||
Notification::make()
|
||||
->body(__('Two-factor authentication disabled'))
|
||||
->success()
|
||||
->send();
|
||||
})
|
||||
->visible(fn () => $this->record->hasTwoFactorEnabled())
|
||||
->requiresConfirmation(),
|
||||
Actions\Action::make('delete')
|
||||
->form([
|
||||
Toggle::make('remove_all_data')
|
||||
->label(__('Delete all servers, sites, databases, etc.'))
|
||||
->default(true)
|
||||
->helperText(__('This will delete all the servers, sites, databases, etc. associated with this user. Servers & sites that belong to multiple users will not be deleted. This action cannot be undone.')),
|
||||
])
|
||||
->requiresConfirmation()
|
||||
->action(function (array $data) {
|
||||
app(DeleteUserAction::class)->execute($this->getRecord(), $data['remove_all_data']);
|
||||
|
||||
Notification::make()
|
||||
->body(__('User deleted'))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$this->redirectRoute('filament.resources.users.index');
|
||||
})
|
||||
->color('danger'),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/UserResource/Pages/ListUsers.php
Normal file
19
app/Filament/Resources/UserResource/Pages/ListUsers.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class ServersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'servers';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return ServerResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return ServerResource::table($table);
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder|Relation
|
||||
{
|
||||
return parent::getTableQuery()
|
||||
->withCount('sites');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class SitesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'sites';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'domain';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return SiteResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return SiteResource::table($table);
|
||||
}
|
||||
}
|
||||
27
app/Filament/Widgets/StatsOverview.php
Normal file
27
app/Filament/Widgets/StatsOverview.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use Filament\Widgets\StatsOverviewWidget\Card;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
|
||||
class StatsOverview extends BaseWidget
|
||||
{
|
||||
protected function getCards(): array
|
||||
{
|
||||
return [
|
||||
Card::make(__('Servers'), Server::count())
|
||||
->url(route('filament.resources.servers.index'))
|
||||
->icon('heroicon-o-server'),
|
||||
Card::make(__('Sites'), Site::count())
|
||||
->url(route('filament.resources.sites.index'))
|
||||
->icon('heroicon-o-globe-alt'),
|
||||
Card::make(__('Users'), User::count())
|
||||
->url(route('filament.resources.users.index'))
|
||||
->icon('heroicon-o-user'),
|
||||
];
|
||||
}
|
||||
}
|
||||
37
app/Filament/Widgets/SystemLogs.php
Normal file
37
app/Filament/Widgets/SystemLogs.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\SystemLog;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
|
||||
class SystemLogs extends BaseWidget
|
||||
{
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected int $defaultTableRecordsPerPageSelectOption = 10;
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return SystemLog::query()
|
||||
->latest()
|
||||
->with('model');
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make(__('Title'))
|
||||
->formatStateUsing(fn (SystemLog $record) => __($record->title, [
|
||||
'site' => $record->model->domain ?? '-Unknown-',
|
||||
'database' => $record->model->name ?? '-Unknown-',
|
||||
]))
|
||||
->description(fn (SystemLog $record) => __($record->description, [
|
||||
'site' => $record->model->domain ?? '-Unknown-',
|
||||
'database' => $record->model->name ?? '-Unknown-',
|
||||
])),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
|
||||
if (!function_exists('setting')) {
|
||||
if (! function_exists('setting')) {
|
||||
/**
|
||||
* @param null $key
|
||||
* @param null $default
|
||||
@@ -12,12 +12,22 @@ if (!function_exists('setting')) {
|
||||
*/
|
||||
function setting($key = null, $default = null)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
Setting::updateOrCreate([
|
||||
'key' => key($key)
|
||||
], [
|
||||
'value' => Arr::first($key)
|
||||
]);
|
||||
if (is_array($settings = $key)) {
|
||||
foreach ($settings as $key => $value) {
|
||||
if ($value === true) {
|
||||
$value = '1';
|
||||
}
|
||||
|
||||
if ($value === false) {
|
||||
$value = '0';
|
||||
}
|
||||
|
||||
Setting::updateOrCreate([
|
||||
'key' => $key,
|
||||
], [
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
cache()->forget('core.settings');
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Models\Alert;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\AlertRequest;
|
||||
|
||||
class AlertController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return inertia('Admin/Alerts/Index', [
|
||||
'alerts' => Alert::query()->latest()->paginate()
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return inertia('Admin/Alerts/Create');
|
||||
}
|
||||
|
||||
public function store(AlertRequest $request)
|
||||
{
|
||||
Alert::create($request->all());
|
||||
|
||||
return redirect()->route('admin.alerts.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return inertia('Admin/Alerts/Edit', [
|
||||
'alert' => Alert::findOrFail($id)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(AlertRequest $request, $id)
|
||||
{
|
||||
Alert::findOrFail($id)->update($request->all());
|
||||
|
||||
return redirect()->route('admin.alerts.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
Alert::findOrFail($id)->delete();
|
||||
|
||||
return redirect()->route('admin.alerts.index');
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class ApplicationLogController extends Controller
|
||||
{
|
||||
protected $final = [];
|
||||
protected $config = [
|
||||
'date' => null
|
||||
];
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->config['date'] = date('Y-m-d');
|
||||
|
||||
if ($date = $request->input('date')) {
|
||||
$this->config['date'] = $date;
|
||||
} else {
|
||||
$request->merge(['date' => date('Y-m-d')]);
|
||||
}
|
||||
|
||||
return inertia('Admin/ApplicationLogs', [
|
||||
'logData' => $this->get(),
|
||||
'filters' => $request->all('date')
|
||||
]);
|
||||
}
|
||||
|
||||
public function getLogFileDates()
|
||||
{
|
||||
$dates = [];
|
||||
$files = glob(storage_path('logs/laravel-*.log'));
|
||||
$files = array_reverse($files);
|
||||
|
||||
foreach ($files as $path) {
|
||||
$fileName = basename($path);
|
||||
preg_match('/(?<=laravel-)(.*)(?=.log)/', $fileName, $dtMatch);
|
||||
$date = $dtMatch[0];
|
||||
array_push($dates, $date);
|
||||
}
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
$availableDates = $this->getLogFileDates();
|
||||
|
||||
if (count($availableDates) == 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'No log available'
|
||||
]);
|
||||
}
|
||||
|
||||
$configDate = $this->config['date'];
|
||||
if ($configDate == null) {
|
||||
$configDate = $availableDates[0];
|
||||
}
|
||||
|
||||
if (!in_array($configDate, $availableDates)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'No log file found with selected date ' . $configDate
|
||||
]);
|
||||
}
|
||||
|
||||
$pattern = "/^\[(?<date>.*)\]\s(?<env>\w+)\.(?<type>\w+):(?<message>.*)/m";
|
||||
|
||||
$fileName = 'laravel-' . $configDate . '.log';
|
||||
$content = file_get_contents(storage_path('logs/' . $fileName));
|
||||
preg_match_all($pattern, $content, $matches, PREG_SET_ORDER, 0);
|
||||
|
||||
$logs = [];
|
||||
foreach ($matches as $match) {
|
||||
$logs[] = [
|
||||
'timestamp' => $match['date'],
|
||||
'env' => $match['env'],
|
||||
'type' => $match['type'],
|
||||
'message' => trim($match['message'])
|
||||
];
|
||||
}
|
||||
|
||||
preg_match('/(?<=laravel-)(.*)(?=.log)/', $fileName, $dtMatch);
|
||||
$date = $dtMatch[0];
|
||||
|
||||
$data = [
|
||||
'available_dates' => $availableDates,
|
||||
'date' => $date,
|
||||
'filename' => $fileName,
|
||||
'logs' => array_reverse($logs)
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user