From 809ce8b6f3ba9253bcf1f276787956da7393ba40 Mon Sep 17 00:00:00 2001 From: DeNNiiInc Date: Thu, 1 Jan 2026 20:25:08 +1100 Subject: [PATCH] Fix delete function with sudo and remove export feature --- install.sh | 1 + webui/assets/script.js | 23 ------------------- webui/workspaces.php | 52 +++++++----------------------------------- 3 files changed, 9 insertions(+), 67 deletions(-) diff --git a/install.sh b/install.sh index 19e59c9..ae6e000 100644 --- a/install.sh +++ b/install.sh @@ -502,6 +502,7 @@ ln -sf $LOOT_DIR /var/www/html/loot 2>/dev/null echo -e "$OKBLUE[*]$RESET Configuring permissions for Web UI... $RESET" echo 'www-data ALL=(ALL) NOPASSWD: /usr/bin/bash /usr/share/sniper/sniper *' > /etc/sudoers.d/www-data-sniper echo 'www-data ALL=(ALL) NOPASSWD: /usr/bin/pkill *' >> /etc/sudoers.d/www-data-sniper +echo 'www-data ALL=(ALL) NOPASSWD: /usr/bin/rm *' >> /etc/sudoers.d/www-data-sniper chmod 440 /etc/sudoers.d/www-data-sniper # Configure Apache Port 8888 diff --git a/webui/assets/script.js b/webui/assets/script.js index 3aa66d5..a60dcc5 100644 --- a/webui/assets/script.js +++ b/webui/assets/script.js @@ -155,7 +155,6 @@ async function loadWorkspaces() {
-
@@ -193,28 +192,6 @@ async function viewWorkspace(name) { } } -async function exportWorkspace(name) { - showNotification("Creating export for: " + name + "...", "info"); - try { - const response = await fetch("workspaces.php", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ action: "export", name: name }), - }); - const result = await response.json(); - - if (result.success && result.downloadUrl) { - showNotification(`Export ready: ${result.filename} (${result.size})`, "success"); - // Trigger download - window.open(result.downloadUrl, "_blank"); - } else { - showNotification("Export failed: " + (result.error || "Unknown error"), "error"); - } - } catch (error) { - showNotification("Export failed.", "error"); - } -} - async function deleteWorkspace(name) { if (!confirm(`Are you sure you want to delete workspace "${name}"?`)) return; diff --git a/webui/workspaces.php b/webui/workspaces.php index 89aa8d3..f854a39 100644 --- a/webui/workspaces.php +++ b/webui/workspaces.php @@ -97,44 +97,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($action === 'delete') { if (is_dir($wsPath)) { - // Delete directory recursively - deleteDirectory($wsPath); - echo json_encode(['success' => true, 'message' => 'Workspace deleted']); + // Delete directory recursively using sudo + exec("sudo rm -rf " . escapeshellarg($wsPath)); + + if (!file_exists($wsPath)) { + echo json_encode(['success' => true, 'message' => 'Workspace deleted']); + } else { + echo json_encode(['success' => false, 'error' => 'Failed to delete workspace. Check permissions.']); + } } else { echo json_encode(['success' => false, 'error' => 'Workspace not found']); } exit; } - - if ($action === 'export') { - if (!is_dir($wsPath)) { - echo json_encode(['success' => false, 'error' => 'Workspace not found']); - exit; - } - - $exportFile = EXPORT_DIR . '/' . $name . '.tar.gz'; - - // Create tar.gz archive - $cmd = "cd " . escapeshellarg(WORKSPACE_DIR) . " && tar -czf " . escapeshellarg($exportFile) . " " . escapeshellarg($name) . " 2>&1"; - $output = shell_exec($cmd); - - if (file_exists($exportFile)) { - $size = filesize($exportFile); - echo json_encode([ - 'success' => true, - 'downloadUrl' => 'workspaces.php?action=download&name=' . urlencode($name), - 'filename' => $name . '.tar.gz', - 'size' => formatBytes($size), - 'message' => 'Export created successfully' - ]); - } else { - echo json_encode([ - 'success' => false, - 'error' => 'Failed to create export: ' . $output - ]); - } - exit; - } } echo json_encode(['error' => 'Invalid request']); @@ -161,14 +136,3 @@ function formatBytes($bytes) return $bytes . ' B'; } } - -function deleteDirectory($dir) -{ - if (!is_dir($dir)) return false; - $files = array_diff(scandir($dir), ['.', '..']); - foreach ($files as $file) { - $path = $dir . '/' . $file; - is_dir($path) ? deleteDirectory($path) : unlink($path); - } - return rmdir($dir); -}