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,29 +1,14 @@
|
||||
<?php
|
||||
// Include this at the top to see potential errors
|
||||
// Comment out in production
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
session_start();
|
||||
|
||||
if(!isset($_SESSION['uname'])){
|
||||
header("location: ../index.html");
|
||||
session_destroy();
|
||||
exit;
|
||||
}
|
||||
|
||||
if(!isset($_SESSION["upPer"]) || $_SESSION["upPer"] != true) {
|
||||
http_response_code(403);
|
||||
echo "You don't have permission to create files.";
|
||||
exit;
|
||||
}
|
||||
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();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'createFile') {
|
||||
$currentPath = isset($_POST['currentPath']) ? normalizePath($_POST['currentPath']) : $defaultPath;
|
||||
$currentPath = requireRemotePath($_POST['currentPath'] ?? $defaultPath, $defaultPath);
|
||||
|
||||
if (!isset($_POST['fileName'])) {
|
||||
http_response_code(400);
|
||||
@@ -41,22 +26,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
||||
|
||||
$fileName = preg_replace('/[^\w\-\.]/', '_', $fileName);
|
||||
|
||||
if (strpos($currentPath, $defaultPath) !== 0) {
|
||||
$currentPath = $defaultPath;
|
||||
if (!isRemoteNameValid($fileName)) {
|
||||
http_response_code(400);
|
||||
exit('Invalid file name.');
|
||||
}
|
||||
|
||||
$newFilePath = $currentPath . '/' . $fileName;
|
||||
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'new_file_');
|
||||
file_put_contents($tempFile, '');
|
||||
|
||||
if ($sftp->put($newFilePath, $tempFile)) {
|
||||
@unlink($tempFile);
|
||||
|
||||
$newFilePath = rtrim($currentPath, '/') . '/' . $fileName;
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
if ($sftp->put($newFilePath, '')) {
|
||||
echo json_encode(['success' => true, 'filePath' => $newFilePath]);
|
||||
} else {
|
||||
@unlink($tempFile);
|
||||
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Failed to create file.']);
|
||||
}
|
||||
@@ -65,4 +44,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
||||
|
||||
http_response_code(400);
|
||||
echo "Invalid request";
|
||||
exit;
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user