From 54643c4c4cbaa47cd99245c6826f4a78b47229e3 Mon Sep 17 00:00:00 2001 From: Roland Stigge Date: Sat, 20 Jan 2018 17:02:32 +0100 Subject: Multiple file uploads at once --- debian/README.Debian | 4 ++++ debian/changelog | 7 ++++++ html/index.html | 2 +- html/webbox.js | 11 +++++---- src/webbox.cpp | 66 ++++++++++++++++++++++++++++------------------------ 5 files changed, 55 insertions(+), 35 deletions(-) diff --git a/debian/README.Debian b/debian/README.Debian index ee1c680..a10e330 100644 --- a/debian/README.Debian +++ b/debian/README.Debian @@ -89,6 +89,10 @@ Also, activate the Apache module mod_headers for the above Headers directive. Only the FastCGI application needs to secured. The static pages in /var/www/webbox should be accessible to the user for login purposes. +After installation of apache and webbox and configuration, apache should be +restarted with: + +# service restart apache2 Example configuration for Apache -------------------------------- diff --git a/debian/changelog b/debian/changelog index 3fe42d2..01dd6f7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +webbox (1.3) unstable; urgency=medium + + * New version + * Multiple files upload + + -- Roland Reichwein Sat, 20 Jan 2018 16:54:38 +0100 + webbox (1.2) unstable; urgency=medium * New version diff --git a/html/index.html b/html/index.html index 40390e0..80fa1d8 100644 --- a/html/index.html +++ b/html/index.html @@ -15,7 +15,7 @@ - + diff --git a/html/webbox.js b/html/webbox.js index 5a55010..72ff987 100644 --- a/html/webbox.js +++ b/html/webbox.js @@ -526,11 +526,11 @@ function onUploadFile() { if (this.status != 200) { message = "HTTP error"; } else { - if (xhr.responseText == "OK") { + if (xhr.responseText == "") { message = "Upload successful."; loadContents(currentDir); // load new file list with uploaded file } else { - message = "Error: " + xhr.responseText; + message = xhr.responseText; } } @@ -544,11 +544,14 @@ function onUploadFile() { progressOff(); } + progressOn(); + var uploadfile = document.getElementById("uploadfile"); var formData = new FormData(); - formData.append("uploadfile", uploadfile.files[0]); - progressOn(); + for (var i = 0; i < uploadfile.files.length; i++) { + formData.append("uploadfile", uploadfile.files[i]); + } xhr.open("POST", "/bin/query" + currentDir + "?command=upload", true); xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password)); diff --git a/src/webbox.cpp b/src/webbox.cpp index 995e688..1bc0664 100644 --- a/src/webbox.cpp +++ b/src/webbox.cpp @@ -13,7 +13,7 @@ #include #include -#define PROGRAMVERSION "1.2" +#define PROGRAMVERSION "1.3" #define BUFSIZE 1000000 // XML special characters: @@ -617,52 +617,58 @@ class UploadCommand: public PostCommand { } else { QByteArray boundary = QByteArray("--") + contentType.split(separator)[1].toUtf8(); int boundaryCount = m_content.count(boundary); - if (boundaryCount != 2) { + if (boundaryCount < 2) { FCGX_PutS(QString("Bad boundary number found: %1").arg(boundaryCount).toUtf8().data(), p.request.out); } else { - int start = m_content.indexOf(boundary) + boundary.size(); - int end = m_content.indexOf(QByteArray("\r\n") + boundary, start); + while (true) { + int start = m_content.indexOf(boundary) + boundary.size(); + int end = m_content.indexOf(QByteArray("\r\n") + boundary, start); - m_content = m_content.mid(start, end - start); + if (end == -1) { // no further boundary found: all handled. + break; + } - // Read filename - start = m_content.indexOf("filename=\""); - if (start == -1) { - FCGX_PutS(QString("Error reading filename / start").toUtf8().data(), p.request.out); - } else { - start += QByteArray("filename=\"").size(); + QByteArray filecontent = m_content.mid(start, end - start); + int nextBoundaryIndex = end; - end = m_content.indexOf(QByteArray("\""), start); - if (end == -1) { - FCGX_PutS(QString("Error reading filename / end").toUtf8().data(), p.request.out); + // Read filename + start = filecontent.indexOf("filename=\""); + if (start == -1) { + FCGX_PutS(QString("Error reading filename / start").toUtf8().data(), p.request.out); } else { - QString filename = QString::fromUtf8(m_content.mid(start, end - start)); + start += QByteArray("filename=\"").size(); - if (filename.size() < 1) { - FCGX_PutS(QString("Bad filename").toUtf8().data(), p.request.out); + end = filecontent.indexOf(QByteArray("\""), start); + if (end == -1) { + FCGX_PutS(QString("Error reading filename / end").toUtf8().data(), p.request.out); } else { - // Remove header - start = m_content.indexOf(QByteArray("\r\n\r\n")); - if (start == -1) { - FCGX_PutS(QString("Error removing upload header").toUtf8().data(), p.request.out); + QString filename = QString::fromUtf8(filecontent.mid(start, end - start)); + + if (filename.size() < 1) { + FCGX_PutS(QString("Bad filename").toUtf8().data(), p.request.out); } else { + // Remove header + start = filecontent.indexOf(QByteArray("\r\n\r\n")); + if (start == -1) { + FCGX_PutS(QString("Error removing upload header").toUtf8().data(), p.request.out); + } else { - m_content = m_content.mid(start + QString("\r\n\r\n").toUtf8().size()); + filecontent = filecontent.mid(start + QString("\r\n\r\n").toUtf8().size()); - QFile file(m_path + "/" + filename); - if (!file.open(QIODevice::WriteOnly)) { - FCGX_PutS(QString("Error opening file").toUtf8().data(), p.request.out); - } else { - qint64 written = file.write(m_content); - if (written != m_content.size()) { - FCGX_PutS(QString("Error writing file").toUtf8().data(), p.request.out); + QFile file(m_path + "/" + filename); + if (!file.open(QIODevice::WriteOnly)) { + FCGX_PutS(QString("Error opening file").toUtf8().data(), p.request.out); } else { - FCGX_PutS("OK", p.request.out); + qint64 written = file.write(filecontent); + if (written != filecontent.size()) { + FCGX_PutS(QString("Error writing file").toUtf8().data(), p.request.out); + } } } } } } + m_content.remove(0, nextBoundaryIndex); } } } -- cgit v1.2.3