From 763001625bdf7ad32b09bf8dcd9ec68bfc4f1e07 Mon Sep 17 00:00:00 2001 From: hystepik Date: Thu, 23 Feb 2023 11:20:19 +0100 Subject: [PATCH 1/3] New : test of big upload on test_forms --- htdocs/core/ajax/flowjs-server.php | 7 +++- htdocs/public/test/test_forms.php | 64 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/htdocs/core/ajax/flowjs-server.php b/htdocs/core/ajax/flowjs-server.php index e1f5feaaf10..480dba39195 100644 --- a/htdocs/core/ajax/flowjs-server.php +++ b/htdocs/core/ajax/flowjs-server.php @@ -35,6 +35,9 @@ if (!defined('NOREQUIREAJAX')) { if (!defined('NOREQUIRESOC')) { define('NOREQUIRESOC', '1'); } +if (!defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} // If there is no need to load and show top and left menu if (!defined("NOLOGIN")) { define("NOLOGIN", '1'); @@ -68,7 +71,7 @@ if (!empty($upload_dir)) { $temp_dir = $upload_dir.'/'.$flowIdentifier; } else { $temp_dir = DOL_DATA_ROOT.'/'.$module.'/temp/'.$flowIdentifier; - $upload_dir = $temp_dir; + $upload_dir = DOL_DATA_ROOT.'/'.$module.'/temp/'; } if ($_SERVER['REQUEST_METHOD'] === 'GET') { @@ -133,7 +136,7 @@ function createFileFromChunks($temp_dir, $upload_dir, $fileName, $chunkSize, $to $total_files = 0; $files = dol_dir_list($temp_dir, 'files'); foreach ($files as $file) { - if (stripos($file, $fileName) !== false) { + if (stripos($file["name"], $fileName) !== false) { $total_files++; } } diff --git a/htdocs/public/test/test_forms.php b/htdocs/public/test/test_forms.php index acc9151798f..e041e1d98fa 100644 --- a/htdocs/public/test/test_forms.php +++ b/htdocs/public/test/test_forms.php @@ -105,6 +105,70 @@ $array = array(1=>'Value 1', 2=>'Value 2', 3=>'Value 3'); $arrayselected = array(1, 3); print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, 'minwidth100'); +print '

'."\n"; + +// Test6a: Upload of big files +print "Test 6a: Upload of big files
\n"; +print "The file will be uploaded in the directory: documents/test_form/temp/
\n"; + +if (is_file(DOL_DOCUMENT_ROOT.'/includes/flowjs/flow.js')) { + print ''; + print ' No file selected.'; + print '
'; + print '
'; + print ''; + print ''; +} else { + print "If this message displays, please add flow.js file which can be found here :https://github.com/flowjs/flow.js and place the js lib in htdocs/includes/flowjs/
\n"; +} + print ''; // End of page From 5f8bff123b8e3d53dea3bb0180fc88c154a5777b Mon Sep 17 00:00:00 2001 From: hystepik Date: Fri, 24 Feb 2023 11:05:54 +0100 Subject: [PATCH 2/3] fix process --- htdocs/core/ajax/flowjs-server.php | 3 --- htdocs/public/test/test_forms.php | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/htdocs/core/ajax/flowjs-server.php b/htdocs/core/ajax/flowjs-server.php index 480dba39195..962db0b8548 100644 --- a/htdocs/core/ajax/flowjs-server.php +++ b/htdocs/core/ajax/flowjs-server.php @@ -35,9 +35,6 @@ if (!defined('NOREQUIREAJAX')) { if (!defined('NOREQUIRESOC')) { define('NOREQUIRESOC', '1'); } -if (!defined('NOCSRFCHECK')) { - define('NOCSRFCHECK', '1'); -} // If there is no need to load and show top and left menu if (!defined("NOLOGIN")) { define("NOLOGIN", '1'); diff --git a/htdocs/public/test/test_forms.php b/htdocs/public/test/test_forms.php index e041e1d98fa..50693000442 100644 --- a/htdocs/public/test/test_forms.php +++ b/htdocs/public/test/test_forms.php @@ -109,7 +109,7 @@ print '

'."\n"; // Test6a: Upload of big files print "Test 6a: Upload of big files
\n"; -print "The file will be uploaded in the directory: documents/test_form/temp/
\n"; +print "The file will be uploaded in the directory: documents/test/temp/
\n"; if (is_file(DOL_DOCUMENT_ROOT.'/includes/flowjs/flow.js')) { print ''; @@ -121,7 +121,7 @@ if (is_file(DOL_DOCUMENT_ROOT.'/includes/flowjs/flow.js')) { jQuery(document).ready(function() { var flow = new Flow({ target:"'.DOL_URL_ROOT.'/core/ajax/flowjs-server.php", - query:{module:"test_form"}, + query:{module:"test", token:"'.newToken().'"}, testChunks:false }); '; @@ -166,7 +166,7 @@ if (is_file(DOL_DOCUMENT_ROOT.'/includes/flowjs/flow.js')) { '; print ''; } else { - print "If this message displays, please add flow.js file which can be found here :https://github.com/flowjs/flow.js and place the js lib in htdocs/includes/flowjs/
\n"; + print "If this message displays, please add flow.js and flow.min.js files which can be found here: https://github.com/flowjs/flow.js and place the js lib in htdocs/includes/flowjs/
\n"; } print ''; From 2cb3e260f7fdc6be019de07663ded89b6e3f3d04 Mon Sep 17 00:00:00 2001 From: hystepik Date: Fri, 24 Feb 2023 12:20:39 +0100 Subject: [PATCH 3/3] add module verification --- htdocs/core/ajax/flowjs-server.php | 9 ++++++++- htdocs/public/test/test_forms.php | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/htdocs/core/ajax/flowjs-server.php b/htdocs/core/ajax/flowjs-server.php index 962db0b8548..d520c57c9c5 100644 --- a/htdocs/core/ajax/flowjs-server.php +++ b/htdocs/core/ajax/flowjs-server.php @@ -62,7 +62,7 @@ $flowTotalSize = GETPOST('flowTotalSize', 'alpha'); top_httphead(); dol_syslog(join(',', $_GET)); -$result = true; +$result = false; if (!empty($upload_dir)) { $temp_dir = $upload_dir.'/'.$flowIdentifier; @@ -71,6 +71,12 @@ if (!empty($upload_dir)) { $upload_dir = DOL_DATA_ROOT.'/'.$module.'/temp/'; } +if ($module != "test" && !isModEnabled($module)) { + echo json_encode("The module ".$module." is not enabled"); + header("HTTP/1.0 400"); + die(); +} + if ($_SERVER['REQUEST_METHOD'] === 'GET') { $chunk_file = $temp_dir.'/'.$flowFilename.'.part'.$flowChunkNumber; if (file_exists($chunk_file)) { @@ -83,6 +89,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (file_exists($upload_dir.'/'.$flowFilename)) { echo json_encode('File '.$flowIdentifier.' was already uploaded'); header("HTTP/1.0 200 Ok"); + die(); } elseif (!empty($_FILES)) foreach ($_FILES as $file) { // check the error status if ($file['error'] != 0) { diff --git a/htdocs/public/test/test_forms.php b/htdocs/public/test/test_forms.php index 50693000442..b7ed524e297 100644 --- a/htdocs/public/test/test_forms.php +++ b/htdocs/public/test/test_forms.php @@ -161,6 +161,11 @@ if (is_file(DOL_DOCUMENT_ROOT.'/includes/flowjs/flow.js')) { $("#filespan").text("No file selected."); $(this).hide(); }) + flow.on("fileError", function(file, message){ + console.log("Error on file upload",file, message); + $("#"+file.uniqueIdentifier+"pgbar").width(20+"%"); + $("#"+file.uniqueIdentifier+"pgbar").children("span").text("ERROR UPLOAD"); + }); } }) ';