51 lines
1.9 KiB
PHP
51 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* /api/crons-inout-classify.php · Classify cron jobs inbound (safe) vs outbound (risk)
|
|
* Zero-send doctrine Hetzner · 18avr2026
|
|
*/
|
|
header('Content-Type: application/json');
|
|
$R = ['ts'=>date('c'),'inbound_safe'=>[],'outbound_risk'=>[],'neutral'=>[],'rules'=>[
|
|
'inbound_keywords'=>['inbox','scrape','enrich','fetch','pull','sync','ingest','harvest','scan','populate'],
|
|
'outbound_risk_keywords'=>['send','push','pmta','kumo','graph.*send','auto.?mail','email.*out','smtp.*send','mta.*out'],
|
|
'safe_outbound'=>['backup','vault','log','health','report','stats','monitor']
|
|
]];
|
|
|
|
// Read cron files
|
|
$cronPaths = ['/etc/cron.d','/var/spool/cron/crontabs'];
|
|
$allLines = [];
|
|
foreach ($cronPaths as $p) {
|
|
if (!is_dir($p)) continue;
|
|
foreach (@scandir($p) as $f) {
|
|
if (in_array($f,['.','..'])) continue;
|
|
$fp = "$p/$f";
|
|
if (!is_file($fp) || !is_readable($fp)) continue;
|
|
foreach (@file($fp, FILE_IGNORE_NEW_LINES) as $ln) {
|
|
$ln = trim($ln);
|
|
if ($ln==='' || $ln[0]==='#' || !preg_match('/^\S+\s+\S+\s+\S+/',$ln)) continue;
|
|
$allLines[] = ['file'=>basename($fp),'cmd'=>$ln];
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($allLines as $item) {
|
|
$cmd = strtolower($item['cmd']);
|
|
$inbound = 0; $outbound = 0;
|
|
foreach ($R['rules']['inbound_keywords'] as $kw) if (strpos($cmd,$kw)!==false) $inbound++;
|
|
foreach ($R['rules']['outbound_risk_keywords'] as $kw) if (preg_match('/\b'.$kw.'/',$cmd)) $outbound++;
|
|
// Safe outbound (not real send)
|
|
foreach ($R['rules']['safe_outbound'] as $kw) if (strpos($cmd,$kw)!==false) $outbound = max(0,$outbound-1);
|
|
|
|
if ($outbound >= 1) $R['outbound_risk'][] = $item;
|
|
elseif ($inbound >= 1) $R['inbound_safe'][] = $item;
|
|
else $R['neutral'][] = $item;
|
|
}
|
|
|
|
$R['summary'] = [
|
|
'total' => count($allLines),
|
|
'inbound_safe_count' => count($R['inbound_safe']),
|
|
'outbound_risk_count' => count($R['outbound_risk']),
|
|
'neutral_count' => count($R['neutral'])
|
|
];
|
|
|
|
echo json_encode($R, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|