mirror of
https://github.com/DeNNiiInc/UltyScan.git
synced 2026-04-17 18:26:00 +00:00
Add live console output streaming
This commit is contained in:
@@ -210,6 +210,7 @@ let statusInterval = null;
|
|||||||
async function checkScanStatus() {
|
async function checkScanStatus() {
|
||||||
const statusBadge = document.getElementById("scan-status");
|
const statusBadge = document.getElementById("scan-status");
|
||||||
const stopBtn = document.getElementById("stop-scan-btn");
|
const stopBtn = document.getElementById("stop-scan-btn");
|
||||||
|
const consoleOutput = document.getElementById("console-output");
|
||||||
if (!statusBadge) return;
|
if (!statusBadge) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -227,6 +228,26 @@ async function checkScanStatus() {
|
|||||||
if (stopBtn) stopBtn.style.display = "none";
|
if (stopBtn) stopBtn.style.display = "none";
|
||||||
stopStatusPolling();
|
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) {
|
} catch (error) {
|
||||||
console.error("Status check failed:", error);
|
console.error("Status check failed:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UltyScan Web Interface - Scan Status
|
* UltyScan Web Interface - Scan Status & Log Streaming
|
||||||
* Returns current scan status as JSON
|
* Returns current scan status and log content as JSON
|
||||||
*/
|
*/
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$logDir = '/var/log/ultyscan';
|
||||||
|
|
||||||
// Check if any sniper scan process is actually running
|
// 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]|sudo.*sniper" | grep -v "grep"');
|
||||||
$output = shell_exec('ps aux 2>/dev/null | grep -E "sniper[[:space:]]+-[tmfwp]" | grep -v "grep"');
|
|
||||||
$running = false;
|
$running = false;
|
||||||
$processes = [];
|
$processes = [];
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ if (!empty($output)) {
|
|||||||
$lines = explode("\n", trim($output));
|
$lines = explode("\n", trim($output));
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
$line = trim($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;
|
$processes[] = $line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +27,9 @@ if (!empty($output)) {
|
|||||||
|
|
||||||
// Get recent log files
|
// Get recent log files
|
||||||
$logs = [];
|
$logs = [];
|
||||||
$logDir = '/var/log/ultyscan';
|
$latestLogContent = '';
|
||||||
|
$latestLogFile = '';
|
||||||
|
|
||||||
if (is_dir($logDir)) {
|
if (is_dir($logDir)) {
|
||||||
$files = glob($logDir . '/scan_*.log');
|
$files = glob($logDir . '/scan_*.log');
|
||||||
if ($files && is_array($files)) {
|
if ($files && is_array($files)) {
|
||||||
@@ -34,6 +37,46 @@ if (is_dir($logDir)) {
|
|||||||
return filemtime($b) - filemtime($a);
|
return filemtime($b) - filemtime($a);
|
||||||
});
|
});
|
||||||
$logs = array_slice($files, 0, 5);
|
$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),
|
'processCount' => count($processes),
|
||||||
'processes' => $processes,
|
'processes' => $processes,
|
||||||
'recentLogs' => $logs,
|
'recentLogs' => $logs,
|
||||||
|
'latestLogFile' => basename($latestLogFile),
|
||||||
|
'logContent' => $latestLogContent,
|
||||||
|
'workspaceOutput' => $workspaceOutput,
|
||||||
'timestamp' => date('Y-m-d H:i:s')
|
'timestamp' => date('Y-m-d H:i:s')
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user