This commit is contained in:
Saeed Vaziry
2025-05-30 11:02:07 +02:00
parent 1b9f826bcb
commit 104cd2fce8
14 changed files with 572 additions and 266 deletions

View File

@ -15,6 +15,8 @@ class Install
*/
public function install(Server $server, array $input): Service
{
Validator::make($input, self::rules($input))->validate();
$input['type'] = config('core.service_types')[$input['name']];
$service = new Service([

View File

@ -2,17 +2,39 @@
namespace App\Http\Controllers;
use App\Actions\Service\Install;
use App\Actions\Service\Manage;
use App\Actions\Service\Uninstall;
use App\Http\Resources\ServiceResource;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
use Spatie\RouteAttributes\Attributes\Delete;
use Spatie\RouteAttributes\Attributes\Get;
use Spatie\RouteAttributes\Attributes\Middleware;
use Spatie\RouteAttributes\Attributes\Post;
use Spatie\RouteAttributes\Attributes\Prefix;
#[Prefix('servers/{server}/services')]
#[Middleware(['auth', 'has-project'])]
class ServiceController extends Controller
{
#[Get('/', name: 'services')]
public function index(Server $server): Response
{
$this->authorize('viewAny', [Service::class, $server]);
$services = $server->services()->simplePaginate(config('web.pagination_size'));
return Inertia::render('services/index', [
'services' => ServiceResource::collection($services),
]);
}
#[Get('{service}/versions', name: 'services.versions')]
public function versions(Server $server, string $service): JsonResponse
{
@ -27,4 +49,88 @@ public function versions(Server $server, string $service): JsonResponse
return response()->json($versions);
}
#[Post('/', name: 'services.store')]
public function store(Request $request, Server $server): RedirectResponse
{
$this->authorize('create', [Service::class, $server]);
app(Install::class)->install($server, $request->input());
return back()->with('success', __(':service is being installed.', [
'service' => $request->input('name'),
]));
}
#[Post('/{service}/start', name: 'services.start')]
public function start(Server $server, Service $service): RedirectResponse
{
$this->authorize('start', $service);
app(Manage::class)->start($service);
return back()->with('success', __(':service is being started.', [
'service' => $service->name,
]));
}
#[Post('/{service}/restart', name: 'services.restart')]
public function restart(Server $server, Service $service): RedirectResponse
{
$this->authorize('restart', $service);
app(Manage::class)->restart($service);
return back()->with('success', __(':service is being restarted.', [
'service' => $service->name,
]));
}
#[Post('/{service}/stop', name: 'services.stop')]
public function stop(Server $server, Service $service): RedirectResponse
{
$this->authorize('stop', $service);
app(Manage::class)->stop($service);
return back()->with('success', __(':service is being stopped.', [
'service' => $service->name,
]));
}
#[Post('/{service}/enable', name: 'services.enable')]
public function enable(Server $server, Service $service): RedirectResponse
{
$this->authorize('enable', $service);
app(Manage::class)->enable($service);
return back()->with('success', __(':service is being enabled.', [
'service' => $service->name,
]));
}
#[Post('/{service}/disable', name: 'services.disable')]
public function disable(Server $server, Service $service): RedirectResponse
{
$this->authorize('disable', $service);
app(Manage::class)->disable($service);
return back()->with('success', __(':service is being disabled.', [
'service' => $service->name,
]));
}
#[Delete('/{service}', name: 'services.destroy')]
public function destroy(Server $server, Service $service): RedirectResponse
{
$this->authorize('delete', $service);
app(Uninstall::class)->uninstall($service);
return back()->with('warning', __(':service is being uninstalled.', [
'service' => $service->name,
]));
}
}

View File

@ -23,6 +23,8 @@ public function toArray(Request $request): array
'version' => $this->version,
'unit' => $this->unit,
'status' => $this->status,
'status_color' => Service::$statusColors[$this->status] ?? 'gray',
'icon' => config('core.service_icons')[$this->name] ?? '',
'is_default' => $this->is_default,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,

View File

@ -10,7 +10,7 @@ abstract class AbstractWebserver extends AbstractService implements Webserver
public function creationRules(array $input): array
{
return [
'type' => [
'name' => [
'required',
function (string $attribute, mixed $value, Closure $fail): void {
$webserverExists = $this->service->server->webserver();