mirror of
https://github.com/michalcz10/USB-RAID-Array.git
synced 2026-11-11 07:59:04 +00:00
53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?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 = requireRemotePath($_POST['delete'], $defaultPath);
|
|
if ($itemToDelete === $defaultPath) {
|
|
http_response_code(400);
|
|
exit('Cannot delete the workspace root.');
|
|
}
|
|
$parentPath = remoteDirname($itemToDelete);
|
|
|
|
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)) {
|
|
if (!deleteFolder($sftp, $itemPath)) return false;
|
|
} else {
|
|
if (!$sftp->delete($itemPath)) return false;
|
|
}
|
|
}
|
|
return $sftp->rmdir($folderPath);
|
|
}
|
|
|
|
$success = deleteFolder($sftp, $itemToDelete);
|
|
} else {
|
|
$success = $sftp->delete($itemToDelete);
|
|
}
|
|
|
|
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;
|