[Libreoffice-commits] online.git: loleaflet/dist loolwsd/FileServer.hpp
Henry Castro
hcastro at collabora.com
Thu Apr 7 21:19:31 UTC 2016
loleaflet/dist/loleaflet.html | 23 +++++++--------------
loolwsd/FileServer.hpp | 45 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 52 insertions(+), 16 deletions(-)
New commits:
commit dd96c6a4de756505cc1d456272a4b279f5020b4d
Author: Henry Castro <hcastro at collabora.com>
Date: Thu Apr 7 17:16:40 2016 -0400
loolwsd: handle a POST request in loleaflet
diff --git a/loleaflet/dist/loleaflet.html b/loleaflet/dist/loleaflet.html
index 656fd0d..a74339a 100644
--- a/loleaflet/dist/loleaflet.html
+++ b/loleaflet/dist/loleaflet.html
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<!-- saved from url=(0054)http://leafletjs.com/examples/quick-start-example.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<title>Document Simple Example</title>
+<title>Collabora Online</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -260,23 +260,16 @@
</style>
<script>
- function getParameterByName(name) {
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
- var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
- results = regex.exec(location.search);
- return results === null ? "" : results[1].replace(/\+/g, " ");
- }
-
- var wopiSrc = getParameterByName('WOPISrc');
- var filePath = getParameterByName('file_path');
- var title = getParameterByName('title');
+ var wopiSrc = 'WOPISRC';
+ var filePath = 'FILEPATH';
+ var title = 'TITLE';
if (title === '') {
title = decodeURIComponent(filePath.substring(filePath.lastIndexOf('/')+1));
}
- var host = getParameterByName('host');
- var permission = getParameterByName('permission');
- var timestamp = getParameterByName('timestamp');
- var closebutton = getParameterByName('closebutton');
+ var host = 'HOST';
+ var permission = 'PERMISSION';
+ var timestamp = 'TIMESTAMP';
+ var closebutton = 'CLOSEBUTTON';
if (wopiSrc === '' && filePath === '') {
vex.dialog.alert('Wrong WOPISrc, usage: WOPISrc=valid encoded URI, or file_path, usage: file_path=/path/to/doc/');
}
diff --git a/loolwsd/FileServer.hpp b/loolwsd/FileServer.hpp
index 5a79793..0511431 100644
--- a/loolwsd/FileServer.hpp
+++ b/loolwsd/FileServer.hpp
@@ -17,6 +17,7 @@
#include <Poco/Net/HTTPCookie.h>
#include <Poco/Net/HTTPBasicCredentials.h>
+#include <Poco/Net/HTMLForm.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPRequestHandler.h>
#include <Poco/Net/HTTPServer.h>
@@ -28,12 +29,15 @@
#include <Poco/Runnable.h>
#include <Poco/StringTokenizer.h>
#include <Poco/URI.h>
+#include <Poco/FileStream.h>
+#include <Poco/StreamCopier.h>
#include <Poco/Util/ServerApplication.h>
#include <Poco/Util/Timer.h>
#include "Common.hpp"
#include "LOOLWSD.hpp"
+using Poco::Net::HTMLForm;
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPRequestHandler;
using Poco::Net::HTTPRequestHandlerFactory;
@@ -43,6 +47,8 @@ using Poco::Net::HTTPServerRequest;
using Poco::Net::HTTPServerResponse;
using Poco::Net::SecureServerSocket;
using Poco::Net::HTTPBasicCredentials;
+using Poco::FileInputStream;
+using Poco::StreamCopier;
using Poco::Util::Application;
class FileServerRequestHandler: public HTTPRequestHandler
@@ -103,6 +109,37 @@ public:
return false;
}
+ void preprocessFile(HTTPServerRequest& request, HTTPServerResponse& response)
+ {
+ Poco::URI requestUri("https", request.getHost(), request.getURI());
+ HTMLForm form(request, request.stream());
+
+ std::string preprocess;
+ const auto host = "wss://" + requestUri.getHost() + ":" + std::to_string(requestUri.getPort());
+ const auto path = Poco::Path(LOOLWSD::FileServerRoot, requestUri.getPath());
+ const auto wopi = form.has("WOPISrc") ?
+ form.get("WOPISrc") + "?access_token=" + form.get("access_token","") : "";
+
+ FileInputStream file(path.toString());
+ StreamCopier::copyToString(file, preprocess);
+ file.close();
+
+ Poco::replaceInPlace(preprocess, std::string("WOPISRC"), wopi);
+ Poco::replaceInPlace(preprocess, std::string("HOST"), form.get("host", host));
+ Poco::replaceInPlace(preprocess, std::string("FILEPATH"), form.get("file_path", ""));
+ Poco::replaceInPlace(preprocess, std::string("TITLE"), form.get("title", ""));
+ Poco::replaceInPlace(preprocess, std::string("PERMISSION"), form.get("permission", ""));
+ Poco::replaceInPlace(preprocess, std::string("TIMESTAMP"), form.get("timestamp", ""));
+ Poco::replaceInPlace(preprocess, std::string("CLOSEBUTTON"), form.get("closebutton", ""));
+
+ response.setContentType("text/html");
+ response.setContentLength(preprocess.length());
+ response.setChunkedTransferEncoding(false);
+
+ std::ostream& ostr = response.send();
+ ostr << preprocess;
+ }
+
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override
{
try
@@ -115,9 +152,15 @@ public:
throw Poco::FileNotFoundException("Invalid file.");
}
+ const std::string endPoint = requestSegments[requestSegments.size() - 1];
+ if (endPoint == "loleaflet.html")
+ {
+ preprocessFile(request, response);
+ return;
+ }
+
if (request.getMethod() == HTTPRequest::HTTP_GET)
{
- const std::string endPoint = requestSegments[requestSegments.size() - 1];
if (endPoint == "admin.html" ||
endPoint == "adminSettings.html" ||
endPoint == "adminAnalytics.html")
More information about the Libreoffice-commits
mailing list