mailwolt/app/Livewire/Ui/Mail/DnsHealthCard.php

44 lines
1.6 KiB
PHP

<?php
namespace App\Livewire\Ui\Mail;
use Livewire\Component;
use App\Models\Domain;
use Illuminate\Support\Facades\Cache;
class DnsHealthCard extends Component
{
public array $rows = []; // [ ['domain'=>..., 'dkim'=>bool, 'dmarc'=>bool, 'tlsa'=>bool], ... ]
public function mount(): void { $this->load(); }
public function render() { return view('livewire.ui.mail.dns-health-card'); }
public function refresh(): void { $this->load(true); }
protected function load(bool $force=false): void
{
$this->rows = Cache::remember('dash.dnshealth', $force ? 1 : 600, function () {
$rows = [];
$domains = Domain::query()->where('is_system', false)->where('is_active', true)->get(['domain']);
foreach ($domains as $d) {
$dom = $d->domain;
$dkim = $this->hasTxt("_domainkey.$dom"); // rough: just any dkim TXT exists
$dmarc = $this->hasTxt("_dmarc.$dom");
$tlsa = $this->hasTlsa("_25._tcp.$dom") || $this->hasTlsa("_465._tcp.$dom") || $this->hasTlsa("_587._tcp.$dom");
$rows[] = compact('dom','dkim','dmarc','tlsa');
}
return $rows;
});
}
protected function hasTxt(string $name): bool
{
$out = @shell_exec("dig +short TXT ".escapeshellarg($name)." 2>/dev/null");
return is_string($out) && trim($out) !== '';
}
protected function hasTlsa(string $name): bool
{
$out = @shell_exec("dig +short TLSA ".escapeshellarg($name)." 2>/dev/null");
return is_string($out) && trim($out) !== '';
}
}