mirror of
https://github.com/DeNNiiInc/UltyScan.git
synced 2026-04-17 18:26:00 +00:00
Fix delete function with sudo and remove export feature
This commit is contained in:
@@ -155,7 +155,6 @@ async function loadWorkspaces() {
|
||||
</div>
|
||||
<div class="workspace-actions">
|
||||
<button class="btn btn-secondary" onclick="viewWorkspace('${escapeHtml(name)}')">View</button>
|
||||
<button class="btn btn-secondary" onclick="exportWorkspace('${escapeHtml(name)}')">Export</button>
|
||||
<button class="btn btn-danger" onclick="deleteWorkspace('${escapeHtml(name)}')">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user