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

@@ -209,6 +209,7 @@ let statusInterval = null;
async function checkScanStatus() {
const statusBadge = document.getElementById("scan-status");
const stopBtn = document.getElementById("stop-scan-btn");
if (!statusBadge) return;
try {
@@ -218,10 +219,12 @@ async function checkScanStatus() {
if (result.running) {
statusBadge.className = "status-badge status-running";
statusBadge.innerHTML = '<span class="spinner"></span> Scan Running';
if (stopBtn) stopBtn.style.display = "inline-flex";
startStatusPolling();
} else {
statusBadge.className = "status-badge status-idle";
statusBadge.textContent = "Idle";
if (stopBtn) stopBtn.style.display = "none";
stopStatusPolling();
}
} catch (error) {

View File

@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -7,14 +8,18 @@
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/style.css">
</head>
<body>
<div class="container">
<!-- Header -->
<header class="header">
<h1>🔍 UltyScan</h1>
<p class="subtitle">Attack Surface Management Platform</p>
<div style="margin-top: 1rem;">
<div style="margin-top: 1rem; display: flex; align-items: center; justify-content: center; gap: 1rem;">
<span id="scan-status" class="status-badge status-idle">Idle</span>
<button id="stop-scan-btn" class="btn btn-danger" style="display: none; padding: 0.5rem 1rem; font-size: 0.85rem;" onclick="stopAllScans()">
Stop Scan
</button>
</div>
</header>
@@ -209,7 +214,9 @@ Ready to scan...</div>
try {
const response = await fetch('execute.php', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'action=update'
});
const result = await response.json();
@@ -225,7 +232,9 @@ Ready to scan...</div>
try {
await fetch('execute.php', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'action=stop'
});
showNotification('Stop signal sent.', 'warning');
@@ -236,4 +245,5 @@ Ready to scan...</div>
}
</script>
</body>
</html>

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));
if (!empty($output)) {
$lines = explode("\n", trim($output));
foreach ($lines as $line) {
if (!empty($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');
if ($files && is_array($files)) {
usort($files, function ($a, $b) {
return filemtime($b) - filemtime($a);
});
$logs = array_slice($files, 0, 5); // Last 5 logs
$logs = array_slice($files, 0, 5);
}
}
echo json_encode([