mirror of
https://github.com/michalcz10/USB-RAID-Array.git
synced 2026-11-11 07:59:04 +00:00
revise backend
This commit is contained in:
@@ -1,26 +1,35 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../includes/auth.php';
|
||||
requireLogin('../../index.php');
|
||||
requirePermission('delPer', 'You do not have permission to perform this operation.');
|
||||
|
||||
require_once __DIR__ . '/../../config/config.php';
|
||||
|
||||
$sftp = initializeSFTP();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete'])) {
|
||||
$itemToDelete = $_POST['delete'];
|
||||
$parentDir = remoteDirname($itemToDelete);
|
||||
$itemToDelete = requireRemotePath($_POST['delete'], $defaultPath);
|
||||
if ($itemToDelete === $defaultPath) {
|
||||
http_response_code(400);
|
||||
exit('Cannot delete the workspace root.');
|
||||
}
|
||||
$parentPath = remoteDirname($itemToDelete);
|
||||
|
||||
if ($parentDir === '/' || $parentDir === '.') {
|
||||
$parentDir = $defaultPath;
|
||||
if ($parentPath === '/' || $parentPath === '.') {
|
||||
$parentPath = $defaultPath;
|
||||
}
|
||||
|
||||
if ($sftp->is_dir($itemToDelete)) {
|
||||
function deleteFolder($sftp, $folderPath) {
|
||||
$items = $sftp->nlist($folderPath);
|
||||
if ($items === false) return false;
|
||||
foreach ($items as $item) {
|
||||
if ($item === '.' || $item === '..') continue;
|
||||
$itemPath = $folderPath . '/' . $item;
|
||||
if ($sftp->is_dir($itemPath)) {
|
||||
deleteFolder($sftp, $itemPath);
|
||||
if (!deleteFolder($sftp, $itemPath)) return false;
|
||||
} else {
|
||||
$sftp->delete($itemPath);
|
||||
if (!$sftp->delete($itemPath)) return false;
|
||||
}
|
||||
}
|
||||
return $sftp->rmdir($folderPath);
|
||||
@@ -31,9 +40,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete'])) {
|
||||
$success = $sftp->delete($itemToDelete);
|
||||
}
|
||||
|
||||
header("Location: index.php?path=" . urlencode($parentDir));
|
||||
if (!$success) {
|
||||
http_response_code(500);
|
||||
exit('Failed to delete the item.');
|
||||
}
|
||||
header("Location: index.php?path=" . urlencode($parentPath));
|
||||
exit;
|
||||
}
|
||||
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user