46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
||
|
||
namespace App\Livewire\Ui\Security;
|
||
|
||
use Livewire\Component;
|
||
use Illuminate\Support\Facades\Cache;
|
||
|
||
class RblCard extends Component
|
||
{
|
||
public string $ip = '–';
|
||
public int $hits = 0;
|
||
public array $lists = [];
|
||
|
||
public function mount(): void { $this->load(); }
|
||
public function render() { return view('livewire.ui.security.rbl-card'); }
|
||
public function refresh(): void { $this->load(true); }
|
||
|
||
protected function load(bool $force=false): void
|
||
{
|
||
$data = Cache::remember('dash.rbl', $force ? 1 : 21600, function () {
|
||
$ip = trim(@file_get_contents('/etc/mailwolt/public_ip') ?: '');
|
||
if ($ip === '') $ip = trim(@shell_exec("curl -fsS --max-time 2 ifconfig.me 2>/dev/null") ?? '');
|
||
if (!preg_match('/^\d+\.\d+\.\d+\.\d+$/', $ip)) $ip = '0.0.0.0';
|
||
|
||
$rev = implode('.', array_reverse(explode('.', $ip)));
|
||
$sources = [
|
||
'zen.spamhaus.org',
|
||
'bl.spamcop.net',
|
||
'dnsbl.sorbs.net',
|
||
'b.barracudacentral.org',
|
||
];
|
||
|
||
$lists = [];
|
||
foreach ($sources as $s) {
|
||
$q = "$rev.$s";
|
||
$res = trim(@shell_exec("dig +short ".escapeshellarg($q)." A 2>/dev/null") ?? '');
|
||
if ($res !== '') $lists[] = $s;
|
||
}
|
||
|
||
return ['ip'=>$ip, 'hits'=>count($lists), 'lists'=>$lists];
|
||
});
|
||
|
||
foreach ($data as $k=>$v) $this->$k = $v;
|
||
}
|
||
}
|