mailwolt/app/Livewire/Ui/Security/SpamAvCard.php

44 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Livewire\Ui\Security;
use Livewire\Component;
use Illuminate\Support\Facades\Cache;
class SpamAvCard extends Component
{
public int $ham = 0;
public int $spam = 0;
public int $reject = 0;
public string $rspamdVer = '';
public string $clamVer = '';
public ?string $sigUpdated = null;
public function mount(): void { $this->load(); }
public function render() { return view('livewire.ui.security.spam-av-card'); }
public function refresh(): void { $this->load(true); }
protected function load(bool $force = false): void
{
$data = Cache::remember('dash.spamav', $force ? 1 : 60, function () {
$out = trim(@shell_exec('rspamc counters 2>/dev/null') ?? '');
// very rough counters (adapt to your setup)
$ham = preg_match('/ham:\s*(\d+)/i', $out, $m1) ? (int)$m1[1] : 0;
$spam = preg_match('/spam:\s*(\d+)/i', $out, $m2) ? (int)$m2[1] : 0;
$reject = preg_match('/reject:\s*(\d+)/i', $out, $m3) ? (int)$m3[1] : 0;
$rspamdVer = trim(@shell_exec('rspamadm version 2>/dev/null') ?? '') ?: '';
$clamVer = trim(@shell_exec('clamd --version 2>/dev/null || clamscan --version 2>/dev/null') ?? '') ?: '';
// last signatures update (freshclam log)
$sigUpdated = null;
$log = @shell_exec('grep -i "Database updated" /var/log/clamav/freshclam.log | tail -n1 2>/dev/null');
if ($log) $sigUpdated = trim($log);
return compact('ham','spam','reject','rspamdVer','clamVer','sigUpdated');
});
foreach ($data as $k => $v) $this->$k = $v;
}
}