Use form posts for transfer jobs

This commit is contained in:
Mikei386
2026-06-23 07:51:38 +02:00
parent 7cddfb19a4
commit 548c752748
7 changed files with 36 additions and 6 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
set -eu set -eu
PLUGIN="u-navigator" PLUGIN="u-navigator"
VERSION="2026.06.23.r007" VERSION="2026.06.23.r008"
PKG_DIR="packages" PKG_DIR="packages"
WORK_DIR=".plugin-build" WORK_DIR=".plugin-build"
PKG_NAME="${PLUGIN}-${VERSION}.tgz" PKG_NAME="${PLUGIN}-${VERSION}.tgz"
Binary file not shown.
Binary file not shown.
@@ -107,6 +107,13 @@ function unav_request_json(): array {
return $data; return $data;
} }
function unav_request_data(): array {
if (!empty($_POST)) {
return $_POST;
}
return unav_request_json();
}
function unav_copy_recursive(string $source, string $destination): void { function unav_copy_recursive(string $source, string $destination): void {
if (is_link($source)) { if (is_link($source)) {
unav_error(400, 'Copying symlinks is not allowed'); unav_error(400, 'Copying symlinks is not allowed');
@@ -12,7 +12,7 @@ if (!in_array($action, ['move', 'copy'], true)) {
unav_error(404, 'Unknown job action'); unav_error(404, 'Unknown job action');
} }
$data = unav_request_json(); $data = unav_request_data();
$source = unav_existing_path($data['source'] ?? null); $source = unav_existing_path($data['source'] ?? null);
$destination = unav_destination_path($data['destination'] ?? null); $destination = unav_destination_path($data['destination'] ?? null);
unav_guard_destination($source['path'], $destination['path']); unav_guard_destination($source['path'], $destination['path']);
+25 -2
View File
@@ -380,6 +380,7 @@ async function handleDrop(event, win, targetPath) {
for (const file of files) { for (const file of files) {
form.append('files', file, file.name); form.append('files', file, file.name);
} }
appendCsrf(form);
await fetchChecked(apiUrl(`upload.php?path=${encodeURIComponent(targetPath)}`), { await fetchChecked(apiUrl(`upload.php?path=${encodeURIComponent(targetPath)}`), {
method: 'POST', method: 'POST',
body: form body: form
@@ -390,10 +391,14 @@ async function handleDrop(event, win, targetPath) {
async function createJob(type, source, destination) { async function createJob(type, source, destination) {
recordDebug('job.create.request', { type, source, destination }); recordDebug('job.create.request', { type, source, destination });
const body = new URLSearchParams();
body.set('source', source);
body.set('destination', destination);
appendCsrf(body);
const job = await api(apiUrl(`job.php?action=${encodeURIComponent(type)}`), { const job = await api(apiUrl(`job.php?action=${encodeURIComponent(type)}`), {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
body: JSON.stringify({ source, destination }) body
}); });
recordDebug('job.create.response', job); recordDebug('job.create.response', job);
state.jobs.set(job.id, job); state.jobs.set(job.id, job);
@@ -911,6 +916,24 @@ function apiUrl(path) {
return `${API_BASE.replace(/\/$/, '')}/${path.replace(/^\//, '')}`; return `${API_BASE.replace(/\/$/, '')}/${path.replace(/^\//, '')}`;
} }
function appendCsrf(body) {
const token = getCsrfToken();
if (!token) {
recordDebug('csrf.missing', {});
return;
}
body.append('csrf_token', token);
recordDebug('csrf.attached', { length: token.length });
}
function getCsrfToken() {
return window.csrf_token
|| document.querySelector('input[name="csrf_token"]')?.value
|| document.querySelector('meta[name="csrf_token"]')?.content
|| document.querySelector('meta[name="csrf-token"]')?.content
|| '';
}
function recordDebug(label, data = {}) { function recordDebug(label, data = {}) {
const item = { const item = {
id: state.nextDebugId++, id: state.nextDebugId++,
+2 -2
View File
@@ -1,7 +1,7 @@
<!DOCTYPE PLUGIN [ <!DOCTYPE PLUGIN [
<!ENTITY name "u-navigator"> <!ENTITY name "u-navigator">
<!ENTITY author "michael"> <!ENTITY author "michael">
<!ENTITY version "2026.06.23.r007"> <!ENTITY version "2026.06.23.r008">
<!ENTITY package "&name;-&version;.tgz"> <!ENTITY package "&name;-&version;.tgz">
]> ]>
<PLUGIN name="&name;" author="&author;" version="&version;" pluginURL="https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/u-navigator.plg"> <PLUGIN name="&name;" author="&author;" version="&version;" pluginURL="https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/u-navigator.plg">
@@ -14,7 +14,7 @@
<FILE Name="/boot/config/plugins/&name;/&package;"> <FILE Name="/boot/config/plugins/&name;/&package;">
<URL>https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package;</URL> <URL>https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package;</URL>
<MD5>c9e2b618f5907747315c5f17e80b132f</MD5> <MD5>6a584ee446fc442c9a3c95877f15d1ae</MD5>
</FILE> </FILE>
<FILE Run="/bin/bash"> <FILE Run="/bin/bash">