mirror of
https://github.com/michalcz10/USB-RAID-Array.git
synced 2026-11-11 16:09:03 +00:00
revise backend
This commit is contained in:
+12
-20
@@ -1,18 +1,7 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if(!isset($_SESSION['uname'])){
|
||||
header("location: ../../index.php");
|
||||
session_destroy();
|
||||
exit;
|
||||
}
|
||||
|
||||
if(!isset($_SESSION["upPer"]) || $_SESSION["upPer"] != true) {
|
||||
die("You don't have permission to rename files or directories.");
|
||||
}
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
require_once __DIR__ . '/../../includes/auth.php';
|
||||
requireLogin('../../index.php');
|
||||
requirePermission('upPer', 'You do not have permission to perform this operation.');
|
||||
|
||||
require_once __DIR__ . '/../../config/config.php';
|
||||
$sftp = initializeSFTP();
|
||||
@@ -20,23 +9,26 @@ $sftp = initializeSFTP();
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$oldPath = isset($_POST['path']) ? $_POST['path'] : '';
|
||||
$newName = isset($_POST['newName']) ? trim($_POST['newName']) : '';
|
||||
$isDirectory = isset($_POST['isDirectory']) && $_POST['isDirectory'] == '1';
|
||||
|
||||
if (empty($oldPath) || empty($newName)) {
|
||||
die("Missing required information for renaming.");
|
||||
}
|
||||
|
||||
$dirPath = remoteDirname($oldPath);
|
||||
$oldName = basename($oldPath);
|
||||
$oldPath = requireRemotePath($oldPath, $defaultPath);
|
||||
if ($oldPath === $defaultPath || !isRemoteNameValid($newName)) {
|
||||
http_response_code(400);
|
||||
exit('Invalid item name or workspace root.');
|
||||
}
|
||||
$directoryPath = remoteDirname($oldPath);
|
||||
|
||||
$newPath = $dirPath . '/' . $newName;
|
||||
$newPath = rtrim($directoryPath, '/') . '/' . $newName;
|
||||
|
||||
if ($sftp->file_exists($newPath) || $sftp->is_dir($newPath)) {
|
||||
die("Error: A file or directory with this name already exists.");
|
||||
}
|
||||
|
||||
if ($sftp->rename($oldPath, $newPath)) {
|
||||
header("Location: index.php?path=" . urlencode($dirPath));
|
||||
header("Location: index.php?path=" . urlencode($directoryPath));
|
||||
exit;
|
||||
} else {
|
||||
die("Failed to rename the item. Please try again.");
|
||||
@@ -45,4 +37,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user