mailwolt/app/Livewire/Ui/System/AlertsCard.php

42 lines
1.6 KiB
PHP

<?php
namespace App\Livewire\Ui\System;
use Livewire\Component;
use Illuminate\Support\Facades\Cache;
class AlertsCard extends Component
{
/** Example structure you can fill from your scheduler/commands */
public array $alerts = []; // [['level'=>'warn|error','msg'=>'text','when'=>'...'], ...]
public function mount(): void { $this->load(); }
public function render() { return view('livewire.ui.system.alerts-card'); }
public function refresh(): void { $this->load(true); }
protected function load(bool $force=false): void
{
$this->alerts = Cache::remember('dash.alerts', $force ? 1 : 60, function () {
$a = [];
// examples: push items based on simple heuristics/files you already have
if (is_file('/var/lib/mailwolt/update/state') && trim(@file_get_contents('/var/lib/mailwolt/update/state')) === 'running') {
$a[] = ['level'=>'info','msg'=>'Update läuft …','when'=>date('H:i')];
}
$cert = '/etc/ssl/ui/fullchain.pem';
if (is_file($cert)) {
$end = trim(@shell_exec("openssl x509 -enddate -noout -in ".escapeshellarg($cert)." 2>/dev/null") ?? '');
if (preg_match('/notAfter=(.+)/', $end, $m)) {
$ts = strtotime($m[1] ?? '');
if ($ts && $ts - time() < 14*86400) {
$days = max(0, floor(($ts-time())/86400));
$a[] = ['level'=>'warn','msg'=>"UI-Zertifikat läuft in {$days} Tagen ab",'when'=>date('H:i')];
}
}
}
return $a;
});
}
}