initial commit
This commit is contained in:
42
app/Http/Requests/StoreCustomerRequest.php
Normal file
42
app/Http/Requests/StoreCustomerRequest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreCustomerRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$baseDomain = config('hosting.plesk.base_domain');
|
||||
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:100', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/'],
|
||||
'subdomain' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:63',
|
||||
'regex:/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/',
|
||||
function (string $attribute, mixed $value, \Closure $fail) use ($baseDomain): void {
|
||||
$domain = strtolower((string) $value).'.'.$baseDomain;
|
||||
if (\App\Models\Customer::query()->where('domain', $domain)->exists()) {
|
||||
$fail("The domain {$domain} is already registered.");
|
||||
}
|
||||
},
|
||||
],
|
||||
'cpu' => ['sometimes', 'integer', 'min:1', 'max:32'],
|
||||
'ram' => ['sometimes', 'integer', 'min:512', 'max:131072'],
|
||||
'disk' => ['sometimes', 'integer', 'min:10', 'max:2048'],
|
||||
];
|
||||
}
|
||||
|
||||
public function domain(): string
|
||||
{
|
||||
return strtolower($this->validated('subdomain')).'.'.config('hosting.plesk.base_domain');
|
||||
}
|
||||
}
|
||||
64
app/Http/Requests/StoreVmRequest.php
Normal file
64
app/Http/Requests/StoreVmRequest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreVmRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('create', Customer::class);
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$baseDomain = config('hosting.plesk.base_domain');
|
||||
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:100', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/'],
|
||||
'subdomain' => [
|
||||
Rule::requiredIf(fn () => $this->boolean('behind_traefik')),
|
||||
'nullable',
|
||||
'string',
|
||||
'max:63',
|
||||
'regex:/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/',
|
||||
],
|
||||
'behind_traefik' => ['boolean'],
|
||||
'user_id' => [
|
||||
Rule::requiredIf(fn () => $this->user()->isAdmin()),
|
||||
'nullable',
|
||||
'exists:users,id',
|
||||
],
|
||||
'ip_pool_id' => ['nullable', 'exists:ip_pools,id'],
|
||||
'cpu' => ['required', 'integer', 'min:1', 'max:32'],
|
||||
'ram' => ['required', 'integer', 'min:512', 'max:131072'],
|
||||
'disk' => ['required', 'integer', 'min:10', 'max:2048'],
|
||||
'devices' => ['nullable', 'array'],
|
||||
'devices.*.type' => ['required_with:devices', Rule::in(array_keys(\App\Models\VmDevice::typesFor($this->user())))],
|
||||
'devices.*.slot' => ['nullable', 'string', 'max:32'],
|
||||
'devices.*.config' => ['nullable', 'array'],
|
||||
'install_iso' => ['nullable', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
public function domain(): ?string
|
||||
{
|
||||
if (! $this->boolean('behind_traefik') || ! $this->filled('subdomain')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return strtolower($this->input('subdomain')).'.'.config('hosting.plesk.base_domain');
|
||||
}
|
||||
|
||||
public function ownerId(): int
|
||||
{
|
||||
if ($this->user()->isAdmin() && $this->filled('user_id')) {
|
||||
return (int) $this->input('user_id');
|
||||
}
|
||||
|
||||
return $this->user()->id;
|
||||
}
|
||||
}
|
||||
28
app/Http/Requests/UpdateVmRequest.php
Normal file
28
app/Http/Requests/UpdateVmRequest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateVmRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('update', $this->route('vm'));
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['sometimes', 'string', 'max:100', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/'],
|
||||
'cpu' => ['sometimes', 'integer', 'min:1', 'max:32'],
|
||||
'ram' => ['sometimes', 'integer', 'min:512', 'max:131072'],
|
||||
'disk' => ['sometimes', 'integer', 'min:10', 'max:2048'],
|
||||
'devices' => ['nullable', 'array'],
|
||||
'devices.*.type' => ['required_with:devices', Rule::in(array_keys(\App\Models\VmDevice::typesFor($this->user())))],
|
||||
'devices.*.slot' => ['nullable', 'string', 'max:32'],
|
||||
'devices.*.config' => ['nullable', 'array'],
|
||||
];
|
||||
}
|
||||
}
|
||||
57
app/Http/Requests/Whmcs/ProvisionServiceRequest.php
Normal file
57
app/Http/Requests/Whmcs/ProvisionServiceRequest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Whmcs;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ProvisionServiceRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'whmcs_service_id' => ['required', 'integer', 'unique:whmcs_services,whmcs_service_id'],
|
||||
'whmcs_client_id' => ['required', 'integer'],
|
||||
'whmcs_order_id' => ['nullable', 'integer'],
|
||||
'client_email' => ['required', 'email', 'max:255'],
|
||||
'client_name' => ['required', 'string', 'max:100'],
|
||||
'plan_slug' => ['required', 'string', 'exists:hosting_plans,slug'],
|
||||
'hostname' => ['required', 'string', 'max:100', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/'],
|
||||
'subdomain' => [
|
||||
Rule::requiredIf(fn () => $this->boolean('behind_traefik', true)),
|
||||
'nullable',
|
||||
'string',
|
||||
'max:63',
|
||||
'regex:/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/',
|
||||
],
|
||||
'behind_traefik' => ['boolean'],
|
||||
'provision_mode' => ['required', Rule::in(['template', 'iso', 'empty'])],
|
||||
'template_slug' => [
|
||||
Rule::requiredIf(fn () => $this->input('provision_mode') === 'template'),
|
||||
'nullable',
|
||||
'string',
|
||||
'max:64',
|
||||
],
|
||||
'iso_volid' => [
|
||||
Rule::requiredIf(fn () => $this->input('provision_mode') === 'iso'),
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function domain(): ?string
|
||||
{
|
||||
if (! $this->boolean('behind_traefik', true) || ! $this->filled('subdomain')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return strtolower($this->input('subdomain')).'.'.config('hosting.plesk.base_domain');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user