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 57f144d commit 018c743
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public function table(Table $table): Table
]);
})
->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'),
]);
}
}
37 changes: 36 additions & 1 deletion web/Modules/Email/App/Services/EmailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

class EmailService
{

public $services = [
[
'service' => 'postfix',
'logPath' => '/var/log/mail.log',
],
[
'service' => 'dovecot',
'logPath' => '/var/log/dovecot.log',
],
[
'service'=>'opendkim',
'logPath'=>'/var/log/mail.log',
],
[
'service' => 'rspamd',
'logPath' => '/var/log/rspamd/rspamd.log',
],
];

public function restartService(string $serviceName): string
{
$output = shell_exec("sudo systemctl restart $serviceName");
Expand All @@ -20,9 +40,24 @@ public function startService(string $serviceName): string
return $output ? trim($output) : "$serviceName started successfully.";
}
public function getLog(string $serviceName): string
{
$service = collect($this->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
{
$logFilePath = "/var/log/{$serviceName}.log"; // Adjust the path as needed
return file_exists($logFilePath) ? file_get_contents($logFilePath) : 'Log file not found.';
if (file_exists($logFilePath)) {
unlink($logFilePath);
return 'Log file deleted successfully.';
} else {
return 'Log file not found.';
}
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<x-filament-panels::page>

<div>
<h1>Service Log</h1>
<pre>{{ $logContents }}</pre>
</div>
</x-filament-panels::page>
<pre>
{{ $logContents }}
</pre>

0 comments on commit 018c743

Please sign in to comment.