Compare commits
255 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
823a39ffa2 | ||
|
|
6953a8d2b2 | ||
|
|
fb40b450b6 | ||
|
|
a28c053945 | ||
|
|
ea0c4ed66d | ||
|
|
7a0716959a | ||
|
|
da322d7b1e | ||
|
|
bbff8a5403 | ||
|
|
c1ad600042 | ||
|
|
5fc32759fd | ||
|
|
59cfd8d71b | ||
|
|
51d5b89df7 | ||
|
|
7c0dcbeb88 | ||
|
|
b4467f8d5b | ||
|
|
363f4ed801 | ||
|
|
1b6b950fb5 | ||
|
|
90988f1538 | ||
|
|
139ba793d0 | ||
|
|
c505dd0924 | ||
|
|
ca5ee33978 | ||
|
|
c2fd5e3fa9 | ||
|
|
b04176ce48 | ||
|
|
5136a4b9f8 | ||
|
|
dcee703aa1 | ||
|
|
7c504339d9 | ||
|
|
5ea0761fe9 | ||
|
|
c9125c3be8 | ||
|
|
84503c19db | ||
|
|
cfd9eba5d7 | ||
|
|
10689d3d12 | ||
|
|
e190fb7805 | ||
|
|
c1351f7d28 | ||
|
|
01f5469e86 | ||
|
|
8c5c86eb6a | ||
|
|
995ada46aa | ||
|
|
2e79381872 | ||
|
|
d1c7b9a418 | ||
|
|
34da2f563d | ||
|
|
5cf77fde1c | ||
|
|
aabf6f27ac | ||
|
|
fbcaee3bdc | ||
|
|
3082c10cdb | ||
|
|
a4d90f0017 | ||
|
|
8adfc9837e | ||
|
|
aa20c8a42b | ||
|
|
0f100d6159 | ||
|
|
7c896243a5 | ||
|
|
954fef7c3e | ||
|
|
105126e498 | ||
|
|
7aa5a8949d | ||
|
|
27079928a7 | ||
|
|
99968e57ec | ||
|
|
f75bc1a551 | ||
|
|
ef347f9381 | ||
|
|
f1aace3d8f | ||
|
|
b2bec62766 | ||
|
|
3a8682bbed | ||
|
|
5cfc1f97fe | ||
|
|
cfc8220f8e | ||
|
|
ac5ffefaed | ||
|
|
cbd2b8e0e9 | ||
|
|
f0f427a7bb | ||
|
|
7b6f651015 | ||
|
|
c793daa79a | ||
|
|
71b436aebe | ||
|
|
06e108da5b | ||
|
|
5677c58dd2 | ||
|
|
58ca801e30 | ||
|
|
e750d7caba | ||
|
|
3c0964ef0e | ||
|
|
33613cdf1c | ||
|
|
abfe174825 | ||
|
|
c750f469bb | ||
|
|
c7ac56d5cc | ||
|
|
6601f44013 | ||
|
|
b7baf862b6 | ||
|
|
ca79f4cf21 | ||
|
|
58ffbe8c74 | ||
|
|
dfa7b995fc | ||
|
|
59c65fe6ee | ||
|
|
087c042c14 | ||
|
|
d1ee488ffd | ||
|
|
34100bc580 | ||
|
|
22d91517fb | ||
|
|
1c088bd4e0 | ||
|
|
fd5bbb7f5d | ||
|
|
426d39bec0 | ||
|
|
8244c2dfb2 | ||
|
|
e7f9d32f68 | ||
|
|
71158a0030 | ||
|
|
573ce14b7a | ||
|
|
00ef1f470f | ||
|
|
a9357034c8 | ||
|
|
a45f5157d4 | ||
|
|
0d1009b8db | ||
|
|
4f0416cd45 | ||
|
|
76655d76d5 | ||
|
|
3b38cbe9ac | ||
|
|
acf37b8850 | ||
|
|
f47a0699d3 | ||
|
|
8ae429b06b | ||
|
|
626dbbcb49 | ||
|
|
b623dd80fd | ||
|
|
3978a7c9f7 | ||
|
|
7d2acb7438 | ||
|
|
096032301c | ||
|
|
c3e99bf2ff | ||
|
|
9795642bc7 | ||
|
|
4281a432fb | ||
|
|
18df5589b1 | ||
|
|
79536eac2e | ||
|
|
6df82fca04 | ||
|
|
cc14123d27 | ||
|
|
bd5e7b87ff | ||
|
|
42568916d6 | ||
|
|
180803cd8a | ||
|
|
08fcb0ce01 | ||
|
|
120b4c9df7 | ||
|
|
0eb66c10f6 | ||
|
|
1a6b14a250 | ||
|
|
072c8569eb | ||
|
|
5b9378255b | ||
|
|
ac3cf16377 | ||
|
|
31154d20f6 | ||
|
|
f8031ac71a | ||
|
|
898ec6a454 | ||
|
|
9dbd54fdf6 | ||
|
|
934017384d | ||
|
|
aee3dc0d93 | ||
|
|
8046687ae7 | ||
|
|
a89ee796c1 | ||
|
|
af1d3c3edc | ||
|
|
e1a54c2781 | ||
|
|
2d9f7d49b5 | ||
|
|
d10b046033 | ||
|
|
1725c0ff65 | ||
|
|
b852756c82 | ||
|
|
f164d878d7 | ||
|
|
ecc10fffcb | ||
|
|
5c75b015ba | ||
|
|
65f7dc697e | ||
|
|
d981f0f899 | ||
|
|
ab50beefab | ||
|
|
58d1215fd6 | ||
|
|
1dc137c314 | ||
|
|
ca51e9bf5f | ||
|
|
c588583dfc | ||
|
|
57c7c53eae | ||
|
|
76a62d9992 | ||
|
|
575aa1c6b1 | ||
|
|
4867a61fd0 | ||
|
|
a63e8f350b | ||
|
|
6c1b4f28af | ||
|
|
09adccf752 | ||
|
|
79bb522dee | ||
|
|
2adc4bc7ca | ||
|
|
0a81d58051 | ||
|
|
cb84438778 | ||
|
|
b0a76d311c | ||
|
|
5604503d26 | ||
|
|
bf55092b3a | ||
|
|
8286e7f9af | ||
|
|
1255221550 | ||
|
|
f4062cd6e7 | ||
|
|
93377ae753 | ||
|
|
a43cd19efd | ||
|
|
e5eec000d3 | ||
|
|
e5c8a62b32 | ||
|
|
9ae1c145b6 | ||
|
|
eb8b75e4f9 | ||
|
|
7378b82adf | ||
|
|
6f3b588f3d | ||
|
|
a2154cf37c | ||
|
|
9dab5f8093 | ||
|
|
9c9469d2f6 | ||
|
|
94acc313b1 | ||
|
|
448398322f | ||
|
|
3a78339396 | ||
|
|
a925a70448 | ||
|
|
e283eacaa3 | ||
|
|
3df6b6baed | ||
|
|
b65526e040 | ||
|
|
673bbf73be | ||
|
|
094d22eaa8 | ||
|
|
0fdba5fdec | ||
|
|
cf0730be89 | ||
|
|
221e67fd12 | ||
|
|
f9074309d1 | ||
|
|
b2bdbb9e30 | ||
|
|
63d0cb9626 | ||
|
|
e3bb3ae4d1 | ||
|
|
31890005ac | ||
|
|
04a216dee1 | ||
|
|
5d403c1202 | ||
|
|
a2d92c67b3 | ||
|
|
0fec3d82a3 | ||
|
|
6530a64f97 | ||
|
|
656f02d652 | ||
|
|
0dbf3bba4d | ||
|
|
ea47c0c3c6 | ||
|
|
b4072c7892 | ||
|
|
e80cd1990a | ||
|
|
2585cc1db4 | ||
|
|
0225828445 | ||
|
|
63af93592d | ||
|
|
b87fcd0f25 | ||
|
|
23a6b3cc55 | ||
|
|
dac3d229fd | ||
|
|
e360d9c5df | ||
|
|
8f100fc027 | ||
|
|
06fb331ae4 | ||
|
|
2bcf02a779 | ||
|
|
1b24664b60 | ||
|
|
2ce96a2062 | ||
|
|
5d737ba328 | ||
|
|
bafe8ba780 | ||
|
|
b7ff40fd72 | ||
|
|
8e036b1c01 | ||
|
|
b016c18880 | ||
|
|
d17ae49155 | ||
|
|
6ef5cd25f5 | ||
|
|
c98f077a0e | ||
|
|
a1f58c8e13 | ||
|
|
37281b01e4 | ||
|
|
65b0a768af | ||
|
|
39af06d3b2 | ||
|
|
7d137dd612 | ||
|
|
ce5e6c18f0 | ||
|
|
3d445ca61a | ||
|
|
8566eaaa6c | ||
|
|
db1647569c | ||
|
|
204afb7eb1 | ||
|
|
37f82d4579 | ||
|
|
2ed440e65f | ||
|
|
57a5ec2206 | ||
|
|
f14bc0494b | ||
|
|
c4147f0125 | ||
|
|
cfd0c3cbe9 | ||
|
|
0d0e2732b5 | ||
|
|
0a7b072eeb | ||
|
|
af6e12ca01 | ||
|
|
5eba94fd9b | ||
|
|
e9756494d9 | ||
|
|
f7f919b5de | ||
|
|
6f434f3b07 | ||
|
|
8820851afa | ||
|
|
4582e955d0 | ||
|
|
e07395b3d5 | ||
|
|
3ad7d06976 | ||
|
|
f57cbb76e3 | ||
|
|
bb3151a2fe | ||
|
|
5b48d204a0 | ||
|
|
680d96882a | ||
|
|
7347356646 | ||
|
|
2652e7ed71 |
@@ -26,6 +26,7 @@ SESSION_LIFETIME=120
|
|||||||
REDIS_HOST=127.0.0.1
|
REDIS_HOST=127.0.0.1
|
||||||
REDIS_PASSWORD=null
|
REDIS_PASSWORD=null
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
|
REDIS_CLIENT=predis
|
||||||
|
|
||||||
MAIL_MAILER=smtp
|
MAIL_MAILER=smtp
|
||||||
MAIL_HOST=smtp.mailtrap.io
|
MAIL_HOST=smtp.mailtrap.io
|
||||||
@@ -36,6 +37,10 @@ MAIL_ENCRYPTION=null
|
|||||||
MAIL_FROM_ADDRESS=null
|
MAIL_FROM_ADDRESS=null
|
||||||
MAIL_FROM_NAME="${APP_NAME}"
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
STRIPE_KEY=your-stripe-key
|
||||||
|
STRIPE_SECRET=your-stripe-secret
|
||||||
|
CASHIER_MODEL=App\Models\User
|
||||||
|
|
||||||
AWS_ACCESS_KEY_ID=
|
AWS_ACCESS_KEY_ID=
|
||||||
AWS_SECRET_ACCESS_KEY=
|
AWS_SECRET_ACCESS_KEY=
|
||||||
AWS_DEFAULT_REGION=us-east-1
|
AWS_DEFAULT_REGION=us-east-1
|
||||||
|
|||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -12,3 +12,7 @@ npm-debug.log
|
|||||||
yarn-error.log
|
yarn-error.log
|
||||||
.idea
|
.idea
|
||||||
.php_cs.cache
|
.php_cs.cache
|
||||||
|
.php-cs-fixer.cache
|
||||||
|
/public/js/resources*.js
|
||||||
|
/storage/views/header.blade.php
|
||||||
|
/storage/views/footer.blade.php
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ $finder = Symfony\Component\Finder\Finder::create()
|
|||||||
->name('*.php')
|
->name('*.php')
|
||||||
->notName('*.blade.php');
|
->notName('*.blade.php');
|
||||||
|
|
||||||
return PhpCsFixer\Config::create()
|
return (new PhpCsFixer\Config)
|
||||||
->setRules([
|
->setRules([
|
||||||
'@PSR2' => true,
|
'@PSR2' => true,
|
||||||
'array_syntax' => ['syntax' => 'short'],
|
'array_syntax' => ['syntax' => 'short'],
|
||||||
'ordered_imports' => ['sortAlgorithm' => 'length'],
|
'ordered_imports' => ['sort_algorithm' => 'length'],
|
||||||
'no_unused_imports' => true,
|
'no_unused_imports' => true,
|
||||||
])
|
])
|
||||||
->setFinder($finder);
|
->setFinder($finder);
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
With Ploi Core, you'll power-launch your webhosting company.
|
With Ploi Core, you'll power-launch your webhosting company.
|
||||||
Using the ploi.io system as backbone you will be able to serve your customers your custom panel & feeling.
|
Using the ploi.io system as backbone you will be able to serve your customers your custom panel & feeling.
|
||||||
|
|
||||||
<p align="center"><img src="https://ploi-core.io/images/featured.png" width="100%"></p>
|
<p align="center"><img src="https://ploi-core.io/images/og.jpg" width="100%"></p>
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
|||||||
44
app/Casts/PermissionCast.php
Normal file
44
app/Casts/PermissionCast.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Casts;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|
||||||
|
class PermissionCast implements CastsAttributes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Cast the given value.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $value
|
||||||
|
* @param array $attributes
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function get($model, $key, $value, $attributes)
|
||||||
|
{
|
||||||
|
if (!$value) {
|
||||||
|
return [
|
||||||
|
'create' => false,
|
||||||
|
'update' => false,
|
||||||
|
'delete' => false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_decode($value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the given value for storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
* @param string $key
|
||||||
|
* @param array $value
|
||||||
|
* @param array $attributes
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function set($model, $key, $value, $attributes)
|
||||||
|
{
|
||||||
|
return json_encode($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
60
app/Console/Commands/Core/Cleanup.php
Normal file
60
app/Console/Commands/Core/Cleanup.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Core;
|
||||||
|
|
||||||
|
use App\Models\SystemLog;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class Cleanup extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'core:cleanup';
|
||||||
|
|
||||||
|
protected $description = 'Clean up any old logs';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
if (!setting('rotate_logs_after')) {
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rotationDate = $this->getRotationDate();
|
||||||
|
|
||||||
|
$rotated = SystemLog::query()
|
||||||
|
->where('created_at', '<', $rotationDate)
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
$this->info('Rotated ' . $rotated . ' system logs!');
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRotationDate()
|
||||||
|
{
|
||||||
|
switch (setting('rotate_logs_after')) {
|
||||||
|
case 'weeks-1':
|
||||||
|
return now()->subWeek();
|
||||||
|
break;
|
||||||
|
case 'months-1':
|
||||||
|
return now()->subMonth();
|
||||||
|
break;
|
||||||
|
case 'months-3':
|
||||||
|
return now()->subMonths(3);
|
||||||
|
break;
|
||||||
|
case 'months-6':
|
||||||
|
return now()->subMonths(6);
|
||||||
|
break;
|
||||||
|
case 'years-1':
|
||||||
|
return now()->subYear();
|
||||||
|
break;
|
||||||
|
case 'years-2':
|
||||||
|
return now()->subYears(2);
|
||||||
|
break;
|
||||||
|
case 'years-3':
|
||||||
|
return now()->subYears(3);
|
||||||
|
break;
|
||||||
|
case 'years-4':
|
||||||
|
return now()->subYears(4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Console/Commands/Core/Css.php
Normal file
31
app/Console/Commands/Core/Css.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Core;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
|
||||||
|
class Css extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'core:css';
|
||||||
|
|
||||||
|
protected $description = 'Generates an theme.css file for you to customize';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
if (file_exists(storage_path('app/public/theme.css')) && !$this->confirm('You seem to already have a theme.css published, are you sure you want to overwrite?')) {
|
||||||
|
$this->warn('Aborted publishing of theme.css.');
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Publishing theme.css file..');
|
||||||
|
|
||||||
|
(new Filesystem)->copy(
|
||||||
|
__DIR__ . '/stubs/theme.css',
|
||||||
|
storage_path('app/public/theme.css')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->info('Done! You can edit the theme.css file inside storage/public/theme.css');
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Console/Commands/Core/CssBackup.php
Normal file
31
app/Console/Commands/Core/CssBackup.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Core;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
|
||||||
|
class CssBackup extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'core:css-backup';
|
||||||
|
|
||||||
|
protected $description = 'Creates a backup from your own created theme.css';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
if (!file_exists(storage_path('app/public/theme.css'))) {
|
||||||
|
$this->warn('There is no custom theme.css, aborting backup.');
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Backing up theme.css file..');
|
||||||
|
|
||||||
|
(new Filesystem)->copy(
|
||||||
|
storage_path('app/public/theme.css'),
|
||||||
|
storage_path('app/public/theme-backup.css')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->info('Done! You can find the CSS backup file here storage/public/theme-backup.css');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,29 +7,25 @@ use App\Models\User;
|
|||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use App\Models\Package;
|
use App\Models\Package;
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Services\Ploi\Ploi;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use App\Services\VersionChecker;
|
use App\Services\VersionChecker;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
class Install extends Command
|
class Install extends Command
|
||||||
{
|
{
|
||||||
protected $company;
|
protected $company;
|
||||||
protected $signature = 'core:install';
|
protected $signature = 'core:install {--force}';
|
||||||
protected $description = 'Installation command for Ploi Core';
|
protected $description = 'Installation command for Ploi Core';
|
||||||
protected $versionChecker;
|
protected $versionChecker;
|
||||||
protected $installationFile = 'app/installation';
|
protected $installationFile = 'app/installation';
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
$this->versionChecker = (new VersionChecker)->getVersions();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$this->init();
|
||||||
$this->intro();
|
$this->intro();
|
||||||
$this->isInstalled();
|
$this->isInstalled();
|
||||||
$this->checkApplicationKey();
|
$this->checkApplicationKey();
|
||||||
@@ -40,35 +36,53 @@ class Install extends Command
|
|||||||
$this->askAboutDefaultPackages();
|
$this->askAboutDefaultPackages();
|
||||||
$this->checkApplicationUrl();
|
$this->checkApplicationUrl();
|
||||||
$this->createInstallationFile();
|
$this->createInstallationFile();
|
||||||
|
$this->linkStorage();
|
||||||
|
|
||||||
$this->info('Succes! Installation has finished.');
|
$this->info('Success! Installation has finished.');
|
||||||
|
$this->line(' ');
|
||||||
|
$this->writeSeparationLine();
|
||||||
|
$this->info('Make sure to also setup emailing, the cronjob and the queue worker.');
|
||||||
|
$this->line(' ');
|
||||||
|
$this->info('Setting up emailing: https://docs.ploi-core.io/getting-started/setting-up-email');
|
||||||
|
$this->info('Setting up cronjob & queue worker: https://docs.ploi-core.io/getting-started/installation');
|
||||||
|
$this->writeSeparationLine();
|
||||||
|
$this->line(' ');
|
||||||
$this->info('Visit your platform at ' . env('APP_URL'));
|
$this->info('Visit your platform at ' . env('APP_URL'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function init()
|
||||||
|
{
|
||||||
|
$this->versionChecker = (new VersionChecker)->getVersions();
|
||||||
|
}
|
||||||
|
|
||||||
protected function askAboutAdministrationAccount()
|
protected function askAboutAdministrationAccount()
|
||||||
{
|
{
|
||||||
$this->info('Let\'s start by setting up your administration account.');
|
if (!User::query()->where('role', User::ADMIN)->count()) {
|
||||||
|
$this->info('Let\'s start by setting up your administration account.');
|
||||||
|
|
||||||
$name = $this->ask('What is your name', $this->company['user_name']);
|
$name = $this->ask('What is your name', $this->company['user_name']);
|
||||||
$email = $this->ask('What is your e-mail address', $this->company['email']);
|
$email = $this->ask('What is your e-mail address', $this->company['email']);
|
||||||
$password = $this->secret('What password do you desire');
|
$password = $this->secret('What password do you desire');
|
||||||
|
|
||||||
$check = User::where('email', $email)->count();
|
$check = User::where('email', $email)->count();
|
||||||
|
|
||||||
if ($check) {
|
if ($check) {
|
||||||
$this->line('');
|
$this->line('');
|
||||||
$this->comment('This user is already present in your system, please refresh your database or use different credentials.');
|
$this->comment('This user is already present in your system, please refresh your database or use different credentials.');
|
||||||
$this->comment('Aborting installation..');
|
$this->comment('Aborting installation..');
|
||||||
|
|
||||||
exit();
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
User::forceCreate([
|
||||||
|
'name' => $name,
|
||||||
|
'email' => $email,
|
||||||
|
'password' => $password,
|
||||||
|
'role' => User::ADMIN
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$this->line('Already found a administrator user in your system. Use that user to login.');
|
||||||
}
|
}
|
||||||
|
|
||||||
User::forceCreate([
|
|
||||||
'name' => $name,
|
|
||||||
'email' => $email,
|
|
||||||
'password' => $password,
|
|
||||||
'role' => User::ADMIN
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function askAboutDefaultPackages()
|
protected function askAboutDefaultPackages()
|
||||||
@@ -85,16 +99,46 @@ class Install extends Command
|
|||||||
Package::create([
|
Package::create([
|
||||||
'name' => 'Basic',
|
'name' => 'Basic',
|
||||||
'maximum_sites' => 5,
|
'maximum_sites' => 5,
|
||||||
|
'site_permissions' => [
|
||||||
|
'create' => true,
|
||||||
|
'update' => true,
|
||||||
|
'delete' => true
|
||||||
|
],
|
||||||
|
'server_permissions' => [
|
||||||
|
'create' => false,
|
||||||
|
'update' => false,
|
||||||
|
'delete' => false
|
||||||
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Package::create([
|
Package::create([
|
||||||
'name' => 'Professional',
|
'name' => 'Professional',
|
||||||
'maximum_sites' => 5,
|
'maximum_sites' => 30,
|
||||||
|
'site_permissions' => [
|
||||||
|
'create' => true,
|
||||||
|
'update' => true,
|
||||||
|
'delete' => true
|
||||||
|
],
|
||||||
|
'server_permissions' => [
|
||||||
|
'create' => false,
|
||||||
|
'update' => false,
|
||||||
|
'delete' => false
|
||||||
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Package::create([
|
Package::create([
|
||||||
'name' => 'Unlimited',
|
'name' => 'Unlimited',
|
||||||
'maximum_sites' => 0,
|
'maximum_sites' => 0,
|
||||||
|
'site_permissions' => [
|
||||||
|
'create' => true,
|
||||||
|
'update' => true,
|
||||||
|
'delete' => true
|
||||||
|
],
|
||||||
|
'server_permissions' => [
|
||||||
|
'create' => false,
|
||||||
|
'update' => false,
|
||||||
|
'delete' => false
|
||||||
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +153,9 @@ class Install extends Command
|
|||||||
->get((new Ploi)->url . 'ping');
|
->get((new Ploi)->url . 'ping');
|
||||||
|
|
||||||
if (!$response->ok() || !$response->json()) {
|
if (!$response->ok() || !$response->json()) {
|
||||||
return false;
|
return [
|
||||||
|
'error' => Arr::get($response->json(), 'message', 'An unknown error has occurred.')
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response->json();
|
return $response->json();
|
||||||
@@ -124,7 +170,7 @@ class Install extends Command
|
|||||||
|
|
||||||
protected function intro()
|
protected function intro()
|
||||||
{
|
{
|
||||||
$this->info('*---------------------------------------------------------------------------*');
|
$this->writeSeparationLine();
|
||||||
$this->line('Ploi Core Installation');
|
$this->line('Ploi Core Installation');
|
||||||
$this->line('Ploi Core version: ' . $this->versionChecker->currentVersion);
|
$this->line('Ploi Core version: ' . $this->versionChecker->currentVersion);
|
||||||
$this->line('Ploi Core remote: ' . $this->versionChecker->remoteVersion);
|
$this->line('Ploi Core remote: ' . $this->versionChecker->remoteVersion);
|
||||||
@@ -134,13 +180,13 @@ class Install extends Command
|
|||||||
$this->line('Website: https://ploi-core.io');
|
$this->line('Website: https://ploi-core.io');
|
||||||
$this->line('E-mail: core@ploi.io');
|
$this->line('E-mail: core@ploi.io');
|
||||||
$this->line('Terms of service: https://ploi-core.io/terms');
|
$this->line('Terms of service: https://ploi-core.io/terms');
|
||||||
$this->info('*---------------------------------------------------------------------------*');
|
$this->writeSeparationLine();
|
||||||
$this->line('');
|
$this->line('');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isInstalled()
|
protected function isInstalled()
|
||||||
{
|
{
|
||||||
if (file_exists(storage_path($this->installationFile))) {
|
if (file_exists(storage_path($this->installationFile)) && !$this->option('force')) {
|
||||||
$this->line('');
|
$this->line('');
|
||||||
$this->comment('Ploi Core has already been installed before.');
|
$this->comment('Ploi Core has already been installed before.');
|
||||||
$this->comment('If you still want to start installation, remove this file to continue: ./storage/' . $this->installationFile);
|
$this->comment('If you still want to start installation, remove this file to continue: ./storage/' . $this->installationFile);
|
||||||
@@ -174,6 +220,11 @@ class Install extends Command
|
|||||||
file_put_contents(storage_path($this->installationFile), json_encode($this->getInstallationPayload(), JSON_PRETTY_PRINT));
|
file_put_contents(storage_path($this->installationFile), json_encode($this->getInstallationPayload(), JSON_PRETTY_PRINT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function linkStorage()
|
||||||
|
{
|
||||||
|
Artisan::call('storage:link');
|
||||||
|
}
|
||||||
|
|
||||||
protected function createDatabaseCredentials(): bool
|
protected function createDatabaseCredentials(): bool
|
||||||
{
|
{
|
||||||
$storeCredentials = $this->confirm(
|
$storeCredentials = $this->confirm(
|
||||||
@@ -240,6 +291,18 @@ class Install extends Command
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($this->company['error'])) {
|
||||||
|
$this->error($this->company['error']);
|
||||||
|
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->company['user']['subscription'] !== 'unlimited') {
|
||||||
|
$this->error('Your subscription does not cover the usage of Ploi Core. Please upgrade your subscription to Unlimited.');
|
||||||
|
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
$this->writeToEnvironmentFile('PLOI_TOKEN', $ploiApiToken);
|
$this->writeToEnvironmentFile('PLOI_TOKEN', $ploiApiToken);
|
||||||
$this->writeToEnvironmentFile('PLOI_CORE_TOKEN', $ploiCoreKey);
|
$this->writeToEnvironmentFile('PLOI_CORE_TOKEN', $ploiCoreKey);
|
||||||
|
|
||||||
@@ -343,4 +406,9 @@ class Install extends Command
|
|||||||
{
|
{
|
||||||
$this->laravel['config'][$key] = $value;
|
$this->laravel['config'][$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function writeSeparationLine()
|
||||||
|
{
|
||||||
|
$this->info('*---------------------------------------------------------------------------*');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
78
app/Console/Commands/Core/stubs/theme.css
vendored
Normal file
78
app/Console/Commands/Core/stubs/theme.css
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
:root {
|
||||||
|
--font-body: 'Inter', sans-serif;
|
||||||
|
|
||||||
|
--color-white: #fff;
|
||||||
|
--color-gray-1: #f7f7f7;
|
||||||
|
--color-gray-2: #e6e6e6;
|
||||||
|
--color-gray-3: #cacaca;
|
||||||
|
--color-gray-4: #888;
|
||||||
|
--color-gray-5: #666;
|
||||||
|
--color-gray-6: #2f2f2f;
|
||||||
|
--color-gray-7: #1b1a1a;
|
||||||
|
--color-gray-8: #101010;
|
||||||
|
|
||||||
|
--color-primary: #1b8ae8;
|
||||||
|
--color-success: #17b35d;
|
||||||
|
--color-warning: #f5a623;
|
||||||
|
--color-danger: #c90c4c;
|
||||||
|
|
||||||
|
--color-text-high-emphasis: var(--color-gray-8);
|
||||||
|
--color-text-medium-emphasis: var(--color-gray-5);
|
||||||
|
--color-text-low-emphasis: var(--color-gray-3);
|
||||||
|
|
||||||
|
--color-text-on-primary: var(--color-white);
|
||||||
|
--color-text-on-success: var(--color-gray-8);
|
||||||
|
--color-text-on-warning: var(--color-white);
|
||||||
|
--color-text-on-danger: var(--color-white);
|
||||||
|
|
||||||
|
--color-border-high-emphasis: var(--color-gray-4);
|
||||||
|
--color-border-medium-emphasis: var(--color-gray-3);
|
||||||
|
--color-border-low-emphasis: var(--color-gray-2);
|
||||||
|
|
||||||
|
--color-backdrop: rgba(0, 0, 0, 0.5);
|
||||||
|
--color-overlay: rgba(255, 255, 255, 0.8);
|
||||||
|
--color-surface-1: var(--color-white);
|
||||||
|
--color-surface-2: var(--color-gray-1);
|
||||||
|
--color-surface-3: var(--color-white);
|
||||||
|
|
||||||
|
--border-radius: 0.5rem;
|
||||||
|
--border-radius-avatar: 4rem;
|
||||||
|
--border-radius-circle: 100%;
|
||||||
|
|
||||||
|
--top-bar-container: 64rem;
|
||||||
|
--top-bar-logo-height: 3.5rem;
|
||||||
|
--top-bar-background-color: var(--color-surface-1);
|
||||||
|
--top-bar-text-color: var(--color-text-medium-emphasis);
|
||||||
|
|
||||||
|
--tab-bar-background-color: var(--color-surface-2);
|
||||||
|
--tab-bar-item-active-background-color: var(--color-surface-1);
|
||||||
|
--tab-bar-item-text-color: var(--color-text-medium-emphasis);
|
||||||
|
--tab-bar-item-active-text-color: var(--color-text-high-emphasis);
|
||||||
|
|
||||||
|
--breadcrumbs-text-color: var(--color-text-medium-emphasis);
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme--dark {
|
||||||
|
--color-primary: #63a6f5;
|
||||||
|
--color-success: #50e3c2;
|
||||||
|
--color-warning: #f5a623;
|
||||||
|
--color-danger: #d4667c;
|
||||||
|
|
||||||
|
--color-text-high-emphasis: var(--color-white);
|
||||||
|
--color-text-medium-emphasis: var(--color-gray-3);
|
||||||
|
--color-text-low-emphasis: var(--color-gray-5);
|
||||||
|
|
||||||
|
--color-text-on-primary: var(--color-gray-7);
|
||||||
|
--color-text-on-success: var(--color-gray-7);
|
||||||
|
--color-text-on-warning: var(--color-gray-7);
|
||||||
|
--color-text-on-danger: var(--color-gray-7);
|
||||||
|
|
||||||
|
--color-border-high-emphasis: var(--color-gray-4);
|
||||||
|
--color-border-medium-emphasis: var(--color-gray-5);
|
||||||
|
--color-border-low-emphasis: var(--color-gray-6);
|
||||||
|
|
||||||
|
--color-surface-1: var(--color-gray-7);
|
||||||
|
--color-surface-2: var(--color-gray-6);
|
||||||
|
--color-surface-3: var(--color-gray-6);
|
||||||
|
--color-overlay: rgba(0, 0, 0, 0.8);
|
||||||
|
}
|
||||||
@@ -3,7 +3,10 @@
|
|||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
use App\Jobs\Core\Ping;
|
use App\Jobs\Core\Ping;
|
||||||
|
use App\Console\Commands\Core\Css;
|
||||||
|
use App\Console\Commands\Core\Cleanup;
|
||||||
use App\Console\Commands\Core\Install;
|
use App\Console\Commands\Core\Install;
|
||||||
|
use App\Console\Commands\Core\CssBackup;
|
||||||
use App\Console\Commands\Core\Synchronize;
|
use App\Console\Commands\Core\Synchronize;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
@@ -11,8 +14,11 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
|||||||
class Kernel extends ConsoleKernel
|
class Kernel extends ConsoleKernel
|
||||||
{
|
{
|
||||||
protected $commands = [
|
protected $commands = [
|
||||||
|
Css::class,
|
||||||
|
CssBackup::class,
|
||||||
Install::class,
|
Install::class,
|
||||||
Synchronize::class,
|
Synchronize::class,
|
||||||
|
Cleanup::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
@@ -20,5 +26,7 @@ class Kernel extends ConsoleKernel
|
|||||||
$schedule->call(function () {
|
$schedule->call(function () {
|
||||||
dispatch(new Ping())->delay(now()->addMinutes(rand(1, 30)));
|
dispatch(new Ping())->delay(now()->addMinutes(rand(1, 30)));
|
||||||
})->dailyAt('02:00');
|
})->dailyAt('02:00');
|
||||||
|
|
||||||
|
$schedule->command('core:cleanup')->daily();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
281
app/Helpers/Country.php
Normal file
281
app/Helpers/Country.php
Normal file
@@ -0,0 +1,281 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!function_exists('countries')) {
|
||||||
|
function countries($key = null)
|
||||||
|
{
|
||||||
|
$arr = [
|
||||||
|
'af' => 'Afghanistan',
|
||||||
|
'al' => 'Albania',
|
||||||
|
'dz' => 'Algeria',
|
||||||
|
'as' => 'American Samoa',
|
||||||
|
'ad' => 'Andorra',
|
||||||
|
'ao' => 'Angola',
|
||||||
|
'ai' => 'Anguilla',
|
||||||
|
'aq' => 'Antarctica',
|
||||||
|
'ag' => 'Antigua and Barbuda',
|
||||||
|
'ar' => 'Argentina',
|
||||||
|
'am' => 'Armenia',
|
||||||
|
'aw' => 'Aruba',
|
||||||
|
'au' => 'Australia',
|
||||||
|
'at' => 'Austria',
|
||||||
|
'az' => 'Azerbaijan',
|
||||||
|
'bs' => 'Bahamas',
|
||||||
|
'bh' => 'Bahrain',
|
||||||
|
'bd' => 'Bangladesh',
|
||||||
|
'bb' => 'Barbados',
|
||||||
|
'by' => 'Belarus',
|
||||||
|
'be' => 'Belgium',
|
||||||
|
'bz' => 'Belize',
|
||||||
|
'bj' => 'Benin',
|
||||||
|
'bm' => 'Bermuda',
|
||||||
|
'bt' => 'Bhutan',
|
||||||
|
'bo' => 'Bolivia',
|
||||||
|
'ba' => 'Bosnia and Herzegovina',
|
||||||
|
'bw' => 'Botswana',
|
||||||
|
'bv' => 'Bouvet Island',
|
||||||
|
'br' => 'Brazil',
|
||||||
|
'bq' => 'British Antarctic Territory',
|
||||||
|
'io' => 'British Indian Ocean Territory',
|
||||||
|
'vg' => 'British Virgin Islands',
|
||||||
|
'bn' => 'Brunei',
|
||||||
|
'bg' => 'Bulgaria',
|
||||||
|
'bf' => 'Burkina Faso',
|
||||||
|
'bi' => 'Burundi',
|
||||||
|
'kh' => 'Cambodia',
|
||||||
|
'cm' => 'Cameroon',
|
||||||
|
'ca' => 'Canada',
|
||||||
|
'ct' => 'Canton and Enderbury Islands',
|
||||||
|
'cv' => 'Cape Verde',
|
||||||
|
'ky' => 'Cayman Islands',
|
||||||
|
'cf' => 'Central African Republic',
|
||||||
|
'td' => 'Chad',
|
||||||
|
'cl' => 'Chile',
|
||||||
|
'cn' => 'China',
|
||||||
|
'cx' => 'Christmas Island',
|
||||||
|
'cc' => 'Cocos [Keeling] Islands',
|
||||||
|
'co' => 'Colombia',
|
||||||
|
'km' => 'Comoros',
|
||||||
|
'cg' => 'Congo - Brazzaville',
|
||||||
|
'cd' => 'Congo - Kinshasa',
|
||||||
|
'ck' => 'Cook Islands',
|
||||||
|
'cr' => 'Costa Rica',
|
||||||
|
'hr' => 'Croatia',
|
||||||
|
'cu' => 'Cuba',
|
||||||
|
'cy' => 'Cyprus',
|
||||||
|
'cz' => 'Czech Republic',
|
||||||
|
'ci' => 'Côte d’Ivoire',
|
||||||
|
'dk' => 'Denmark',
|
||||||
|
'dj' => 'Djibouti',
|
||||||
|
'dm' => 'Dominica',
|
||||||
|
'do' => 'Dominican Republic',
|
||||||
|
'nq' => 'Dronning Maud Land',
|
||||||
|
'dd' => 'East Germany',
|
||||||
|
'ec' => 'Ecuador',
|
||||||
|
'eg' => 'Egypt',
|
||||||
|
'sv' => 'El Salvador',
|
||||||
|
'gq' => 'Equatorial Guinea',
|
||||||
|
'er' => 'Eritrea',
|
||||||
|
'ee' => 'Estonia',
|
||||||
|
'et' => 'Ethiopia',
|
||||||
|
'fk' => 'Falkland Islands',
|
||||||
|
'fo' => 'Faroe Islands',
|
||||||
|
'fj' => 'Fiji',
|
||||||
|
'fi' => 'Finland',
|
||||||
|
'fr' => 'France',
|
||||||
|
'gf' => 'French Guiana',
|
||||||
|
'pf' => 'French Polynesia',
|
||||||
|
'tf' => 'French Southern Territories',
|
||||||
|
'fq' => 'French Southern and Antarctic Territories',
|
||||||
|
'ga' => 'Gabon',
|
||||||
|
'gm' => 'Gambia',
|
||||||
|
'ge' => 'Georgia',
|
||||||
|
'de' => 'Germany',
|
||||||
|
'gh' => 'Ghana',
|
||||||
|
'gi' => 'Gibraltar',
|
||||||
|
'gr' => 'Greece',
|
||||||
|
'gl' => 'Greenland',
|
||||||
|
'gd' => 'Grenada',
|
||||||
|
'gp' => 'Guadeloupe',
|
||||||
|
'gu' => 'Guam',
|
||||||
|
'gt' => 'Guatemala',
|
||||||
|
'gg' => 'Guernsey',
|
||||||
|
'gn' => 'Guinea',
|
||||||
|
'gw' => 'Guinea-Bissau',
|
||||||
|
'gy' => 'Guyana',
|
||||||
|
'ht' => 'Haiti',
|
||||||
|
'hm' => 'Heard Island and McDonald Islands',
|
||||||
|
'hn' => 'Honduras',
|
||||||
|
'hk' => 'Hong Kong SAR China',
|
||||||
|
'hu' => 'Hungary',
|
||||||
|
'is' => 'Iceland',
|
||||||
|
'in' => 'India',
|
||||||
|
'id' => 'Indonesia',
|
||||||
|
'ir' => 'Iran',
|
||||||
|
'iq' => 'Iraq',
|
||||||
|
'ie' => 'Ireland',
|
||||||
|
'im' => 'Isle of Man',
|
||||||
|
'il' => 'Israel',
|
||||||
|
'it' => 'Italy',
|
||||||
|
'jm' => 'Jamaica',
|
||||||
|
'jp' => 'Japan',
|
||||||
|
'je' => 'Jersey',
|
||||||
|
'jt' => 'Johnston Island',
|
||||||
|
'jo' => 'Jordan',
|
||||||
|
'kz' => 'Kazakhstan',
|
||||||
|
'ke' => 'Kenya',
|
||||||
|
'ki' => 'Kiribati',
|
||||||
|
'kw' => 'Kuwait',
|
||||||
|
'kg' => 'Kyrgyzstan',
|
||||||
|
'la' => 'Laos',
|
||||||
|
'lv' => 'Latvia',
|
||||||
|
'lb' => 'Lebanon',
|
||||||
|
'ls' => 'Lesotho',
|
||||||
|
'lr' => 'Liberia',
|
||||||
|
'ly' => 'Libya',
|
||||||
|
'li' => 'Liechtenstein',
|
||||||
|
'lt' => 'Lithuania',
|
||||||
|
'lu' => 'Luxembourg',
|
||||||
|
'mo' => 'Macau SAR China',
|
||||||
|
'mk' => 'Macedonia',
|
||||||
|
'mg' => 'Madagascar',
|
||||||
|
'mw' => 'Malawi',
|
||||||
|
'my' => 'Malaysia',
|
||||||
|
'mv' => 'Maldives',
|
||||||
|
'ml' => 'Mali',
|
||||||
|
'mt' => 'Malta',
|
||||||
|
'mh' => 'Marshall Islands',
|
||||||
|
'mq' => 'Martinique',
|
||||||
|
'mr' => 'Mauritania',
|
||||||
|
'mu' => 'Mauritius',
|
||||||
|
'yt' => 'Mayotte',
|
||||||
|
'fx' => 'Metropolitan France',
|
||||||
|
'mx' => 'Mexico',
|
||||||
|
'fm' => 'Micronesia',
|
||||||
|
'mi' => 'Midway Islands',
|
||||||
|
'md' => 'Moldova',
|
||||||
|
'mc' => 'Monaco',
|
||||||
|
'mn' => 'Mongolia',
|
||||||
|
'me' => 'Montenegro',
|
||||||
|
'ms' => 'Montserrat',
|
||||||
|
'ma' => 'Morocco',
|
||||||
|
'mz' => 'Mozambique',
|
||||||
|
'mm' => 'Myanmar [Burma]',
|
||||||
|
'na' => 'Namibia',
|
||||||
|
'nr' => 'Nauru',
|
||||||
|
'np' => 'Nepal',
|
||||||
|
'nl' => 'Netherlands',
|
||||||
|
'an' => 'Netherlands Antilles',
|
||||||
|
'nt' => 'Neutral Zone',
|
||||||
|
'nc' => 'New Caledonia',
|
||||||
|
'nz' => 'New Zealand',
|
||||||
|
'ni' => 'Nicaragua',
|
||||||
|
'ne' => 'Niger',
|
||||||
|
'ng' => 'Nigeria',
|
||||||
|
'nu' => 'Niue',
|
||||||
|
'nf' => 'Norfolk Island',
|
||||||
|
'kp' => 'North Korea',
|
||||||
|
'vd' => 'North Vietnam',
|
||||||
|
'mp' => 'Northern Mariana Islands',
|
||||||
|
'no' => 'Norway',
|
||||||
|
'om' => 'Oman',
|
||||||
|
'pc' => 'Pacific Islands Trust Territory',
|
||||||
|
'pk' => 'Pakistan',
|
||||||
|
'pw' => 'Palau',
|
||||||
|
'ps' => 'Palestinian Territories',
|
||||||
|
'pa' => 'Panama',
|
||||||
|
'pz' => 'Panama Canal Zone',
|
||||||
|
'pg' => 'Papua New Guinea',
|
||||||
|
'py' => 'Paraguay',
|
||||||
|
'yd' => 'People\'s Democratic Republic of Yemen',
|
||||||
|
'pe' => 'Peru',
|
||||||
|
'ph' => 'Philippines',
|
||||||
|
'pn' => 'Pitcairn Islands',
|
||||||
|
'pl' => 'Poland',
|
||||||
|
'pt' => 'Portugal',
|
||||||
|
'pr' => 'Puerto Rico',
|
||||||
|
'qa' => 'Qatar',
|
||||||
|
'ro' => 'Romania',
|
||||||
|
'ru' => 'Russia',
|
||||||
|
'rw' => 'Rwanda',
|
||||||
|
're' => 'Réunion',
|
||||||
|
'bl' => 'Saint Barthélemy',
|
||||||
|
'sh' => 'Saint Helena',
|
||||||
|
'kn' => 'Saint Kitts and Nevis',
|
||||||
|
'lc' => 'Saint Lucia',
|
||||||
|
'mf' => 'Saint Martin',
|
||||||
|
'pm' => 'Saint Pierre and Miquelon',
|
||||||
|
'vc' => 'Saint Vincent and the Grenadines',
|
||||||
|
'ws' => 'Samoa',
|
||||||
|
'sm' => 'San Marino',
|
||||||
|
'sa' => 'Saudi Arabia',
|
||||||
|
'sn' => 'Senegal',
|
||||||
|
'rs' => 'Serbia',
|
||||||
|
'cs' => 'Serbia and Montenegro',
|
||||||
|
'sc' => 'Seychelles',
|
||||||
|
'sl' => 'Sierra Leone',
|
||||||
|
'sg' => 'Singapore',
|
||||||
|
'sk' => 'Slovakia',
|
||||||
|
'si' => 'Slovenia',
|
||||||
|
'sb' => 'Solomon Islands',
|
||||||
|
'so' => 'Somalia',
|
||||||
|
'za' => 'South Africa',
|
||||||
|
'gs' => 'South Georgia and the South Sandwich Islands',
|
||||||
|
'kr' => 'South Korea',
|
||||||
|
'es' => 'Spain',
|
||||||
|
'lk' => 'Sri Lanka',
|
||||||
|
'sd' => 'Sudan',
|
||||||
|
'sr' => 'Suriname',
|
||||||
|
'sj' => 'Svalbard and Jan Mayen',
|
||||||
|
'sz' => 'Swaziland',
|
||||||
|
'se' => 'Sweden',
|
||||||
|
'ch' => 'Switzerland',
|
||||||
|
'sy' => 'Syria',
|
||||||
|
'st' => 'São Tomé and Príncipe',
|
||||||
|
'tw' => 'Taiwan',
|
||||||
|
'tj' => 'Tajikistan',
|
||||||
|
'tz' => 'Tanzania',
|
||||||
|
'th' => 'Thailand',
|
||||||
|
'tl' => 'Timor-Leste',
|
||||||
|
'tg' => 'Togo',
|
||||||
|
'tk' => 'Tokelau',
|
||||||
|
'to' => 'Tonga',
|
||||||
|
'tt' => 'Trinidad and Tobago',
|
||||||
|
'tn' => 'Tunisia',
|
||||||
|
'tr' => 'Turkey',
|
||||||
|
'tm' => 'Turkmenistan',
|
||||||
|
'tc' => 'Turks and Caicos Islands',
|
||||||
|
'tv' => 'Tuvalu',
|
||||||
|
'um' => 'U.S. Minor Outlying Islands',
|
||||||
|
'pu' => 'U.S. Miscellaneous Pacific Islands',
|
||||||
|
'vi' => 'U.S. Virgin Islands',
|
||||||
|
'ug' => 'Uganda',
|
||||||
|
'ua' => 'Ukraine',
|
||||||
|
'su' => 'Union of Soviet Socialist Republics',
|
||||||
|
'ae' => 'United Arab Emirates',
|
||||||
|
'en' => 'United Kingdom (EN)',
|
||||||
|
'uk' => 'United Kingdom (UK)',
|
||||||
|
'gb' => 'United Kingdom (GB)',
|
||||||
|
'us' => 'United States',
|
||||||
|
'zz' => 'Unknown or Invalid Region',
|
||||||
|
'uy' => 'Uruguay',
|
||||||
|
'uz' => 'Uzbekistan',
|
||||||
|
'vu' => 'Vanuatu',
|
||||||
|
'va' => 'Vatican City',
|
||||||
|
've' => 'Venezuela',
|
||||||
|
'vn' => 'Vietnam',
|
||||||
|
'wk' => 'Wake Island',
|
||||||
|
'wf' => 'Wallis and Futuna',
|
||||||
|
'eh' => 'Western Sahara',
|
||||||
|
'ye' => 'Yemen',
|
||||||
|
'zm' => 'Zambia',
|
||||||
|
'zw' => 'Zimbabwe',
|
||||||
|
'ax' => 'Åland Islands',
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($key && array_key_exists($key, $arr)) {
|
||||||
|
return $arr[strtolower($key)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (!function_exists('languages')) {
|
if (!function_exists('languages')) {
|
||||||
function languages()
|
function languages(): array
|
||||||
{
|
{
|
||||||
$languages = [
|
$languages = [
|
||||||
'en'
|
'en'
|
||||||
|
|||||||
80
app/Http/Controllers/Admin/AlertController.php
Normal file
80
app/Http/Controllers/Admin/AlertController.php
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Models\Alert;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Admin\AlertRequest;
|
||||||
|
|
||||||
|
class AlertController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return inertia('Admin/Alerts/Index', [
|
||||||
|
'alerts' => Alert::query()->latest()->paginate()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
return inertia('Admin/Alerts/Create');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(AlertRequest $request)
|
||||||
|
{
|
||||||
|
Alert::create($request->all());
|
||||||
|
|
||||||
|
return redirect()->route('admin.alerts.index');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for editing the specified resource.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function edit($id)
|
||||||
|
{
|
||||||
|
return inertia('Admin/Alerts/Edit', [
|
||||||
|
'alert' => Alert::findOrFail($id)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function update(AlertRequest $request, $id)
|
||||||
|
{
|
||||||
|
Alert::findOrFail($id)->update($request->all());
|
||||||
|
|
||||||
|
return redirect()->route('admin.alerts.index');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
Alert::findOrFail($id)->delete();
|
||||||
|
|
||||||
|
return redirect()->route('admin.alerts.index');
|
||||||
|
}
|
||||||
|
}
|
||||||
98
app/Http/Controllers/Admin/ApplicationLogController.php
Normal file
98
app/Http/Controllers/Admin/ApplicationLogController.php
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
|
class ApplicationLogController extends Controller
|
||||||
|
{
|
||||||
|
protected $final = [];
|
||||||
|
protected $config = [
|
||||||
|
'date' => null
|
||||||
|
];
|
||||||
|
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
$this->config['date'] = date('Y-m-d');
|
||||||
|
|
||||||
|
if ($date = $request->input('date')) {
|
||||||
|
$this->config['date'] = $date;
|
||||||
|
} else {
|
||||||
|
$request->merge(['date' => date('Y-m-d')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return inertia('Admin/ApplicationLogs', [
|
||||||
|
'logData' => $this->get(),
|
||||||
|
'filters' => $request->all('date')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLogFileDates()
|
||||||
|
{
|
||||||
|
$dates = [];
|
||||||
|
$files = glob(storage_path('logs/laravel-*.log'));
|
||||||
|
$files = array_reverse($files);
|
||||||
|
|
||||||
|
foreach ($files as $path) {
|
||||||
|
$fileName = basename($path);
|
||||||
|
preg_match('/(?<=laravel-)(.*)(?=.log)/', $fileName, $dtMatch);
|
||||||
|
$date = $dtMatch[0];
|
||||||
|
array_push($dates, $date);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get()
|
||||||
|
{
|
||||||
|
$availableDates = $this->getLogFileDates();
|
||||||
|
|
||||||
|
if (count($availableDates) == 0) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'No log available'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$configDate = $this->config['date'];
|
||||||
|
if ($configDate == null) {
|
||||||
|
$configDate = $availableDates[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($configDate, $availableDates)) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'No log file found with selected date ' . $configDate
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pattern = "/^\[(?<date>.*)\]\s(?<env>\w+)\.(?<type>\w+):(?<message>.*)/m";
|
||||||
|
|
||||||
|
$fileName = 'laravel-' . $configDate . '.log';
|
||||||
|
$content = file_get_contents(storage_path('logs/' . $fileName));
|
||||||
|
preg_match_all($pattern, $content, $matches, PREG_SET_ORDER, 0);
|
||||||
|
|
||||||
|
$logs = [];
|
||||||
|
foreach ($matches as $match) {
|
||||||
|
$logs[] = [
|
||||||
|
'timestamp' => $match['date'],
|
||||||
|
'env' => $match['env'],
|
||||||
|
'type' => $match['type'],
|
||||||
|
'message' => trim($match['message'])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
preg_match('/(?<=laravel-)(.*)(?=.log)/', $fileName, $dtMatch);
|
||||||
|
$date = $dtMatch[0];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'available_dates' => $availableDates,
|
||||||
|
'date' => $date,
|
||||||
|
'filename' => $fileName,
|
||||||
|
'logs' => array_reverse($logs)
|
||||||
|
];
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,14 +10,17 @@ use App\Http\Controllers\Controller;
|
|||||||
|
|
||||||
class DashboardController extends Controller
|
class DashboardController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function __invoke()
|
||||||
{
|
{
|
||||||
return inertia('Admin/Dashboard', [
|
return inertia('Admin/Dashboard', [
|
||||||
'servers' => Server::count(),
|
'servers' => Server::count(),
|
||||||
'sites' => Site::count(),
|
'sites' => Site::count(),
|
||||||
'users' => User::count(),
|
'users' => User::count(),
|
||||||
'logs' => SystemLog::latest()->limit(10)->with('model')->get()
|
'logs' => SystemLog::query()
|
||||||
->map(function (SystemLog $systemLog) {
|
->latest()
|
||||||
|
->with('model')
|
||||||
|
->paginate(5)
|
||||||
|
->through(function (SystemLog $systemLog) {
|
||||||
return [
|
return [
|
||||||
'title' => __($systemLog->title, [
|
'title' => __($systemLog->title, [
|
||||||
'site' => $systemLog->model->domain ?? '-Unknown-'
|
'site' => $systemLog->model->domain ?? '-Unknown-'
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Models\DocumentationItem;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\DocumentationCategory;
|
||||||
|
use App\Http\Requests\Admin\DocumentationArticleRequest;
|
||||||
|
|
||||||
|
class DocumentationArticleController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$articles = DocumentationItem::query()->with('category:id,title')->latest()->paginate();
|
||||||
|
|
||||||
|
return inertia('Admin/Documentation/Articles/Index', [
|
||||||
|
'articles' => $articles
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$categories = DocumentationCategory::pluck('title', 'id');
|
||||||
|
|
||||||
|
return inertia('Admin/Documentation/Articles/Create', [
|
||||||
|
'categories' => $categories,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(DocumentationArticleRequest $request)
|
||||||
|
{
|
||||||
|
$article = DocumentationItem::create([
|
||||||
|
'title' => $request->input('title'),
|
||||||
|
'content' => $request->input('content')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$article->documentation_category_id = $request->input('category_id');
|
||||||
|
$article->save();
|
||||||
|
|
||||||
|
return redirect()->route('admin.documentation.articles.index')->with('success', __('Documentation article has been created'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit($id)
|
||||||
|
{
|
||||||
|
$article = DocumentationItem::findOrFail($id);
|
||||||
|
|
||||||
|
$categories = DocumentationCategory::pluck('title', 'id');
|
||||||
|
|
||||||
|
return inertia('Admin/Documentation/Articles/Edit', [
|
||||||
|
'article' => $article,
|
||||||
|
'categories' => $categories
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(DocumentationArticleRequest $request, $id)
|
||||||
|
{
|
||||||
|
$article = DocumentationItem::findOrFail($id);
|
||||||
|
|
||||||
|
$article->update([
|
||||||
|
'title' => $request->input('title'),
|
||||||
|
'content' => $request->input('content')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$article->documentation_category_id = $request->input('category_id');
|
||||||
|
$article->save();
|
||||||
|
|
||||||
|
return redirect()->route('admin.documentation.articles.index')->with('success', __('Documentation article has been updated'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,53 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\DocumentationCategory;
|
||||||
|
use App\Http\Requests\Admin\DocumentationCategoryRequest;
|
||||||
|
|
||||||
class DocumentationController extends Controller
|
class DocumentationController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return inertia('Admin/Documentation/Index');
|
$categories = DocumentationCategory::query()->latest()->paginate();
|
||||||
|
|
||||||
|
return inertia('Admin/Documentation/Index', [
|
||||||
|
'categories' => $categories
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
return inertia('Admin/Documentation/Create');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(DocumentationCategoryRequest $request)
|
||||||
|
{
|
||||||
|
DocumentationCategory::create([
|
||||||
|
'title' => $request->input('title'),
|
||||||
|
'description' => $request->input('description')
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect()->route('admin.documentation.index')->with('success', __('Documentation category has been created'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit($id)
|
||||||
|
{
|
||||||
|
$category = DocumentationCategory::findOrFail($id);
|
||||||
|
|
||||||
|
return inertia('Admin/Documentation/Edit', [
|
||||||
|
'category' => $category
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(DocumentationCategoryRequest $request, $id)
|
||||||
|
{
|
||||||
|
$category = DocumentationCategory::findOrFail($id);
|
||||||
|
|
||||||
|
$category->update([
|
||||||
|
'title' => $request->input('title'),
|
||||||
|
'description' => $request->input('description'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect()->route('admin.documentation.index')->with('success', __('Documentation category has been updated'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Models\Package;
|
use App\Models\Package;
|
||||||
|
use App\Models\Provider;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Admin\PackageRequest;
|
use App\Http\Requests\Admin\PackageRequest;
|
||||||
|
|
||||||
@@ -19,25 +20,32 @@ class PackageController extends Controller
|
|||||||
|
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
return inertia('Admin/Packages/Create');
|
$providers = Provider::get(['name', 'label', 'id'])->pluck('nameWithLabel', 'id');
|
||||||
|
|
||||||
|
return inertia('Admin/Packages/Create', [
|
||||||
|
'providers' => $providers
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(PackageRequest $request)
|
public function store(PackageRequest $request)
|
||||||
{
|
{
|
||||||
Package::create($request->all());
|
$package = Package::create($request->validated());
|
||||||
|
|
||||||
return redirect()->route('admin.packages.index')->with('success', 'Package has been created');
|
$package->providers()->sync($request->input('providers'));
|
||||||
}
|
|
||||||
|
|
||||||
public function show($id)
|
return redirect()->route('admin.packages.index')->with('success', __('Package has been created'));
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
|
$package = Package::with('providers:id')->findOrFail($id);
|
||||||
|
|
||||||
|
$providers = Provider::get(['name', 'label', 'id'])->pluck('nameWithLabel', 'id');
|
||||||
|
|
||||||
return inertia('Admin/Packages/Edit', [
|
return inertia('Admin/Packages/Edit', [
|
||||||
'package' => Package::findOrFail($id)
|
'package' => $package,
|
||||||
|
'providers' => $providers,
|
||||||
|
'syncedProviders' => $package->providers->pluck('id')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +55,9 @@ class PackageController extends Controller
|
|||||||
|
|
||||||
$package->update($request->validated());
|
$package->update($request->validated());
|
||||||
|
|
||||||
return redirect()->route('admin.packages.index')->with('success', 'Package has been updated');
|
$package->providers()->sync($request->input('providers'));
|
||||||
|
|
||||||
|
return redirect()->route('admin.packages.index')->with('success', __('Package has been updated'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
@@ -56,6 +66,6 @@ class PackageController extends Controller
|
|||||||
|
|
||||||
$package->delete();
|
$package->delete();
|
||||||
|
|
||||||
return redirect()->route('admin.packages.index')->with('success', 'Package has been removed');
|
return redirect()->route('admin.packages.index')->with('success', __('Package has been removed'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,38 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Models\Provider;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Admin\ProviderRequest;
|
||||||
|
|
||||||
class ProviderController extends Controller
|
class ProviderController extends Controller
|
||||||
{
|
{
|
||||||
//
|
public function edit($id)
|
||||||
|
{
|
||||||
|
$provider = Provider::findOrFail($id);
|
||||||
|
|
||||||
|
return inertia('Admin/Services/Provider/Edit', [
|
||||||
|
'provider' => $provider,
|
||||||
|
'availablePlans' => $provider->plans()->pluck('label', 'id'),
|
||||||
|
'availableRegions' => $provider->regions()->pluck('label', 'id'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(ProviderRequest $request, $id)
|
||||||
|
{
|
||||||
|
$provider = Provider::findOrFail($id);
|
||||||
|
|
||||||
|
$provider->update($request->validated());
|
||||||
|
|
||||||
|
return redirect()->route('admin.services.index')->with('success', __('Provider has been updated'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$provider = Provider::findOrFail($id);
|
||||||
|
|
||||||
|
$provider->delete();
|
||||||
|
|
||||||
|
return redirect()->route('admin.services.index')->with('success', __('Provider has been deleted'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Requests\Admin\ServerAttachRequest;
|
|
||||||
use App\Models\Server;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\Server;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Admin\ServerAttachRequest;
|
||||||
|
|
||||||
class ServerController extends Controller
|
class ServerController extends Controller
|
||||||
{
|
{
|
||||||
@@ -14,7 +14,7 @@ class ServerController extends Controller
|
|||||||
{
|
{
|
||||||
$server = Server::findOrFail($id);
|
$server = Server::findOrFail($id);
|
||||||
|
|
||||||
$users = $server->users()->select('id', 'name', 'email')->get()->map(function($user){
|
$users = $server->users()->select('id', 'name', 'email')->get()->map(function ($user) {
|
||||||
return [
|
return [
|
||||||
'id' => $user->id,
|
'id' => $user->id,
|
||||||
'name' => $user->name,
|
'name' => $user->name,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Provider;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
class ServiceController extends Controller
|
class ServiceController extends Controller
|
||||||
@@ -11,8 +12,12 @@ class ServiceController extends Controller
|
|||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return inertia('Admin/Services/Index', [
|
return inertia('Admin/Services/Index', [
|
||||||
'servers' => Server::withCount('sites')->latest()->paginate(5, ['*'], 'servers_per_page'),
|
'servers' => Server::query()->withCount('sites', 'users')->latest()->paginate(config('core.pagination.per_page'), ['*'], 'servers_per_page'),
|
||||||
'sites' => Site::with('server:id,name')->latest()->paginate(5, ['*'], 'sites_per_page'),
|
'sites' => Site::with('server:id,name')->withCount('users')->latest()->paginate(config('core.pagination.per_page'), ['*'], 'sites_per_page'),
|
||||||
|
'providers' => Provider::query()
|
||||||
|
->withCount('regions', 'plans', 'servers')
|
||||||
|
->latest()
|
||||||
|
->paginate(config('core.pagination.per_page'), ['*'], 'providers_per_page'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,10 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Models\Package;
|
use App\Models\Package;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use App\Http\Requests\Admin\SettingRequest;
|
use App\Http\Requests\Admin\SettingRequest;
|
||||||
|
|
||||||
class SettingController extends Controller
|
class SettingController extends Controller
|
||||||
@@ -18,15 +21,21 @@ class SettingController extends Controller
|
|||||||
'documentation' => setting('documentation'),
|
'documentation' => setting('documentation'),
|
||||||
'allow_registration' => setting('allow_registration'),
|
'allow_registration' => setting('allow_registration'),
|
||||||
'default_package' => setting('default_package'),
|
'default_package' => setting('default_package'),
|
||||||
|
'receive_email_on_server_creation' => setting('receive_email_on_server_creation'),
|
||||||
|
'isolate_per_site_per_user' => setting('isolate_per_site_per_user'),
|
||||||
'enable_api' => setting('enable_api'),
|
'enable_api' => setting('enable_api'),
|
||||||
'api_token' => setting('api_token') ? decrypt(setting('api_token')) : null,
|
'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'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$packages = Package::pluck('name', 'id');
|
$packages = Package::pluck('name', 'id');
|
||||||
|
|
||||||
return inertia('Admin/Settings', [
|
return inertia('Admin/Settings', [
|
||||||
'company_settings' => $settings,
|
'company_settings' => $settings,
|
||||||
'packages' => $packages
|
'packages' => $packages,
|
||||||
|
'languages' => languages()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,18 +49,93 @@ class SettingController extends Controller
|
|||||||
'allow_registration',
|
'allow_registration',
|
||||||
'documentation',
|
'documentation',
|
||||||
'default_package',
|
'default_package',
|
||||||
|
'receive_email_on_server_creation',
|
||||||
|
'isolate_per_site_per_user',
|
||||||
'enable_api',
|
'enable_api',
|
||||||
'api_token',
|
'api_token',
|
||||||
|
'default_language',
|
||||||
|
'rotate_logs_after',
|
||||||
]) as $key => $value) {
|
]) as $key => $value) {
|
||||||
if ($key === 'api_token') {
|
if ($key === 'api_token') {
|
||||||
$value = encrypt($value);
|
$value = encrypt($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($key === 'default_package' && $value === 'false') {
|
||||||
|
$value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value === 'false') {
|
||||||
|
$value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value === 'true') {
|
||||||
|
$value = 1;
|
||||||
|
}
|
||||||
|
|
||||||
setting([$key => $value]);
|
setting([$key => $value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($logo = $request->file('logo')) {
|
||||||
|
// If we previously had a logo, rotate that
|
||||||
|
if ($oldLogo = setting('logo')) {
|
||||||
|
Storage::delete(str_replace('/storage/', '/public/', $oldLogo));
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = Str::random();
|
||||||
|
|
||||||
|
$request->file('logo')->storePubliclyAs('logo', 'logo-' . $version . '.' . $request->file('logo')->extension(), 'public');
|
||||||
|
setting(['logo' => '/storage/logo/logo-' . $version . '.' . $request->file('logo')->extension()]);
|
||||||
|
}
|
||||||
|
|
||||||
cache()->forget('core.settings');
|
cache()->forget('core.settings');
|
||||||
|
|
||||||
return redirect()->route('admin.settings')->with('success', __('Settings have been updated'));
|
return redirect()->route('admin.settings')->with('success', __('Settings have been updated'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function terms()
|
||||||
|
{
|
||||||
|
return inertia('Admin/Terms', [
|
||||||
|
'terms_settings' => [
|
||||||
|
'logo' => setting('logo'),
|
||||||
|
'name' => setting('name'),
|
||||||
|
'terms_required' => setting('accept_terms_required'),
|
||||||
|
'terms' => setting('terms'),
|
||||||
|
'privacy' => setting('privacy')
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateTerms(Request $request)
|
||||||
|
{
|
||||||
|
setting(['accept_terms_required' => $request->input('terms_required'),]);
|
||||||
|
setting(['terms' => $request->input('terms'),]);
|
||||||
|
setting(['privacy' => $request->input('privacy'),]);
|
||||||
|
|
||||||
|
return redirect()->route('admin.settings.terms')->with('success', __('Terms have been updated'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function termsTemplate(Request $request)
|
||||||
|
{
|
||||||
|
$template = file_get_contents(storage_path('templates/terms-of-service.md'));
|
||||||
|
$template = str_replace([
|
||||||
|
'{NAME}',
|
||||||
|
'{WEBSITE}',
|
||||||
|
'{DATE}'
|
||||||
|
], [
|
||||||
|
setting('name'),
|
||||||
|
config('app.url'),
|
||||||
|
date('Y-m-d')
|
||||||
|
], $template);
|
||||||
|
|
||||||
|
return ['content' => $template];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeLogo(Request $request)
|
||||||
|
{
|
||||||
|
Storage::delete(setting('logo'));
|
||||||
|
|
||||||
|
setting(['logo' => null]);
|
||||||
|
|
||||||
|
return redirect()->back()->with('success', 'Logo has ben removed');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Requests\Admin\ServerAttachRequest;
|
|
||||||
use App\Models\Server;
|
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Admin\ServerAttachRequest;
|
||||||
|
|
||||||
class SiteController extends Controller
|
class SiteController extends Controller
|
||||||
{
|
{
|
||||||
@@ -15,7 +14,7 @@ class SiteController extends Controller
|
|||||||
{
|
{
|
||||||
$site = Site::findOrFail($id);
|
$site = Site::findOrFail($id);
|
||||||
|
|
||||||
$users = $site->users()->select('id', 'name', 'email')->get()->map(function($user){
|
$users = $site->users()->select('id', 'name', 'email')->get()->map(function ($user) {
|
||||||
return [
|
return [
|
||||||
'id' => $user->id,
|
'id' => $user->id,
|
||||||
'name' => $user->name,
|
'name' => $user->name,
|
||||||
|
|||||||
56
app/Http/Controllers/Admin/SynchronizeProviderController.php
Normal file
56
app/Http/Controllers/Admin/SynchronizeProviderController.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Models\Provider;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
|
class SynchronizeProviderController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
if ($this->isDemo()) {
|
||||||
|
return redirect('/')->with('info', __('This feature is not available in demo mode.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$availableProviders = $this->getPloi()->user()->serverProviders()->getData();
|
||||||
|
|
||||||
|
$currentProviders = Provider::query()
|
||||||
|
->whereNotIn('id', array_keys((array)$availableProviders))
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return inertia('Admin/Services/Providers', [
|
||||||
|
'availableProviders' => $availableProviders,
|
||||||
|
'currentProviders' => $currentProviders
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function synchronize(Request $request, $providerId)
|
||||||
|
{
|
||||||
|
$ploiProvider = $this->getPloi()->user()->serverProviders($providerId)->getData();
|
||||||
|
|
||||||
|
$provider = Provider::updateOrCreate([
|
||||||
|
'ploi_id' => $ploiProvider->id,
|
||||||
|
], [
|
||||||
|
'label' => $ploiProvider->label,
|
||||||
|
'name' => $ploiProvider->name
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($ploiProvider->provider->plans as $plan) {
|
||||||
|
$provider->plans()->updateOrCreate([
|
||||||
|
'plan_id' => $plan->id
|
||||||
|
], [
|
||||||
|
'label' => $plan->name,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($ploiProvider->provider->regions as $region) {
|
||||||
|
$provider->regions()->updateOrCreate([
|
||||||
|
'region_id' => $region->id
|
||||||
|
], [
|
||||||
|
'label' => $region->name,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Services\Ploi\Ploi;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
@@ -11,15 +10,15 @@ class SynchronizeServerController extends Controller
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
if (config('app.demo')) {
|
if ($this->isDemo()) {
|
||||||
return redirect('/')->with('info', __('This feature is not available in demo mode.'));
|
return redirect('/')->with('info', __('This feature is not available in demo mode.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$availableServers = $this->getPloi()->synchronize()->servers()->getData();
|
||||||
|
|
||||||
$availableServers = $ploi->synchronize()->servers()->getData();
|
$currentServers = Server::query()
|
||||||
|
->whereNotIn('id', array_keys((array)$availableServers))
|
||||||
$currentServers = Server::whereNotIn('id', array_keys((array)$availableServers))->get();
|
->get();
|
||||||
|
|
||||||
return inertia('Admin/Services/Servers', [
|
return inertia('Admin/Services/Servers', [
|
||||||
'availableServers' => $availableServers,
|
'availableServers' => $availableServers,
|
||||||
@@ -29,15 +28,37 @@ class SynchronizeServerController extends Controller
|
|||||||
|
|
||||||
public function synchronizeServer(Request $request)
|
public function synchronizeServer(Request $request)
|
||||||
{
|
{
|
||||||
Server::updateOrCreate([
|
Server::query()
|
||||||
'ploi_id' => $request->input('id')
|
->updateOrCreate([
|
||||||
], [
|
'ploi_id' => $request->input('id')
|
||||||
'status' => $request->input('status'),
|
], [
|
||||||
'name' => $request->input('name'),
|
'status' => $request->input('status'),
|
||||||
'ip' => $request->input('ip_address'),
|
'name' => $request->input('name'),
|
||||||
'ssh_port' => $request->input('ssh_port', 22),
|
'ip' => $request->input('ip_address'),
|
||||||
'internal_ip' => $request->input('internal_ip'),
|
'ssh_port' => $request->input('ssh_port', 22),
|
||||||
'available_php_versions' => $request->input('installed_php_versions')
|
'internal_ip' => $request->input('internal_ip'),
|
||||||
]);
|
'available_php_versions' => $request->input('installed_php_versions')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function synchronizeAll(Request $request)
|
||||||
|
{
|
||||||
|
$availableServers = $this->getPloi()->synchronize()->servers()->getData();
|
||||||
|
|
||||||
|
foreach ($availableServers as $availableServer) {
|
||||||
|
Server::query()
|
||||||
|
->updateOrCreate([
|
||||||
|
'ploi_id' => $availableServer->id
|
||||||
|
], [
|
||||||
|
'status' => $availableServer->status,
|
||||||
|
'name' => $availableServer->name,
|
||||||
|
'ip' => $availableServer->ip_address,
|
||||||
|
'ssh_port' => $availableServer->ssh_port,
|
||||||
|
'internal_ip' => $availableServer->internal_ip,
|
||||||
|
'available_php_versions' => $availableServer->installed_php_versions
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response('ok');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,85 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Models\Site;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
class SynchronizeSiteController extends Controller
|
class SynchronizeSiteController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return inertia('Admin/Services/Sites');
|
if ($this->isDemo()) {
|
||||||
|
return redirect('/')->with('info', __('This feature is not available in demo mode.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$availableSites = $this->getPloi()->synchronize()->sites()->getData();
|
||||||
|
|
||||||
|
$currentSites = Site::query()
|
||||||
|
->whereNotIn('id', array_keys((array)$availableSites))
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return inertia('Admin/Services/Sites', [
|
||||||
|
'availableSites' => $availableSites,
|
||||||
|
'currentSites' => $currentSites
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function synchronizeSite(Request $request)
|
||||||
|
{
|
||||||
|
$server = Server::query()->where('ploi_id', $request->input('server_id'))->firstOrFail();
|
||||||
|
|
||||||
|
/* @var $site \App\Models\Site */
|
||||||
|
$site = Site::query()
|
||||||
|
->updateOrCreate([
|
||||||
|
'ploi_id' => $request->input('id')
|
||||||
|
], [
|
||||||
|
'domain' => $request->input('domain'),
|
||||||
|
'php_version' => $request->input('php_version'),
|
||||||
|
'project' => $request->input('project_type')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$site->status = $request->input('status');
|
||||||
|
$site->server_id = $server->id;
|
||||||
|
$site->save();
|
||||||
|
|
||||||
|
$certificates = $this->getPloi()->server($request->input('server_id'))->sites($request->input('id'))->certificates()->get()->getData();
|
||||||
|
|
||||||
|
if ($certificates) {
|
||||||
|
foreach ($certificates as $certificate) {
|
||||||
|
$site->certificates()->updateOrCreate([
|
||||||
|
'ploi_id' => $certificate->id,
|
||||||
|
], [
|
||||||
|
'status' => $certificate->status,
|
||||||
|
'ploi_id' => $certificate->id,
|
||||||
|
'domain' => $certificate->domain,
|
||||||
|
'type' => $certificate->type,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response('ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function synchronizeAll(Request $request)
|
||||||
|
{
|
||||||
|
$availableSites = $this->getPloi()->synchronize()->sites()->getData();
|
||||||
|
|
||||||
|
foreach ($availableSites as $availableSite) {
|
||||||
|
$server = Server::query()->where('ploi_id', $availableSite->server_id)->firstOrFail();
|
||||||
|
|
||||||
|
$site = Site::query()
|
||||||
|
->updateOrCreate([
|
||||||
|
'ploi_id' => $availableSite->server_id
|
||||||
|
], [
|
||||||
|
'domain' => $availableSite->domain,
|
||||||
|
'php_version' => $availableSite->php_version,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$site->status = $availableSite->status;
|
||||||
|
$site->server_id = $server->id;
|
||||||
|
$site->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,19 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use App\Jobs\Core\UpdateSystem;
|
use App\Jobs\Core\UpdateSystem;
|
||||||
use App\Services\VersionChecker;
|
use App\Services\VersionChecker;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
|
||||||
|
|
||||||
class SystemController extends Controller
|
class SystemController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index(MasterSupervisorRepository $masterSupervisorRepository)
|
||||||
{
|
{
|
||||||
if (config('app.demo')) {
|
|
||||||
return redirect('/')->with('info', __('This feature is not available in demo mode.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$version = (new VersionChecker)->getVersions();
|
$version = (new VersionChecker)->getVersions();
|
||||||
|
|
||||||
return inertia('Admin/System', [
|
return inertia('Admin/System', [
|
||||||
@@ -22,7 +19,8 @@ class SystemController extends Controller
|
|||||||
'out_of_date' => $version->isOutOfDate(),
|
'out_of_date' => $version->isOutOfDate(),
|
||||||
'current' => $version->currentVersion,
|
'current' => $version->currentVersion,
|
||||||
'remote' => $version->remoteVersion
|
'remote' => $version->remoteVersion
|
||||||
]
|
],
|
||||||
|
'horizonRunning' => !!$masterSupervisorRepository->all()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ class UserController extends Controller
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$users = User::with('package:id,name')
|
$users = User::query()
|
||||||
|
->withCount('sites', 'servers')
|
||||||
|
->with('package:id,name')
|
||||||
->when(request()->input('search'), function ($query, $value) {
|
->when(request()->input('search'), function ($query, $value) {
|
||||||
return $query->where('name', 'like', '%' . $value . '%')->orWhere('email', 'like', '%' . $value . '%');
|
return $query->where('name', 'like', '%' . $value . '%')->orWhere('email', 'like', '%' . $value . '%');
|
||||||
})
|
})
|
||||||
->latest()
|
->latest()
|
||||||
->paginate(5);
|
->paginate(config('core.pagination.per_page'));
|
||||||
|
|
||||||
return inertia('Admin/Users/Index', [
|
return inertia('Admin/Users/Index', [
|
||||||
'filters' => request()->all('search'),
|
'filters' => request()->all('search'),
|
||||||
@@ -31,7 +33,8 @@ class UserController extends Controller
|
|||||||
return inertia('Admin/Users/Create', [
|
return inertia('Admin/Users/Create', [
|
||||||
'packages' => $packages,
|
'packages' => $packages,
|
||||||
'languages' => languages(),
|
'languages' => languages(),
|
||||||
'defaultPackage' => (string)setting('default_package')
|
'defaultPackage' => (string)setting('default_package'),
|
||||||
|
'defaultLanguage' => (string)setting('default_language', 'en'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,8 +47,8 @@ class UserController extends Controller
|
|||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($package = $request->input('package')) {
|
if ($request->input('package') && Package::find($request->input('package'))) {
|
||||||
$user->package_id = $package;
|
$user->package_id = $request->input('package');
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +57,17 @@ class UserController extends Controller
|
|||||||
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
//
|
$user = User::query()->findOrFail($id);
|
||||||
|
|
||||||
|
$servers = $user->servers()->withCount('sites')->latest()->paginate(config('core.pagination.per_page'), ['*'], 'page_servers');
|
||||||
|
|
||||||
|
$sites = $user->sites()->with('server:id,name')->latest()->paginate(config('core.pagination.per_page'), ['*'], 'page_sites');
|
||||||
|
|
||||||
|
return inertia('Admin/Users/Show', [
|
||||||
|
'user' => $user,
|
||||||
|
'sites' => $sites,
|
||||||
|
'servers' => $servers,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Api\UserRequest;
|
use App\Http\Requests\Api\UserRequest;
|
||||||
use App\Http\Resources\Api\UserResource;
|
use App\Http\Resources\Api\UserResource;
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use Illuminate\Http\Request;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Providers\RouteServiceProvider;
|
use App\Providers\RouteServiceProvider;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rules\Password;
|
||||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||||
|
|
||||||
class RegisterController extends Controller
|
class RegisterController extends Controller
|
||||||
@@ -27,11 +28,27 @@ class RegisterController extends Controller
|
|||||||
|
|
||||||
protected function validator(array $data)
|
protected function validator(array $data)
|
||||||
{
|
{
|
||||||
return Validator::make($data, [
|
$rules = [
|
||||||
'name' => ['required', 'string', 'max:255'],
|
'name' => ['required', 'string', 'max:255'],
|
||||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
'password' => [
|
||||||
]);
|
'required',
|
||||||
|
'string',
|
||||||
|
'confirmed',
|
||||||
|
Password::min(6)
|
||||||
|
->letters()
|
||||||
|
->numbers()
|
||||||
|
->uncompromised()
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (setting('accept_terms_required')) {
|
||||||
|
$rules['terms'] = [
|
||||||
|
'accepted'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Validator::make($data, $rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function create(array $data)
|
protected function create(array $data)
|
||||||
@@ -45,8 +62,8 @@ class RegisterController extends Controller
|
|||||||
|
|
||||||
protected function registered(Request $request, $user)
|
protected function registered(Request $request, $user)
|
||||||
{
|
{
|
||||||
if ($defaultPackage = setting('default_package')) {
|
if (setting('default_package') && setting('default_package') != 'false') {
|
||||||
$user->package_id = $defaultPackage;
|
$user->package_id = setting('default_package');
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,17 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Routing\Controller as BaseController;
|
use Illuminate\Routing\Controller as BaseController;
|
||||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
|
|
||||||
class Controller extends BaseController
|
class Controller extends BaseController
|
||||||
{
|
{
|
||||||
use ValidatesRequests, AuthorizesRequests;
|
use ValidatesRequests, AuthorizesRequests, HasPloi;
|
||||||
|
|
||||||
|
protected function isDemo()
|
||||||
|
{
|
||||||
|
return config('app.demo');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ class DashboardController extends Controller
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$package = auth()->user()->package;
|
|
||||||
|
|
||||||
$logs = auth()->user()->systemLogs()
|
$logs = auth()->user()->systemLogs()
|
||||||
->with('model')
|
->with('model')
|
||||||
->latest()
|
->latest()
|
||||||
@@ -31,9 +29,6 @@ class DashboardController extends Controller
|
|||||||
return inertia('Dashboard/Index', [
|
return inertia('Dashboard/Index', [
|
||||||
'sites' => auth()->user()->sites()->count(),
|
'sites' => auth()->user()->sites()->count(),
|
||||||
'servers' => auth()->user()->servers()->count(),
|
'servers' => auth()->user()->servers()->count(),
|
||||||
'package' => [
|
|
||||||
'name' => $package->name ?? 'None'
|
|
||||||
],
|
|
||||||
'logs' => $logs,
|
'logs' => $logs,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,43 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use App\Models\DocumentationItem;
|
use App\Models\DocumentationItem;
|
||||||
use App\Http\Resources\DocumentationItemResource;
|
use App\Models\DocumentationCategory;
|
||||||
|
use App\Http\Resources\DocumentationCategoryRouteResource;
|
||||||
|
|
||||||
class DocumentationController extends Controller
|
class DocumentationController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$documentationItems = DocumentationItem::latest()->paginate();
|
$items = DocumentationCategory::query()->oldest()->get();
|
||||||
|
|
||||||
return inertia('Documentation/Index', [
|
return inertia('Documentation/Index', [
|
||||||
'items' => DocumentationItemResource::collection($documentationItems)
|
'items' => DocumentationCategoryRouteResource::collection($items)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(DocumentationCategory $documentationCategory)
|
||||||
|
{
|
||||||
|
$items = DocumentationCategory::query()->oldest()->get();
|
||||||
|
|
||||||
|
return inertia('Documentation/Show', [
|
||||||
|
'category' => $documentationCategory,
|
||||||
|
'articles' => $documentationCategory->items()->latest()->get(),
|
||||||
|
'items' => DocumentationCategoryRouteResource::collection($items)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showArticle(DocumentationCategory $documentationCategory, DocumentationItem $documentationItem)
|
||||||
|
{
|
||||||
|
$items = DocumentationCategory::query()->oldest()->get();
|
||||||
|
|
||||||
|
$documentationItem->content = Str::markdown($documentationItem->content);
|
||||||
|
|
||||||
|
return inertia('Documentation/Article', [
|
||||||
|
'category' => $documentationCategory,
|
||||||
|
'article' => $documentationItem,
|
||||||
|
'items' => DocumentationCategoryRouteResource::collection($items)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,29 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class PageController extends Controller
|
class PageController extends Controller
|
||||||
{
|
{
|
||||||
public function installationIncomplete()
|
public function installationIncomplete()
|
||||||
{
|
{
|
||||||
return inertia('Core/InstallationIncomplete');
|
return inertia('Core/InstallationIncomplete');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function show($slug)
|
||||||
|
{
|
||||||
|
if ($slug === 'terms-of-service' && setting('terms')) {
|
||||||
|
return inertia('Pages/Terms', [
|
||||||
|
'content' => Str::markdown(setting('terms'))
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($slug === 'privacy-policy' && setting('privacy')) {
|
||||||
|
return inertia('Pages/Privacy', [
|
||||||
|
'content' => Str::markdown(setting('privacy'))
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
231
app/Http/Controllers/Profile/ProfileBillingController.php
Normal file
231
app/Http/Controllers/Profile/ProfileBillingController.php
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Profile;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Package;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Stripe\Exception\InvalidRequestException;
|
||||||
|
|
||||||
|
class ProfileBillingController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
/* @var $user User */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
|
$sortByType = array_key_first($request->input('sortBy', []));
|
||||||
|
|
||||||
|
$packages = Package::query()
|
||||||
|
->where(function ($query) {
|
||||||
|
return $query
|
||||||
|
->where(function ($query) {
|
||||||
|
return $query
|
||||||
|
->where('price_monthly', '>', 0)
|
||||||
|
->orWhere('price_yearly', '>', 0);
|
||||||
|
})
|
||||||
|
->whereNotNull('plan_id');
|
||||||
|
})
|
||||||
|
->when($request->input('sortBy.' . $sortByType), function ($query, $value) use ($sortByType) {
|
||||||
|
if ($sortByType === 'price') {
|
||||||
|
return $value === 'asc'
|
||||||
|
? $query->orderBy('price_monthly', 'asc')
|
||||||
|
: $query->orderBy('price_monthly', 'desc');
|
||||||
|
}
|
||||||
|
if ($sortByType === 'servers') {
|
||||||
|
return $value === 'asc'
|
||||||
|
? $query->orderBy('maximum_servers', 'asc')
|
||||||
|
: $query->orderBy('maximum_servers', 'desc');
|
||||||
|
}
|
||||||
|
if ($sortByType === 'sites') {
|
||||||
|
return $value === 'asc'
|
||||||
|
? $query->orderBy('maximum_sites', 'asc')
|
||||||
|
: $query->orderBy('maximum_sites', 'desc');
|
||||||
|
}
|
||||||
|
if ($sortByType === 'name') {
|
||||||
|
return $value === 'asc'
|
||||||
|
? $query->orderBy('name', 'asc')
|
||||||
|
: $query->orderBy('name', 'desc');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}, function ($query) {
|
||||||
|
return $query->orderBy('price_monthly', 'asc');
|
||||||
|
})
|
||||||
|
->get()
|
||||||
|
->transform(function (Package $package) {
|
||||||
|
$currency = $this->transformCurrency($package->currency);
|
||||||
|
|
||||||
|
$package->period = 'monthly';
|
||||||
|
|
||||||
|
if ($package->price_yearly > 0) {
|
||||||
|
$package->period = 'yearly';
|
||||||
|
}
|
||||||
|
|
||||||
|
$package->price_monthly = ($currency ?? '[Unknown currency]') . number_format($package->price_monthly, 2, ',', '.');
|
||||||
|
$package->price_yearly = ($currency ?? '[Unknown currency]') . number_format($package->price_yearly, 2, ',', '.');
|
||||||
|
|
||||||
|
return $package;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
$clientSecret = $user->createSetupIntent()->client_secret;
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
return inertia('Profile/BillingError');
|
||||||
|
}
|
||||||
|
|
||||||
|
$subscription = $user->subscription();
|
||||||
|
|
||||||
|
return inertia('Profile/Billing', [
|
||||||
|
'packages' => $packages,
|
||||||
|
'countries' => countries(),
|
||||||
|
'subscription' => $subscription,
|
||||||
|
'public_key' => config('cashier.key'),
|
||||||
|
'ends' => $subscription ? Carbon::createFromTimeStamp($subscription->asStripeSubscription()->current_period_end)->format('F jS, Y') ?? null : null,
|
||||||
|
'data_client_secret' => $clientSecret,
|
||||||
|
'card' => [
|
||||||
|
'last_four' => $user->card_last_four,
|
||||||
|
'brand' => $user->card_brand
|
||||||
|
],
|
||||||
|
'filters' => [
|
||||||
|
'sort' => [
|
||||||
|
$sortByType => $request->input('sortBy.' . $sortByType, 'asc'),
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateCard(Request $request)
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$user->createOrGetStripeCustomer([
|
||||||
|
'name' => $request->input('billing_details.name'),
|
||||||
|
'description' => 'Ploi Core Customer ' . $request->input('billing_details.name'),
|
||||||
|
'address' => [
|
||||||
|
'line1' => $request->input('billing_details.address.line1'),
|
||||||
|
'postal_code' => $request->input('billing_details.address.postal_code'),
|
||||||
|
'city' => $request->input('billing_details.address.city'),
|
||||||
|
'country' => $request->input('billing_details.address.country'),
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($user->paymentMethods() as $paymentMethod) {
|
||||||
|
$paymentMethod->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->addPaymentMethod($request->get('payment_method'));
|
||||||
|
$user->updateDefaultPaymentMethod($request->get('payment_method'));
|
||||||
|
$user->updateDefaultPaymentMethodFromStripe();
|
||||||
|
|
||||||
|
return redirect()->route('profile.billing.index')->with('success', 'Your card has been added, you can now update your plan');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteCard(Request $request)
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$user->deletePaymentMethods();
|
||||||
|
|
||||||
|
return redirect()->route('profile.billing.index')->with('success', 'Your credit card has been removed from your account');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatePlan(Request $request)
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
|
if (!$user->hasStripeId() || !$user->defaultPaymentMethod()) {
|
||||||
|
return redirect()->route('profile.billing.index')->with('error', 'You cannot change your plan without a valid creditcard, please update your billing details first');
|
||||||
|
}
|
||||||
|
|
||||||
|
$plan = Package::query()->findOrFail($request->input('plan'));
|
||||||
|
|
||||||
|
$planId = $plan->plan_id;
|
||||||
|
|
||||||
|
// Only do something if the user is not already subscribed to this plan.
|
||||||
|
if ($user->subscribedToPlan($planId, 'default')) {
|
||||||
|
return redirect()->route('profile.billing.index')->with('error', 'You did not select a different plan');
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the user is already subscribed to the default plan, we have to swap it. Otherwise create a new one.
|
||||||
|
try {
|
||||||
|
if ($user->subscribed('default')) {
|
||||||
|
$user->subscription('default')->swap($planId);
|
||||||
|
} else {
|
||||||
|
if ($coupon = $request->input('coupon')) {
|
||||||
|
$user->newSubscription('default', $planId)
|
||||||
|
->withCoupon($coupon)
|
||||||
|
->create($user->defaultPaymentMethod()->id);
|
||||||
|
} else {
|
||||||
|
$user->newSubscription('default', $planId)->create($user->defaultPaymentMethod()->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (InvalidRequestException $exception) {
|
||||||
|
$error = $exception->getJsonBody();
|
||||||
|
|
||||||
|
return redirect()->route('profile.billing.index')->with('error', Arr::get($error, 'error.message'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->package_id = $plan->id;
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
return redirect()->route('profile.billing.index')->with('success', sprintf("Your plan has been updated to %s", $plan->name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cancel(Request $request)
|
||||||
|
{
|
||||||
|
/* @var $user \App\Models\User */
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$subscription = $user->subscription('default')->cancel();
|
||||||
|
|
||||||
|
return redirect()->route('profile.billing.index')->with('success', __('Your subscription has been cancelled, your end date is ' . $subscription->ends_at));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function invoices(Request $request)
|
||||||
|
{
|
||||||
|
return $request->user()->invoices()->map(function ($invoice) {
|
||||||
|
$symbol = $this->transformCurrency($invoice->currency);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $invoice->id,
|
||||||
|
'created' => Carbon::createFromTimestamp($invoice->created)->format('Y-m-d H:i:s'),
|
||||||
|
'number' => $invoice->number,
|
||||||
|
'status' => $invoice->status,
|
||||||
|
'total' => $symbol . number_format($invoice->total / 100, 2, ',', '.'),
|
||||||
|
'currency' => $invoice->currency,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pdf(Request $request, $id)
|
||||||
|
{
|
||||||
|
return $request->user()->downloadInvoice($id, [
|
||||||
|
'vendor' => setting('name'),
|
||||||
|
'product' => 'Webhosting'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function transformCurrency($key)
|
||||||
|
{
|
||||||
|
$currencies = [
|
||||||
|
Package::CURRENCY_EURO => '€',
|
||||||
|
Package::CURRENCY_USD => '$',
|
||||||
|
Package::CURRENCY_NOK => 'KR ',
|
||||||
|
Package::CURRENCY_CAD => 'CAD $',
|
||||||
|
Package::CURRENCY_AUD => 'AUD $',
|
||||||
|
Package::CURRENCY_GBP => 'GBP £',
|
||||||
|
Package::CURRENCY_INR => 'INR ₹',
|
||||||
|
Package::CURRENCY_THB => 'THB ',
|
||||||
|
Package::CURRENCY_BRL=> 'BRL R$ ',
|
||||||
|
];
|
||||||
|
|
||||||
|
return $currencies[strtolower($key)] ?? '$';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Profile;
|
|||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
use App\Http\Requests\UserProfileRequest;
|
use App\Http\Requests\UserProfileRequest;
|
||||||
use App\Http\Resources\UserProfileResource;
|
use App\Http\Resources\UserProfileResource;
|
||||||
|
|
||||||
@@ -13,7 +12,8 @@ class ProfileController extends Controller
|
|||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return inertia('Profile/Index', [
|
return inertia('Profile/Index', [
|
||||||
'profile' => new UserProfileResource(auth()->user())
|
'profile' => new UserProfileResource(auth()->user()),
|
||||||
|
'countries' => countries()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,21 +38,20 @@ class ProfileController extends Controller
|
|||||||
return $mode;
|
return $mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requestFtpPassword(Request $request)
|
public function destroy(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, ['password' => 'required|string']);
|
/* @var $user \App\Models\User */
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
if (!Hash::check($request->input('password'), $request->user()->password)) {
|
$user->sites()->detach();
|
||||||
return response([
|
$user->servers()->detach();
|
||||||
'message' => 'The given data was invalid',
|
$user->supportTicketReplies()->delete();
|
||||||
'errors' => [
|
$user->supportTickets()->delete();
|
||||||
'password' => [
|
|
||||||
trans('auth.failed')
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ['ftp_password' => decrypt($request->user()->ftp_password)];
|
$user->delete();
|
||||||
|
|
||||||
|
auth()->logout();
|
||||||
|
|
||||||
|
return redirect()->route('login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Profile;
|
||||||
|
|
||||||
|
use App\Models\UserProvider;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\ProfileIntegrationRequest;
|
||||||
|
|
||||||
|
class ProfileIntegrationController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$providers = auth()->user()->providers()->latest()->get()->map(function ($provider) {
|
||||||
|
return [
|
||||||
|
'id' => $provider->id,
|
||||||
|
'type' => $provider->type,
|
||||||
|
'created_at' => $provider->created_at->format('Y-m-d H:i:s')
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return inertia('Profile/Integrations', [
|
||||||
|
'providers' => $providers,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(ProfileIntegrationRequest $request)
|
||||||
|
{
|
||||||
|
$request->user()->providers()->updateOrCreate([
|
||||||
|
'type' => UserProvider::TYPE_CLOUDFLARE
|
||||||
|
], [
|
||||||
|
'type' => UserProvider::TYPE_CLOUDFLARE,
|
||||||
|
'token' => $request->input('meta.api_key'),
|
||||||
|
'meta' => [
|
||||||
|
'cloudflare_email' => encrypt($request->input('meta.cloudflare_email'))
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect()->route('profile.integrations.index');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($providerId)
|
||||||
|
{
|
||||||
|
auth()->user()->providers()->findOrFail($providerId)->delete();
|
||||||
|
|
||||||
|
return redirect()->route('profile.integrations.index');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Profile;
|
namespace App\Http\Controllers\Profile;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Rules\MatchOldPassword;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use App\Rules\MatchOldPassword;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
class ProfilePasswordController extends Controller
|
class ProfilePasswordController extends Controller
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Profile;
|
namespace App\Http\Controllers\Profile;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
class ProfileSettingController extends Controller
|
class ProfileSettingController extends Controller
|
||||||
{
|
{
|
||||||
@@ -12,7 +12,8 @@ class ProfileSettingController extends Controller
|
|||||||
{
|
{
|
||||||
return inertia('Profile/Settings', [
|
return inertia('Profile/Settings', [
|
||||||
'profile' => [
|
'profile' => [
|
||||||
'theme' => auth()->user()->theme
|
'theme' => auth()->user()->theme,
|
||||||
|
'keyboard_shortcuts' => auth()->user()->keyboard_shortcuts,
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -27,7 +28,10 @@ class ProfileSettingController extends Controller
|
|||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->user()->update(['theme' => $request->input('theme')]);
|
$request->user()->update([
|
||||||
|
'theme' => $request->input('theme'),
|
||||||
|
'keyboard_shortcuts' => $request->input('keyboard_shortcuts', true),
|
||||||
|
]);
|
||||||
|
|
||||||
return redirect()->route('profile.settings.index')->with('success', __('Instellingen zijn aangepast'));
|
return redirect()->route('profile.settings.index')->with('success', __('Instellingen zijn aangepast'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,43 +2,98 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Jobs\Servers\DeleteServer;
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
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\Http\Resources\ServerResource;
|
||||||
|
use App\Mail\Server\ServerCreatedEmail;
|
||||||
|
use App\Http\Requests\ServerUpdateRequest;
|
||||||
|
use App\Mail\Admin\Server\AdminServerCreatedEmail;
|
||||||
|
|
||||||
class ServerController extends Controller
|
class ServerController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$servers = auth()->user()->servers()->latest()->paginate();
|
$servers = auth()->user()->servers()
|
||||||
|
->withCount('sites')
|
||||||
|
->latest()
|
||||||
|
->paginate();
|
||||||
|
|
||||||
|
$providers = auth()->user()->package ? auth()->user()->package->providers()->pluck('name', 'id') : [];
|
||||||
|
|
||||||
return inertia('Servers/Index', [
|
return inertia('Servers/Index', [
|
||||||
'servers' => ServerResource::collection($servers)
|
'servers' => ServerResource::collection($servers),
|
||||||
|
'dataProviders' => $providers
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(Request $request)
|
public function store(ServerRequest $request)
|
||||||
{
|
{
|
||||||
abort_if(!$request->user()->can('create', Server::class), 403);
|
$provider = $request->user()->package->providers()->findOrFail($request->input('provider'));
|
||||||
|
$region = $provider->regions()->findOrFail($request->input('region'));
|
||||||
|
$plan = $provider->plans()->findOrFail($request->input('plan'));
|
||||||
|
|
||||||
// TODO
|
/* @var $server \App\Models\Server */
|
||||||
|
$server = $request->user()->servers()->create([
|
||||||
|
'name' => $request->input('name'),
|
||||||
|
'database_type' => $request->input('database_type', 'mysql')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$server->provider()->associate($provider);
|
||||||
|
$server->providerRegion()->associate($region);
|
||||||
|
$server->providerPlan()->associate($plan);
|
||||||
|
$server->save();
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('servers.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$server = auth()->user()->servers()->findOrFail($id);
|
$server = auth()->user()->servers()->findOrFail($id);
|
||||||
|
|
||||||
|
if ($server->status === Server::STATUS_BUSY) {
|
||||||
|
return redirect()->back()->with('info', 'This server is currently busy, please check back later.');
|
||||||
|
}
|
||||||
|
|
||||||
return inertia('Servers/Show', [
|
return inertia('Servers/Show', [
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
'sites' => $server->sites()->latest()->paginate(5, ['*'], 'sites_per_page'),
|
'sites' => $server->sites()->latest()->paginate(5, ['*'], 'sites_per_page'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function update(ServerUpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$server = $request->user()->servers()->findOrFail($id);
|
||||||
|
|
||||||
|
$server->update([
|
||||||
|
'name' => $request->input('name')
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect()->route('servers.settings.show', $id)->with('success', __('Server information has been updated'));
|
||||||
|
}
|
||||||
|
|
||||||
public function destroy(Request $request, $id)
|
public function destroy(Request $request, $id)
|
||||||
{
|
{
|
||||||
$server = $request->user()->servers()->findOrFail($id);
|
$server = $request->user()->servers()->findOrFail($id);
|
||||||
|
|
||||||
|
$this->authorize('delete', $server);
|
||||||
|
|
||||||
dispatch(new DeleteServer($server->ploi_id));
|
dispatch(new DeleteServer($server->ploi_id));
|
||||||
|
|
||||||
$request->user()->systemLogs()->create([
|
$request->user()->systemLogs()->create([
|
||||||
@@ -50,4 +105,26 @@ class ServerController extends Controller
|
|||||||
|
|
||||||
return redirect()->route('servers.index')->with('success', __('Your server is deleted'));
|
return redirect()->route('servers.index')->with('success', __('Your server is deleted'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function plansAndRegions(Request $request, $providerId)
|
||||||
|
{
|
||||||
|
$provider = $request->user()->package->providers()->findOrFail($providerId);
|
||||||
|
|
||||||
|
$regions = $provider->regions()
|
||||||
|
->when($provider->allowed_regions, function ($query) use ($provider) {
|
||||||
|
return $query->whereIn('id', $provider->allowed_regions);
|
||||||
|
})
|
||||||
|
->pluck('label', 'id');
|
||||||
|
|
||||||
|
$plans = $provider->plans()
|
||||||
|
->when($provider->allowed_plans, function ($query) use ($provider) {
|
||||||
|
return $query->whereIn('id', $provider->allowed_plans);
|
||||||
|
})
|
||||||
|
->pluck('label', 'id');
|
||||||
|
|
||||||
|
return [
|
||||||
|
'regions' => $regions,
|
||||||
|
'plans' => $plans,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class ServerSettingController extends Controller
|
class ServerSettingController extends Controller
|
||||||
{
|
{
|
||||||
public function show($id)
|
public function show($id)
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ class SiteCertificateController extends Controller
|
|||||||
|
|
||||||
$certificate = $site->certificates()->create([
|
$certificate = $site->certificates()->create([
|
||||||
'domain' => $request->input('domain'),
|
'domain' => $request->input('domain'),
|
||||||
|
'type' => $request->input('type', 'letsencrypt'),
|
||||||
|
'certificate' => $request->input('certificate'),
|
||||||
|
'private' => $request->input('private')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$certificate->server_id = $site->server_id;
|
$certificate->server_id = $site->server_id;
|
||||||
|
|||||||
@@ -3,11 +3,13 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use App\Jobs\Sites\CreateSite;
|
use App\Jobs\Sites\CreateSite;
|
||||||
use App\Jobs\Sites\DeleteSite;
|
use App\Jobs\Sites\DeleteSite;
|
||||||
use App\Http\Requests\SiteRequest;
|
use App\Http\Requests\SiteRequest;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use App\Http\Resources\SiteResource;
|
use App\Http\Resources\SiteResource;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
class SiteController extends Controller
|
class SiteController extends Controller
|
||||||
{
|
{
|
||||||
@@ -19,7 +21,7 @@ class SiteController extends Controller
|
|||||||
return $query->where('server_id', $value);
|
return $query->where('server_id', $value);
|
||||||
})
|
})
|
||||||
->latest()
|
->latest()
|
||||||
->paginate(10);
|
->paginate(config('core.pagination.per_page'));
|
||||||
|
|
||||||
$availableServers = auth()->user()->servers()->pluck('name', 'id');
|
$availableServers = auth()->user()->servers()->pluck('name', 'id');
|
||||||
|
|
||||||
@@ -35,11 +37,25 @@ class SiteController extends Controller
|
|||||||
$server = $request->user()->servers()->findOrFail($serverId);
|
$server = $request->user()->servers()->findOrFail($serverId);
|
||||||
} else {
|
} else {
|
||||||
$server = Server::query()
|
$server = Server::query()
|
||||||
->doesntHave('users')
|
->where('maximum_sites', '>', 0)
|
||||||
|
->where(function ($query) {
|
||||||
|
return $query
|
||||||
|
->where(function ($query) {
|
||||||
|
return $query->whereHas('users', function ($query) {
|
||||||
|
return $query->where('user_id', auth()->id());
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->orWhere(function ($query) {
|
||||||
|
return $query->doesntHave('users');
|
||||||
|
});
|
||||||
|
})
|
||||||
->withCount('sites')
|
->withCount('sites')
|
||||||
->having('sites_count', '<', DB::raw('maximum_sites'))
|
|
||||||
->inRandomOrder()
|
->inRandomOrder()
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
if ($server && $server->sites_count >= $server->maximum_sites) {
|
||||||
|
$server = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$server) {
|
if (!$server) {
|
||||||
@@ -72,13 +88,16 @@ class SiteController extends Controller
|
|||||||
|
|
||||||
return inertia('Sites/Show', [
|
return inertia('Sites/Show', [
|
||||||
'site' => $site,
|
'site' => $site,
|
||||||
|
'system_user' => $site->getSystemUser(false),
|
||||||
'ip_address' => $site->server->ip
|
'ip_address' => $site->server->ip
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy($id)
|
public function destroy(Request $request, $id)
|
||||||
{
|
{
|
||||||
$site = auth()->user()->sites()->findOrFail($id);
|
$site = $request->user()->sites()->findOrFail($id);
|
||||||
|
|
||||||
|
$this->authorize('delete', $site);
|
||||||
|
|
||||||
dispatch(new DeleteSite($site->server->ploi_id, $site->ploi_id));
|
dispatch(new DeleteSite($site->server->ploi_id, $site->ploi_id));
|
||||||
|
|
||||||
@@ -86,4 +105,28 @@ class SiteController extends Controller
|
|||||||
|
|
||||||
return redirect()->route('sites.index')->with('success', __('Your website is deleted'));
|
return redirect()->route('sites.index')->with('success', __('Your website is deleted'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function requestFtpPassword(Request $request, $id)
|
||||||
|
{
|
||||||
|
if ($request->user()->requires_password_for_ftp) {
|
||||||
|
$this->validate($request, ['password' => 'required|string']);
|
||||||
|
|
||||||
|
if (!Hash::check($request->input('password'), $request->user()->password)) {
|
||||||
|
return response([
|
||||||
|
'message' => 'The given data was invalid',
|
||||||
|
'errors' => [
|
||||||
|
'password' => [
|
||||||
|
trans('auth.failed')
|
||||||
|
]
|
||||||
|
]
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$site = $request->user()->sites()->findOrFail($id);
|
||||||
|
|
||||||
|
$systemUser = $site->getSystemUser();
|
||||||
|
|
||||||
|
return ['ftp_password' => decrypt(Arr::get($systemUser, 'ftp_password'))];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Site;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use App\Models\UserProvider;
|
||||||
|
use App\Services\Cloudflare;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Requests\SiteDnsRequest;
|
||||||
|
|
||||||
class SiteDnsController extends Controller
|
class SiteDnsController extends Controller
|
||||||
{
|
{
|
||||||
@@ -16,9 +21,18 @@ class SiteDnsController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(Request $request)
|
public function store(SiteDnsRequest $request, $id)
|
||||||
{
|
{
|
||||||
//
|
$site = auth()->user()->sites()->findOrFail($id);
|
||||||
|
|
||||||
|
$dns = $this->getDnsInstance($site);
|
||||||
|
|
||||||
|
$dns->addRecord(
|
||||||
|
$request->input('name'),
|
||||||
|
$request->input('address'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return redirect()->route('sites.dns.index', $id)->with('success', __('DNS record has been created'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
@@ -28,10 +42,31 @@ class SiteDnsController extends Controller
|
|||||||
|
|
||||||
public function records($id)
|
public function records($id)
|
||||||
{
|
{
|
||||||
|
$site = auth()->user()->sites()->findOrFail($id);
|
||||||
|
|
||||||
|
$dns = $this->getDnsInstance($site);
|
||||||
|
|
||||||
|
return $dns->listRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy($id)
|
public function destroy($id, $recordId)
|
||||||
{
|
{
|
||||||
//
|
$site = auth()->user()->sites()->findOrFail($id);
|
||||||
|
|
||||||
|
$dns = $this->getDnsInstance($site);
|
||||||
|
|
||||||
|
$dns->deleteRecord($recordId);
|
||||||
|
|
||||||
|
return redirect()->route('sites.dns.index', $id)->with('success', __('DNS record has been removed'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDnsInstance(Site $site)
|
||||||
|
{
|
||||||
|
$provider = auth()->user()->providers()->where('type', UserProvider::TYPE_CLOUDFLARE)->first();
|
||||||
|
|
||||||
|
$cloudflare = new Cloudflare(decrypt(Arr::get($provider->meta, 'cloudflare_email')), decrypt($provider->token));
|
||||||
|
$cloudflare->zone(decrypt($site->dns_id));
|
||||||
|
|
||||||
|
return $cloudflare;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ class SiteSettingController extends Controller
|
|||||||
{
|
{
|
||||||
$site = auth()->user()->sites()->findOrFail($id);
|
$site = auth()->user()->sites()->findOrFail($id);
|
||||||
|
|
||||||
|
$this->authorize('update', $site);
|
||||||
|
|
||||||
$availablePhpVersions = $site->server->available_php_versions;
|
$availablePhpVersions = $site->server->available_php_versions;
|
||||||
|
|
||||||
return inertia('Sites/Settings', [
|
return inertia('Sites/Settings', [
|
||||||
@@ -23,6 +25,8 @@ class SiteSettingController extends Controller
|
|||||||
{
|
{
|
||||||
$site = $request->user()->sites()->findOrFail($id);
|
$site = $request->user()->sites()->findOrFail($id);
|
||||||
|
|
||||||
|
$this->authorize('update', $site);
|
||||||
|
|
||||||
$site->update($request->all());
|
$site->update($request->all());
|
||||||
|
|
||||||
return redirect()->route('sites.settings.show', $id)->with('success', __('Site settings have been updated'));
|
return redirect()->route('sites.settings.show', $id)->with('success', __('Site settings have been updated'));
|
||||||
@@ -32,6 +36,8 @@ class SiteSettingController extends Controller
|
|||||||
{
|
{
|
||||||
$site = $request->user()->sites()->findOrFail($id);
|
$site = $request->user()->sites()->findOrFail($id);
|
||||||
|
|
||||||
|
$this->authorize('update', $site);
|
||||||
|
|
||||||
dispatch(new ChangePhpVersion($site, $request->input('version')));
|
dispatch(new ChangePhpVersion($site, $request->input('version')));
|
||||||
|
|
||||||
$request->user()->systemLogs()->create([
|
$request->user()->systemLogs()->create([
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class Kernel extends HttpKernel
|
|||||||
protected $middleware = [
|
protected $middleware = [
|
||||||
// \App\Http\Middleware\TrustHosts::class,
|
// \App\Http\Middleware\TrustHosts::class,
|
||||||
\App\Http\Middleware\TrustProxies::class,
|
\App\Http\Middleware\TrustProxies::class,
|
||||||
\Fruitcake\Cors\HandleCors::class,
|
\Illuminate\Http\Middleware\HandleCors::class,
|
||||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||||
\App\Http\Middleware\TrimStrings::class,
|
\App\Http\Middleware\TrimStrings::class,
|
||||||
@@ -45,6 +45,7 @@ class Kernel extends HttpKernel
|
|||||||
\App\Http\Middleware\SetLocale::class,
|
\App\Http\Middleware\SetLocale::class,
|
||||||
\App\Http\Middleware\Demo::class,
|
\App\Http\Middleware\Demo::class,
|
||||||
\App\Http\Middleware\InstallationComplete::class,
|
\App\Http\Middleware\InstallationComplete::class,
|
||||||
|
\App\Http\Middleware\HandleInertiaRequests::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
'api' => [
|
'api' => [
|
||||||
@@ -67,6 +68,7 @@ class Kernel extends HttpKernel
|
|||||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||||
|
'has.access' => \App\Http\Middleware\HasAccessToThisGroup::class,
|
||||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||||
'global.api.authenticated' => \App\Http\Middleware\GlobalApiAuthenticated::class,
|
'global.api.authenticated' => \App\Http\Middleware\GlobalApiAuthenticated::class,
|
||||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Demo
|
|||||||
protected $safeRoutes = [
|
protected $safeRoutes = [
|
||||||
'login',
|
'login',
|
||||||
'logout',
|
'logout',
|
||||||
//'profile/toggle-theme'
|
'profile/toggle-theme'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $allowedIps = [
|
protected $allowedIps = [
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use App\Services\Ploi\Exceptions\Http\Unauthenticated;
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use App\Services\Ploi\Exceptions\Http\Unauthenticated;
|
||||||
|
|
||||||
class GlobalApiAuthenticated
|
class GlobalApiAuthenticated
|
||||||
{
|
{
|
||||||
|
|||||||
133
app/Http/Middleware/HandleInertiaRequests.php
Normal file
133
app/Http/Middleware/HandleInertiaRequests.php
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
|
|
||||||
|
class HandleInertiaRequests extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determines the current asset version.
|
||||||
|
*
|
||||||
|
* @see https://inertiajs.com/asset-versioning
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function version(Request $request)
|
||||||
|
{
|
||||||
|
return parent::version($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the props that are shared by default.
|
||||||
|
*
|
||||||
|
* @see https://inertiajs.com/shared-data
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function share(Request $request)
|
||||||
|
{
|
||||||
|
return array_merge(parent::share($request), [
|
||||||
|
'auth' => function () use ($request) {
|
||||||
|
$package = auth()->user()->package ?? [];
|
||||||
|
|
||||||
|
$can = $package ? [
|
||||||
|
'servers' => [
|
||||||
|
'create' => Arr::get($package->server_permissions, 'create', false),
|
||||||
|
'update' => Arr::get($package->server_permissions, 'update', false),
|
||||||
|
'delete' => Arr::get($package->server_permissions, 'delete', false),
|
||||||
|
],
|
||||||
|
'sites' => [
|
||||||
|
'create' => Arr::get($package->site_permissions, 'create', false),
|
||||||
|
'update' => Arr::get($package->site_permissions, 'update', false),
|
||||||
|
'delete' => Arr::get($package->site_permissions, 'delete', false),
|
||||||
|
]
|
||||||
|
] : [];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'user' => Auth::user() ? [
|
||||||
|
'id' => Auth::user()->id,
|
||||||
|
'name' => Auth::user()->name,
|
||||||
|
'email' => Auth::user()->email,
|
||||||
|
'role' => Auth::user()->role,
|
||||||
|
'user_name' => Auth::user()->user_name,
|
||||||
|
'avatar' => Auth::user()->getGravatar(),
|
||||||
|
'theme' => Auth::user()->theme,
|
||||||
|
'keyboard_shortcuts' => Auth::user()->keyboard_shortcuts,
|
||||||
|
'requires_password_for_ftp' => Auth::user()->requires_password_for_ftp,
|
||||||
|
'address' => Auth::user()->address,
|
||||||
|
'country' => Auth::user()->country,
|
||||||
|
'zip' => Auth::user()->zip,
|
||||||
|
'city' => Auth::user()->city,
|
||||||
|
] : null,
|
||||||
|
'package' => auth()->user() && auth()->user()->package ? [
|
||||||
|
'name' => auth()->user()->package->name,
|
||||||
|
'maximum_sites' => auth()->user()->package->maximum_sites
|
||||||
|
] : [
|
||||||
|
'name' => __('None')
|
||||||
|
],
|
||||||
|
'can' => $can,
|
||||||
|
'integrations' => [
|
||||||
|
'cloudflare' => (bool)auth()->user() ? auth()->user()->providers()->where('type', UserProvider::TYPE_CLOUDFLARE)->count() : false,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
'settings' => function () {
|
||||||
|
return [
|
||||||
|
'demo' => config('app.demo'),
|
||||||
|
'name' => setting('name', 'Company'),
|
||||||
|
'support' => setting('support', false),
|
||||||
|
'documentation' => setting('documentation', false),
|
||||||
|
'logo' => setting('logo'),
|
||||||
|
'allow_registration' => setting('allow_registration'),
|
||||||
|
'billing' => config('cashier.key') && config('cashier.secret'),
|
||||||
|
'has_terms' => (bool)setting('terms'),
|
||||||
|
'has_privacy' => (bool)setting('privacy'),
|
||||||
|
'accept_terms_required' => (bool)setting('accept_terms_required')
|
||||||
|
];
|
||||||
|
},
|
||||||
|
'flash' => function () {
|
||||||
|
return [
|
||||||
|
'success' => Session::get('success'),
|
||||||
|
'error' => Session::get('error'),
|
||||||
|
'info' => Session::get('info'),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
'errors' => function () {
|
||||||
|
return Session::get('errors')
|
||||||
|
? Session::get('errors')->getBag('default')->getMessages()
|
||||||
|
: (object)[];
|
||||||
|
},
|
||||||
|
'errors_count' => function () {
|
||||||
|
return Session::get('errors')
|
||||||
|
? count(Session::get('errors')->getBag('default')->getMessages())
|
||||||
|
: 0;
|
||||||
|
},
|
||||||
|
'system_alert' => function () {
|
||||||
|
$alert = Alert::query()
|
||||||
|
->where(function ($query) {
|
||||||
|
return $query
|
||||||
|
->whereNull('expires_at')
|
||||||
|
->orWhere('expires_at', '>', now());
|
||||||
|
})
|
||||||
|
->first(['message', 'expires_at', 'type']);
|
||||||
|
|
||||||
|
if (!$alert) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'message' => $alert->message,
|
||||||
|
'type' => $alert->type
|
||||||
|
];
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
app/Http/Middleware/HasAccessToThisGroup.php
Normal file
27
app/Http/Middleware/HasAccessToThisGroup.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class HasAccessToThisGroup
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next, $group)
|
||||||
|
{
|
||||||
|
if ($group === 'servers') {
|
||||||
|
$package = $request->user()->package ?? [];
|
||||||
|
|
||||||
|
if (
|
||||||
|
!Arr::get($package->server_permissions, 'create', false) &&
|
||||||
|
!Arr::get($package->server_permissions, 'update', false) &&
|
||||||
|
!Arr::get($package->server_permissions, 'delete', false)
|
||||||
|
) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
|
||||||
|
|
||||||
class TrustProxies extends Middleware
|
class TrustProxies extends Middleware
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The trusted proxies for this application.
|
* The trusted proxies for this application.
|
||||||
*
|
*
|
||||||
* @var array|string|null
|
* @var array<int, string>|string|null
|
||||||
*/
|
*/
|
||||||
protected $proxies;
|
protected $proxies;
|
||||||
|
|
||||||
@@ -19,5 +19,10 @@ class TrustProxies extends Middleware
|
|||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $headers = Request::HEADER_X_FORWARDED_ALL;
|
protected $headers =
|
||||||
|
Request::HEADER_X_FORWARDED_FOR |
|
||||||
|
Request::HEADER_X_FORWARDED_HOST |
|
||||||
|
Request::HEADER_X_FORWARDED_PORT |
|
||||||
|
Request::HEADER_X_FORWARDED_PROTO |
|
||||||
|
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||||
}
|
}
|
||||||
|
|||||||
50
app/Http/Requests/Admin/AlertRequest.php
Normal file
50
app/Http/Requests/Admin/AlertRequest.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin;
|
||||||
|
|
||||||
|
use App\Models\Alert;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class AlertRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return auth()->check() && auth()->user()->isAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'message' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:500'
|
||||||
|
],
|
||||||
|
'type' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
Rule::in([
|
||||||
|
Alert::TYPE_INFO,
|
||||||
|
Alert::TYPE_DANGER,
|
||||||
|
Alert::TYPE_WARNING
|
||||||
|
])
|
||||||
|
],
|
||||||
|
'expires_at' => [
|
||||||
|
'nullable',
|
||||||
|
'date',
|
||||||
|
'date_format:Y-m-d H:i:s'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
42
app/Http/Requests/Admin/DocumentationArticleRequest.php
Normal file
42
app/Http/Requests/Admin/DocumentationArticleRequest.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class DocumentationArticleRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return auth()->check() && auth()->user()->isAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:255'
|
||||||
|
],
|
||||||
|
'content' => [
|
||||||
|
'required',
|
||||||
|
'min:2'
|
||||||
|
],
|
||||||
|
'category_id' => [
|
||||||
|
'required',
|
||||||
|
'exists:documentation_categories,id'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Http/Requests/Admin/DocumentationCategoryRequest.php
Normal file
38
app/Http/Requests/Admin/DocumentationCategoryRequest.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class DocumentationCategoryRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return auth()->check() && auth()->user()->isAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:255'
|
||||||
|
],
|
||||||
|
'description' => [
|
||||||
|
'nullable',
|
||||||
|
'string'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests\Admin;
|
namespace App\Http\Requests\Admin;
|
||||||
|
|
||||||
|
use App\Models\Package;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
class PackageRequest extends FormRequest
|
class PackageRequest extends FormRequest
|
||||||
@@ -29,15 +31,68 @@ class PackageRequest extends FormRequest
|
|||||||
'string',
|
'string',
|
||||||
'max:255'
|
'max:255'
|
||||||
],
|
],
|
||||||
|
'currency' => [
|
||||||
|
'nullable',
|
||||||
|
Rule::in([
|
||||||
|
Package::CURRENCY_USD,
|
||||||
|
Package::CURRENCY_EURO,
|
||||||
|
Package::CURRENCY_NOK,
|
||||||
|
Package::CURRENCY_AUD,
|
||||||
|
Package::CURRENCY_CAD,
|
||||||
|
Package::CURRENCY_GBP,
|
||||||
|
Package::CURRENCY_INR,
|
||||||
|
Package::CURRENCY_THB,
|
||||||
|
Package::CURRENCY_BRL,
|
||||||
|
])
|
||||||
|
],
|
||||||
'maximum_sites' => [
|
'maximum_sites' => [
|
||||||
'required',
|
'required',
|
||||||
'numeric',
|
'numeric',
|
||||||
'min:0',
|
'min:0',
|
||||||
],
|
],
|
||||||
'server_creation' => [
|
'maximum_servers' => [
|
||||||
'required',
|
'required',
|
||||||
'boolean'
|
'numeric',
|
||||||
|
'min:0',
|
||||||
|
],
|
||||||
|
'plan_id' => [
|
||||||
|
'nullable',
|
||||||
|
],
|
||||||
|
'price_monthly' => [
|
||||||
|
'nullable',
|
||||||
|
'numeric',
|
||||||
|
],
|
||||||
|
'price_yearly' => [
|
||||||
|
'nullable',
|
||||||
|
'numeric',
|
||||||
|
],
|
||||||
|
'server_permissions' => [
|
||||||
|
'array'
|
||||||
|
],
|
||||||
|
'site_permissions' => [
|
||||||
|
'array'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation()
|
||||||
|
{
|
||||||
|
$merge = [];
|
||||||
|
|
||||||
|
// If we don't have the monthly price filled in, merge a default
|
||||||
|
if (!$this->price_monthly) {
|
||||||
|
$merge['price_monthly'] = 0.000;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->price_yearly) {
|
||||||
|
$merge['price_yearly'] = 0.000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we don't have the currency filled in, merge a default
|
||||||
|
if (!$this->price_monthly || !$this->price_yearly) {
|
||||||
|
$merge['currency'] = Package::CURRENCY_USD;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->merge($merge);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
app/Http/Requests/Admin/ProviderRequest.php
Normal file
42
app/Http/Requests/Admin/ProviderRequest.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ProviderRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return auth()->check() && auth()->user()->isAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:255'
|
||||||
|
],
|
||||||
|
'allowed_plans' => [
|
||||||
|
'nullable',
|
||||||
|
'array'
|
||||||
|
],
|
||||||
|
'allowed_regions' => [
|
||||||
|
'nullable',
|
||||||
|
'array'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,12 @@ class SettingRequest extends FormRequest
|
|||||||
'email' => [
|
'email' => [
|
||||||
'nullable',
|
'nullable',
|
||||||
'email'
|
'email'
|
||||||
|
],
|
||||||
|
|
||||||
|
'logo' => [
|
||||||
|
'nullable',
|
||||||
|
'image',
|
||||||
|
'max:2000'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
63
app/Http/Requests/ProfileIntegrationRequest.php
Normal file
63
app/Http/Requests/ProfileIntegrationRequest.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Models\UserProvider;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use App\Rules\CloudflareGeneralTest;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ProfileIntegrationRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return auth()->check();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'provider' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
Rule::in([
|
||||||
|
UserProvider::TYPE_CLOUDFLARE
|
||||||
|
])
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($this->input('provider') === UserProvider::TYPE_CLOUDFLARE) {
|
||||||
|
$rules['meta.api_key'] = [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
new CloudflareGeneralTest($this->input('meta.cloudflare_email'))
|
||||||
|
];
|
||||||
|
|
||||||
|
$rules['meta.cloudflare_email'] = [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'email'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'meta.api_key.required' => __('The API key field is required'),
|
||||||
|
'meta.cloudflare_email.required' => __('The Cloudflare email field is required'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
57
app/Http/Requests/ServerRequest.php
Normal file
57
app/Http/Requests/ServerRequest.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class ServerRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->can('create', Server::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'alpha_dash',
|
||||||
|
'max:40'
|
||||||
|
],
|
||||||
|
'provider' => [
|
||||||
|
'required',
|
||||||
|
'not_in:0',
|
||||||
|
'exists:provider_plans,id'
|
||||||
|
],
|
||||||
|
'region' => [
|
||||||
|
'required',
|
||||||
|
'not_in:0',
|
||||||
|
'exists:provider_regions,id'
|
||||||
|
],
|
||||||
|
'plan' => [
|
||||||
|
'required',
|
||||||
|
'not_in:0',
|
||||||
|
'exists:provider_plans,id'
|
||||||
|
],
|
||||||
|
'database_type' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
Rule::in(['mysql', 'mariadb', 'postgresql', 'postgresql13'])
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
36
app/Http/Requests/ServerUpdateRequest.php
Normal file
36
app/Http/Requests/ServerUpdateRequest.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ServerUpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->can('update', Server::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'alpha_dash',
|
||||||
|
'max:40'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,15 +25,36 @@ class SiteCertificateRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
$rules = [];
|
||||||
'domain' => [
|
|
||||||
'required',
|
if ($this->input('type') === 'letsencrypt') {
|
||||||
'string',
|
$rules = [
|
||||||
Rule::unique('certificates', 'domain')->where(function ($query) {
|
'domain' => [
|
||||||
return $query->where('site_id', $this->route('site'));
|
'required',
|
||||||
}),
|
'string',
|
||||||
new LetsEncryptMatchHostWithIp($this->route('site'))
|
Rule::unique('certificates', 'domain')->where(function ($query) {
|
||||||
]
|
return $query->where('site_id', $this->route('site'));
|
||||||
];
|
}),
|
||||||
|
new LetsEncryptMatchHostWithIp($this->route('site'))
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->input('type') === 'custom') {
|
||||||
|
$rules = [
|
||||||
|
'certificate' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'min:5'
|
||||||
|
],
|
||||||
|
'private' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'min:5'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rules;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
app/Http/Requests/SiteDnsRequest.php
Normal file
37
app/Http/Requests/SiteDnsRequest.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class SiteDnsRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return auth()->check();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
],
|
||||||
|
'address' => [
|
||||||
|
'required',
|
||||||
|
'ipv4'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests;
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Models\Site;
|
||||||
use App\Rules\Hostname;
|
use App\Rules\Hostname;
|
||||||
use App\Rules\ValidateMaximumSites;
|
use App\Rules\ValidateMaximumSites;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
@@ -15,7 +16,7 @@ class SiteRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
return auth()->check();
|
return $this->user()->can('create', Site::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,6 +41,22 @@ class UserProfileRequest extends FormRequest
|
|||||||
'required',
|
'required',
|
||||||
'string',
|
'string',
|
||||||
Rule::in(languages()),
|
Rule::in(languages()),
|
||||||
|
],
|
||||||
|
'address' => [
|
||||||
|
'nullable',
|
||||||
|
'string'
|
||||||
|
],
|
||||||
|
'country' => [
|
||||||
|
'nullable',
|
||||||
|
'string'
|
||||||
|
],
|
||||||
|
'zip' => [
|
||||||
|
'nullable',
|
||||||
|
'string'
|
||||||
|
],
|
||||||
|
'city' => [
|
||||||
|
'nullable',
|
||||||
|
'string'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
23
app/Http/Resources/DocumentationCategoryRouteResource.php
Normal file
23
app/Http/Resources/DocumentationCategoryRouteResource.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class DocumentationCategoryRouteResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => $this->title,
|
||||||
|
'to' => route('documentation.show', $this->id),
|
||||||
|
'active' => object_get(request()->route('documentationCategory'), 'id') === $this->id ? true : false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,11 @@ class UserProfileResource extends JsonResource
|
|||||||
return [
|
return [
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
'language' => $this->language
|
'language' => $this->language,
|
||||||
|
'address' => $this->address,
|
||||||
|
'country' => $this->country,
|
||||||
|
'zip' => $this->zip,
|
||||||
|
'city' => $this->city
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,45 +2,46 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Apps;
|
namespace App\Jobs\Apps;
|
||||||
|
|
||||||
|
use App\Models\Database;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class InstallApp implements ShouldQueue
|
class InstallApp implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $site;
|
public Site $site;
|
||||||
public $type;
|
public $type;
|
||||||
public $options;
|
public $options;
|
||||||
|
|
||||||
/**
|
public function __construct(Site $site, string $type = Site::PROJECT_WORDPRESS, array $options = [])
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param Site $site
|
|
||||||
* @param string $type
|
|
||||||
* @param array $options
|
|
||||||
*/
|
|
||||||
public function __construct(Site $site, $type = Site::PROJECT_WORDPRESS, array $options = [])
|
|
||||||
{
|
{
|
||||||
$this->site = $site;
|
$this->site = $site;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$response = $this->getPloi()
|
||||||
|
->server($this->site->server->ploi_id)
|
||||||
|
->sites($this->site->ploi_id)
|
||||||
|
->app()
|
||||||
|
->install($this->type, $this->options);
|
||||||
|
|
||||||
$ploi->server($this->site->server->ploi_id)->sites($this->site->ploi_id)->app()->install($this->type, $this->options);
|
if (Arr::get($this->options, 'create_database', false)) {
|
||||||
|
$database = $this->site->databases()->create([
|
||||||
|
'name' => $response->database_name,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$database->status = Database::STATUS_ACTIVE;
|
||||||
|
$database->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Jobs\Apps;
|
namespace App\Jobs\Apps;
|
||||||
|
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -12,9 +12,9 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class UninstallApp implements ShouldQueue
|
class UninstallApp implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $site;
|
public Site $site;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
@@ -37,9 +37,11 @@ class UninstallApp implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$this->getPloi()
|
||||||
|
->server($this->site->server->ploi_id)
|
||||||
$ploi->server($this->site->server->ploi_id)->sites($this->site->ploi_id)->app()->uninstall($this->site->project);
|
->sites($this->site->ploi_id)
|
||||||
|
->app()
|
||||||
|
->uninstall($this->site->project);
|
||||||
|
|
||||||
$this->site->project = null;
|
$this->site->project = null;
|
||||||
$this->site->save();
|
$this->site->save();
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Certificates;
|
namespace App\Jobs\Certificates;
|
||||||
|
|
||||||
|
use App\Traits\HasPloi;
|
||||||
use App\Models\Certificate;
|
use App\Models\Certificate;
|
||||||
use App\Services\Ploi\Ploi;
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -12,38 +12,44 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class CreateCertificate implements ShouldQueue
|
class CreateCertificate implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $certificate;
|
public Certificate $certificate;
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param Certificate $certificate
|
|
||||||
*/
|
|
||||||
public function __construct(Certificate $certificate)
|
public function __construct(Certificate $certificate)
|
||||||
{
|
{
|
||||||
$this->certificate = $certificate;
|
$this->certificate = $certificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
if ($this->certificate->type === 'letsencrypt') {
|
||||||
|
$ploiCertificate = $this->getPloi()
|
||||||
|
->server($this->certificate->server->ploi_id)
|
||||||
|
->sites($this->certificate->site->ploi_id)
|
||||||
|
->certificates()
|
||||||
|
->create(
|
||||||
|
$this->certificate->domain
|
||||||
|
);
|
||||||
|
|
||||||
$ploiCertificate = $ploi->server($this->certificate->server->ploi_id)
|
$this->certificate->ploi_id = $ploiCertificate->id;
|
||||||
->sites($this->certificate->site->ploi_id)
|
$this->certificate->save();
|
||||||
->certificates()
|
}
|
||||||
->create(
|
|
||||||
$this->certificate->domain
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->certificate->ploi_id = $ploiCertificate->id;
|
if ($this->certificate->type === 'custom') {
|
||||||
$this->certificate->save();
|
$ploiCertificate = $this->getPloi()
|
||||||
|
->server($this->certificate->server->ploi_id)
|
||||||
|
->sites($this->certificate->site->ploi_id)
|
||||||
|
->certificates()
|
||||||
|
->create(
|
||||||
|
$this->certificate->certificate,
|
||||||
|
$this->certificate->type,
|
||||||
|
$this->certificate->private
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->certificate->ploi_id = $ploiCertificate->id;
|
||||||
|
$this->certificate->save();
|
||||||
|
}
|
||||||
|
|
||||||
// Lets fetch the status after 5 seconds
|
// Lets fetch the status after 5 seconds
|
||||||
dispatch(new FetchCertificateStatus($this->certificate))->delay(now()->addSeconds(5));
|
dispatch(new FetchCertificateStatus($this->certificate))->delay(now()->addSeconds(5));
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Certificates;
|
namespace App\Jobs\Certificates;
|
||||||
|
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -11,7 +11,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class DeleteCertificate implements ShouldQueue
|
class DeleteCertificate implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $serverPloiId;
|
public $serverPloiId;
|
||||||
public $sitePloiId;
|
public $sitePloiId;
|
||||||
@@ -42,9 +42,8 @@ class DeleteCertificate implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$this->getPloi()
|
||||||
|
->server($this->serverPloiId)
|
||||||
$ploi->server($this->serverPloiId)
|
|
||||||
->sites($this->sitePloiId)
|
->sites($this->sitePloiId)
|
||||||
->certificates()
|
->certificates()
|
||||||
->delete($this->certificatePloiId);
|
->delete($this->certificatePloiId);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Certificates;
|
namespace App\Jobs\Certificates;
|
||||||
|
|
||||||
|
use App\Traits\HasPloi;
|
||||||
use App\Models\Certificate;
|
use App\Models\Certificate;
|
||||||
use App\Services\Ploi\Ploi;
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use App\Traits\JobHasThresholds;
|
use App\Traits\JobHasThresholds;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
@@ -13,7 +13,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class FetchCertificateStatus implements ShouldQueue
|
class FetchCertificateStatus implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds, HasPloi;
|
||||||
|
|
||||||
public $certificate;
|
public $certificate;
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ class FetchCertificateStatus implements ShouldQueue
|
|||||||
* @param Certificate $certificate
|
* @param Certificate $certificate
|
||||||
* @param int $threshold
|
* @param int $threshold
|
||||||
*/
|
*/
|
||||||
public function __construct(Certificate $certificate, $threshold = 0)
|
public function __construct(Certificate $certificate, int $threshold = 0)
|
||||||
{
|
{
|
||||||
$this->certificate = $certificate;
|
$this->certificate = $certificate;
|
||||||
$this->setThreshold($threshold);
|
$this->setThreshold($threshold);
|
||||||
@@ -43,9 +43,8 @@ class FetchCertificateStatus implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$ploiCronjob = $this->getPloi()
|
||||||
|
->server($this->certificate->server->ploi_id)
|
||||||
$ploiCronjob = $ploi->server($this->certificate->server->ploi_id)
|
|
||||||
->sites($this->certificate->site->ploi_id)
|
->sites($this->certificate->site->ploi_id)
|
||||||
->certificates()
|
->certificates()
|
||||||
->get($this->certificate->ploi_id)
|
->get($this->certificate->ploi_id)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Jobs\Core;
|
|||||||
|
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Services\Ploi\Ploi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
|
use App\Services\VersionChecker;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -16,21 +17,29 @@ class Ping implements ShouldQueue
|
|||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$version = new VersionChecker;
|
||||||
|
|
||||||
|
$version->flushVersionData();
|
||||||
|
|
||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
'Accept' => 'application/json',
|
'Accept' => 'application/json',
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'X-Ploi-Core-Key' => config('services.ploi.core-token')
|
'X-Ploi-Core-Key' => config('services.ploi.core-token')
|
||||||
])
|
])
|
||||||
->withToken(config('services.ploi.token'))
|
->withToken(config('services.ploi.token'))
|
||||||
->get((new Ploi)->url . 'ping');
|
->post((new Ploi)->url . 'ping', [
|
||||||
|
'version' => $version->getApplicationVersion(),
|
||||||
|
'php_version' => phpversion(),
|
||||||
|
'panel_url' => config('app.url')
|
||||||
|
]);
|
||||||
|
|
||||||
if (!$response->ok() || !$response->json()) {
|
if (!$response->ok() || !$response->json()) {
|
||||||
|
|
||||||
// Something went wrong..
|
// Something went wrong..
|
||||||
|
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$response->json();
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Jobs\Core;
|
|||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
@@ -12,26 +13,13 @@ class UpdateSystem implements ShouldQueue
|
|||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
shell_exec('git pull origin master');
|
shell_exec('git pull origin master');
|
||||||
shell_exec('composer install --no-interaction --prefer-dist --no-dev --optimize-autoloader --quiet');
|
shell_exec('composer install --no-interaction --prefer-dist --no-dev --optimize-autoloader --quiet');
|
||||||
|
|
||||||
|
Artisan::call('horizon:terminate');
|
||||||
|
|
||||||
cache()->forget('ploi-core-current-version');
|
cache()->forget('ploi-core-current-version');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Jobs\Cronjobs;
|
namespace App\Jobs\Cronjobs;
|
||||||
|
|
||||||
use App\Models\Cronjob;
|
use App\Models\Cronjob;
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -12,7 +12,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class CreateCronjob implements ShouldQueue
|
class CreateCronjob implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $cronjob;
|
public $cronjob;
|
||||||
|
|
||||||
@@ -35,13 +35,14 @@ class CreateCronjob implements ShouldQueue
|
|||||||
{
|
{
|
||||||
$owner = $this->cronjob->site->users()->first();
|
$owner = $this->cronjob->site->users()->first();
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$ploiCronjob = $this->getPloi()
|
||||||
|
->server($this->cronjob->server->ploi_id)
|
||||||
$ploiCronjob = $ploi->server($this->cronjob->server->ploi_id)->cronjobs()->create(
|
->cronjobs()
|
||||||
$this->cronjob->command,
|
->create(
|
||||||
$this->cronjob->frequency,
|
$this->cronjob->command,
|
||||||
$owner->user_name
|
$this->cronjob->frequency,
|
||||||
);
|
$owner->user_name
|
||||||
|
);
|
||||||
|
|
||||||
$this->cronjob->ploi_id = $ploiCronjob->id;
|
$this->cronjob->ploi_id = $ploiCronjob->id;
|
||||||
$this->cronjob->save();
|
$this->cronjob->save();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Cronjobs;
|
namespace App\Jobs\Cronjobs;
|
||||||
|
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -11,7 +11,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class DeleteCronjob implements ShouldQueue
|
class DeleteCronjob implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $serverPloiId;
|
public $serverPloiId;
|
||||||
public $cronjobPloiId;
|
public $cronjobPloiId;
|
||||||
@@ -39,8 +39,9 @@ class DeleteCronjob implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$this->getPloi()
|
||||||
|
->server($this->serverPloiId)
|
||||||
$ploi->server($this->serverPloiId)->cronjobs()->delete($this->cronjobPloiId);
|
->cronjobs()
|
||||||
|
->delete($this->cronjobPloiId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Jobs\Cronjobs;
|
namespace App\Jobs\Cronjobs;
|
||||||
|
|
||||||
use App\Models\Cronjob;
|
use App\Models\Cronjob;
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use App\Traits\JobHasThresholds;
|
use App\Traits\JobHasThresholds;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
@@ -13,7 +13,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class FetchCronjobStatus implements ShouldQueue
|
class FetchCronjobStatus implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds, HasPloi;
|
||||||
|
|
||||||
public $cronjob;
|
public $cronjob;
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ class FetchCronjobStatus implements ShouldQueue
|
|||||||
* @param Cronjob $cronjob
|
* @param Cronjob $cronjob
|
||||||
* @param int $threshold
|
* @param int $threshold
|
||||||
*/
|
*/
|
||||||
public function __construct(Cronjob $cronjob, $threshold = 0)
|
public function __construct(Cronjob $cronjob, int $threshold = 0)
|
||||||
{
|
{
|
||||||
$this->cronjob = $cronjob;
|
$this->cronjob = $cronjob;
|
||||||
$this->setThreshold($threshold);
|
$this->setThreshold($threshold);
|
||||||
@@ -43,9 +43,11 @@ class FetchCronjobStatus implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$ploiCronjob = $this->getPloi()
|
||||||
|
->server($this->cronjob->server->ploi_id)
|
||||||
$ploiCronjob = $ploi->server($this->cronjob->server->ploi_id)->cronjobs()->get($this->cronjob->ploi_id)->getData();
|
->cronjobs()
|
||||||
|
->get($this->cronjob->ploi_id)
|
||||||
|
->getData();
|
||||||
|
|
||||||
if ($ploiCronjob->status !== Cronjob::STATUS_ACTIVE) {
|
if ($ploiCronjob->status !== Cronjob::STATUS_ACTIVE) {
|
||||||
$this->incrementThreshold();
|
$this->incrementThreshold();
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Databases;
|
namespace App\Jobs\Databases;
|
||||||
|
|
||||||
|
use App\Traits\HasPloi;
|
||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Services\Ploi\Ploi;
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -12,7 +12,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class CreateDatabase implements ShouldQueue
|
class CreateDatabase implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $database;
|
public $database;
|
||||||
public $password;
|
public $password;
|
||||||
@@ -38,9 +38,10 @@ class CreateDatabase implements ShouldQueue
|
|||||||
{
|
{
|
||||||
$databaseUser = $this->database->users()->first();
|
$databaseUser = $this->database->users()->first();
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$ploiDatabase = $this->getPloi()
|
||||||
|
->server($this->database->server->ploi_id)
|
||||||
$ploiDatabase = $ploi->server($this->database->server->ploi_id)->databases()->create($this->database->name, $databaseUser->name, $this->password);
|
->databases()
|
||||||
|
->create($this->database->name, $databaseUser->name, $this->password);
|
||||||
|
|
||||||
$this->database->ploi_id = $ploiDatabase->id;
|
$this->database->ploi_id = $ploiDatabase->id;
|
||||||
$this->database->save();
|
$this->database->save();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Databases;
|
namespace App\Jobs\Databases;
|
||||||
|
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -11,7 +11,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class DeleteDatabase implements ShouldQueue
|
class DeleteDatabase implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $serverPloiId;
|
public $serverPloiId;
|
||||||
public $databasePloiId;
|
public $databasePloiId;
|
||||||
@@ -40,8 +40,6 @@ class DeleteDatabase implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$this->getPloi()->server($this->serverPloiId)->databases()->delete($this->databasePloiId);
|
||||||
|
|
||||||
$ploi->server($this->serverPloiId)->databases()->delete($this->databasePloiId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Databases;
|
namespace App\Jobs\Databases;
|
||||||
|
|
||||||
|
use App\Traits\HasPloi;
|
||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Services\Ploi\Ploi;
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use App\Traits\JobHasThresholds;
|
use App\Traits\JobHasThresholds;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
@@ -13,7 +13,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class FetchDatabaseStatus implements ShouldQueue
|
class FetchDatabaseStatus implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds, HasPloi;
|
||||||
|
|
||||||
public $database;
|
public $database;
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ class FetchDatabaseStatus implements ShouldQueue
|
|||||||
* @param Database $database
|
* @param Database $database
|
||||||
* @param int $threshold
|
* @param int $threshold
|
||||||
*/
|
*/
|
||||||
public function __construct(Database $database, $threshold = 0)
|
public function __construct(Database $database, int $threshold = 0)
|
||||||
{
|
{
|
||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
$this->setThreshold($threshold);
|
$this->setThreshold($threshold);
|
||||||
@@ -43,9 +43,11 @@ class FetchDatabaseStatus implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$ploiDatabase = $this->getPloi()
|
||||||
|
->server($this->database->server->ploi_id)
|
||||||
$ploiDatabase = $ploi->server($this->database->server->ploi_id)->databases()->get($this->database->ploi_id)->getData();
|
->databases()
|
||||||
|
->get($this->database->ploi_id)
|
||||||
|
->getData();
|
||||||
|
|
||||||
if ($ploiDatabase->status !== Database::STATUS_ACTIVE) {
|
if ($ploiDatabase->status !== Database::STATUS_ACTIVE) {
|
||||||
$this->incrementThreshold();
|
$this->incrementThreshold();
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Redirects;
|
namespace App\Jobs\Redirects;
|
||||||
|
|
||||||
|
use App\Traits\HasPloi;
|
||||||
use App\Models\Redirect;
|
use App\Models\Redirect;
|
||||||
use App\Services\Ploi\Ploi;
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -12,7 +12,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class CreateRedirect implements ShouldQueue
|
class CreateRedirect implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $redirect;
|
public $redirect;
|
||||||
|
|
||||||
@@ -33,9 +33,7 @@ class CreateRedirect implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$ploiRedirect = $this->getPloi()
|
||||||
|
|
||||||
$ploiRedirect = $ploi
|
|
||||||
->server($this->redirect->server->ploi_id)
|
->server($this->redirect->server->ploi_id)
|
||||||
->sites($this->redirect->site->ploi_id)
|
->sites($this->redirect->site->ploi_id)
|
||||||
->redirects()
|
->redirects()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Redirects;
|
namespace App\Jobs\Redirects;
|
||||||
|
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -11,7 +11,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class DeleteRedirect implements ShouldQueue
|
class DeleteRedirect implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $serverPloiId;
|
public $serverPloiId;
|
||||||
public $sitePloiId;
|
public $sitePloiId;
|
||||||
@@ -42,9 +42,8 @@ class DeleteRedirect implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$this->getPloi()
|
||||||
|
->server($this->serverPloiId)
|
||||||
$ploi->server($this->serverPloiId)
|
|
||||||
->sites($this->sitePloiId)
|
->sites($this->sitePloiId)
|
||||||
->redirects()
|
->redirects()
|
||||||
->delete($this->redirectPloiId);
|
->delete($this->redirectPloiId);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Redirects;
|
namespace App\Jobs\Redirects;
|
||||||
|
|
||||||
|
use App\Traits\HasPloi;
|
||||||
use App\Models\Redirect;
|
use App\Models\Redirect;
|
||||||
use App\Services\Ploi\Ploi;
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use App\Traits\JobHasThresholds;
|
use App\Traits\JobHasThresholds;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
@@ -13,7 +13,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class FetchRedirectStatus implements ShouldQueue
|
class FetchRedirectStatus implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds, HasPloi;
|
||||||
|
|
||||||
public $redirect;
|
public $redirect;
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ class FetchRedirectStatus implements ShouldQueue
|
|||||||
* @param Redirect $redirect
|
* @param Redirect $redirect
|
||||||
* @param int $threshold
|
* @param int $threshold
|
||||||
*/
|
*/
|
||||||
public function __construct(Redirect $redirect, $threshold = 0)
|
public function __construct(Redirect $redirect, int $threshold = 0)
|
||||||
{
|
{
|
||||||
$this->redirect = $redirect;
|
$this->redirect = $redirect;
|
||||||
$this->setThreshold($threshold);
|
$this->setThreshold($threshold);
|
||||||
@@ -43,9 +43,8 @@ class FetchRedirectStatus implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$ploiRedirect = $this->getPloi()
|
||||||
|
->server($this->redirect->server->ploi_id)
|
||||||
$ploiRedirect = $ploi->server($this->redirect->server->ploi_id)
|
|
||||||
->sites($this->redirect->site->ploi_id)
|
->sites($this->redirect->site->ploi_id)
|
||||||
->redirects()
|
->redirects()
|
||||||
->get($this->redirect->ploi_id)->getData();
|
->get($this->redirect->ploi_id)->getData();
|
||||||
|
|||||||
47
app/Jobs/Servers/CreateServer.php
Normal file
47
app/Jobs/Servers/CreateServer.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\Servers;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Traits\HasPloi;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
|
||||||
|
class CreateServer implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
|
public $server;
|
||||||
|
public $tries = 1;
|
||||||
|
|
||||||
|
public function __construct(Server $server)
|
||||||
|
{
|
||||||
|
$this->server = $server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$ploiServer = $this->getPloi()->server()->create(
|
||||||
|
$this->server->name,
|
||||||
|
$this->server->provider->ploi_id,
|
||||||
|
$this->server->providerRegion->region_id,
|
||||||
|
$this->server->providerPlan->plan_id,
|
||||||
|
'server',
|
||||||
|
$this->server->database_type
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->server->ploi_id = $ploiServer->id;
|
||||||
|
$this->server->save();
|
||||||
|
|
||||||
|
// Let's fetch the status after 5 minutes
|
||||||
|
dispatch(new FetchServerStatus($this->server))->delay(now()->addMinutes(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function failed(\Exception $exception)
|
||||||
|
{
|
||||||
|
$this->server->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Servers;
|
namespace App\Jobs\Servers;
|
||||||
|
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class DeleteServer implements ShouldQueue
|
class DeleteServer implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $serverPloiId;
|
public $serverPloiId;
|
||||||
|
|
||||||
@@ -32,8 +32,6 @@ class DeleteServer implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$this->getPloi()->server($this->serverPloiId)->delete();
|
||||||
|
|
||||||
$ploi->server($this->serverPloiId)->delete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
68
app/Jobs/Servers/FetchServerStatus.php
Normal file
68
app/Jobs/Servers/FetchServerStatus.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\Servers;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Traits\HasPloi;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use App\Traits\JobHasThresholds;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
|
||||||
|
class FetchServerStatus implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds, HasPloi;
|
||||||
|
|
||||||
|
public $server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @param Server $server
|
||||||
|
* @param int $threshold
|
||||||
|
*/
|
||||||
|
public function __construct(Server $server, $threshold = 0)
|
||||||
|
{
|
||||||
|
$this->server = $server;
|
||||||
|
$this->setThreshold($threshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
// If we tried over 10 times, game over, delete the site
|
||||||
|
if ($this->hasReachedThresholdLimit(10)) {
|
||||||
|
$this->server->delete();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ploiServer = $this->getPloi()->server($this->server->ploi_id)->get()->getData();
|
||||||
|
|
||||||
|
if ($ploiServer->status !== Server::STATUS_ACTIVE) {
|
||||||
|
$this->incrementThreshold();
|
||||||
|
|
||||||
|
dispatch(new self($this->server, $this->threshold))->delay(now()->addMinutes(2));
|
||||||
|
|
||||||
|
// Check if an IP address is present already
|
||||||
|
if ($ploiServer->ip_address && !$this->server->ip) {
|
||||||
|
$this->server->ip = $ploiServer->ip_address;
|
||||||
|
$this->server->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->server->status = $ploiServer->status;
|
||||||
|
$this->server->ip = $ploiServer->ip_address;
|
||||||
|
$this->server->internal_ip = $ploiServer->internal_ip;
|
||||||
|
$this->server->available_php_versions = $ploiServer->installed_php_versions;
|
||||||
|
$this->server->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Servers;
|
|
||||||
|
|
||||||
use App\Models\Server;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
|
|
||||||
class SynchronizeServers implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$ploi = new \App\Services\Ploi\Ploi(config('services.ploi.token'));
|
|
||||||
|
|
||||||
$servers = $ploi->server()->get()->getData();
|
|
||||||
|
|
||||||
foreach ($servers as $server) {
|
|
||||||
Server::firstOrCreate([
|
|
||||||
'ip' => $server->ip_address,
|
|
||||||
], [
|
|
||||||
'name' => $server->name
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Jobs\Sites;
|
namespace App\Jobs\Sites;
|
||||||
|
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -12,7 +12,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class ChangePhpVersion implements ShouldQueue
|
class ChangePhpVersion implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $site;
|
public $site;
|
||||||
public $version;
|
public $version;
|
||||||
@@ -36,9 +36,7 @@ class ChangePhpVersion implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$this->getPloi()->server($this->site->server->ploi_id)->sites($this->site->ploi_id)->phpVersion($this->version);
|
||||||
|
|
||||||
$ploi->server($this->site->server->ploi_id)->sites($this->site->ploi_id)->phpVersion($this->version);
|
|
||||||
|
|
||||||
$this->site->php_version = $this->version;
|
$this->site->php_version = $this->version;
|
||||||
$this->site->save();
|
$this->site->save();
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
namespace App\Jobs\Sites;
|
namespace App\Jobs\Sites;
|
||||||
|
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -12,7 +13,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class CreateSite implements ShouldQueue
|
class CreateSite implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $site;
|
public $site;
|
||||||
|
|
||||||
@@ -33,16 +34,14 @@ class CreateSite implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$systemUser = $this->site->getSystemUser();
|
||||||
|
|
||||||
$owner = $this->site->users()->first();
|
$ploiSite = $this->getPloi()->server($this->site->server->ploi_id)->sites()->create(
|
||||||
|
|
||||||
$ploiSite = $ploi->server($this->site->server->ploi_id)->sites()->create(
|
|
||||||
$this->site->domain,
|
$this->site->domain,
|
||||||
'/public',
|
'/public',
|
||||||
'/',
|
'/',
|
||||||
$owner->user_name,
|
Arr::get($systemUser, 'user_name'),
|
||||||
decrypt($owner->ftp_password)
|
decrypt(Arr::get($systemUser, 'ftp_password'))
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->site->ploi_id = $ploiSite->data->id;
|
$this->site->ploi_id = $ploiSite->data->id;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Sites;
|
namespace App\Jobs\Sites;
|
||||||
|
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -11,7 +11,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class DeleteSite implements ShouldQueue
|
class DeleteSite implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||||
|
|
||||||
public $serverPloiId;
|
public $serverPloiId;
|
||||||
public $sitePloiId;
|
public $sitePloiId;
|
||||||
@@ -34,8 +34,6 @@ class DeleteSite implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$this->getPloi()->server($this->serverPloiId)->sites()->delete($this->sitePloiId);
|
||||||
|
|
||||||
$ploi->server($this->serverPloiId)->sites()->delete($this->sitePloiId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Jobs\Sites;
|
namespace App\Jobs\Sites;
|
||||||
|
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\Services\Ploi\Ploi;
|
use App\Traits\HasPloi;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use App\Traits\JobHasThresholds;
|
use App\Traits\JobHasThresholds;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
@@ -13,7 +13,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
|
|
||||||
class FetchSiteStatus implements ShouldQueue
|
class FetchSiteStatus implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHasThresholds, HasPloi;
|
||||||
|
|
||||||
public $site;
|
public $site;
|
||||||
|
|
||||||
@@ -43,9 +43,7 @@ class FetchSiteStatus implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ploi = new Ploi(config('services.ploi.token'));
|
$ploiSite = $this->getPloi()->server($this->site->server->ploi_id)->sites()->get($this->site->ploi_id)->getData();
|
||||||
|
|
||||||
$ploiSite = $ploi->server($this->site->server->ploi_id)->sites()->get($this->site->ploi_id)->getData();
|
|
||||||
|
|
||||||
if ($ploiSite->status !== Site::STATUS_ACTIVE) {
|
if ($ploiSite->status !== Site::STATUS_ACTIVE) {
|
||||||
$this->incrementThreshold();
|
$this->incrementThreshold();
|
||||||
|
|||||||
42
app/Mail/Admin/Server/AdminServerCreatedEmail.php
Normal file
42
app/Mail/Admin/Server/AdminServerCreatedEmail.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail\Admin\Server;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class AdminServerCreatedEmail extends Mailable implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $user;
|
||||||
|
public $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
|
||||||
|
->subject(__('A user has created a new server'))
|
||||||
|
->markdown('emails.admin.server.new-server');
|
||||||
|
}
|
||||||
|
}
|
||||||
42
app/Mail/Server/ServerCreatedEmail.php
Normal file
42
app/Mail/Server/ServerCreatedEmail.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail\Server;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class ServerCreatedEmail extends Mailable implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $user;
|
||||||
|
public $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
|
||||||
|
->subject(__('Your new server is being created'))
|
||||||
|
->markdown('emails.server.new-server');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,10 @@ namespace App\Mail\User;
|
|||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Mail\Mailable;
|
use Illuminate\Mail\Mailable;
|
||||||
use Illuminate\Support\Facades\URL;
|
use Illuminate\Support\Facades\URL;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
class WelcomeEmail extends Mailable implements ShouldQueue
|
class WelcomeEmail extends Mailable implements ShouldQueue
|
||||||
{
|
{
|
||||||
|
|||||||
28
app/Models/Alert.php
Normal file
28
app/Models/Alert.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Alert extends Model
|
||||||
|
{
|
||||||
|
const TYPE_INFO = 'info';
|
||||||
|
const TYPE_WARNING = 'warning';
|
||||||
|
const TYPE_DANGER = 'danger';
|
||||||
|
|
||||||
|
public $fillable = [
|
||||||
|
'type',
|
||||||
|
'message',
|
||||||
|
'expires_at'
|
||||||
|
];
|
||||||
|
|
||||||
|
public $dates = [
|
||||||
|
'expires_at'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function serializeDate(DateTimeInterface $date)
|
||||||
|
{
|
||||||
|
return $date->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,10 @@ class Certificate extends Model
|
|||||||
|
|
||||||
public $fillable = [
|
public $fillable = [
|
||||||
'domain',
|
'domain',
|
||||||
'type'
|
'type',
|
||||||
|
'certificate',
|
||||||
|
'private',
|
||||||
|
'ploi_id',
|
||||||
|
'status'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
18
app/Models/DocumentationCategory.php
Normal file
18
app/Models/DocumentationCategory.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class DocumentationCategory extends Model
|
||||||
|
{
|
||||||
|
public $fillable = [
|
||||||
|
'title',
|
||||||
|
'description'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function items()
|
||||||
|
{
|
||||||
|
return $this->hasMany(DocumentationItem::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,5 +6,13 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
|
|
||||||
class DocumentationItem extends Model
|
class DocumentationItem extends Model
|
||||||
{
|
{
|
||||||
//
|
public $fillable = [
|
||||||
|
'title',
|
||||||
|
'content'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function category()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(DocumentationCategory::class, 'documentation_category_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,19 +2,37 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Casts\PermissionCast;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Package extends Model
|
class Package extends Model
|
||||||
{
|
{
|
||||||
|
const CURRENCY_EURO = 'eur';
|
||||||
|
const CURRENCY_USD = 'usd';
|
||||||
|
const CURRENCY_NOK = 'nok';
|
||||||
|
const CURRENCY_AUD = 'aud';
|
||||||
|
const CURRENCY_CAD = 'cad';
|
||||||
|
const CURRENCY_GBP = 'gbp';
|
||||||
|
const CURRENCY_INR = 'inr';
|
||||||
|
const CURRENCY_THB = 'thb';
|
||||||
|
const CURRENCY_BRL = 'brl';
|
||||||
|
|
||||||
public $fillable = [
|
public $fillable = [
|
||||||
'name',
|
'name',
|
||||||
|
'plan_id', // This does not reflect a internal database relation, it reflects the plan ID from the PSP
|
||||||
|
'currency',
|
||||||
|
'price_hourly',
|
||||||
|
'price_monthly',
|
||||||
|
'price_yearly',
|
||||||
'maximum_sites',
|
'maximum_sites',
|
||||||
'maximum_servers',
|
'maximum_servers',
|
||||||
'server_creation'
|
'site_permissions',
|
||||||
|
'server_permissions'
|
||||||
];
|
];
|
||||||
|
|
||||||
public $casts = [
|
public $casts = [
|
||||||
'server_creation' => 'boolean'
|
'site_permissions' => PermissionCast::class,
|
||||||
|
'server_permissions' => PermissionCast::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
public function users()
|
public function users()
|
||||||
@@ -22,6 +40,11 @@ class Package extends Model
|
|||||||
return $this->hasMany(User::class);
|
return $this->hasMany(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function providers()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Provider::class);
|
||||||
|
}
|
||||||
|
|
||||||
protected static function booted()
|
protected static function booted()
|
||||||
{
|
{
|
||||||
static::deleting(function ($package) {
|
static::deleting(function ($package) {
|
||||||
|
|||||||
@@ -8,6 +8,22 @@ class Provider extends Model
|
|||||||
{
|
{
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'allowed_plans' => 'json',
|
||||||
|
'allowed_regions' => 'json',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function getNameWithLabelAttribute()
|
||||||
|
{
|
||||||
|
$string = $this->name;
|
||||||
|
|
||||||
|
if ($this->label) {
|
||||||
|
$string .= ' (' . $this->label . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
public function plans()
|
public function plans()
|
||||||
{
|
{
|
||||||
return $this->hasMany(ProviderPlan::class);
|
return $this->hasMany(ProviderPlan::class);
|
||||||
@@ -17,4 +33,30 @@ class Provider extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(ProviderRegion::class);
|
return $this->hasMany(ProviderRegion::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function packages()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Package::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function servers()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Server::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function booted()
|
||||||
|
{
|
||||||
|
static::deleting(function (self $provider) {
|
||||||
|
$provider->regions()->delete();
|
||||||
|
$provider->plans()->delete();
|
||||||
|
$provider->packages()->detach();
|
||||||
|
|
||||||
|
foreach ($provider->servers as $server) {
|
||||||
|
$server->provider_id = null;
|
||||||
|
$server->provider_plan_id = null;
|
||||||
|
$server->provider_region_id = null;
|
||||||
|
$server->save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user