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 05b08a6 commit 99adad6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 deletions.
46 changes: 25 additions & 21 deletions web/Modules/Email/App/Filament/Pages/EmailHealthStatusPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;
use Filament\Tables\Actions\Action;
use Filament\Tables\Actions\ActionGroup;
use Filament\Tables\Actions\ViewAction;
use Filament\Tables\Columns\BadgeColumn;
use Modules\Email\App\Services\EmailService;
Expand Down Expand Up @@ -71,27 +72,30 @@ public function table(Table $table): Table
->requiresConfirmation()
->color('danger')
->visible(fn (EmailHealthStatus $record) => $record->status === ServiceStatus::RUNNING),
ViewAction::make('viewLogs')
->label('View Logs')
->icon('heroicon-o-document')
->modalContent(function (EmailHealthStatus $record){
$serviceName = strtolower($record->service);
$emailService = new EmailService();
$logContents = $emailService->getLog($serviceName);
return view('email::filament.pages.view-log-modal',[
'logContents' => $logContents
]);
})
->color('info'),
Action::make('deleteLogs')
->label('Delete Logs')
->action(function (EmailHealthStatus $record) {
$serviceName = strtolower($record->service);
$emailService = new EmailService();
$emailService->deleteLog($serviceName);
})
->requiresConfirmation()
->color('danger'),

ActionGroup::make([
Action::make('viewLogs')
->label('View Logs')
->modalContent(function (EmailHealthStatus $record){
$serviceName = strtolower($record->service);
$emailService = new EmailService();
$logContents = $emailService->getLog($serviceName);
return view('email::filament.pages.view-log-modal',[
'logContents' => $logContents
]);
})
->color('info'),
Action::make('deleteLogs')
->label('Delete Logs')
->action(function (EmailHealthStatus $record) {
$serviceName = strtolower($record->service);
$emailService = new EmailService();
$emailService->truncateLog($serviceName);
})
->requiresConfirmation()
->color('danger')
])->label('Logs')

]);
}
}
27 changes: 9 additions & 18 deletions web/Modules/Email/App/Models/EmailHealthStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Modules\Email\App\Enums\ServiceStatus;
use Modules\Email\App\Services\EmailHealthService;
use Modules\Email\App\Services\EmailService;
use Sushi\Sushi;

class EmailHealthStatus extends Model
Expand All @@ -24,24 +25,14 @@ public function getRows()
{
$service = new EmailHealthService();

$rows = [
[
'service' => 'Dovecot',
'status' => ServiceStatus::from($service->checkServiceStatus('dovecot')),
],
[
'service' => 'Postfix',
'status' => ServiceStatus::from($service->checkServiceStatus('postfix')),
],
[
'service' => 'OpenDKIM',
'status' => ServiceStatus::from($service->checkServiceStatus('opendkim')),
],
[
'service' => 'Firewall',
'status' => ServiceStatus::from($service->checkServiceStatus('firewalld')),
],
];
$rows = [];
foreach (EmailService::$services as $serviceInfo) {
$serviceName = $serviceInfo['service'];
$rows[] = [
'service' => ucfirst($serviceName),
'status' => ServiceStatus::from($service->checkServiceStatus($serviceName)),
];
}

return $rows;
}
Expand Down
27 changes: 16 additions & 11 deletions web/Modules/Email/App/Services/EmailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class EmailService
{

public $services = [
public static $services = [
[
'service' => 'postfix',
'logPath' => '/var/log/mail.log',
Expand All @@ -19,9 +19,13 @@ class EmailService
'logPath'=>'/var/log/mail.log',
],
[
'service' => 'rspamd',
'logPath' => '/var/log/rspamd/rspamd.log',
'service' => 'firewalld',
'logPath' => '/var/log/firewalld',
],
[
'service' => 'syslog',
'logPath' => '/var/log/syslog',
]
];

public function restartService(string $serviceName): string
Expand All @@ -41,23 +45,24 @@ public function startService(string $serviceName): string
}
public function getLog(string $serviceName): string
{
$service = collect($this->services)->firstWhere('service', $serviceName);
$service = collect(self::$services)->firstWhere('service', $serviceName);

if ($service && file_exists($service['logPath'])) {
return file_get_contents($service['logPath']);
}

return 'Log file not found.';
}
public function deleteLog(string $serviceName): string
public function truncateLog(string $serviceName): string
{
$logFilePath = "/var/log/{$serviceName}.log"; // Adjust the path as needed
if (file_exists($logFilePath)) {
unlink($logFilePath);
return 'Log file deleted successfully.';
} else {
return 'Log file not found.';
$service = collect(self::$services)->firstWhere('service', $serviceName);

if ($service && file_exists($service['logPath'])) {
file_put_contents($service['logPath'], '');
return 'Log file truncated.';
}

return 'Log file not found.';
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<pre style="max-width: 100%; max-height: 100vh; overflow: auto;">
<pre style="max-width: 100%; max-height: 500px; overflow: auto;font-size:12px">
{{ $logContents }}
</pre>

0 comments on commit 99adad6

Please sign in to comment.