Compare commits
98 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50768d5648 | ||
|
|
7cfe8d64c4 | ||
|
|
f6f5385751 | ||
|
|
62084f590e | ||
|
|
c7edf262f6 | ||
|
|
1ce6e8cace | ||
|
|
57f783490b | ||
|
|
eaab262629 | ||
|
|
e2e05f9cbf | ||
|
|
24ce8bc60d | ||
|
|
75592aaeb2 | ||
|
|
c11ad19220 | ||
|
|
db799a7d6a | ||
|
|
7fea371857 | ||
|
|
d7b3899e71 | ||
|
|
e2886fb67e | ||
|
|
57c8997dd0 | ||
|
|
2df031a60f | ||
|
|
77384a1abe | ||
|
|
7b20082537 | ||
|
|
3531e4b296 | ||
|
|
4e92501985 | ||
|
|
d7632d8289 | ||
|
|
f404b3e9c6 | ||
|
|
730f9b7451 | ||
|
|
2fe5fd70c9 | ||
|
|
6afe8738df | ||
|
|
761a940abd | ||
|
|
f87c1dd5ee | ||
|
|
de70310c90 | ||
|
|
11f9b1ed48 | ||
|
|
060a6b72a7 | ||
|
|
70cc81f110 | ||
|
|
bcc1a9b9a8 | ||
|
|
1c601a6efd | ||
|
|
fee31d03a7 | ||
|
|
b09dc1ba9d | ||
|
|
dae15c620b | ||
|
|
996a048a76 | ||
|
|
8c20f23dfd | ||
|
|
c80818df4c | ||
|
|
d5e77ae31f | ||
|
|
a14d2c44a1 | ||
|
|
3048747ed6 | ||
|
|
20bf6c4784 | ||
|
|
9b02be5be1 | ||
|
|
d141503b6f | ||
|
|
6a8e4e8edf | ||
|
|
89bbf44b3b | ||
|
|
db1f40bf6f | ||
|
|
5933a06dd3 | ||
|
|
3c510906ee | ||
|
|
b43f4cf292 | ||
|
|
9cc046eeed | ||
|
|
8291ac6714 | ||
|
|
c578ee70c0 | ||
|
|
90501e37fd | ||
|
|
ec45b0dac0 | ||
|
|
34b838c259 | ||
|
|
28ffc8e240 | ||
|
|
c9179fbf90 | ||
|
|
fe5268971a | ||
|
|
8c246e2dba | ||
|
|
81fcfac803 | ||
|
|
ff22b96a8d | ||
|
|
4a2faf0bce | ||
|
|
5c39d07bf5 | ||
|
|
9870aec79f | ||
|
|
833a03e992 | ||
|
|
e074ab5be4 | ||
|
|
b5963693e6 | ||
|
|
1b7ea67fde | ||
|
|
d4f2b9839e | ||
|
|
817f6a175c | ||
|
|
b3619e5941 | ||
|
|
33784410e5 | ||
|
|
6ecf7904fe | ||
|
|
21986f2394 | ||
|
|
4d8212e56f | ||
|
|
865f2958cf | ||
|
|
17890d13ad | ||
|
|
2d33455731 | ||
|
|
49481f9b6a | ||
|
|
7bb800cc0a | ||
|
|
1b8c2c764f | ||
|
|
cb1a1c4c06 | ||
|
|
ddd80a8687 | ||
|
|
010d4569c2 | ||
|
|
62ae0f8299 | ||
|
|
2a3d9cabd0 | ||
|
|
e2a58cf2df | ||
|
|
0fd6db251b | ||
|
|
94d50c11ef | ||
|
|
14c6faafa2 | ||
|
|
ea21076eda | ||
|
|
d378323602 | ||
|
|
f074dee990 | ||
|
|
7bd2917ec4 |
41
.github/workflows/master.yml
vendored
Normal file
41
.github/workflows/master.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
name: Run tests & build files
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Run tests
|
||||
uses: ./.github/workflows/run-tests.yml
|
||||
|
||||
deploy:
|
||||
needs: test
|
||||
name: Prepare build assets
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup PHP with PECL extension
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
extensions: pcntl
|
||||
|
||||
- run: composer install
|
||||
name: Install dependencies
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '12.x'
|
||||
- run: npm install
|
||||
- run: npm run production
|
||||
|
||||
- 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 push origin
|
||||
33
.github/workflows/run-tests.yml
vendored
Normal file
33
.github/workflows/run-tests.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
name: "Run tests"
|
||||
|
||||
on:
|
||||
push:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Pest (PHP ${{ matrix.php }} – ${{ matrix.os }})
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
php: [8.0, 8.1]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, mysql
|
||||
coverage: none
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
composer install
|
||||
|
||||
- name: Execute tests
|
||||
run: vendor/bin/pest
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,8 +1,10 @@
|
||||
/node_modules
|
||||
/node_modules.nosync
|
||||
/public/hot
|
||||
/public/storage
|
||||
/storage/*.key
|
||||
/vendor
|
||||
/vendor.nosync
|
||||
.env
|
||||
.env.backup
|
||||
.phpunit.result.cache
|
||||
@@ -16,3 +18,6 @@ yarn-error.log
|
||||
/public/js/resources*.js
|
||||
/storage/views/header.blade.php
|
||||
/storage/views/footer.blade.php
|
||||
rr
|
||||
.rr.yaml
|
||||
.DS_Store
|
||||
|
||||
56
app/Actions/Server/CreateServerAction.php
Normal file
56
app/Actions/Server/CreateServerAction.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
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 Illuminate\Support\Facades\Mail;
|
||||
|
||||
class CreateServerAction
|
||||
{
|
||||
public function execute(ServerData $serverData): Server
|
||||
{
|
||||
[$provider, $providerRegion, $providerPlan] = $this->determineProviderRegionPlan($serverData);
|
||||
|
||||
$server = $serverData->getUser()->servers()->create([
|
||||
'name' => $serverData->name,
|
||||
'database_type' => $serverData->database_type,
|
||||
]);
|
||||
|
||||
$server->provider()->associate($provider);
|
||||
$server->providerRegion()->associate($providerRegion);
|
||||
$server->providerPlan()->associate($providerPlan);
|
||||
$server->save();
|
||||
|
||||
dispatch(new CreateServer($server));
|
||||
|
||||
$this->sendAdminServerCreatedEmails($server);
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
protected function determineProviderRegionPlan(ServerData $serverData): array
|
||||
{
|
||||
$provider = $serverData->getUser()->package->providers()->findOrFail($serverData->provider_id);
|
||||
$region = $provider->regions()->findOrFail($serverData->provider_region_id);
|
||||
$plan = $provider->plans()->findOrFail($serverData->provider_plan_id);
|
||||
|
||||
return [$provider, $region, $plan];
|
||||
}
|
||||
|
||||
protected function sendAdminServerCreatedEmails(Server $server): void
|
||||
{
|
||||
if (! setting('receive_email_on_server_creation')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admins = User::query()->where('role', User::ADMIN)->get();
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
Mail::to($admin)->send(new AdminServerCreatedEmail(auth()->user(), $server));
|
||||
}
|
||||
}
|
||||
}
|
||||
76
app/Actions/Site/CreateSiteAction.php
Normal file
76
app/Actions/Site/CreateSiteAction.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
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 Illuminate\Support\Facades\Mail;
|
||||
|
||||
class CreateSiteAction
|
||||
{
|
||||
public function execute(SiteData $siteData): ?Site
|
||||
{
|
||||
$server = $this->determineServer($siteData);
|
||||
|
||||
if ( ! $server ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$site = $server->sites()->create($siteData->toArray());
|
||||
|
||||
$siteData->getUser()->sites()->save($site);
|
||||
|
||||
dispatch(new CreateSite($site));
|
||||
|
||||
$siteData->getUser()->systemLogs()->create([
|
||||
'title' => 'New site :site created',
|
||||
'description' => 'A new site has been created',
|
||||
])->model()->associate($site)->save();
|
||||
|
||||
$this->sendAdminSiteCreatedEmails($server, $site, $siteData->getUser());
|
||||
|
||||
return $site;
|
||||
}
|
||||
|
||||
protected function determineServer(SiteData $siteData): ?Server
|
||||
{
|
||||
if ( $siteData->server_id ) {
|
||||
return $siteData->getUser()->servers()->findOrFail($siteData->server_id);
|
||||
}
|
||||
|
||||
$server = Server::query()
|
||||
->where('maximum_sites', '>', 0)
|
||||
->where(function ($query) use ($siteData) {
|
||||
return $query
|
||||
->where(fn ($query) => $query->whereHas('users', fn ($query) => $query->where('user_id', $siteData->getUser()->id)))
|
||||
->orWhere(function ($query) {
|
||||
return $query->doesntHave('users');
|
||||
});
|
||||
})
|
||||
->withCount('sites')
|
||||
->inRandomOrder()
|
||||
->first();
|
||||
|
||||
return $server && $server->sites_count < $server->maximum_sites
|
||||
? $server
|
||||
: null;
|
||||
}
|
||||
|
||||
protected function sendAdminSiteCreatedEmails(Server $server, Model|Site $site, User $user): void
|
||||
{
|
||||
if ( ! setting('receive_email_on_site_creation') ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admins = User::where('role', User::ADMIN)->get();
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
Mail::to($admin)->send(new AdminSiteCreatedEmail(user: $user, server: $server, site: $site));
|
||||
}
|
||||
}
|
||||
}
|
||||
26
app/Casts/SiteAlias.php
Normal file
26
app/Casts/SiteAlias.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
|
||||
class SiteAlias implements CastsAttributes
|
||||
{
|
||||
public function get($model, string $key, $value, array $attributes)
|
||||
{
|
||||
if (!$value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$data = json_decode($value, true);
|
||||
|
||||
sort($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function set($model, string $key, $value, array $attributes)
|
||||
{
|
||||
return json_encode($value);
|
||||
}
|
||||
}
|
||||
@@ -202,9 +202,9 @@ class Install extends Command
|
||||
{
|
||||
if (!config('app.key')) {
|
||||
$this->call('key:generate');
|
||||
}
|
||||
|
||||
$this->info('Application key has been set');
|
||||
$this->info('Application key has been set');
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkApplicationUrl()
|
||||
@@ -315,7 +315,7 @@ class Install extends Command
|
||||
protected function runDatabaseMigrations()
|
||||
{
|
||||
$this->info('Running database migrations..');
|
||||
$this->call('migrate');
|
||||
$this->call('migrate', ['--force' => true]);
|
||||
$this->info('Database migrations successful');
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class Synchronize extends Command
|
||||
{
|
||||
protected $signature = 'core:synchronize';
|
||||
|
||||
protected $description = 'Synchronze data';
|
||||
protected $description = 'Synchronize data';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
24
app/Console/Commands/Core/Trial.php
Normal file
24
app/Console/Commands/Core/Trial.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Core;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class Trial extends Command
|
||||
{
|
||||
protected $signature = 'core:trial';
|
||||
|
||||
protected $description = 'Check for expired trials';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
User::query()
|
||||
->where('trial_ends_at', '<', now())
|
||||
->each(function (User $user) {
|
||||
$user->trial_ends_at = null;
|
||||
$user->package_id = setting('default_package');
|
||||
$user->save();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
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\Cleanup;
|
||||
@@ -19,6 +20,7 @@ class Kernel extends ConsoleKernel
|
||||
Install::class,
|
||||
Synchronize::class,
|
||||
Cleanup::class,
|
||||
Trial::class,
|
||||
];
|
||||
|
||||
protected function schedule(Schedule $schedule)
|
||||
@@ -28,5 +30,6 @@ class Kernel extends ConsoleKernel
|
||||
})->dailyAt('02:00');
|
||||
|
||||
$schedule->command('core:cleanup')->daily();
|
||||
$schedule->command('core:trial')->dailyAt('10:00');
|
||||
}
|
||||
}
|
||||
|
||||
48
app/DataTransferObjects/ServerData.php
Normal file
48
app/DataTransferObjects/ServerData.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use App\DataTransferObjects\Support\Concerns\BelongsToUser;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use App\Models\Provider;
|
||||
use App\Models\ProviderPlan;
|
||||
use App\Models\ProviderRegion;
|
||||
use App\Models\Server;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Spatie\LaravelData\Attributes\Validation\AlphaDash;
|
||||
use Spatie\LaravelData\Attributes\Validation\Exists;
|
||||
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\StringType;
|
||||
|
||||
class ServerData extends Data
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
public function __construct(
|
||||
public ?int $id = null,
|
||||
#[StringType]
|
||||
public ?string $status = null,
|
||||
#[StringType, AlphaDash, Max( 40 )]
|
||||
public string $name,
|
||||
#[NotIn( 0 ), Exists( Provider::class, 'id' )]
|
||||
public int $provider_id,
|
||||
#[NotIn( 0 ), Exists( ProviderRegion::class, 'id' )]
|
||||
public int $provider_region_id,
|
||||
#[NotIn( 0 ), Exists( ProviderPlan::class, 'id' )]
|
||||
public int $provider_plan_id,
|
||||
#[StringType, In( ['mysql', 'mariadb', 'postgresql', 'postgresql13'] )]
|
||||
public string $database_type,
|
||||
#[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]));
|
||||
}
|
||||
}
|
||||
60
app/DataTransferObjects/SiteData.php
Normal file
60
app/DataTransferObjects/SiteData.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use App\DataTransferObjects\Support\Concerns\BelongsToUser;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use App\DataTransferObjects\Support\Rules\CustomRule;
|
||||
use App\Models\Server;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use App\Rules\Hostname;
|
||||
use App\Rules\ValidateMaximumSites;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Spatie\LaravelData\Attributes\Validation\Exists;
|
||||
use Spatie\LaravelData\Attributes\Validation\IntegerType;
|
||||
use Spatie\LaravelData\Attributes\Validation\StringType;
|
||||
|
||||
class SiteData extends Data
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
public function __construct(
|
||||
public ?int $id = null,
|
||||
public ?string $status = null,
|
||||
#[Exists( Server::class, 'id' ), IntegerType]
|
||||
public ?int $server_id = null,
|
||||
#[StringType, CustomRule(Hostname::class, ValidateMaximumSites::class)]
|
||||
public ?string $domain = null,
|
||||
#[Exists(User::class, 'id'), IntegerType]
|
||||
public ?int $user_id = null,
|
||||
public ?Carbon $created_at = null,
|
||||
) {}
|
||||
|
||||
public static function authorize(): bool
|
||||
{
|
||||
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(), [
|
||||
'id',
|
||||
'status',
|
||||
'server_id',
|
||||
'domain',
|
||||
'user_id',
|
||||
'created_at',
|
||||
]);
|
||||
}
|
||||
}
|
||||
15
app/DataTransferObjects/Support/Casts/CarbonCast.php
Normal file
15
app/DataTransferObjects/Support/Casts/CarbonCast.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support\Casts;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use Spatie\LaravelData\Casts\Cast;
|
||||
use Spatie\LaravelData\Support\DataProperty;
|
||||
|
||||
class CarbonCast implements Cast
|
||||
{
|
||||
public function cast(DataProperty $property, mixed $value): mixed
|
||||
{
|
||||
return Carbon::parse($value);
|
||||
}
|
||||
}
|
||||
13
app/DataTransferObjects/Support/Concerns/BelongsToUser.php
Normal file
13
app/DataTransferObjects/Support/Concerns/BelongsToUser.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support\Concerns;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
trait BelongsToUser
|
||||
{
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return User::find($this->user_id);
|
||||
}
|
||||
}
|
||||
17
app/DataTransferObjects/Support/Data.php
Normal file
17
app/DataTransferObjects/Support/Data.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
class Data extends \Spatie\LaravelData\Data
|
||||
{
|
||||
public static function collection(Paginator|Enumerable|array|AbstractCursorPaginator|DataCollection|AbstractPaginator $items): \App\DataTransferObjects\Support\DataCollection
|
||||
{
|
||||
return new \App\DataTransferObjects\Support\DataCollection(static::class, $items);
|
||||
}
|
||||
}
|
||||
23
app/DataTransferObjects/Support/DataCollection.php
Normal file
23
app/DataTransferObjects/Support/DataCollection.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
use Spatie\LaravelData\Support\TransformationType;
|
||||
|
||||
class DataCollection extends \Spatie\LaravelData\DataCollection
|
||||
{
|
||||
public function transform(TransformationType $type): array
|
||||
{
|
||||
$transformer = new DataCollectionTransformer(
|
||||
$this->dataClass,
|
||||
$type,
|
||||
$this->getInclusionTree(),
|
||||
$this->getExclusionTree(),
|
||||
$this->items,
|
||||
$this->through,
|
||||
$this->filter
|
||||
);
|
||||
|
||||
return $transformer->transform();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class DataCollectionTransformer extends \Spatie\LaravelData\Transformers\DataCollectionTransformer
|
||||
{
|
||||
protected function wrapPaginatedArray(array $paginated): array
|
||||
{
|
||||
return [
|
||||
'data' => $paginated['data'],
|
||||
'links' => [
|
||||
'first' => $paginated['first_page_url'],
|
||||
'last' => $paginated['last_page_url'],
|
||||
'prev' => $paginated['prev_page_url'],
|
||||
'next' => $paginated['next_page_url'],
|
||||
],
|
||||
'meta' => [
|
||||
'current_page' => $paginated['current_page'],
|
||||
'from' => $paginated['from'],
|
||||
'last_page' => $paginated['last_page'],
|
||||
'links' => $paginated['links'],
|
||||
'path' => $paginated['path'],
|
||||
'per_page' => $paginated['per_page'],
|
||||
'to' => $paginated['to'],
|
||||
'total' => $paginated['total'],
|
||||
],
|
||||
];
|
||||
|
||||
return [
|
||||
'data' => $paginated['data'],
|
||||
'links' => $paginated['links'] ?? [],
|
||||
'meta' => Arr::except($paginated, [
|
||||
'data',
|
||||
'links',
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
24
app/DataTransferObjects/Support/Rules/CustomRule.php
Normal file
24
app/DataTransferObjects/Support/Rules/CustomRule.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support\Rules;
|
||||
|
||||
use Attribute;
|
||||
use Spatie\LaravelData\Attributes\Validation\ValidationAttribute;
|
||||
|
||||
#[Attribute( Attribute::TARGET_PROPERTY )]
|
||||
class CustomRule extends ValidationAttribute
|
||||
{
|
||||
protected array $rules = [];
|
||||
|
||||
public function __construct(...$rules)
|
||||
{
|
||||
$this->rules = $rules;
|
||||
}
|
||||
|
||||
public function getRules(): array
|
||||
{
|
||||
return collect($this->rules)
|
||||
->map(fn (string $rule) => new $rule())
|
||||
->all();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support\Transformers;
|
||||
|
||||
use Spatie\LaravelData\Support\DataProperty;
|
||||
use Spatie\LaravelData\Transformers\Transformer;
|
||||
|
||||
class CarbonTransformer implements Transformer
|
||||
{
|
||||
public function transform(DataProperty $property, mixed $value): mixed
|
||||
{
|
||||
return $value->toISOString();
|
||||
}
|
||||
}
|
||||
31
app/DataTransferObjects/UserData.php
Normal file
31
app/DataTransferObjects/UserData.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use App\Models\Package;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Carbon;
|
||||
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;
|
||||
|
||||
class UserData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public ?int $id = null,
|
||||
public ?string $avatar = null,
|
||||
#[StringType, Max(255)]
|
||||
public ?string $name = null,
|
||||
#[StringType, Email, Max(255), Unique(User::class)]
|
||||
public ?string $email = null,
|
||||
#[Exists( Package::class, 'id'), IntegerType]
|
||||
public ?int $package_id = null,
|
||||
#[StringType]
|
||||
public ?string $blocked = null,
|
||||
public ?Carbon $created_at = null,
|
||||
) {}
|
||||
}
|
||||
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Middleware\HandleInertiaRequests;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
@@ -29,10 +33,10 @@ class Handler extends ExceptionHandler
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* @param \Throwable $exception
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
@@ -42,24 +46,21 @@ class Handler extends ExceptionHandler
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Throwable $exception
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @param Request $request
|
||||
* @param Throwable $exception
|
||||
* @return Response
|
||||
*
|
||||
* @throws \Throwable
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
$response = parent::render($request, $exception);
|
||||
|
||||
if (in_array($response->status(), [404, 403])) {
|
||||
\Route::any($request->path(), function () use ($exception, $request) {
|
||||
return parent::render($request, $exception);
|
||||
})->middleware('web');
|
||||
|
||||
return inertia()->render('Errors/' . $response->status(), ['status' => $response->status()])
|
||||
->toResponse($request)
|
||||
->setStatusCode($response->status());
|
||||
// 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.*')) {
|
||||
return app(HandleInertiaRequests::class)
|
||||
->handle($request, fn () => inertia()->render('Errors/' . $response->status(), ['status' => $response->status()])
|
||||
->toResponse($request));
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
if (!function_exists('setting')) {
|
||||
/**
|
||||
* @param null $key
|
||||
* @param null $default
|
||||
* @return array|ArrayAccess|bool|\Illuminate\Contracts\Foundation\Application|mixed
|
||||
* @return array|ArrayAccess|bool|Application|mixed
|
||||
*/
|
||||
function setting($key = null, $default = null)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
\App\Models\Setting::updateOrCreate([
|
||||
Setting::updateOrCreate([
|
||||
'key' => key($key)
|
||||
], [
|
||||
'value' => Arr::first($key)
|
||||
@@ -20,6 +22,7 @@ if (!function_exists('setting')) {
|
||||
try {
|
||||
cache()->forget('core.settings');
|
||||
} catch (Exception $e) {
|
||||
//
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -28,7 +31,7 @@ if (!function_exists('setting')) {
|
||||
$value = Arr::get(app('settings'), $key, $default);
|
||||
|
||||
// Boolean casting
|
||||
if ($value === "0" || $value === "1") {
|
||||
if ($value === "0" || $value === "1" && $key !== 'trial_package') {
|
||||
return (bool) $value;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,39 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Admin\ServerResource;
|
||||
use App\Http\Requests\Admin\ServerAttachRequest;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return inertia('Admin/Servers/Index', [
|
||||
'filters' => request()->all('search'),
|
||||
'servers' => ServerResource::collection(
|
||||
Server::query()
|
||||
->when(request()->input('search'), function (Builder $query, $value) {
|
||||
return $query
|
||||
->where('name', 'like', '%' . $value . '%')
|
||||
->orWhere('ip', 'like', '%' . $value . '%')
|
||||
->orWhereHas('users', function (Builder $query) use ($value) {
|
||||
return $query
|
||||
->where('name', 'LIKE', '%' . $value . '%')
|
||||
->orWhere('email', 'LIKE', '%' . $value . '%');
|
||||
});
|
||||
})
|
||||
->with('users:id,name')
|
||||
->withCount('sites')
|
||||
->latest()
|
||||
->paginate(config('core.pagination.per_page'))
|
||||
->withQueryString()
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$server = Server::findOrFail($id);
|
||||
|
||||
@@ -22,12 +22,15 @@ class SettingController extends Controller
|
||||
'allow_registration' => setting('allow_registration'),
|
||||
'default_package' => setting('default_package'),
|
||||
'receive_email_on_server_creation' => setting('receive_email_on_server_creation'),
|
||||
'receive_email_on_site_creation' => setting('receive_email_on_site_creation'),
|
||||
'isolate_per_site_per_user' => setting('isolate_per_site_per_user'),
|
||||
'enable_api' => setting('enable_api'),
|
||||
'api_token' => setting('api_token') ? decrypt(setting('api_token')) : null,
|
||||
'rotate_logs_after' => setting('rotate_logs_after') ? setting('rotate_logs_after') : null,
|
||||
'default_language' => setting('default_language', 'en'),
|
||||
'has_logo' => (bool)setting('logo'),
|
||||
'trial' => setting('trial'),
|
||||
'trial_package' => setting('trial_package'),
|
||||
];
|
||||
|
||||
$packages = Package::pluck('name', 'id');
|
||||
@@ -50,11 +53,14 @@ class SettingController extends Controller
|
||||
'documentation',
|
||||
'default_package',
|
||||
'receive_email_on_server_creation',
|
||||
'receive_email_on_site_creation',
|
||||
'isolate_per_site_per_user',
|
||||
'enable_api',
|
||||
'api_token',
|
||||
'default_language',
|
||||
'rotate_logs_after',
|
||||
'trial',
|
||||
'trial_package'
|
||||
]) as $key => $value) {
|
||||
if ($key === 'api_token') {
|
||||
$value = encrypt($value);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Resources\Admin\SiteResource;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -10,6 +11,23 @@ use App\Http\Requests\Admin\ServerAttachRequest;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return inertia('Admin/Sites/Index', [
|
||||
'filters' => request()->all('search'),
|
||||
'sites' => SiteResource::collection(
|
||||
Site::query()
|
||||
->when(request()->input('search'), function ($query, $value) {
|
||||
return $query->where('domain', 'like', '%' . $value . '%');
|
||||
})
|
||||
->with('server:id,name', 'users:id,name')
|
||||
->latest()
|
||||
->paginate(config('core.pagination.per_page'))
|
||||
->withQueryString()
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$site = Site::findOrFail($id);
|
||||
|
||||
@@ -72,7 +72,7 @@ class SynchronizeSiteController extends Controller
|
||||
|
||||
$site = Site::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $availableSite->server_id
|
||||
'ploi_id' => $availableSite->id
|
||||
], [
|
||||
'domain' => $availableSite->domain,
|
||||
'php_version' => $availableSite->php_version,
|
||||
|
||||
@@ -2,17 +2,25 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Inertia\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Jobs\Core\UpdateSystem;
|
||||
use App\Services\VersionChecker;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
|
||||
|
||||
class SystemController extends Controller
|
||||
{
|
||||
public function index(MasterSupervisorRepository $masterSupervisorRepository)
|
||||
public function index(Request $request, MasterSupervisorRepository $masterSupervisorRepository): Response|RedirectResponse
|
||||
{
|
||||
$version = (new VersionChecker)->getVersions();
|
||||
if ($request->input('flush', false)) {
|
||||
app(VersionChecker::class)->flushVersionData();
|
||||
|
||||
return redirect()->route('admin.system')->with('success', __('Refreshed versions'));
|
||||
}
|
||||
|
||||
$version = app(VersionChecker::class)->getVersions();
|
||||
|
||||
return inertia('Admin/System', [
|
||||
'version' => [
|
||||
@@ -20,11 +28,11 @@ class SystemController extends Controller
|
||||
'current' => $version->currentVersion,
|
||||
'remote' => $version->remoteVersion
|
||||
],
|
||||
'horizonRunning' => !!$masterSupervisorRepository->all()
|
||||
'horizonRunning' => (bool) $masterSupervisorRepository->all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
dispatch(new UpdateSystem);
|
||||
|
||||
|
||||
30
app/Http/Controllers/Api/ServerController.php
Normal file
30
app/Http/Controllers/Api/ServerController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Actions\Server\CreateServerAction;
|
||||
use App\DataTransferObjects\ServerData;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
public function store(Request $request): Response
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => ['required'],
|
||||
'provider_id' => ['required'],
|
||||
'provider_region_id' => ['required'],
|
||||
'provider_plan_id' => ['required'],
|
||||
'database_type' => ['required'],
|
||||
'user_id' => ['required'],
|
||||
]);
|
||||
|
||||
$server = app(CreateServerAction::class)->execute(
|
||||
ServerData::validate($data)
|
||||
);
|
||||
|
||||
return response(content: ['data' => ServerData::from($server->refresh())->toArray()], status: 201);
|
||||
}
|
||||
}
|
||||
48
app/Http/Controllers/Api/SiteController.php
Normal file
48
app/Http/Controllers/Api/SiteController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Actions\Site\CreateSiteAction;
|
||||
use App\DataTransferObjects\SiteData;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
public function index(): mixed
|
||||
{
|
||||
return SiteData::collection(Site::paginate());
|
||||
}
|
||||
|
||||
public function store(Request $request): Response|JsonResponse
|
||||
{
|
||||
// Required parameters are validated at the controller level. For example in the API you need to manually pass a user_id,
|
||||
// whilst in the "authenticated part" the user id is takes as Auth::id(). Validation of universal rules is done at the
|
||||
// data-object level (e.g. exists:server_id).
|
||||
$data = $request->validate([
|
||||
'server_id' => ['required'],
|
||||
'domain' => ['required'],
|
||||
'user_id' => ['required'],
|
||||
]);
|
||||
|
||||
$site = app(CreateSiteAction::class)->execute(
|
||||
SiteData::validate($data)
|
||||
);
|
||||
|
||||
$site->refresh();
|
||||
|
||||
return $site
|
||||
? response(content: ['data' => SiteData::from($site)->toArray()], status: 201)
|
||||
: response()->json([
|
||||
'message' => __('It seems there is no free server room for this site to take place. Please get in touch with support to resolve this.'),
|
||||
], 422);
|
||||
}
|
||||
|
||||
public function show(Site $site): Response
|
||||
{
|
||||
return response(content: ['data' => SiteData::from($site)]);
|
||||
}
|
||||
}
|
||||
@@ -2,27 +2,62 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Models\User;
|
||||
use App\DataTransferObjects\UserData;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\UserRequest;
|
||||
use App\Http\Resources\Api\UserResource;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index()
|
||||
public function index(): mixed
|
||||
{
|
||||
return UserResource::collection(User::latest()->paginate());
|
||||
return UserData::collection(User::latest()->paginate());
|
||||
}
|
||||
|
||||
public function store(UserRequest $request)
|
||||
public function show(User $user): Response
|
||||
{
|
||||
$user = User::create($request->validated());
|
||||
|
||||
return new UserResource($user);
|
||||
return response(content: ['data' => UserData::from($user)], status: 200);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
public function store(Request $request): Response
|
||||
{
|
||||
return new UserResource(User::findOrFail($id));
|
||||
$data = $request->validate([
|
||||
'name' => ['required'],
|
||||
'email' => ['required'],
|
||||
'package_id' => ['nullable'],
|
||||
]);
|
||||
|
||||
$userData = UserData::validate($data);
|
||||
|
||||
$user = User::create($userData->toArray());
|
||||
|
||||
return response(content: ['data' => UserData::from($user)], status: 201);
|
||||
}
|
||||
|
||||
public function update(User $user, Request $request): Response
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => [],
|
||||
'email' => [],
|
||||
'package_id' => [],
|
||||
'blocked' => [],
|
||||
]);
|
||||
|
||||
$userData = UserData::validate($data);
|
||||
|
||||
$user->update(
|
||||
Arr::only($userData->toArray(), array_keys($data))
|
||||
);
|
||||
|
||||
return response(content: ['data' => UserData::from($user)], status: 200);
|
||||
}
|
||||
|
||||
public function destroy(User $user): Response
|
||||
{
|
||||
$user->delete();
|
||||
|
||||
return response(status: 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AuthenticateTwoFactorController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return inertia('Auth/ConfirmTwoFactorAuthentication');
|
||||
}
|
||||
|
||||
public function confirm(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'code' => 'totp'
|
||||
]);
|
||||
|
||||
session()->put('auth.two_factor_authenticated_at', now());
|
||||
|
||||
return redirect()->away(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
@@ -35,10 +35,7 @@ class RegisterController extends Controller
|
||||
'required',
|
||||
'string',
|
||||
'confirmed',
|
||||
Password::min(6)
|
||||
->letters()
|
||||
->numbers()
|
||||
->uncompromised()
|
||||
Password::defaults()
|
||||
],
|
||||
];
|
||||
|
||||
@@ -53,18 +50,33 @@ class RegisterController extends Controller
|
||||
|
||||
protected function create(array $data)
|
||||
{
|
||||
return User::create([
|
||||
$fields = [
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => $data['password'],
|
||||
]);
|
||||
];
|
||||
|
||||
if ($days = setting('trial')) {
|
||||
$fields['trial_ends_at'] = now()->addDays($days);
|
||||
}
|
||||
|
||||
return User::create($fields);
|
||||
}
|
||||
|
||||
protected function registered(Request $request, $user)
|
||||
{
|
||||
if (setting('default_package') && setting('default_package') != 'false') {
|
||||
if (
|
||||
setting('default_package') &&
|
||||
setting('default_package') != 'false' &&
|
||||
!setting('trial')
|
||||
) {
|
||||
$user->package_id = setting('default_package');
|
||||
$user->save();
|
||||
}
|
||||
|
||||
if (setting('trial') && setting('trial_package')) {
|
||||
$user->package_id = setting('trial_package');
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers\Profile;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\UserProfileRequest;
|
||||
use App\Http\Resources\UserProfileResource;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
@@ -40,7 +41,7 @@ class ProfileController extends Controller
|
||||
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
/* @var $user \App\Models\User */
|
||||
/* @var $user User */
|
||||
$user = $request->user();
|
||||
|
||||
$user->sites()->detach();
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Profile;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Rules\MatchOldPassword;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class ProfilePasswordController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return inertia('Profile/Security');
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'current_password' => ['required', new MatchOldPassword],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
]);
|
||||
|
||||
$request->user()->update(['password' => $request->input('password')]);
|
||||
|
||||
return redirect()->route('profile.security.index')->with('success', __('Your password has been updated'));
|
||||
}
|
||||
}
|
||||
45
app/Http/Controllers/Profile/ProfileSecurityController.php
Normal file
45
app/Http/Controllers/Profile/ProfileSecurityController.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Profile;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Rules\MatchOldPassword;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProfileSecurityController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$twoFactorAuth = $request->user()->twoFactorAuth()->first();
|
||||
|
||||
// Only show recovery codes once.
|
||||
$recoveryCodes = $twoFactorAuth?->recovery_codes_generated_at?->gt(now()->subSecond(1))
|
||||
? $request->user()->getRecoveryCodes()
|
||||
: [];
|
||||
|
||||
return inertia('Profile/Security', [
|
||||
'twoFactor' => [
|
||||
'secret' => [
|
||||
'qr_code' => $twoFactorAuth?->toQr(),
|
||||
'uri' => $twoFactorAuth?->toUri(),
|
||||
'string' => $twoFactorAuth?->toString(),
|
||||
],
|
||||
'recoveryCodes' => $recoveryCodes,
|
||||
'enabled' => $request->user()->hasTwoFactorEnabled(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function updatePassword(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'current_password' => ['required', new MatchOldPassword],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
]);
|
||||
|
||||
$request->user()->update(['password' => $request->input('password')]);
|
||||
|
||||
return redirect()->route('profile.security.index')->with('success', __('Your password has been updated'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Profile\TwoFactorAuthentication;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ConfirmTwoFactorAuthenticationController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'code' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$activated = $request->user()->confirmTwoFactorAuth($request->input('code'));
|
||||
|
||||
if ($activated) {
|
||||
session()->put('auth.two_factor_authenticated_at', now());
|
||||
|
||||
return redirect()
|
||||
->route('profile.security.index')
|
||||
->with('success', __('Your two factor authentication has been activated'));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('profile.security.index')
|
||||
->with('error', __('Please check your confirmation code'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Profile\TwoFactorAuthentication;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RegenerateRecoveryCodesController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): RedirectResponse
|
||||
{
|
||||
$request->user()->generateRecoveryCodes();
|
||||
|
||||
return redirect()
|
||||
->route('profile.security.index')
|
||||
->with('success', __('Your recovery codes have been regenerated'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Profile\TwoFactorAuthentication;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class TwoFactorAuthenticationController extends Controller
|
||||
{
|
||||
public function create(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasTwoFactorEnabled()) {
|
||||
return redirect()->route('profile.security.index')->with('error', __('Your two factor authentication is already enabled'));
|
||||
}
|
||||
|
||||
$request->user()->createTwoFactorAuth();
|
||||
|
||||
return redirect()->route('profile.security.index')->with('success', __('Your two factor authentication has been enabled'));
|
||||
}
|
||||
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
$request->user()->disableTwoFactorAuth();
|
||||
|
||||
return redirect()
|
||||
->route('profile.security.index')
|
||||
->with('success', __('Two factor authentication has been disabled'));
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Jobs\Servers\CreateServer;
|
||||
use App\Jobs\Servers\DeleteServer;
|
||||
use App\Http\Requests\ServerRequest;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Http\Resources\ServerResource;
|
||||
use App\Mail\Server\ServerCreatedEmail;
|
||||
use App\Actions\Server\CreateServerAction;
|
||||
use App\DataTransferObjects\ServerData;
|
||||
use App\Http\Requests\ServerUpdateRequest;
|
||||
use App\Mail\Admin\Server\AdminServerCreatedEmail;
|
||||
use App\Http\Resources\ServerResource;
|
||||
use App\Jobs\Servers\DeleteServer;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
@@ -31,34 +29,23 @@ class ServerController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(ServerRequest $request)
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$provider = $request->user()->package->providers()->findOrFail($request->input('provider'));
|
||||
$region = $provider->regions()->findOrFail($request->input('region'));
|
||||
$plan = $provider->plans()->findOrFail($request->input('plan'));
|
||||
$this->authorize('create', Server::class);
|
||||
|
||||
/* @var $server \App\Models\Server */
|
||||
$server = $request->user()->servers()->create([
|
||||
'name' => $request->input('name'),
|
||||
'database_type' => $request->input('database_type', 'mysql')
|
||||
$data = $request->validate([
|
||||
'name' => ['required'],
|
||||
'provider_id' => ['required'],
|
||||
'provider_region_id' => ['required'],
|
||||
'provider_plan_id' => ['required'],
|
||||
'database_type' => ['required'],
|
||||
]);
|
||||
|
||||
$server->provider()->associate($provider);
|
||||
$server->providerRegion()->associate($region);
|
||||
$server->providerPlan()->associate($plan);
|
||||
$server->save();
|
||||
$data['user_id'] = Auth::id();
|
||||
|
||||
dispatch(new CreateServer($server));
|
||||
|
||||
Mail::to($request->user())->send(new ServerCreatedEmail($request->user(), $server));
|
||||
|
||||
if (setting('receive_email_on_server_creation')) {
|
||||
$admins = User::query()->where('role', User::ADMIN)->get();
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
Mail::to($admin)->send(new AdminServerCreatedEmail($request->user(), $server));
|
||||
}
|
||||
}
|
||||
app(CreateServerAction::class)->execute(
|
||||
ServerData::validate($data)
|
||||
);
|
||||
|
||||
return redirect()->route('servers.index');
|
||||
}
|
||||
|
||||
43
app/Http/Controllers/SiteAliasController.php
Normal file
43
app/Http/Controllers/SiteAliasController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\SiteAliasRequest;
|
||||
use App\Http\Resources\SiteAliasResource;
|
||||
use App\Jobs\Aliases\CreateAlias;
|
||||
use App\Jobs\Aliases\DeleteAlias;
|
||||
|
||||
class SiteAliasController extends Controller
|
||||
{
|
||||
public function index($id)
|
||||
{
|
||||
$site = auth()->user()->sites()->findOrFail($id);
|
||||
|
||||
return inertia('Sites/Aliases', [
|
||||
'site' => $site,
|
||||
'aliases' => $site->aliases
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(SiteAliasRequest $request, $id)
|
||||
{
|
||||
$site = $request->user()->sites()->findOrFail($id);
|
||||
|
||||
$site->addAlias($request->input('domain'));
|
||||
|
||||
dispatch(new CreateAlias($site, $request->input('domain'), $request->boolean('request_new_certificate')));
|
||||
|
||||
return redirect()->route('sites.aliases.index', $id)->with('success', __('Alias has been created'));
|
||||
}
|
||||
|
||||
public function destroy($id, $alias)
|
||||
{
|
||||
$site = auth()->user()->sites()->findOrFail($id);
|
||||
|
||||
dispatch(new DeleteAlias($site, $alias));
|
||||
|
||||
$site->removeAlias($alias);
|
||||
|
||||
return redirect()->route('sites.aliases.index', $id)->with('success', __('Alias has been deleted'));
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,22 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Server;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Jobs\Sites\CreateSite;
|
||||
use App\Jobs\Sites\DeleteSite;
|
||||
use App\Http\Requests\SiteRequest;
|
||||
use App\Http\Resources\SiteResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Http\Requests\SiteRequest;
|
||||
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\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\DataTransferObjects\SiteData;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use App\Actions\Site\CreateSiteAction;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
@@ -17,6 +25,7 @@ class SiteController extends Controller
|
||||
{
|
||||
$sites = auth()->user()
|
||||
->sites()
|
||||
->with('server:id,name')
|
||||
->when(request('server'), function ($query, $value) {
|
||||
return $query->where('server_id', $value);
|
||||
})
|
||||
@@ -27,12 +36,18 @@ class SiteController extends Controller
|
||||
|
||||
return inertia('Sites/Index', [
|
||||
'sites' => SiteResource::collection($sites),
|
||||
'availableServers' => $availableServers
|
||||
'availableServers' => $availableServers,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(SiteRequest $request)
|
||||
public function store(SiteRequest $request): RedirectResponse
|
||||
{
|
||||
if (Site::query()->where('domain', $request->input('domain'))->exists()) {
|
||||
return redirect()->back()->withErrors([
|
||||
'domain' => 'This domain is not available.'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($serverId = $request->input('server_id')) {
|
||||
$server = $request->user()->servers()->findOrFail($serverId);
|
||||
} else {
|
||||
@@ -64,32 +79,31 @@ class SiteController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
$site = $server->sites()->create($request->all());
|
||||
$request->merge(['user_id' => auth()->id()]);
|
||||
|
||||
$request->user()->sites()->save($site);
|
||||
$site = app(CreateSiteAction::class)->execute(
|
||||
SiteData::validate($request)
|
||||
);
|
||||
|
||||
dispatch(new CreateSite($site));
|
||||
|
||||
$request->user()->systemLogs()->create([
|
||||
'title' => 'New site :site created',
|
||||
'description' => 'A new site has been created'
|
||||
])->model()->associate($site)->save();
|
||||
|
||||
return redirect()->route('sites.index')->with('success', __('Your website is being created'));
|
||||
return $site
|
||||
? redirect()->route('sites.index')->with('success', __('Your website is being created'))
|
||||
: redirect()->back()->withErrors([
|
||||
'domain' => __('It seems there is no free server room for this site to take place. Please get in touch with support to resolve this.'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$site = auth()->user()->sites()->findOrFail($id);
|
||||
|
||||
if (!$site->isActive()) {
|
||||
if (! $site->isActive()) {
|
||||
return redirect()->route('sites.index')->with('info', __('This site does not seem to be active, please wait for the process to finish'));
|
||||
}
|
||||
|
||||
return inertia('Sites/Show', [
|
||||
'site' => $site,
|
||||
'system_user' => $site->getSystemUser(false),
|
||||
'ip_address' => $site->server->ip
|
||||
'ip_address' => $site->server->ip,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -111,14 +125,14 @@ class SiteController extends Controller
|
||||
if ($request->user()->requires_password_for_ftp) {
|
||||
$this->validate($request, ['password' => 'required|string']);
|
||||
|
||||
if (!Hash::check($request->input('password'), $request->user()->password)) {
|
||||
if (! Hash::check($request->input('password'), $request->user()->password)) {
|
||||
return response([
|
||||
'message' => 'The given data was invalid',
|
||||
'errors' => [
|
||||
'password' => [
|
||||
trans('auth.failed')
|
||||
]
|
||||
]
|
||||
trans('auth.failed'),
|
||||
],
|
||||
],
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\Databases\CreateDatabase;
|
||||
use App\Jobs\Databases\DeleteDatabase;
|
||||
use App\Http\Requests\SiteDatabaseRequest;
|
||||
use App\Http\Resources\SiteDatabaseResource;
|
||||
use App\Jobs\Databases\CreateDatabase;
|
||||
use App\Jobs\Databases\DeleteDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SiteDatabaseController extends Controller
|
||||
{
|
||||
@@ -24,11 +25,11 @@ class SiteDatabaseController extends Controller
|
||||
$site = auth()->user()->sites()->findOrFail($id);
|
||||
|
||||
$database = $site->databases()->create([
|
||||
'name' => $request->input('name')
|
||||
'name' => Str::of($site->domain)->limit(8)->remove(['.', '-'])->lower()->append('_')->append($request->input('name'))
|
||||
]);
|
||||
|
||||
$database->users()->create([
|
||||
'name' => $request->input('user_name'),
|
||||
'name' => $request->input('user_name', ),
|
||||
]);
|
||||
|
||||
$database->server_id = $site->server_id;
|
||||
|
||||
@@ -65,6 +65,7 @@ class Kernel extends HttpKernel
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.blocked' => \App\Http\Middleware\UserBlocked::class,
|
||||
'auth.2fa' => \App\Http\Middleware\EnforceTwoFactorAuthenticationIfEnabled::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Laragear\TwoFactor\Facades\Auth2FA;
|
||||
|
||||
class EnforceTwoFactorAuthenticationIfEnabled
|
||||
{
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
if (auth()->guest()) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if (! $request->user()->hasTwoFactorEnabled()) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$twoFactorAuthenticatedAt = session()->get('auth.two_factor_authenticated_at');
|
||||
|
||||
if ($twoFactorAuthenticatedAt && Carbon::parse($twoFactorAuthenticatedAt)->gt(now()->subHours(3))) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
return redirect()->route('auth.confirm-2fa.index');
|
||||
}
|
||||
}
|
||||
@@ -8,28 +8,27 @@ use App\Services\Ploi\Exceptions\Http\Unauthenticated;
|
||||
|
||||
class GlobalApiAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
if (!$this->isAuthenticated($request)) {
|
||||
abort_unless($this->hasApiEnabled(), 404);
|
||||
|
||||
abort_unless($this->isAuthenticated($request), 403);
|
||||
|
||||
if (! $this->isAuthenticated($request)) {
|
||||
throw new Unauthenticated('Unauthenticated for global access.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
protected function hasApiEnabled(): bool
|
||||
{
|
||||
return setting('enable_api') && (bool) setting('api_token');
|
||||
}
|
||||
|
||||
protected function isAuthenticated(Request $request)
|
||||
{
|
||||
return
|
||||
setting('enable_api') &&
|
||||
setting('api_token') &&
|
||||
$request->bearerToken() &&
|
||||
$request->bearerToken() === decrypt(setting('api_token'));
|
||||
return $request->bearerToken()
|
||||
&& $request->bearerToken() === decrypt(setting('api_token'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Alert;
|
||||
use Inertia\Middleware;
|
||||
use Illuminate\Support\Arr;
|
||||
use App\Models\UserProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Inertia\Middleware;
|
||||
|
||||
class HandleInertiaRequests extends Middleware
|
||||
{
|
||||
@@ -16,7 +16,7 @@ class HandleInertiaRequests extends Middleware
|
||||
* Determines the current asset version.
|
||||
*
|
||||
* @see https://inertiajs.com/asset-versioning
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
public function version(Request $request)
|
||||
@@ -28,7 +28,7 @@ class HandleInertiaRequests extends Middleware
|
||||
* Defines the props that are shared by default.
|
||||
*
|
||||
* @see https://inertiajs.com/shared-data
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function share(Request $request)
|
||||
@@ -68,13 +68,14 @@ class HandleInertiaRequests extends Middleware
|
||||
] : null,
|
||||
'package' => auth()->user() && auth()->user()->package ? [
|
||||
'name' => auth()->user()->package->name,
|
||||
'maximum_sites' => auth()->user()->package->maximum_sites
|
||||
'maximum_sites' => auth()->user()->package->maximum_sites,
|
||||
'trial' => auth()->user()->onTrial()
|
||||
] : [
|
||||
'name' => __('None')
|
||||
],
|
||||
'can' => $can,
|
||||
'integrations' => [
|
||||
'cloudflare' => (bool)auth()->user() ? auth()->user()->providers()->where('type', UserProvider::TYPE_CLOUDFLARE)->count() : false,
|
||||
'cloudflare' => (bool) auth()->user() ? auth()->user()->providers()->where('type', UserProvider::TYPE_CLOUDFLARE)->count() : false,
|
||||
]
|
||||
];
|
||||
},
|
||||
@@ -124,7 +125,7 @@ class HandleInertiaRequests extends Middleware
|
||||
}
|
||||
|
||||
return [
|
||||
'message' => $alert->message,
|
||||
'message_html' => $alert->messageHtml,
|
||||
'type' => $alert->type
|
||||
];
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ class SettingRequest extends FormRequest
|
||||
'nullable',
|
||||
'image',
|
||||
'max:2000'
|
||||
],
|
||||
|
||||
'trial_package' => [
|
||||
'required_with:trial'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
15
app/Http/Requests/Api/SiteRequest.php
Normal file
15
app/Http/Requests/Api/SiteRequest.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SiteRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'server_id'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UserRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return $this->bearerToken() && $this->bearerToken() === setting('api_token');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255'
|
||||
],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'email',
|
||||
'max:255',
|
||||
'unique:users'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,9 @@ class ServerRequest extends FormRequest
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
return [
|
||||
'name' => [
|
||||
'required',
|
||||
|
||||
28
app/Http/Requests/SiteAliasRequest.php
Normal file
28
app/Http/Requests/SiteAliasRequest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Rules\Hostname;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SiteAliasRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'domain' => [
|
||||
'required',
|
||||
'string',
|
||||
new Hostname,
|
||||
],
|
||||
'request_new_certificate' => [
|
||||
'required',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
21
app/Http/Resources/Admin/ServerResource.php
Normal file
21
app/Http/Resources/Admin/ServerResource.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ServerResource extends JsonResource
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'ip' => $this->ip,
|
||||
'users' => $this->users,
|
||||
'sites_count' => $this->sites_count,
|
||||
'maximum_sites' => $this->maximum_sites,
|
||||
'created_at' => $this->created_at->format('Y-m-d H:i:s')
|
||||
];
|
||||
}
|
||||
}
|
||||
13
app/Http/Resources/Admin/SiteResource.php
Normal file
13
app/Http/Resources/Admin/SiteResource.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SiteResource extends JsonResource
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,7 @@ use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
|
||||
@@ -7,12 +7,6 @@ use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SiteResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
/* @var $this \App\Models\Site */
|
||||
@@ -20,7 +14,11 @@ class SiteResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'status' => $this->parseStatus($this->status),
|
||||
'domain' => $this->domain,
|
||||
'php_version' => $this->php_version,
|
||||
'project' => $this->project,
|
||||
'server' => $this->server ? [
|
||||
'name' => $this->server->name
|
||||
] : null,
|
||||
'created_at' => $this->created_at
|
||||
];
|
||||
}
|
||||
|
||||
69
app/Jobs/Aliases/CreateAlias.php
Normal file
69
app/Jobs/Aliases/CreateAlias.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Aliases;
|
||||
|
||||
use App\Jobs\Certificates\CreateCertificate;
|
||||
use App\Jobs\Certificates\DeleteCertificate;
|
||||
use App\Models\Certificate;
|
||||
use App\Models\Site;
|
||||
use App\Traits\HasPloi;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CreateAlias implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||
|
||||
public function __construct(
|
||||
public Site $site,
|
||||
public string $alias,
|
||||
public bool $requestNewCertificate = false,
|
||||
) {}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->getPloi()
|
||||
->server($this->site->server->ploi_id)
|
||||
->sites($this->site->ploi_id)
|
||||
->aliases()
|
||||
->create([$this->alias]);
|
||||
|
||||
if ($this->requestNewCertificate) {
|
||||
$currentCertificate = $this
|
||||
->site
|
||||
->certificates()
|
||||
->whereIn('status', [Certificate::STATUS_ACTIVE, Certificate::STATUS_BUSY])
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if (! $currentCertificate) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(new DeleteCertificate($this->site->server->ploi_id, $this->site->ploi_id, $currentCertificate->ploi_id));
|
||||
|
||||
$newCertificate = $this->site->certificates()->create([
|
||||
'domain' => $currentCertificate->domain . ',' . $this->alias,
|
||||
'type' => $currentCertificate->type,
|
||||
'certificate' => $currentCertificate->certificate,
|
||||
'private' => $currentCertificate->private
|
||||
]);
|
||||
|
||||
$currentCertificate->delete();
|
||||
|
||||
$newCertificate->server_id = $this->site->server_id;
|
||||
$newCertificate->save();
|
||||
|
||||
dispatch(new CreateCertificate($newCertificate))->delay(now()->addSeconds(5));
|
||||
}
|
||||
}
|
||||
|
||||
public function failed()
|
||||
{
|
||||
$this->site->aliases = array_diff($this->site->aliases, [$this->alias]);
|
||||
$this->site->save();
|
||||
}
|
||||
}
|
||||
35
app/Jobs/Aliases/DeleteAlias.php
Normal file
35
app/Jobs/Aliases/DeleteAlias.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Aliases;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Traits\HasPloi;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class DeleteAlias implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||
|
||||
public Site $site;
|
||||
public string $alias;
|
||||
|
||||
public function __construct(Site $site, $alias)
|
||||
{
|
||||
$this->site = $site;
|
||||
$this->alias = $alias;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->getPloi()
|
||||
->server($this->site->server->ploi_id)
|
||||
->sites($this->site->ploi_id)
|
||||
->aliases()
|
||||
->delete($this->alias);
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,12 @@ namespace App\Jobs\Servers;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Traits\HasPloi;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CreateServer implements ShouldQueue
|
||||
{
|
||||
@@ -40,7 +41,7 @@ class CreateServer implements ShouldQueue
|
||||
dispatch(new FetchServerStatus($this->server))->delay(now()->addMinutes(5));
|
||||
}
|
||||
|
||||
public function failed(\Exception $exception)
|
||||
public function failed(Exception $exception)
|
||||
{
|
||||
$this->server->delete();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Jobs\Sites;
|
||||
|
||||
use Throwable;
|
||||
use App\Models\Site;
|
||||
use App\Traits\HasPloi;
|
||||
use Illuminate\Support\Arr;
|
||||
@@ -15,24 +16,12 @@ class CreateSite implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||
|
||||
public $site;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param Site $site
|
||||
*/
|
||||
public function __construct(Site $site)
|
||||
{
|
||||
$this->site = $site;
|
||||
public function __construct(
|
||||
public Site $site,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
$systemUser = $this->site->getSystemUser();
|
||||
|
||||
@@ -51,8 +40,12 @@ class CreateSite implements ShouldQueue
|
||||
dispatch(new FetchSiteStatus($this->site))->delay(now()->addSeconds(3));
|
||||
}
|
||||
|
||||
public function failed(\Exception $exception)
|
||||
public function failed(Throwable $exception): void
|
||||
{
|
||||
$this->site->delete();
|
||||
|
||||
if (app()->isLocal()) {
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
app/Listeners/ResetTwoFactorAuthenticationSession.php
Normal file
13
app/Listeners/ResetTwoFactorAuthenticationSession.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Auth\Events\Logout;
|
||||
|
||||
class ResetTwoFactorAuthenticationSession
|
||||
{
|
||||
public function handle(Logout $event): void
|
||||
{
|
||||
session()->put('auth.two_factor_authenticated_at', null);
|
||||
}
|
||||
}
|
||||
@@ -13,26 +13,15 @@ class AdminServerCreatedEmail extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $user;
|
||||
public $server;
|
||||
public User $user;
|
||||
public Server $server;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param User $user
|
||||
* @param Server $server
|
||||
*/
|
||||
public function __construct(User $user, Server $server)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this
|
||||
|
||||
34
app/Mail/Admin/Site/AdminSiteCreatedEmail.php
Normal file
34
app/Mail/Admin/Site/AdminSiteCreatedEmail.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail\Admin\Site;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class AdminSiteCreatedEmail extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public User $user;
|
||||
public Server $server;
|
||||
public Site $site;
|
||||
|
||||
public function __construct(User $user, Server $server, Site $site)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->server = $server;
|
||||
$this->site = $site;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
return $this
|
||||
->subject(__('A user has created a new site'))
|
||||
->markdown('emails.admin.site.new-site');
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,15 @@
|
||||
namespace App\Models;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Alert extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
const TYPE_INFO = 'info';
|
||||
const TYPE_WARNING = 'warning';
|
||||
const TYPE_DANGER = 'danger';
|
||||
@@ -21,8 +26,23 @@ class Alert extends Model
|
||||
'expires_at'
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'message_html'
|
||||
];
|
||||
|
||||
protected function serializeDate(DateTimeInterface $date)
|
||||
{
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
public function messageHtml(): Attribute
|
||||
{
|
||||
return Attribute::get(function ($value, array $attributes) {
|
||||
return Str::of($attributes['message'])
|
||||
->markdown()
|
||||
->trim(PHP_EOL)
|
||||
->replace(PHP_EOL, '<br />')
|
||||
->value();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,13 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\PermissionCast;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Package extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
const CURRENCY_EURO = 'eur';
|
||||
const CURRENCY_USD = 'usd';
|
||||
const CURRENCY_NOK = 'nok';
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Provider extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProviderPlan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
}
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProviderRegion extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
}
|
||||
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
|
||||
class Server extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
const STATUS_BUSY = 'busy';
|
||||
const STATUS_ACTIVE = 'active';
|
||||
|
||||
@@ -32,11 +36,17 @@ class Server extends Model
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->morphToMany(User::class, 'service', 'user_service')
|
||||
return $this
|
||||
->morphToMany(User::class, 'service', 'user_service')
|
||||
->using(UserService::class)
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function user(): HasOneThrough
|
||||
{
|
||||
return $this->hasOneThrough(User::class, UserService::class, 'service_id', 'id', 'id', 'user_id');
|
||||
}
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->morphMany(SystemLog::class, 'model');
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\SiteAlias;
|
||||
use DateTimeInterface;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property mixed|string domain
|
||||
*/
|
||||
class Site extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
const STATUS_BUSY = 'busy';
|
||||
const STATUS_ACTIVE = 'active';
|
||||
|
||||
@@ -21,7 +24,12 @@ class Site extends Model
|
||||
'ploi_id',
|
||||
'domain',
|
||||
'dns_id',
|
||||
'project'
|
||||
'project',
|
||||
'aliases'
|
||||
];
|
||||
|
||||
public $casts = [
|
||||
'aliases' => SiteAlias::class,
|
||||
];
|
||||
|
||||
public function setDnsIdAttribute($value)
|
||||
@@ -65,6 +73,11 @@ class Site extends Model
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function user(): HasOneThrough
|
||||
{
|
||||
return $this->hasOneThrough(User::class, UserService::class, 'service_id', 'id', 'id', 'user_id');
|
||||
}
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->morphMany(SystemLog::class, 'model');
|
||||
@@ -98,6 +111,22 @@ class Site extends Model
|
||||
] + ($withPassword ? ['ftp_password' => $user->ftp_password] : []);
|
||||
}
|
||||
|
||||
public function addAlias($alias)
|
||||
{
|
||||
$aliases = $this->aliases;
|
||||
|
||||
$aliases[] = $alias;
|
||||
|
||||
$this->aliases = $aliases;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function removeAlias($alias)
|
||||
{
|
||||
$this->aliases = array_diff($this->aliases, [$alias]);
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public static function booted()
|
||||
{
|
||||
static::creating(function (self $site) {
|
||||
@@ -105,7 +134,9 @@ class Site extends Model
|
||||
});
|
||||
|
||||
static::created(function (self $site) {
|
||||
$site->systemUsers()->create();
|
||||
$site->systemUsers()->create([
|
||||
'user_name' => Str::of($site->domain)->remove(['.', '-'])->limit(8, '')->lower()
|
||||
]);
|
||||
});
|
||||
|
||||
static::deleting(function (self $site) {
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\Encrypted;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SiteSystemUser extends Model
|
||||
{
|
||||
@@ -17,21 +19,21 @@ class SiteSystemUser extends Model
|
||||
'ftp_password' => Encrypted::class,
|
||||
];
|
||||
|
||||
public function site()
|
||||
public function site(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Site::class, 'site_system_user_attached');
|
||||
}
|
||||
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $siteSystemUser) {
|
||||
$siteSystemUser->user_name = strtolower(Str::random(10));
|
||||
$siteSystemUser->ftp_password = Str::random();
|
||||
$siteSystemUser->user_name ??= strtolower(Str::random(10));
|
||||
$siteSystemUser->ftp_password ??= Str::random();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,21 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\Encrypted;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Cashier\Billable;
|
||||
use App\Mail\User\WelcomeEmail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Contracts\Translation\HasLocalePreference;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
use Laragear\TwoFactor\Contracts\TwoFactorAuthenticatable;
|
||||
use Laragear\TwoFactor\TwoFactorAuthentication;
|
||||
use Laravel\Cashier\Billable;
|
||||
|
||||
class User extends Authenticatable implements HasLocalePreference
|
||||
class User extends Authenticatable implements HasLocalePreference, TwoFactorAuthenticatable
|
||||
{
|
||||
use Billable, Notifiable;
|
||||
use Billable, HasFactory, Notifiable, TwoFactorAuthentication;
|
||||
|
||||
const ADMIN = 'admin';
|
||||
const RESELLER = 'reseller';
|
||||
@@ -34,7 +37,8 @@ class User extends Authenticatable implements HasLocalePreference
|
||||
'blocked',
|
||||
'theme',
|
||||
'keyboard_shortcuts',
|
||||
'requires_password_for_ftp'
|
||||
'requires_password_for_ftp',
|
||||
'package_id'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -47,7 +51,8 @@ class User extends Authenticatable implements HasLocalePreference
|
||||
'email_verified_at' => 'datetime',
|
||||
'ftp_password' => Encrypted::class,
|
||||
'keyboard_shortcuts' => 'boolean',
|
||||
'requires_password_for_ftp' => 'boolean'
|
||||
'requires_password_for_ftp' => 'boolean',
|
||||
'trial_ends_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
@@ -95,13 +100,15 @@ class User extends Authenticatable implements HasLocalePreference
|
||||
|
||||
public function servers()
|
||||
{
|
||||
return $this->morphedByMany(Server::class, 'service', 'user_service')
|
||||
return $this
|
||||
->morphedByMany(Server::class, 'service', 'user_service')
|
||||
->using(UserService::class)->withTimestamps();
|
||||
}
|
||||
|
||||
public function sites()
|
||||
{
|
||||
return $this->morphedByMany(Site::class, 'service', 'user_service')
|
||||
return $this
|
||||
->morphedByMany(Site::class, 'service', 'user_service')
|
||||
->using(UserService::class)->withTimestamps();
|
||||
}
|
||||
|
||||
@@ -125,7 +132,7 @@ class User extends Authenticatable implements HasLocalePreference
|
||||
return $this->hasMany(UserProvider::class);
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $user) {
|
||||
$user->user_name = strtolower(Str::random(10));
|
||||
@@ -134,10 +141,18 @@ class User extends Authenticatable implements HasLocalePreference
|
||||
if (!$user->language) {
|
||||
$user->language = setting('default_language', 'en');
|
||||
}
|
||||
|
||||
if ($days = setting('trial')) {
|
||||
$user->trial_ends_at = now()->addDays($days);
|
||||
}
|
||||
});
|
||||
|
||||
static::created(function (self $user) {
|
||||
Mail::to($user)->send(new WelcomeEmail($user));
|
||||
// Usually I don't like using such conditions. However, otherwise when using Mail::fake(),
|
||||
// this would fake all emails going out leading to possible unexpected results as well.
|
||||
if (! app()->runningUnitTests()) {
|
||||
Mail::to($user)->send(new WelcomeEmail($user));
|
||||
}
|
||||
});
|
||||
|
||||
static::deleting(function (self $user) {
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class SitePolicy
|
||||
{
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Exception;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -13,10 +15,21 @@ class AppServiceProvider extends ServiceProvider
|
||||
return $app['cache']->remember('core.settings', now()->addDay(), function () {
|
||||
try {
|
||||
return Setting::pluck('value', 'key')->toArray();
|
||||
} catch (\Exception $exception) {
|
||||
} catch (Exception $exception) {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
Password::defaults(function () {
|
||||
$rule = Password::min(6);
|
||||
|
||||
return $this->app->isProduction()
|
||||
? $rule->letters()->numbers()->uncompromised()
|
||||
: $rule;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Listeners\ResetTwoFactorAuthenticationSession;
|
||||
use Illuminate\Auth\Events\Logout;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
@@ -18,6 +20,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
Logout::class => [
|
||||
ResetTwoFactorAuthenticationSession::class,
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -31,17 +31,19 @@ class RouteServiceProvider extends ServiceProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
public function boot(): void
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
$this->routes(function () {
|
||||
if (setting('enable_api')) {
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->namespace . '\Api')
|
||||
->group(base_path('routes/api.php'));
|
||||
}
|
||||
// The settings('enable_api') is now handled by the GlobalApiAuthenticated middleware,
|
||||
// because the conditional inside this service makes testing very hard. This doesn't
|
||||
// matter for existing users, because now the middleware will return 404 responses.
|
||||
Route::prefix('api')
|
||||
->middleware(['api', 'global.api.authenticated'])
|
||||
->namespace($this->namespace . '\Api')
|
||||
->as('api.')
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
@@ -60,7 +62,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureRateLimiting()
|
||||
protected function configureRateLimiting(): void
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60);
|
||||
|
||||
@@ -2,16 +2,34 @@
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Validation\DataAwareRule;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class ValidateMaximumSites implements Rule
|
||||
class ValidateMaximumSites implements Rule, DataAwareRule
|
||||
{
|
||||
protected array $data;
|
||||
|
||||
public function setData($data): static
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getUser(): User
|
||||
{
|
||||
return $this->data['user_id'] ?? null
|
||||
? User::find($this->data['user_id'])
|
||||
: auth()->user();
|
||||
}
|
||||
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$package = auth()->user()->package;
|
||||
$package = $this->getUser()->package;
|
||||
|
||||
// If the user does not have a package, it can continue
|
||||
if (!$package) {
|
||||
if (! $package) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,7 +38,7 @@ class ValidateMaximumSites implements Rule
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($package->maximum_sites <= auth()->user()->sites()->count()) {
|
||||
if ($package->maximum_sites <= $this->getUser()->sites()->count()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,41 +2,46 @@
|
||||
|
||||
namespace App\Services\Ploi\Http;
|
||||
|
||||
use Illuminate\Http\Client\Response as ClientResponse;
|
||||
use stdClass;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class Response
|
||||
{
|
||||
private $json;
|
||||
private $response;
|
||||
protected ?stdClass $json;
|
||||
|
||||
public function __construct(ResponseInterface $response)
|
||||
protected ClientResponse $response;
|
||||
|
||||
public function __construct(ClientResponse $response)
|
||||
{
|
||||
$this->setResponse($response);
|
||||
$this->decodeJson();
|
||||
}
|
||||
|
||||
private function setResponse(ResponseInterface $response): self
|
||||
private function setResponse(ClientResponse $response): self
|
||||
{
|
||||
$this->response = $response;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResponse(): ResponseInterface
|
||||
public function getResponse(): ClientResponse
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
private function decodeJson(): self
|
||||
{
|
||||
$json = json_decode($this->getResponse()->getBody());
|
||||
$json = $this->getResponse()->json();
|
||||
|
||||
return $this->setJson($json);
|
||||
}
|
||||
|
||||
public function setJson(stdClass $json = null): self
|
||||
public function setJson(stdClass|array $json = null): self
|
||||
{
|
||||
if (is_array($json)) {
|
||||
$json = json_decode(json_encode($json));
|
||||
}
|
||||
|
||||
$this->json = $json;
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
namespace App\Services\Ploi;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use App\Services\Ploi\Http\Response;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Services\Ploi\Resources\User;
|
||||
use App\Services\Ploi\Resources\Server;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use App\Services\Ploi\Resources\Synchronize;
|
||||
use App\Services\Ploi\Exceptions\Http\NotFound;
|
||||
use App\Services\Ploi\Exceptions\Http\NotValid;
|
||||
@@ -19,19 +20,22 @@ use App\Services\Ploi\Exceptions\Http\PerformingMaintenance;
|
||||
class Ploi
|
||||
{
|
||||
public $url;
|
||||
private $guzzle;
|
||||
|
||||
private $apiToken;
|
||||
|
||||
private $apiCoreToken;
|
||||
|
||||
protected PendingRequest $client;
|
||||
|
||||
public function __construct(string $token = null, string $coreApiToken = null)
|
||||
{
|
||||
$this->url = config('services.ploi-api.url');
|
||||
|
||||
if (!$token) {
|
||||
if (! $token) {
|
||||
$token = config('services.ploi.token');
|
||||
}
|
||||
|
||||
if (!$coreApiToken) {
|
||||
if (! $coreApiToken) {
|
||||
$coreApiToken = config('services.ploi.core-token');
|
||||
}
|
||||
|
||||
@@ -57,18 +61,13 @@ class Ploi
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function buildClient()
|
||||
public function buildClient(): static
|
||||
{
|
||||
// Generate a new Guzzle client
|
||||
$this->guzzle = new Client([
|
||||
'base_uri' => $this->url,
|
||||
'http_errors' => false,
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $this->getApiToken(),
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Ploi-Core-Key' => $this->getCoreApiToken()
|
||||
],
|
||||
$this->client = Http::baseUrl($this->url)->withHeaders([
|
||||
'Authorization' => 'Bearer ' . $this->getApiToken(),
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Ploi-Core-Key' => $this->getCoreApiToken(),
|
||||
]);
|
||||
|
||||
return $this;
|
||||
@@ -86,10 +85,18 @@ class Ploi
|
||||
|
||||
public function makeAPICall(string $url, string $method = 'get', array $options = []): Response
|
||||
{
|
||||
if (!in_array($method, ['get', 'post', 'patch', 'delete'])) {
|
||||
if (! in_array($method, ['get', 'post', 'patch', 'delete'])) {
|
||||
throw new Exception('Invalid method type');
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a temporary method that was necessary for the switch from the Guzzle client to the Http facade.
|
||||
* We _should not_ need this, but it feels safer to keep this fallback code around for now.
|
||||
*/
|
||||
if (count($options) === 1 && array_key_exists('body', $options)) {
|
||||
$options = is_string($options['body']) ? json_decode($options['body']) : $options['body'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Because we're calling the method dynamically PHPStorm doesn't
|
||||
* know that we're getting a response back, so we manually
|
||||
@@ -97,7 +104,7 @@ class Ploi
|
||||
*
|
||||
* @var ResponseInterface $response
|
||||
*/
|
||||
$response = $this->guzzle->{$method}($url, $options);
|
||||
$response = $this->client->{$method}($url, $options);
|
||||
|
||||
switch ($response->getStatusCode()) {
|
||||
case 401:
|
||||
|
||||
42
app/Services/Ploi/Resources/Alias.php
Normal file
42
app/Services/Ploi/Resources/Alias.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Ploi\Resources;
|
||||
|
||||
class Alias extends Resource
|
||||
{
|
||||
public function __construct(Server $server, Site $site)
|
||||
{
|
||||
parent::__construct($server->getPloi());
|
||||
|
||||
$this->setServer($server);
|
||||
$this->setSite($site);
|
||||
|
||||
$this->buildEndpoint();
|
||||
}
|
||||
|
||||
public function buildEndpoint(): self
|
||||
{
|
||||
$this->setEndpoint($this->getSite()->getEndpoint() . '/aliases');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
return $this->getPloi()->makeAPICall($this->getEndpoint());
|
||||
}
|
||||
|
||||
public function create(array $aliases)
|
||||
{
|
||||
$options = [
|
||||
'aliases' => $aliases,
|
||||
];
|
||||
|
||||
return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options);
|
||||
}
|
||||
|
||||
public function delete(string $alias)
|
||||
{
|
||||
return $this->getPloi()->makeAPICall($this->getEndpoint() . '/' . $alias, 'delete');
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use App\Services\Ploi\Exceptions\Http\NotValid;
|
||||
class App extends Resource
|
||||
{
|
||||
private $server;
|
||||
|
||||
private $site;
|
||||
|
||||
public function __construct(Server $server, Site $site, int $id = null)
|
||||
@@ -51,9 +52,7 @@ class App extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'create_database' => Arr::get($options, 'create_database', false)
|
||||
]),
|
||||
'create_database' => Arr::get($options, 'create_database', false),
|
||||
];
|
||||
|
||||
try {
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Services\Ploi\Exceptions\Http\NotValid;
|
||||
class Certificate extends Resource
|
||||
{
|
||||
private $server;
|
||||
|
||||
private $site;
|
||||
|
||||
public function __construct(Server $server, Site $site, int $id = null)
|
||||
@@ -50,11 +51,9 @@ class Certificate extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'type' => $type,
|
||||
'certificate' => $certificate,
|
||||
'private' => $private,
|
||||
]),
|
||||
'type' => $type,
|
||||
'certificate' => $certificate,
|
||||
'private' => $private,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -48,11 +48,9 @@ class Cronjob extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'command' => $command,
|
||||
'frequency' => $frequency,
|
||||
'user' => $user,
|
||||
]),
|
||||
'command' => $command,
|
||||
'frequency' => $frequency,
|
||||
'user' => $user,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -48,11 +48,9 @@ class Daemon extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'command' => $command,
|
||||
'system_user' => $systemUser,
|
||||
'processes' => $processes
|
||||
]),
|
||||
'command' => $command,
|
||||
'system_user' => $systemUser,
|
||||
'processes' => $processes,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -48,11 +48,9 @@ class Database extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'name' => $name,
|
||||
'user' => $user,
|
||||
'password' => $password,
|
||||
]),
|
||||
'name' => $name,
|
||||
'user' => $user,
|
||||
'password' => $password,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -54,9 +54,7 @@ class Deployment extends Resource
|
||||
}
|
||||
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'deploy_script' => $script
|
||||
]),
|
||||
'deploy_script' => $script,
|
||||
];
|
||||
|
||||
$this->setEndpoint($this->getEndpoint() . '/deploy/script');
|
||||
|
||||
@@ -48,12 +48,10 @@ class NetworkRule extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'name' => $name,
|
||||
'port' => $port,
|
||||
'type' => $type,
|
||||
'from_ip_address' => $fromIpAddress,
|
||||
]),
|
||||
'name' => $name,
|
||||
'port' => $port,
|
||||
'type' => $type,
|
||||
'from_ip_address' => $fromIpAddress,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -56,14 +56,12 @@ class Queue extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'connection' => $connection,
|
||||
'queue' => $queue,
|
||||
'maximum_seconds' => $maximumSeconds,
|
||||
'sleep' => $sleep,
|
||||
'processes' => $processes,
|
||||
'maximum_tries' => $maximumTries
|
||||
]),
|
||||
'connection' => $connection,
|
||||
'queue' => $queue,
|
||||
'maximum_seconds' => $maximumSeconds,
|
||||
'sleep' => $sleep,
|
||||
'processes' => $processes,
|
||||
'maximum_tries' => $maximumTries
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Services\Ploi\Exceptions\Http\NotValid;
|
||||
class Redirect extends Resource
|
||||
{
|
||||
private $server;
|
||||
|
||||
private $site;
|
||||
|
||||
public function __construct(Server $server, Site $site, int $id = null)
|
||||
@@ -50,11 +51,9 @@ class Redirect extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'redirect_from' => $redirectFrom,
|
||||
'redirect_to' => $redirectTo,
|
||||
'type' => $type,
|
||||
]),
|
||||
'redirect_from' => $redirectFrom,
|
||||
'redirect_to' => $redirectTo,
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -50,7 +50,7 @@ class Server extends Resource
|
||||
$this->setId($id);
|
||||
}
|
||||
|
||||
if (!$this->getId()) {
|
||||
if (! $this->getId()) {
|
||||
throw new RequiresId('No server ID set');
|
||||
}
|
||||
|
||||
@@ -75,16 +75,14 @@ class Server extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'name' => $name,
|
||||
'plan' => $plan,
|
||||
'region' => $region,
|
||||
'credential' => $provider,
|
||||
'type' => $type,
|
||||
'database_type' => $databaseType,
|
||||
'webserver_type' => $webserverType,
|
||||
'php_version' => $phpVersion
|
||||
]),
|
||||
'name' => $name,
|
||||
'plan' => $plan,
|
||||
'region' => $region,
|
||||
'credential' => $provider,
|
||||
'type' => $type,
|
||||
'database_type' => $databaseType,
|
||||
'webserver_type' => $webserverType,
|
||||
'php_version' => $phpVersion,
|
||||
];
|
||||
|
||||
// Make the request
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Services\Ploi\Resources;
|
||||
|
||||
use stdClass;
|
||||
use Exception;
|
||||
use App\Services\Ploi\Exceptions\Http\NotValid;
|
||||
use Services\Ploi\Exceptions\Resource\RequiresId;
|
||||
use Services\Ploi\Exceptions\Resource\Server\Site\DomainAlreadyExists;
|
||||
@@ -74,13 +75,11 @@ class Site extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'root_domain' => $domain,
|
||||
'web_directory' => $webDirectory,
|
||||
'project_root' => $projectRoot,
|
||||
'system_user' => $systemUser,
|
||||
'system_user_password' => $systemUserPassword
|
||||
]),
|
||||
'root_domain' => $domain,
|
||||
'web_directory' => $webDirectory,
|
||||
'project_root' => $projectRoot,
|
||||
'system_user' => $systemUser,
|
||||
'system_user_password' => $systemUserPassword,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
@@ -92,23 +91,23 @@ class Site extends Resource
|
||||
} catch (NotValid $exception) {
|
||||
$errors = json_decode($exception->getMessage())->errors;
|
||||
|
||||
if (!empty($errors->root_domain)
|
||||
if (! empty($errors->root_domain)
|
||||
&& $errors->root_domain[0] === 'The root domain has already been taken.') {
|
||||
throw new DomainAlreadyExists($domain . ' already exists!');
|
||||
}
|
||||
|
||||
throw $exception;
|
||||
} catch (\Exception $exception) {
|
||||
} catch (Exception $exception) {
|
||||
info($exception->getMessage());
|
||||
}
|
||||
|
||||
// TODO: Debugging purposes
|
||||
if (!$response->getJson() || !isset($response->getJson()->data)) {
|
||||
throw new \Exception($response->getJson()->error ?? 'Unknown error has occured');
|
||||
if (! $response->getJson() || ! isset($response->getJson()->data)) {
|
||||
throw new Exception($response->getJson()->error ?? 'Unknown error has occured');
|
||||
}
|
||||
|
||||
// Set the id of the site
|
||||
$this->setId($response->getJson()->data->id);
|
||||
$this->setId($response->getData()->id);
|
||||
|
||||
// Return the data
|
||||
return $response->getJson();
|
||||
@@ -133,7 +132,7 @@ class Site extends Resource
|
||||
$this->setId($id);
|
||||
}
|
||||
|
||||
if (!$this->getId()) {
|
||||
if (! $this->getId()) {
|
||||
throw new RequiresId('No Site ID set');
|
||||
}
|
||||
|
||||
@@ -142,7 +141,7 @@ class Site extends Resource
|
||||
$response = $this->getPloi()->makeAPICall($this->getEndpoint());
|
||||
|
||||
// Wrap the logs if they're not already wrapped
|
||||
if (!is_array($response->getJson()->data)) {
|
||||
if (! is_array($response->getJson()->data)) {
|
||||
return [$response->getJson()->data];
|
||||
}
|
||||
|
||||
@@ -153,9 +152,7 @@ class Site extends Resource
|
||||
{
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'php_version' => $version,
|
||||
]),
|
||||
'php_version' => $version,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
@@ -204,4 +201,9 @@ class Site extends Resource
|
||||
{
|
||||
return new App($this->getServer(), $this, $id);
|
||||
}
|
||||
|
||||
public function aliases($id = null): Alias
|
||||
{
|
||||
return new Alias($this->getServer(), $this, $id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +48,8 @@ class SystemUser extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'name' => $name,
|
||||
'sudo' => $sudo
|
||||
]),
|
||||
'name' => $name,
|
||||
'sudo' => $sudo,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Exception;
|
||||
|
||||
class VersionChecker
|
||||
{
|
||||
public $remoteVersion;
|
||||
@@ -35,12 +37,13 @@ class VersionChecker
|
||||
return $this->currentVersion < $this->remoteVersion || $this->currentVersion != $this->remoteVersion;
|
||||
}
|
||||
|
||||
public function flushVersionData()
|
||||
public function flushVersionData(): void
|
||||
{
|
||||
try {
|
||||
cache()->forget('ploi-core-current-version');
|
||||
cache()->forget('ploi-core-remote-version');
|
||||
} catch (\Exception $exception) {
|
||||
} catch (Exception $exception) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,16 +11,20 @@
|
||||
"require": {
|
||||
"php": "^8.0.2",
|
||||
"ext-json": "*",
|
||||
"aws/aws-sdk-php": "^3.224",
|
||||
"cloudflare/sdk": "^1.3",
|
||||
"guzzlehttp/guzzle": "^7.4.1",
|
||||
"inertiajs/inertia-laravel": "^0.5.4",
|
||||
"laragear/two-factor": "^1.1",
|
||||
"laravel/cashier": "^12.16",
|
||||
"laravel/framework": "^9.0.2",
|
||||
"laravel/horizon": "^5.8",
|
||||
"laravel/octane": "^1.2",
|
||||
"laravel/tinker": "^2.0",
|
||||
"laravel/ui": "^2.1|^3.3.0",
|
||||
"pragmarx/google2fa-laravel": "^1.3",
|
||||
"predis/predis": "^1.1",
|
||||
"spatie/laravel-data": "^1.5.1",
|
||||
"spiral/roadrunner": "^2.8.2",
|
||||
"symfony/http-client": "^6.0",
|
||||
"symfony/mailgun-mailer": "^6.0",
|
||||
"symfony/postmark-mailer": "^6.0",
|
||||
@@ -28,18 +32,25 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-debugbar": "^3.3",
|
||||
"spatie/laravel-ignition": "^1.0",
|
||||
"doctrine/dbal": "^3.3",
|
||||
"friendsofphp/php-cs-fixer": "^3.1.0",
|
||||
"fzaninotto/faker": "^1.9.1",
|
||||
"laravel/dusk": "^6.15",
|
||||
"mockery/mockery": "^1.3.1",
|
||||
"nunomaduro/collision": "^6.1",
|
||||
"phpunit/phpunit": "^9.5.4"
|
||||
"pestphp/pest": "^1.21",
|
||||
"pestphp/pest-plugin-laravel": "^1.2",
|
||||
"phpunit/phpunit": "^9.5.4",
|
||||
"spatie/laravel-ignition": "^1.0",
|
||||
"spatie/laravel-ray": "^1.29"
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
|
||||
3836
composer.lock
generated
3836
composer.lock
generated
File diff suppressed because it is too large
Load Diff
44
config/data.php
Normal file
44
config/data.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use App\DataTransferObjects\Support\Casts\CarbonCast;
|
||||
use App\DataTransferObjects\Support\Transformers\CarbonTransformer;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Spatie\LaravelData\Transformers\ArrayableTransformer;
|
||||
|
||||
return [
|
||||
/*
|
||||
* The package will use this date format when working with dates through the app
|
||||
*/
|
||||
'date_format' => DATE_ATOM,
|
||||
|
||||
/*
|
||||
* Global transformers will take complex types and transform them into simple
|
||||
* types.
|
||||
*/
|
||||
'transformers' => [
|
||||
DateTimeInterface::class => CarbonTransformer::class,
|
||||
Arrayable::class => ArrayableTransformer::class,
|
||||
// BackedEnum::class => Spatie\LaravelData\Transformers\EnumTransformer::class,
|
||||
],
|
||||
|
||||
/*
|
||||
* Global casts will cast values into complex types when creating a data
|
||||
* object from simple types.
|
||||
*/
|
||||
'casts' => [
|
||||
DateTimeInterface::class => CarbonCast::class,
|
||||
// BackedEnum::class => Spatie\LaravelData\Casts\EnumCast::class,
|
||||
],
|
||||
|
||||
/*
|
||||
* Rule inferrers can be configured here. They will automatically add
|
||||
* validation rules to properties of a data object based upon
|
||||
* the type of the property.
|
||||
*/
|
||||
'rule_inferrers' => [
|
||||
Spatie\LaravelData\RuleInferrers\BuiltInTypesRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\AttributesRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\NullableRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\RequiredRuleInferrer::class,
|
||||
],
|
||||
];
|
||||
221
config/octane.php
Normal file
221
config/octane.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
use Laravel\Octane\Contracts\OperationTerminated;
|
||||
use Laravel\Octane\Events\RequestHandled;
|
||||
use Laravel\Octane\Events\RequestReceived;
|
||||
use Laravel\Octane\Events\RequestTerminated;
|
||||
use Laravel\Octane\Events\TaskReceived;
|
||||
use Laravel\Octane\Events\TaskTerminated;
|
||||
use Laravel\Octane\Events\TickReceived;
|
||||
use Laravel\Octane\Events\TickTerminated;
|
||||
use Laravel\Octane\Events\WorkerErrorOccurred;
|
||||
use Laravel\Octane\Events\WorkerStarting;
|
||||
use Laravel\Octane\Events\WorkerStopping;
|
||||
use Laravel\Octane\Listeners\CollectGarbage;
|
||||
use Laravel\Octane\Listeners\DisconnectFromDatabases;
|
||||
use Laravel\Octane\Listeners\EnsureUploadedFilesAreValid;
|
||||
use Laravel\Octane\Listeners\EnsureUploadedFilesCanBeMoved;
|
||||
use Laravel\Octane\Listeners\FlushTemporaryContainerInstances;
|
||||
use Laravel\Octane\Listeners\FlushUploadedFiles;
|
||||
use Laravel\Octane\Listeners\ReportException;
|
||||
use Laravel\Octane\Listeners\StopWorkerIfNecessary;
|
||||
use Laravel\Octane\Octane;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Octane Server
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the default "server" that will be used by Octane
|
||||
| when starting, restarting, or stopping your server via the CLI. You
|
||||
| are free to change this to the supported server of your choosing.
|
||||
|
|
||||
| Supported: "roadrunner", "swoole"
|
||||
|
|
||||
*/
|
||||
|
||||
'server' => env('OCTANE_SERVER', 'roadrunner'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Force HTTPS
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When this configuration value is set to "true", Octane will inform the
|
||||
| framework that all absolute links must be generated using the HTTPS
|
||||
| protocol. Otherwise your links may be generated using plain HTTP.
|
||||
|
|
||||
*/
|
||||
|
||||
'https' => env('OCTANE_HTTPS', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Octane Listeners
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| All of the event listeners for Octane's events are defined below. These
|
||||
| listeners are responsible for resetting your application's state for
|
||||
| the next request. You may even add your own listeners to the list.
|
||||
|
|
||||
*/
|
||||
|
||||
'listeners' => [
|
||||
WorkerStarting::class => [
|
||||
EnsureUploadedFilesAreValid::class,
|
||||
EnsureUploadedFilesCanBeMoved::class,
|
||||
],
|
||||
|
||||
RequestReceived::class => [
|
||||
...Octane::prepareApplicationForNextOperation(),
|
||||
...Octane::prepareApplicationForNextRequest(),
|
||||
//
|
||||
],
|
||||
|
||||
RequestHandled::class => [
|
||||
//
|
||||
],
|
||||
|
||||
RequestTerminated::class => [
|
||||
// FlushUploadedFiles::class,
|
||||
],
|
||||
|
||||
TaskReceived::class => [
|
||||
...Octane::prepareApplicationForNextOperation(),
|
||||
//
|
||||
],
|
||||
|
||||
TaskTerminated::class => [
|
||||
//
|
||||
],
|
||||
|
||||
TickReceived::class => [
|
||||
...Octane::prepareApplicationForNextOperation(),
|
||||
//
|
||||
],
|
||||
|
||||
TickTerminated::class => [
|
||||
//
|
||||
],
|
||||
|
||||
OperationTerminated::class => [
|
||||
FlushTemporaryContainerInstances::class,
|
||||
// DisconnectFromDatabases::class,
|
||||
// CollectGarbage::class,
|
||||
],
|
||||
|
||||
WorkerErrorOccurred::class => [
|
||||
ReportException::class,
|
||||
StopWorkerIfNecessary::class,
|
||||
],
|
||||
|
||||
WorkerStopping::class => [
|
||||
//
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Warm / Flush Bindings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The bindings listed below will either be pre-warmed when a worker boots
|
||||
| or they will be flushed before every new request. Flushing a binding
|
||||
| will force the container to resolve that binding again when asked.
|
||||
|
|
||||
*/
|
||||
|
||||
'warm' => [
|
||||
...Octane::defaultServicesToWarm(),
|
||||
],
|
||||
|
||||
'flush' => [
|
||||
//
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Octane Cache Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While using Swoole, you may leverage the Octane cache, which is powered
|
||||
| by a Swoole table. You may set the maximum number of rows as well as
|
||||
| the number of bytes per row using the configuration options below.
|
||||
|
|
||||
*/
|
||||
|
||||
'cache' => [
|
||||
'rows' => 1000,
|
||||
'bytes' => 10000,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Octane Swoole Tables
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While using Swoole, you may define additional tables as required by the
|
||||
| application. These tables can be used to store data that needs to be
|
||||
| quickly accessed by other workers on the particular Swoole server.
|
||||
|
|
||||
*/
|
||||
|
||||
'tables' => [
|
||||
'example:1000' => [
|
||||
'name' => 'string:1000',
|
||||
'votes' => 'int',
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| File Watching
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following list of files and directories will be watched when using
|
||||
| the --watch option offered by Octane. If any of the directories and
|
||||
| files are changed, Octane will automatically reload your workers.
|
||||
|
|
||||
*/
|
||||
|
||||
'watch' => [
|
||||
'app',
|
||||
'bootstrap',
|
||||
'config',
|
||||
'database',
|
||||
'public/**/*.php',
|
||||
'resources/**/*.php',
|
||||
'routes',
|
||||
'composer.lock',
|
||||
'.env',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Garbage Collection Threshold
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When executing long-lived PHP scripts such as Octane, memory can build
|
||||
| up before being cleared by PHP. You can force Octane to run garbage
|
||||
| collection if your application consumes this amount of megabytes.
|
||||
|
|
||||
*/
|
||||
|
||||
'garbage' => 50,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Maximum Execution Time
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following setting configures the maximum execution time for requests
|
||||
| being handled by Octane. You may set this value to 0 to indicate that
|
||||
| there isn't a specific time limit on Octane request execution time.
|
||||
|
|
||||
*/
|
||||
|
||||
'max_execution_time' => 30,
|
||||
|
||||
];
|
||||
151
config/two-factor.php
Normal file
151
config/two-factor.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| TwoFactorAuthentication Model
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "TwoFactorAuthentication" trait from this package, we need
|
||||
| to know which Eloquent model should be used to retrieve your two factor
|
||||
| authentication records. You can use your own for more advanced logic.
|
||||
|
|
||||
*/
|
||||
|
||||
'model' => \Laragear\TwoFactor\Models\TwoFactorAuthentication::class,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Codes can only be used one time, so we will hold them in the cache for
|
||||
| the period it shouldn't be used again. You can customize the default
|
||||
| cache store to use. Using "null" will use the default cache store.
|
||||
|
|
||||
*/
|
||||
|
||||
'cache' => [
|
||||
'store' => null,
|
||||
'prefix' => '2fa.code',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Recovery Codes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the recovery codes generation. By default is enabled
|
||||
| so users have a way to authenticate without a code generator. The length
|
||||
| of the codes, as their quantity, can be configured to tighten security.
|
||||
|
|
||||
*/
|
||||
|
||||
'recovery' => [
|
||||
'enabled' => true,
|
||||
'codes' => 10,
|
||||
'length' => 16,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Safe Devices
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Authenticating with Two-Factor Codes can become very obnoxious when the
|
||||
| user does it every time. "Safe devices" allows to remember the device
|
||||
| for a period of time which 2FA Codes won't be asked when login in.
|
||||
|
|
||||
*/
|
||||
|
||||
'safe_devices' => [
|
||||
'enabled' => false,
|
||||
'cookie' => '_2fa_remember',
|
||||
'max_devices' => 3,
|
||||
'expiration_days' => 14,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Require Two-Factor Middleware
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The "2fa.confirm" middleware acts as a gatekeeper to a route by asking
|
||||
| the user to confirm with a 2FA Code. This configuration sets the key
|
||||
| of the session to remember the data and how much time to remember.
|
||||
|
|
||||
| Time is set in minutes.
|
||||
|
|
||||
*/
|
||||
|
||||
'confirm' => [
|
||||
'key' => '_2fa',
|
||||
'time' => 60 * 3, // 3 hours
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Two-Factor Login Helper
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the Login Helper, these defaults will be used to show the 2FA
|
||||
| form, and hold the encrypted login credentials in the session for only
|
||||
| the next request. You can also override them at run-time on attempt.
|
||||
|
|
||||
*/
|
||||
|
||||
'login' => [
|
||||
'view' => 'two-factor::login',
|
||||
'key' => '_2fa_login',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Secret Length
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The package uses a shared secret length of 160-bit, as recommended by the
|
||||
| RFC 4226. This makes it compatible with most 2FA apps. You can change it
|
||||
| freely but consider the standard allows shared secrets down to 128-bit.
|
||||
|
|
||||
*/
|
||||
|
||||
'secret_length' => 20,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| TOTP config
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While this package uses recommended RFC 4226 and RDC 6238 settings, you
|
||||
| can further configure how TOTP should work. These settings are saved
|
||||
| for each 2FA authentication, so it will only affect new accounts.
|
||||
|
|
||||
*/
|
||||
|
||||
'issuer' => env('OTP_TOTP_ISSUER'),
|
||||
|
||||
'totp' => [
|
||||
'digits' => 6,
|
||||
'seconds' => 30,
|
||||
'window' => 1,
|
||||
'algorithm' => 'sha1',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| QR Code Config
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This package uses the BaconQrCode generator package to generate QR codes
|
||||
| as SVG. These size and image margin values are used to create them. You
|
||||
| can always your own code to create personalized QR Codes from the URI.
|
||||
|
|
||||
*/
|
||||
|
||||
'qr_code' => [
|
||||
'size' => 400,
|
||||
'margin' => 4,
|
||||
],
|
||||
];
|
||||
24
database/factories/AlertFactory.php
Normal file
24
database/factories/AlertFactory.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class AlertFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'message' => $this->faker->word(),
|
||||
'type' => $this->faker->paragraph(),
|
||||
'expires_at' => now(),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
|
||||
public function message(string $message): static
|
||||
{
|
||||
return $this->set('message', $message);
|
||||
}
|
||||
}
|
||||
42
database/factories/PackageFactory.php
Normal file
42
database/factories/PackageFactory.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Package;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class PackageFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'Unlimited',
|
||||
'maximum_sites' => 0,
|
||||
'maximum_servers' => 1,
|
||||
'price_hourly' => 0,
|
||||
'price_monthly' => 0,
|
||||
'price_yearly' => 0,
|
||||
'plan_id' => null,
|
||||
'currency' => Package::CURRENCY_EURO,
|
||||
'site_permissions' => [
|
||||
'create' => true,
|
||||
'update' => true,
|
||||
'delete' => true,
|
||||
],
|
||||
'server_permissions' => [
|
||||
'create' => true,
|
||||
'update' => true,
|
||||
'delete' => true,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function serverPermissions(array $permissions = []): static
|
||||
{
|
||||
return $this->set('server_permissions', array_merge([
|
||||
'create' => true,
|
||||
'update' => true,
|
||||
'delete' => true,
|
||||
], $permissions));
|
||||
}
|
||||
}
|
||||
31
database/factories/ProviderFactory.php
Normal file
31
database/factories/ProviderFactory.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\ProviderPlan;
|
||||
use App\Models\ProviderRegion;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ProviderFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'ploi_id' => null,
|
||||
'label' => $this->faker->word(),
|
||||
'name' => $this->faker->name(),
|
||||
'allowed_plans' => null,
|
||||
'allowed_regions' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function withRegion(): static
|
||||
{
|
||||
return $this->has(ProviderRegion::factory(), 'regions');
|
||||
}
|
||||
|
||||
public function withPlan(): static
|
||||
{
|
||||
return $this->has(ProviderPlan::factory(), 'plans');
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user