Fix scan status detection and add stop button in header

This commit is contained in:
2026-01-01 17:33:24 +11:00
parent 7e2fc7edce
commit b1430f058c
3 changed files with 47 additions and 33 deletions

View File

@@ -7,22 +7,21 @@
header('Content-Type: application/json');
// Check if any sniper process is running
$output = shell_exec('pgrep -f "sniper" 2>/dev/null');
$running = !empty(trim($output));
// Get list of running scans
// Check if any sniper scan process is actually running
// We look specifically for sniper with scan arguments, not just any process matching
$output = shell_exec('ps aux 2>/dev/null | grep -E "sniper[[:space:]]+-[tmfwp]" | grep -v "grep"');
$running = false;
$processes = [];
if ($running) {
$psOutput = shell_exec('ps aux | grep "sniper" | grep -v grep 2>/dev/null');
if (!empty($psOutput)) {
$lines = explode("\n", trim($psOutput));
foreach ($lines as $line) {
if (!empty($line)) {
$processes[] = $line;
}
if (!empty($output)) {
$lines = explode("\n", trim($output));
foreach ($lines as $line) {
$line = trim($line);
if (!empty($line) && strpos($line, 'status.php') === false) {
$processes[] = $line;
}
}
$running = count($processes) > 0;
}
// Get recent log files
@@ -30,10 +29,12 @@ $logs = [];
$logDir = '/var/log/ultyscan';
if (is_dir($logDir)) {
$files = glob($logDir . '/scan_*.log');
usort($files, function ($a, $b) {
return filemtime($b) - filemtime($a);
});
$logs = array_slice($files, 0, 5); // Last 5 logs
if ($files && is_array($files)) {
usort($files, function ($a, $b) {
return filemtime($b) - filemtime($a);
});
$logs = array_slice($files, 0, 5);
}
}
echo json_encode([