Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Dec 6, 2024
1 parent 244b697 commit fb32352
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 26 deletions.
36 changes: 35 additions & 1 deletion web/Modules/Email/App/Filament/Pages/EmailHealthStatusPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\BadgeColumn;
use Modules\Email\App\Services\EmailService;
use Filament\Tables\Columns\TextColumn;
use Modules\Email\App\Enums\ServiceStatus;
use Filament\Tables\Concerns\InteractsWithTable;
Expand Down Expand Up @@ -36,6 +38,38 @@ public function table(Table $table): Table
->badge()
->sortable(),
])
->query(fn () => EmailHealthStatus::query());
->query(fn () => EmailHealthStatus::query())
->actions([
Action::make('restart')
->label('Restart')
->action(function (EmailHealthStatus $record) {
$emailService = new EmailService();
$serviceName = strtolower($record->service);
$emailService->restartService($serviceName);
})
->requiresConfirmation()
->color('warning')
->visible(fn (EmailHealthStatus $record) => $record->status === ServiceStatus::RUNNING),
Action::make('start')
->label('Start')
->action(function (EmailHealthStatus $record) {
$emailService = new EmailService();
$serviceName = strtolower($record->service);
$emailService->startService($serviceName);
})
->requiresConfirmation()
->color('success')
->visible(fn (EmailHealthStatus $record) => $record->status === ServiceStatus::NOT_RUNNING),
Action::make('stop')
->label('Stop')
->action(function (EmailHealthStatus $record) {
$emailService = new EmailService();
$serviceName = strtolower($record->service);
$emailService->stopService($serviceName);
})
->requiresConfirmation()
->color('danger')
->visible(fn (EmailHealthStatus $record) => $record->status === ServiceStatus::RUNNING),
]);
}
}
8 changes: 4 additions & 4 deletions web/Modules/Email/App/Models/EmailHealthStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public function getRows()
$rows = [
[
'service' => 'Dovecot',
'status' => ServiceStatus::from($service->checkDovecotStatus()),
'status' => ServiceStatus::from($service->checkServiceStatus('dovecot')),
],
[
'service' => 'Postfix',
'status' => ServiceStatus::from($service->checkPostfixStatus()),
'status' => ServiceStatus::from($service->checkServiceStatus('postfix')),
],
[
'service' => 'OpenDKIM',
'status' => ServiceStatus::from($service->checkOpenDkimStatus()),
'status' => ServiceStatus::from($service->checkServiceStatus('opendkim')),
],
[
'service' => 'Firewall',
'status' => ServiceStatus::from($service->checkFirewallStatus()),
'status' => ServiceStatus::from($service->checkServiceStatus('firewalld')),
],
];

Expand Down
22 changes: 1 addition & 21 deletions web/Modules/Email/App/Services/EmailHealthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,7 @@

class EmailHealthService
{
public function checkDovecotStatus(): string
{
return $this->checkServiceStatus('dovecot');
}

public function checkPostfixStatus(): string
{
return $this->checkServiceStatus('postfix');
}

public function checkOpenDkimStatus(): string
{
return $this->checkServiceStatus('opendkim');
}

public function checkFirewallStatus(): string
{
return $this->checkServiceStatus('firewalld');
}

private function checkServiceStatus(string $serviceName): string
public function checkServiceStatus(string $serviceName): string
{
$status = shell_exec("systemctl is-active $serviceName");
return trim($status) === 'active' ? 'Running' : 'NotRunning';
Expand Down
23 changes: 23 additions & 0 deletions web/Modules/Email/App/Services/EmailService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Modules\Email\App\Services;

class EmailService
{
public function restartService(string $serviceName): string
{
$output = shell_exec("sudo systemctl restart $serviceName");
return $output ? trim($output) : "$serviceName restarted successfully.";
}
public function stopService(string $serviceName): string
{
$output = shell_exec("sudo systemctl stop $serviceName");
return $output ? trim($output) : "$serviceName stopped successfully.";
}
public function startService(string $serviceName): string
{
$output = shell_exec("sudo systemctl start $serviceName");
return $output ? trim($output) : "$serviceName started successfully.";
}
}

0 comments on commit fb32352

Please sign in to comment.