Add live console output streaming

This commit is contained in:
2026-01-01 17:48:35 +11:00
parent c9cfb19174
commit 1d149443d5
2 changed files with 73 additions and 6 deletions

View File

@@ -210,6 +210,7 @@ let statusInterval = null;
async function checkScanStatus() {
const statusBadge = document.getElementById("scan-status");
const stopBtn = document.getElementById("stop-scan-btn");
const consoleOutput = document.getElementById("console-output");
if (!statusBadge) return;
try {
@@ -227,6 +228,26 @@ async function checkScanStatus() {
if (stopBtn) stopBtn.style.display = "none";
stopStatusPolling();
}
// Update console with log content
if (consoleOutput && (result.logContent || result.workspaceOutput)) {
let output = "UltyScan Console\n";
output += "================\n";
if (result.latestLogFile) {
output += `Log: ${result.latestLogFile}\n`;
}
output += `Time: ${result.timestamp}\n`;
output += "----------------\n\n";
if (result.workspaceOutput) {
output += result.workspaceOutput;
} else if (result.logContent) {
output += result.logContent;
}
consoleOutput.textContent = output;
consoleOutput.scrollTop = consoleOutput.scrollHeight;
}
} catch (error) {
console.error("Status check failed:", error);
}

View File

@@ -1,15 +1,16 @@
<?php
/**
* UltyScan Web Interface - Scan Status
* Returns current scan status as JSON
* UltyScan Web Interface - Scan Status & Log Streaming
* Returns current scan status and log content as JSON
*/
header('Content-Type: application/json');
$logDir = '/var/log/ultyscan';
// 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"');
$output = shell_exec('ps aux 2>/dev/null | grep -E "sniper[[:space:]]+-[tmfwp]|sudo.*sniper" | grep -v "grep"');
$running = false;
$processes = [];
@@ -17,7 +18,7 @@ if (!empty($output)) {
$lines = explode("\n", trim($output));
foreach ($lines as $line) {
$line = trim($line);
if (!empty($line) && strpos($line, 'status.php') === false) {
if (!empty($line) && strpos($line, 'status.php') === false && strpos($line, 'php') === false) {
$processes[] = $line;
}
}
@@ -26,7 +27,9 @@ if (!empty($output)) {
// Get recent log files
$logs = [];
$logDir = '/var/log/ultyscan';
$latestLogContent = '';
$latestLogFile = '';
if (is_dir($logDir)) {
$files = glob($logDir . '/scan_*.log');
if ($files && is_array($files)) {
@@ -34,6 +37,46 @@ if (is_dir($logDir)) {
return filemtime($b) - filemtime($a);
});
$logs = array_slice($files, 0, 5);
// Get content of the latest log file
if (count($logs) > 0) {
$latestLogFile = $logs[0];
// Read last 100 lines of the log file
$content = file_get_contents($latestLogFile);
if ($content !== false) {
$allLines = explode("\n", $content);
$lastLines = array_slice($allLines, -100);
$latestLogContent = implode("\n", $lastLines);
}
}
}
}
// Also check for currently running workspace output
$workspaceOutput = '';
if ($running && !empty($processes)) {
// Try to find the workspace from the process
foreach ($processes as $proc) {
if (preg_match('/-w\s+[\'"]?([^\s\'"]+)/', $proc, $matches)) {
$workspace = $matches[1];
$workspaceLogDir = "/usr/share/sniper/loot/workspace/$workspace/output";
if (is_dir($workspaceLogDir)) {
$workspaceFiles = glob($workspaceLogDir . '/sniper-*.txt');
if ($workspaceFiles && count($workspaceFiles) > 0) {
usort($workspaceFiles, function ($a, $b) {
return filemtime($b) - filemtime($a);
});
$latestFile = $workspaceFiles[0];
$content = file_get_contents($latestFile);
if ($content !== false) {
$allLines = explode("\n", $content);
$lastLines = array_slice($allLines, -50);
$workspaceOutput = implode("\n", $lastLines);
}
}
}
break;
}
}
}
@@ -42,5 +85,8 @@ echo json_encode([
'processCount' => count($processes),
'processes' => $processes,
'recentLogs' => $logs,
'latestLogFile' => basename($latestLogFile),
'logContent' => $latestLogContent,
'workspaceOutput' => $workspaceOutput,
'timestamp' => date('Y-m-d H:i:s')
]);