loleaflet/build/build.js | 2 loleaflet/dist/admin.html | 128 +++++ loleaflet/dist/admin/admin-src.js | 710 ------------------------------- loleaflet/dist/admin/admin.html | 129 ----- loleaflet/dist/admin/adminAnalytics.html | 100 ---- loleaflet/dist/admin/adminSettings.html | 107 ---- loolwsd/Admin.cpp | 113 ---- loolwsd/Common.hpp | 2 loolwsd/FileServer.hpp | 153 ------ loolwsd/LOOLWSD.cpp | 40 - loolwsd/LOOLWSD.hpp | 1 loolwsd/cert.pem | 24 - loolwsd/configure.ac | 2 loolwsd/key.pem | 27 - 14 files changed, 150 insertions(+), 1388 deletions(-)
New commits: commit 9a66e75e8348ac1844f2e187c65e3f1eb7c233b9 Author: Tor Lillqvist <[email protected]> Date: Mon Mar 21 16:52:55 2016 +0200 Revert "loolwsd: SSL infrastructure" This reverts commit fb9c9a9ec7833e290833e1133780ac4b39a92bf7. diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp index fd7ee55..053ce94 100644 --- a/loolwsd/Common.hpp +++ b/loolwsd/Common.hpp @@ -37,8 +37,6 @@ constexpr int SMALL_MESSAGE_SIZE = READ_BUFFER_SIZE / 2; static const std::string JailedDocumentRoot = "/user/docs/"; static const std::string CHILD_URI = "/loolws/child?"; static const std::string LOLEAFLET_PATH = "/loleaflet/dist/loleaflet.html?"; -static const std::string SSL_CERT_FILE = "cert.pem"; -static const std::string SSL_KEY_FILE = "key.pem"; #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index ba30f41..2c47456 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -62,8 +62,6 @@ DEALINGS IN THE SOFTWARE. #include <Poco/File.h> #include <Poco/FileStream.h> #include <Poco/Mutex.h> -#include <Poco/Net/ConsoleCertificateHandler.h> -#include <Poco/Net/Context.h> #include <Poco/Net/HTMLForm.h> #include <Poco/Net/HTTPClientSession.h> #include <Poco/Net/HTTPRequest.h> @@ -74,17 +72,12 @@ DEALINGS IN THE SOFTWARE. #include <Poco/Net/HTTPServerParams.h> #include <Poco/Net/HTTPServerRequest.h> #include <Poco/Net/HTTPServerResponse.h> -#include <Poco/Net/InvalidCertificateHandler.h> -#include <Poco/Net/KeyConsoleHandler.h> #include <Poco/Net/MessageHeader.h> #include <Poco/Net/Net.h> #include <Poco/Net/NetException.h> #include <Poco/Net/PartHandler.h> -#include <Poco/Net/PrivateKeyPassphraseHandler.h> -#include <Poco/Net/SecureServerSocket.h> #include <Poco/Net/ServerSocket.h> #include <Poco/Net/SocketAddress.h> -#include <Poco/Net/SSLManager.h> #include <Poco/Net/WebSocket.h> #include <Poco/Path.h> #include <Poco/Process.h> @@ -137,7 +130,6 @@ using Poco::Net::HTTPServerResponse; using Poco::Net::MessageHeader; using Poco::Net::NameValueCollection; using Poco::Net::PartHandler; -using Poco::Net::SecureServerSocket; using Poco::Net::ServerSocket; using Poco::Net::Socket; using Poco::Net::SocketAddress; @@ -1096,22 +1088,6 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) return Application::EXIT_USAGE; } - Poco::Crypto::initializeCrypto(); - - // SSL initialize - Poco::Net::initializeSSL(); - Poco::Net::Context::Params sslParams; - sslParams.certificateFile = Path(Application::instance().commandPath()).parent().toString() + SSL_CERT_FILE; - sslParams.privateKeyFile = Path(Application::instance().commandPath()).parent().toString() + SSL_KEY_FILE; - // Don't ask clients for certificate - sslParams.verificationMode = Poco::Net::Context::VERIFY_NONE; - - Poco::SharedPtr<Poco::Net::PrivateKeyPassphraseHandler> consoleHandler = new Poco::Net::KeyConsoleHandler(true); - Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> invalidCertHandler = new Poco::Net::ConsoleCertificateHandler(false); - - Poco::Net::Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::SERVER_USE, sslParams); - Poco::Net::SSLManager::instance().initializeServer(consoleHandler, invalidCertHandler, sslContext); - char *locale = setlocale(LC_ALL, nullptr); if (locale == nullptr || std::strcmp(locale, "C") == 0) setlocale(LC_ALL, "en_US.utf8"); @@ -1217,7 +1193,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) params2->setMaxThreads(MAX_SESSIONS); // Start a server listening on the port for clients - SecureServerSocket svs(ClientPortNumber); + ServerSocket svs(ClientPortNumber); ThreadPool threadPool(NumPreSpawnedChildren*6, MAX_SESSIONS * 2); HTTPServer srv(new RequestHandlerFactory<ClientRequestHandler>(), threadPool, svs, params1); @@ -1350,9 +1326,6 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) Util::removeFile(path, true); } - Poco::Net::uninitializeSSL(); - Poco::Crypto::uninitializeCrypto(); - Log::info("Process [loolwsd] finished."); return Application::EXIT_OK; } diff --git a/loolwsd/cert.pem b/loolwsd/cert.pem deleted file mode 100644 index 8573263..0000000 --- a/loolwsd/cert.pem +++ /dev/null @@ -1,24 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIECzCCAvOgAwIBAgIJAODbP0OufIfRMA0GCSqGSIb3DQEBCwUAMIGbMQswCQYD -VQQGEwJJTjETMBEGA1UECAwKQ2hhbmRpZ2FyaDETMBEGA1UEBwwKQ2hhbmRpZ2Fy -aDESMBAGA1UECgwJQ29sbGFib3JhMRIwEAYDVQQLDAlDb2xsYWJvcmExEjAQBgNV -BAMMCWxvY2FsaG9zdDEmMCQGCSqGSIb3DQEJARYXcHJhbmF2a0Bjb2xsYWJvcmEu -Y28udWswHhcNMTYwMzE3MTkyOTUwWhcNMTcwMzE3MTkyOTUwWjCBmzELMAkGA1UE -BhMCSU4xEzARBgNVBAgMCkNoYW5kaWdhcmgxEzARBgNVBAcMCkNoYW5kaWdhcmgx -EjAQBgNVBAoMCUNvbGxhYm9yYTESMBAGA1UECwwJQ29sbGFib3JhMRIwEAYDVQQD -DAlsb2NhbGhvc3QxJjAkBgkqhkiG9w0BCQEWF3ByYW5hdmtAY29sbGFib3JhLmNv -LnVrMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAurOVgcqAuIeXIySR -vc2ZBUrliOd4uUxjIXaKv6SJKucnYON9tLqFtfvbHr6dRN8ii2rtVzSt4xGmL7y/ -tt6g+Bw9J2vz94pr6fK8HsSO4SCEegCDqUlcjYL8lNo64ko+tXEDyyAP6U44wY0o -QSxSBabFf/r2hnquMIkhA1rBdwlL7dUi6lj1CBP/RRIamo3xu5Jnr28brd4eDrFT -Ozd/smZFsYXJttXIVIogBFeedQJwXzhlFOfW2U/6lDUdmS8elcTy5Q53m/AYm2SI -t17H6hJtKulxme/9u2vuZyEsUQZKH7h4eM7vn+ycOyhC7Us6w8h1I4E/lQ2KpHCG -avnNgQIDAQABo1AwTjAdBgNVHQ4EFgQUTv8kVhooEjV+xmMv9XK2dVMcvfQwHwYD -VR0jBBgwFoAUTv8kVhooEjV+xmMv9XK2dVMcvfQwDAYDVR0TBAUwAwEB/zANBgkq -hkiG9w0BAQsFAAOCAQEAKWMHIRErOd/N0OB9HXYiFOht5FB0G7lcxVi2/xuQZ7+a -fE35J2PPnKh4T9ZJRNfVR9hLUiW4/PUol28R+199OTn0mmDvvBv+39qJCS/GW/+f -h7S1xE0xEGe5Mhur9TZA2XFNinp+TaQhS6/cmSKa+Mmhh8eHEezycjTR9+xERass -e8ksYDDzUbcSF/z6iZxy8ISjx1ShIzARdu0wLO91TiDW5HFy1wDWRxuoEZsJvMwc -aYHZmL1TneKm2zsHbEa8RKszhVu2RkgKUfbfHuWNgxisLe0zR9s0j9UZsbmBt235 -H4uIDQovurvlm5aiLPIUTEnRN1dCF0n7k9KQQslZmA== ------END CERTIFICATE----- diff --git a/loolwsd/configure.ac b/loolwsd/configure.ac index f4993e9..f903f57 100644 --- a/loolwsd/configure.ac +++ b/loolwsd/configure.ac @@ -119,7 +119,7 @@ AS_IF([test `uname -s` = Linux], AS_IF([test "$enable_tests" != "no"], [PKG_CHECK_MODULES([CPPUNIT], [cppunit])]) -LIBS="$LIBS -lPocoNet${POCO_DEBUG_SUFFIX} -lPocoUtil${POCO_DEBUG_SUFFIX} -lPocoJSON${POCO_DEBUG_SUFFIX} -lPocoFoundation${POCO_DEBUG_SUFFIX} -lPocoXML${POCO_DEBUG_SUFFIX} -lPocoNetSSL${POCO_DEBUG_SUFFIX} -lPocoCrypto${POCO_DEBUG_SUFFIX}" +LIBS="$LIBS -lPocoNet${POCO_DEBUG_SUFFIX} -lPocoUtil${POCO_DEBUG_SUFFIX} -lPocoJSON${POCO_DEBUG_SUFFIX} -lPocoFoundation${POCO_DEBUG_SUFFIX} -lPocoXML${POCO_DEBUG_SUFFIX}" AC_CHECK_HEADERS([LibreOfficeKit/LibreOfficeKit.h], [], diff --git a/loolwsd/key.pem b/loolwsd/key.pem deleted file mode 100644 index ddcfd07..0000000 --- a/loolwsd/key.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpQIBAAKCAQEAurOVgcqAuIeXIySRvc2ZBUrliOd4uUxjIXaKv6SJKucnYON9 -tLqFtfvbHr6dRN8ii2rtVzSt4xGmL7y/tt6g+Bw9J2vz94pr6fK8HsSO4SCEegCD -qUlcjYL8lNo64ko+tXEDyyAP6U44wY0oQSxSBabFf/r2hnquMIkhA1rBdwlL7dUi -6lj1CBP/RRIamo3xu5Jnr28brd4eDrFTOzd/smZFsYXJttXIVIogBFeedQJwXzhl -FOfW2U/6lDUdmS8elcTy5Q53m/AYm2SIt17H6hJtKulxme/9u2vuZyEsUQZKH7h4 -eM7vn+ycOyhC7Us6w8h1I4E/lQ2KpHCGavnNgQIDAQABAoIBAQCKDL3w4ZZ6W6/y -iVjGep66Hh5JM7a9dPEbzjZb7EKMma0xZCUQHJc/8AGe4x0QztkRM7hZMhedffBe -/fbYNhfaPa8uVhFoKU8QBq75JSfs6Qlr2LOB2j/4VzGCsza1Gmbx7KX8bTG2tmMb -Is/wGOBxU1ZYAm6FE3N3af4iJ9pDtDTHggY+mq7g4VyKOpTcp2j/r970sh9vq1Es -+FyTWsTEx47Ar0X7/n4xb/cVyNQQh/78uDZZ3o1pnTUDtKH7VD8gFWuNdG9Vase3 -xUSwXuAvTBmxip5TrTjSnuhsLPWYqulwy89P+zsDHbBLZMW5Xl3Vpwq2J1AzmwuW -LJewDO4tAoGBAOxkvL+KUHa0/eapx9iBM2hd/MZYCYVGfRm1IBdeIKuE/ITKHF2v -2fo6GPaOfZibtSCbeMwwhnsuZ7Efz2qAPzla9is4gK3bJYiFT5fVDlyoDUdA4+Nr -3mBH4aoBRXrEsektjdSpryFydmMb8reJ0J/cKJ4n083yIMjSv5bAwiW/AoGBAMov -wNkSrWIqBuk83UdLzD7qENqT5S1qCvXyiKFqrWozgfulyIJXKebmtOKI2rnsG8bz -puZSaUvx79UvhZKOMtTjYoK1IMB7hxRVV/YsjkyIONHCwhbYSJXcWkRsgdmSn8Db -Zs4oQMfflC4IaH3I2w7EdRLOAI0g7eRTRxclMVy/AoGBAI0TBU1ttt1Q4CFy+y/q -0woa5QpdabkeuvPHkxI++1JA+A4rK8iBdJ2PZGxn1u5nJi4CepGo9+i1Ze5fpIHT -bWfGMBjVDH40xW522GwtGvgS1nHKePW03y4oV7UEMzmz/tTAed8LMNfOHnbBLBV6 -aoWsdpUEAbPrJsOSegH2oSazAoGAAm5Yj0OeOhPvSVamAnly1z7RPQ+SLd2cjCCC -bA5wT1qXMYNoychqhJA5lI+4sYuZOecsFpDfGz6pd5K+tGhpTA3/3Tp4Tlgt45yz -Fg6rF1h79mm1E7k+Bi9EFpaHaSpOKW956Piq7rxNd9A6EWkc2Sybi8JWV1wSADDQ -JgMYeNkCgYEAo0bpz8e+ZMTs3acnOwn8xT0tY9Q57hjTJfftZLjugyh9Y/6T85CR -Wcpyq6HfEFWKImgM9XJllCqCH9JgXs/IouH0N3B2zG1ySKCK4qVimd+RJPNcn1Nf -Pda7R2pJuvGglIBJi9EFNHGkUzF74ptru5Hins/+EVDpIRyl6ZJTfUg= ------END RSA PRIVATE KEY----- commit 1ba4d27aba94f7f6a7acc79ea2a1360daa2bd229 Author: Tor Lillqvist <[email protected]> Date: Mon Mar 21 16:52:54 2016 +0200 Revert "loolwsd: FileServer class to serve static contents" This reverts commit 8f435d6e7eabbbfb72b338a7da13b0a63d4709be. diff --git a/loolwsd/FileServer.hpp b/loolwsd/FileServer.hpp deleted file mode 100644 index 9c62e41..0000000 --- a/loolwsd/FileServer.hpp +++ /dev/null @@ -1,154 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef INCLUDED_FILE_SERVER_HPP -#define INCLUDED_FILE_SERVER_HPP - -#include <string> -#include <vector> - -#include <Poco/Net/NetException.h> - -#include <Poco/Net/HTTPCookie.h> -#include <Poco/Net/HTTPBasicCredentials.h> -#include <Poco/Net/HTTPRequest.h> -#include <Poco/Net/HTTPRequestHandler.h> -#include <Poco/Net/HTTPServer.h> -#include <Poco/Net/HTTPServerParams.h> -#include <Poco/Net/HTTPServerRequest.h> -#include <Poco/Net/HTTPServerResponse.h> -#include <Poco/Net/SecureServerSocket.h> -#include <Poco/Net/WebSocket.h> -#include <Poco/Runnable.h> -#include <Poco/StringTokenizer.h> -#include <Poco/URI.h> -#include <Poco/Util/ServerApplication.h> -#include <Poco/Util/Timer.h> - -#include "Common.hpp" - -using Poco::Net::HTTPRequest; -using Poco::Net::HTTPRequestHandler; -using Poco::Net::HTTPRequestHandlerFactory; -using Poco::Net::HTTPResponse; -using Poco::Net::HTTPServerParams; -using Poco::Net::HTTPServerRequest; -using Poco::Net::HTTPServerResponse; -using Poco::Net::SecureServerSocket; -using Poco::Net::HTTPBasicCredentials; -using Poco::Util::Application; - -class FileServerRequestHandler: public HTTPRequestHandler -{ -public: - void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override - { - try - { - Poco::URI requestUri(request.getURI()); - std::vector<std::string> requestSegments; - requestUri.getPathSegments(requestSegments); - - // FIXME: We might want to package all dist files from leaflet to some other dir (?) - const std::string loleafletPath = Poco::Path(Application::instance().commandPath()).parent().parent().toString() + "loleaflet"; - const std::string endPoint = requestSegments[requestSegments.size() - 1]; - - if (request.getMethod() == HTTPRequest::HTTP_GET) - { - // FIXME: Some nice way to ask for credentials for protected files - if (endPoint == "admin.html" || - endPoint == "adminSettings.html" || - endPoint == "adminAnalytics.html") - { - HTTPBasicCredentials credentials(request); - // TODO: Read username and password from config file - if (credentials.getUsername() == "admin" - && credentials.getPassword() == "admin") - { - const std::string htmlMimeType = "text/html"; - // generate and set the cookie - const std::string keyPath = Poco::Path(Application::instance().commandPath()).parent().toString() + SSL_KEY_FILE; - JWTAuth authAgent(keyPath, "admin", "admin", "admin"); - const std::string jwtToken = authAgent.getAccessToken(); - Poco::Net::HTTPCookie cookie("jwt", jwtToken); - response.addCookie(cookie); - response.setContentType(htmlMimeType); - response.sendFile(loleafletPath + "/debug/document/" + endPoint, htmlMimeType); - } - else - { - Log::info("Wrong admin credentials."); - throw Poco::Net::NotAuthenticatedException("Wrong credentials."); - } - } - else if (requestSegments.size() > 1 && requestSegments[0] == "dist") - { - const std::string filePath = requestUri.getPath(); - const std::size_t extPoint = endPoint.find_last_of("."); - if (extPoint == std::string::npos) - return; - - const std::string fileType = endPoint.substr(extPoint + 1); - std::string mimeType; - if (fileType == "js") - mimeType = "application/javascript"; - else if (fileType == "css") - mimeType = "text/css"; - else - mimeType = "text/plain"; - - response.setContentType(mimeType); - response.sendFile(loleafletPath + request.getURI(), mimeType); - } - else - { - throw Poco::FileNotFoundException(""); - } - } - } - catch (Poco::Net::NotAuthenticatedException& exc) - { - Log::info ("FileServerRequestHandler::NotAuthenticated"); - response.set("WWW-Authenticate", "Basic realm=\"online\""); - response.setStatus(HTTPResponse::HTTP_UNAUTHORIZED); - response.setContentLength(0); - response.send(); - } - catch (Poco::FileNotFoundException& exc) - { - Log::info("FileServerRequestHandler:: File " + request.getURI() + " not found."); - response.setStatus(HTTPResponse::HTTP_NOT_FOUND); - response.setContentLength(0); - response.send(); - } - } -}; - -class FileServer -{ -public: - FileServer() - { - Log::info("File server ctor."); - } - - ~FileServer() - { - Log::info("File Server dtor."); - } - - FileServerRequestHandler* createRequestHandler() - { - return new FileServerRequestHandler(); - } -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 3ccce7d4ca80859cbf3c1cfd501d235a54b87c55 Author: Tor Lillqvist <[email protected]> Date: Mon Mar 21 16:52:53 2016 +0200 Revert "loolwsd: Use JWT authentication to access admin console" This reverts commit a0d3c5f3e4dc26790ec72ce434cb664ad302e7b7. diff --git a/loolwsd/Admin.cpp b/loolwsd/Admin.cpp index 0bf1718..a1c11cc 100644 --- a/loolwsd/Admin.cpp +++ b/loolwsd/Admin.cpp @@ -12,21 +12,15 @@ #include <sys/poll.h> #include <sys/prctl.h> -#include <Poco/Net/HTTPCookie.h> -#include <Poco/Net/HTTPBasicCredentials.h> -#include <Poco/Net/HTTPRequest.h> #include <Poco/Net/HTTPRequestHandler.h> #include <Poco/Net/HTTPServerParams.h> #include <Poco/Net/HTTPServerRequest.h> #include <Poco/Net/HTTPServerResponse.h> #include <Poco/Net/NetException.h> -#include <Poco/Net/SecureServerSocket.h> #include <Poco/Net/WebSocket.h> #include <Poco/StringTokenizer.h> -#include <Poco/Util/ServerApplication.h> #include <Poco/Util/Timer.h> -#include "Auth.hpp" #include "Admin.hpp" #include "AdminModel.hpp" #include "Common.hpp" @@ -36,31 +30,41 @@ using namespace LOOLProtocol; -using Poco::StringTokenizer; -using Poco::Net::HTTPBasicCredentials; -using Poco::Net::HTTPCookie; -using Poco::Net::HTTPRequest; using Poco::Net::HTTPRequestHandler; using Poco::Net::HTTPRequestHandlerFactory; using Poco::Net::HTTPResponse; using Poco::Net::HTTPServerParams; using Poco::Net::HTTPServerRequest; using Poco::Net::HTTPServerResponse; -using Poco::Net::SecureServerSocket; using Poco::Net::ServerSocket; using Poco::Net::Socket; using Poco::Net::WebSocket; using Poco::Net::WebSocketException; -using Poco::Util::Application; +using Poco::StringTokenizer; /// Handle admin requests. class AdminRequestHandler: public HTTPRequestHandler { -private: - void handleWSRequests(HTTPServerRequest& request, HTTPServerResponse& response, int nSessionId) +public: + + AdminRequestHandler(Admin* adminManager) + : _admin(adminManager) + { } + + void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override { + assert(request.serverAddress().port() == ADMIN_PORT_NUMBER); + + // Different session id pool for admin sessions (?) + const auto nSessionId = Util::decodeId(LOOLWSD::GenSessionId()); + const std::string thread_name = "admin_ws_" + std::to_string(nSessionId); try { + if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) + Log::error("Cannot set thread name to " + thread_name + "."); + + Log::debug("Thread [" + thread_name + "] started."); + auto ws = std::make_shared<WebSocket>(request, response); { @@ -309,90 +313,11 @@ private: break; } } - catch (const Poco::Net::NotAuthenticatedException& exc) - { - Log::info("NotAuthenticatedException"); - response.set("WWW-Authenticate", "Basic realm=\"ws-online\""); - response.setStatus(HTTPResponse::HTTP_UNAUTHORIZED); - response.setContentLength(0); - response.send(); - } catch (const std::exception& exc) { Log::error(std::string("AdminRequestHandler::handleRequest: Exception: ") + exc.what()); } - } - -public: - - AdminRequestHandler(Admin* adminManager) - : _admin(adminManager) - { } - - void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override - { - assert(request.serverAddress().port() == ADMIN_PORT_NUMBER); - - // Different session id pool for admin sessions (?) - const auto nSessionId = Util::decodeId(LOOLWSD::GenSessionId()); - const std::string thread_name = "admin_ws_" + std::to_string(nSessionId); - - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + thread_name + "."); - Log::debug("Thread [" + thread_name + "] started."); - - try - { - std::string requestURI = request.getURI(); - StringTokenizer pathTokens(requestURI, "/", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); - - if (request.find("Upgrade") != request.end() && Poco::icompare(request["Upgrade"], "websocket") == 0) - { - if (request.find("Cookie") != request.end()) - { - // FIXME: Handle other cookie params like '; httponly; secure' - const std::size_t pos = request["Cookie"].find_first_of("="); - if (pos == std::string::npos) - throw Poco::Net::NotAuthenticatedException("Missing JWT"); - - const std::string jwtToken = request["Cookie"].substr(pos + 1); - Log::info("Verifying JWT token: " + jwtToken); - const std::string keyPath = Poco::Path(Application::instance().commandPath()).parent().toString() + SSL_KEY_FILE; - JWTAuth authAgent(keyPath, "admin", "admin", "admin"); - if (authAgent.verify(jwtToken)) - { - Log::trace("JWT token is valid"); - handleWSRequests(request, response, nSessionId); - } - else - { - Log::info("Invalid JWT token"); - throw Poco::Net::NotAuthenticatedException("Invalid Token"); - } - } - else - { - Log::info("Missing authentication cookie. Handshake declined."); - throw Poco::Net::NotAuthenticatedException("Missing token"); - } - } - } - catch(const Poco::Net::NotAuthenticatedException& exc) - { - Log::info("Admin::NotAuthneticated"); - response.set("WWW-Authenticate", "Basic realm=\"online\""); - response.setStatus(HTTPResponse::HTTP_UNAUTHORIZED); - response.setContentLength(0); - response.send(); - } - catch (const std::exception& exc) - { - Log::info("Unknown Exception caught"); - response.setStatusAndReason(HTTPResponse::HTTP_BAD_REQUEST); - response.setContentLength(0); - response.send(); - } Log::debug("Thread [" + thread_name + "] finished."); } @@ -430,7 +355,7 @@ private: /// An admin command processor. Admin::Admin(const Poco::Process::PID brokerPid, const int brokerPipe, const int notifyPipe) : - _srv(new AdminRequestHandlerFactory(this), SecureServerSocket(ADMIN_PORT_NUMBER), new HTTPServerParams), + _srv(new AdminRequestHandlerFactory(this), ServerSocket(ADMIN_PORT_NUMBER), new HTTPServerParams), _model(AdminModel()) { Admin::BrokerPid = brokerPid; commit e41be7c0f4fe00a4e2dc3d9e4ac347612e2b5cfe Author: Tor Lillqvist <[email protected]> Date: Mon Mar 21 16:52:52 2016 +0200 Revert "loleaflet: Move admin console related files to dist/admin" This reverts commit 3a09c992f71f5dfee12386f289c520737c224436. diff --git a/loleaflet/build/build.js b/loleaflet/build/build.js index bf41ee2..db7e536 100644 --- a/loleaflet/build/build.js +++ b/loleaflet/build/build.js @@ -121,7 +121,7 @@ exports.build = function (callback, version, compsBase32, buildName) { // Also combine and copy the admin JS files // TODO: Also minify if admin complexity increases in future var adminNewSrc = combineFiles(getAdminFiles()), - adminPath = 'dist/admin/admin-src.js', + adminPath = 'dist/admin-src.js', adminOldSrc = loadSilently(adminPath); if (adminNewSrc != adminOldSrc) { diff --git a/loleaflet/dist/admin/admin.html b/loleaflet/dist/admin.html similarity index 50% rename from loleaflet/dist/admin/admin.html rename to loleaflet/dist/admin.html index 647b31b..806d54d 100644 --- a/loleaflet/dist/admin/admin.html +++ b/loleaflet/dist/admin.html @@ -11,16 +11,13 @@ <title>LibreOffice Online - Admin console</title> <!-- Bootstrap core CSS --> - <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet"> + <link href="/loleaflet/dist/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> - <link href="../bootstrap/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> + <link href="/loleaflet/dist/bootstrap/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> <!-- Custom styles for this template --> - <link href="../bootstrap/dashboard.css" rel="stylesheet"> - - <link rel="stylesheet" href="../dialog/vex.css" /> - <link rel="stylesheet" href="../dialog/vex-theme-plain.css" /> + <link href="/loleaflet/dist/bootstrap/dashboard.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> @@ -30,52 +27,58 @@ </head> <body> - <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> - <script>window.jQuery || document.write('<script src="bootstrap/assets/js/vendor/jquery.min.js"><\/script>')</script> - <script src="../dialog/vex.combined.min.js"></script> - <script src="admin-src.js"></script> - <script>vex.defaultOptions.className = 'vex-theme-plain';</script> + <script src="/loleaflet/dist/admin-src.js"></script> <script> - host = 'wss://' + window.location.hostname + ':9989'; + 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 host = getParameterByName('host'); new AdminSocketOverview(host); </script> <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container-fluid"> - <div class="navbar-header"> - <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> - <span class="sr-only">Toggle navigation</span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - </button> - <a class="navbar-brand" href="#">LibreOffice Online - Admin console</a> - </div> - <div id="navbar" class="navbar-collapse collapse"> - <ul class="nav navbar-nav navbar-right"> - <li><a href="admin.html">Dashboard</a></li> - <li><a href="adminSettings.html">Settings</a></li> - <li><a href="#">Help</a></li> - </ul> - <form class="navbar-form navbar-right"> - <input type="text" class="form-control" placeholder="Search..."> - </form> - </div> + <div class="navbar-header"> + <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> + <span class="sr-only">Toggle navigation</span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + </button> + <a class="navbar-brand" href="#">LibreOffice Online - Admin console</a> + </div> + <div id="navbar" class="navbar-collapse collapse"> + <ul class="nav navbar-nav navbar-right"> + <li><a href="#">Dashboard</a></li> + <li><a href="#">Settings</a></li> + <li><a href="#">Profile</a></li> + <li><a href="#">Help</a></li> + </ul> + <form class="navbar-form navbar-right"> + <input type="text" class="form-control" placeholder="Search..."> + </form> + </div> </div> </nav> <div class="container-fluid"> <div class="row"> - <div class="col-sm-3 col-md-2 sidebar"> - <ul class="nav nav-sidebar"> - <li class="active"><a href="#">Overview <span class="sr-only">(current)</span></a></li> - <li><a href="adminAnalytics.html">Analytics</a></li> - </ul> - </div> - <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> - <h1 class="page-header">Dashboard</h1> + <div class="col-sm-3 col-md-2 sidebar"> + <ul class="nav nav-sidebar"> + <li class="active"><a href="#">Overview <span class="sr-only">(current)</span></a></li> + <li><a href="#">Reports</a></li> + <li><a href="#">Analytics</a></li> + <li><a href="#">Export</a></li> + </ul> + </div> + <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> + <h1 class="page-header">Dashboard</h1> <div class="row placeholders"> <div class="col-xs-6 col-sm-3 placeholder"> @@ -111,19 +114,15 @@ </div> </div> - <div id="rowContextMenu" class="dropdown clearfix"> - <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;margin-bottom:5px;"> - <li><a tabindex="-1" href="#">Kill</a></li> - </ul> - </div> - <!-- Bootstrap core JavaScript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> - <script src="../bootstrap/js/bootstrap.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> + <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script> + <script src="../../dist/bootstrap/js/bootstrap.min.js"></script> <!-- Just to make our placeholder images work. Don't actually copy the next line! --> - <script src="../bootstrap/assets/js/vendor/holder.min.js"></script> + <script src="../../dist/bootstrap/assets/js/vendor/holder.min.js"></script> <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> - <script src="../bootstrap/assets/js/ie10-viewport-bug-workaround.js"></script> + <script src="../../dist/bootstrap/assets/js/ie10-viewport-bug-workaround.js"></script> </body> </html> diff --git a/loleaflet/dist/admin/admin-src.js b/loleaflet/dist/admin/admin-src.js deleted file mode 100644 index 26de51f..0000000 --- a/loleaflet/dist/admin/admin-src.js +++ /dev/null @@ -1,710 +0,0 @@ -/* - Base.js, version 1.1a - Copyright 2006-2010, Dean Edwards - License: http://www.opensource.org/licenses/mit-license.php -*/ - -var Base = function() { - // dummy -}; - -Base.extend = function(_instance, _static) { // subclass - var extend = Base.prototype.extend; - - // build the prototype - Base._prototyping = true; - var proto = new this; - extend.call(proto, _instance); - proto.base = function() { - // call this method from any other method to invoke that method's ancestor - }; - delete Base._prototyping; - - // create the wrapper for the constructor function - //var constructor = proto.constructor.valueOf(); //-dean - var constructor = proto.constructor; - var klass = proto.constructor = function() { - if (!Base._prototyping) { - if (this._constructing || this.constructor == klass) { // instantiation - this._constructing = true; - constructor.apply(this, arguments); - delete this._constructing; - } else if (arguments[0] != null) { // casting - return (arguments[0].extend || extend).call(arguments[0], proto); - } - } - }; - - // build the class interface - klass.ancestor = this; - klass.extend = this.extend; - klass.forEach = this.forEach; - klass.implement = this.implement; - klass.prototype = proto; - klass.toString = this.toString; - klass.valueOf = function(type) { - //return (type == "object") ? klass : constructor; //-dean - return (type == "object") ? klass : constructor.valueOf(); - }; - extend.call(klass, _static); - // class initialisation - if (typeof klass.init == "function") klass.init(); - return klass; -}; - -Base.prototype = { - extend: function(source, value) { - if (arguments.length > 1) { // extending with a name/value pair - var ancestor = this[source]; - if (ancestor && (typeof value == "function") && // overriding a method? - // the valueOf() comparison is to avoid circular references - (!ancestor.valueOf || ancestor.valueOf() != value.valueOf()) && - /\bbase\b/.test(value)) { - // get the underlying method - var method = value.valueOf(); - // override - value = function() { - var previous = this.base || Base.prototype.base; - this.base = ancestor; - var returnValue = method.apply(this, arguments); - this.base = previous; - return returnValue; - }; - // point to the underlying method - value.valueOf = function(type) { - return (type == "object") ? value : method; - }; - value.toString = Base.toString; - } - this[source] = value; - } else if (source) { // extending with an object literal - var extend = Base.prototype.extend; - // if this object has a customised extend method then use it - if (!Base._prototyping && typeof this != "function") { - extend = this.extend || extend; - } - var proto = {toSource: null}; - // do the "toString" and other methods manually - var hidden = ["constructor", "toString", "valueOf"]; - // if we are prototyping then include the constructor - var i = Base._prototyping ? 0 : 1; - while (key = hidden[i++]) { - if (source[key] != proto[key]) { - extend.call(this, key, source[key]); - - } - } - // copy each of the source object's properties to this object - for (var key in source) { - if (!proto[key]) extend.call(this, key, source[key]); - } - } - return this; - } -}; - -// initialise -Base = Base.extend({ - constructor: function() { - this.extend(arguments[0]); - } -}, { - ancestor: Object, - version: "1.1", - - forEach: function(object, block, context) { - for (var key in object) { - if (this.prototype[key] === undefined) { - block.call(context, object[key], key, object); - } - } - }, - - implement: function() { - for (var i = 0; i < arguments.length; i++) { - if (typeof arguments[i] == "function") { - // if it's a function, call it - arguments[i](this.prototype); - } else { - // add the interface using the extend method - this.prototype.extend(arguments[i]); - } - } - return this; - }, - - toString: function() { - return String(this.valueOf()); - } -}); - - - -/* - Utility class -*/ -/* global Base */ -var Util = Base.extend({ - constructor: null - -}, { // class itnerface - - humanize: function humanFileSize(kbytes) { - var unit = 1000; - var units = ['kB', 'MB', 'GB', 'TB']; - for (var i = 0; Math.abs(kbytes) >= unit && i < units.length; i++) { - kbytes /= unit; - } - - return kbytes.toFixed(1) + ' ' + units[i]; - } -}); - - -/* - Abstract class -*/ - -/* global vex Base */ -/* exported AdminSocketBase */ -var AdminSocketBase = Base.extend({ - socket: null, - - constructor: function(host) { - // because i am abstract - if (this.constructor === AdminSocketBase) { - throw new Error('Cannot instantiate abstract class'); - } - - // We do not allow such child class to instantiate websocket that do not implement - // onSocketMessage and onSocketOpen. - if (typeof this.onSocketMessage === 'function' && typeof this.onSocketOpen === 'function') { - this.socket = new WebSocket(host); - this.socket.onopen = this.onSocketOpen.bind(this); - this.socket.onclose = this.onSocketClose.bind(this); - this.socket.onmessage = this.onSocketMessage.bind(this); - this.socket.onerror = this.onSocketError.bind(this); - this.socket.binaryType = 'arraybuffer'; - } - }, - - onSocketOpen: function() { - /* Implemented by child */ - }, - - onSocketMessage: function() { - /* Implemented by child */ - }, - - onSocketClose: function() { - this.socket.onerror = function() {}; - this.socket.onclose = function() {}; - this.socket.onmessage = function() {}; - this.socket.close(); - }, - - onSocketError: function() { - vex.dialog.alert('Connection error'); - } -}); - - -/* - Socket to be intialized on opening the overview page in Admin console -*/ -/* global vex $ Util AdminSocketBase */ -var AdminSocketOverview = AdminSocketBase.extend({ - constructor: function(host) { - this.base(host); - }, - - _basicStatsIntervalId: 0, - - _getBasicStats: function() { - this.socket.send('total_mem'); - this.socket.send('active_docs_count'); - this.socket.send('active_users_count'); - }, - - onSocketOpen: function() { - this.socket.send('documents'); - this.socket.send('subscribe document addview rmview rmdoc'); - - this._getBasicStats(); - var socketOverview = this; - this._basicStatsIntervalId = - setInterval(function() { - return socketOverview._getBasicStats(); - }, 5000); - - // Allow table rows to have a context menu for killing children - $('body').on('contextmenu', 'table tr', function(ev) { - $('#rowContextMenu').css({ - display: 'block', - left: ev.pageX, - top: ev.pageY - }) - .data('rowToKill', ev.target.parentElement.id); - - return false; - }) - .click(function() { - $('#rowContextMenu').hide(); - }); - - $('#rowContextMenu').on('click', 'a', function() { - vex.dialog.confirm({ - message: 'Are you sure you want to kill this child ?', - callback: function(value) { - if (value) { - var killPid = ($('#rowContextMenu').data('rowToKill')).substring('doc'.length); - socketOverview.socket.send('kill ' + killPid); - } - $('#rowContextMenu').hide(); - } - }); - }); - }, - - onSocketMessage: function(e) { - var textMsg; - if (typeof e.data === 'string') { - textMsg = e.data; - } - else { - textMsg = ''; - } - - var tableContainer = document.getElementById('doclist'); - var rowContainer; - var pidEle, urlEle, viewsEle, memEle, docEle; - var nViews, nTotalViews; - var docProps, sPid, sUrl, sViews, sMem; - if (textMsg.startsWith('documents')) { - var documents = textMsg.substring('documents'.length); - documents = documents.trim().split('\n'); - for (var i = 0; i < documents.length; i++) { - if (documents[i] === '') { - continue; - } - docProps = documents[i].trim().split(' '); - sPid = docProps[0]; - sUrl = docProps[1]; - sViews = docProps[2]; - sMem = docProps[3]; - if (sUrl === '0') { - continue; - } - rowContainer = document.createElement('tr'); - rowContainer.id = 'doc' + sPid; - tableContainer.appendChild(rowContainer); - - pidEle = document.createElement('td'); - pidEle.innerHTML = sPid; - rowContainer.appendChild(pidEle); - - urlEle = document.createElement('td'); - urlEle.innerHTML = sUrl; - rowContainer.appendChild(urlEle); - - viewsEle = document.createElement('td'); - viewsEle.id = 'docview' + sPid; - viewsEle.innerHTML = sViews; - rowContainer.appendChild(viewsEle); - - memEle = document.createElement('td'); - memEle.innerHTML = Util.humanize(parseInt(sMem)); - rowContainer.appendChild(memEle); - } - } - else if (textMsg.startsWith('addview')) { - sPid = textMsg.substring('addview'.length).trim().split(' ')[0]; - nViews = parseInt(document.getElementById('docview' + sPid).innerHTML); - document.getElementById('docview' + sPid).innerHTML = nViews + 1; - nTotalViews = parseInt(document.getElementById('active_users_count').innerHTML); - document.getElementById('active_users_count').innerHTML = nTotalViews + 1; - } - else if (textMsg.startsWith('rmview')) { - sPid = textMsg.substring('addview'.length).trim().split(' ')[0]; - nViews = parseInt(document.getElementById('docview' + sPid).innerHTML); - document.getElementById('docview' + sPid).innerHTML = nViews - 1; - nTotalViews = parseInt(document.getElementById('active_users_count').innerHTML); - document.getElementById('active_users_count').innerHTML = nTotalViews - 1; - } - else if (textMsg.startsWith('document')) { - textMsg = textMsg.substring('document'.length); - docProps = textMsg.trim().split(' '); - sPid = docProps[0]; - sUrl = docProps[1]; - sMem = docProps[2]; - - docEle = document.getElementById('doc' + sPid); - if (docEle) { - tableContainer.removeChild(docEle); - } - if (sUrl === '0') { - return; - } - - rowContainer = document.createElement('tr'); - rowContainer.id = 'doc' + docProps[0]; - tableContainer.appendChild(rowContainer); - - pidEle = document.createElement('td'); - pidEle.innerHTML = docProps[0]; - rowContainer.appendChild(pidEle); - - urlEle = document.createElement('td'); - urlEle.innerHTML = docProps[1]; - rowContainer.appendChild(urlEle); - - viewsEle = document.createElement('td'); - viewsEle.innerHTML = 0; - viewsEle.id = 'docview' + docProps[0]; - rowContainer.appendChild(viewsEle); - - memEle = document.createElement('td'); - memEle.innerHTML = Util.humanize(parseInt(sMem)); - rowContainer.appendChild(memEle); - - var totalUsersEle = document.getElementById('active_docs_count'); - totalUsersEle.innerHTML = parseInt(totalUsersEle.innerHTML) + 1; - } - else if (textMsg.startsWith('total_mem') || - textMsg.startsWith('active_docs_count') || - textMsg.startsWith('active_users_count')) - { - textMsg = textMsg.split(' '); - var sCommand = textMsg[0]; - var nData = parseInt(textMsg[1]); - - if (sCommand === 'total_mem') { - nData = Util.humanize(nData); - } - document.getElementById(sCommand).innerHTML = nData; - } - else if (textMsg.startsWith('rmdoc')) { - textMsg = textMsg.substring('rmdoc'.length); - docProps = textMsg.trim().split(' '); - sPid = docProps[0]; - docEle = document.getElementById('doc' + sPid); - if (docEle) { - tableContainer.removeChild(docEle); - } - } - }, - - onSocketClose: function() { - clearInterval(this._basicStatsIntervalId); - } -}); - - -/* - Socket to be intialized on opening the analytics page in Admin console - containing various graphs to show to the user on specified interval -*/ - -/* global d3 Util AdminSocketBase */ -var AdminSocketAnalytics = AdminSocketBase.extend({ - constructor: function(host) { - this.base(host); - }, - - _memStatsData: [], - _cpuStatsData: [], - - _memStatsSize: 0, - _memStatsInterval: 0, - - _cpuStatsSize: 0, - _cpuStatsInterval: 0, - - _initMemStatsData: function(memStatsSize, memStatsInterval, reset) { - if (reset) { - this._memStatsData = []; - } - - var offset = this._memStatsData.length * memStatsInterval; - for (var i = 0; i < memStatsSize; i++) { - this._memStatsData.unshift({time: -(offset), value: 0}); - offset += memStatsInterval; - } - }, - - _initCpuStatsData: function() { - for (var i = 0; i < this._cpuStatsSize; i++) { - this._cpuStatsData.push({time: -((this._cpuStatsSize - i - 1) * this._cpuStatsInterval), value: 0}); - } - }, - - onSocketOpen: function() { - this.socket.send('subscribe mem_stats cpu_stats settings'); - this.socket.send('settings'); - this.socket.send('mem_stats'); - }, - - _createMemData: function() { - for (var i = this._memStatsRawData.length - 1, j = this._memStatsData.length - 1; i >= 0 && j >= 0; i--, j--) { - this._memStatsData[j].value = parseInt(this._memStatsRawData[i]); - } - }, - - _d3xAxis: null, - _d3yAxis: null, - _d3line: null, - _xScale: null, - _yScale: null, - - _graphWidth: 1000, - _graphHeight: 500, - _graphMargins: { - top: 20, - right: 20, - bottom: 20, - left: 100 - }, - - _setUpAxis: function() { - this._xScale = d3.scale.linear().range([this._graphMargins.left, this._graphWidth - this._graphMargins.right]).domain([d3.min(this._memStatsData, function(d) { - return d.time; - }), d3.max(this._memStatsData, function(d) { - return d.time; - })]); - - - this._yScale = d3.scale.linear().range([this._graphHeight - this._graphMargins.bottom, this._graphMargins.top]).domain([d3.min(this._memStatsData, function(d) { - return d.value; - }), d3.max(this._memStatsData, function(d) { - return d.value; - })]); - - this._d3xAxis = d3.svg.axis() - .scale(this._xScale) - .tickFormat(function(d) { - d = Math.abs(d / 1000); - var units = ['s', 'min', 'hr']; - for (var i = 0; i < units.length && Math.abs(d) >= 60; i++) { - d = parseInt(d / 60); - } - return parseInt(d) + units[i] + ' ago'; - }); - - this._d3yAxis = d3.svg.axis() - .scale(this._yScale) - .tickFormat(function (d) { - return Util.humanize(d); - }) - .orient('left'); - - var xScale = this._xScale; - var yScale = this._yScale; - - this._d3line = d3.svg.line() - .x(function(d) { - return xScale(d.time); - }) - .y(function(d) { - return yScale(d.value); - }); - }, - - _createMemGraph: function() { - var vis = d3.select('#visualisation'); - - this._setUpAxis(); - - vis.append('svg:g') - .attr('class', 'x-axis') - .attr('transform', 'translate(0,' + (this._graphHeight - this._graphMargins.bottom) + ')') - .call(this._d3xAxis); - - vis.append('svg:g') - .attr('class', 'y-axis') - .attr('transform', 'translate(' + this._graphMargins.left + ',0)') - .call(this._d3yAxis); - - vis.append('svg:path') - .attr('d', this._d3line(this._memStatsData)) - .attr('class', 'line') - .attr('stroke', 'blue') - .attr('stroke-width', 2) - .attr('fill', 'none'); - }, - - _addNewMemData: function(data) { - // make a space for new data - for (var i = this._memStatsData.length - 1; i > 0; i--) { - this._memStatsData[i].time = this._memStatsData[i - 1].time; - } - - // push new data at time '0' - this._memStatsData.push({time: 0, value: parseInt(data)}); - - // remove extra items - if (this._memStatsData.length > this._memStatsSize) { - this._memStatsData.shift(); - } - }, - - _updateMemGraph: function() { - var svg = d3.select('#visualisation'); - - this._setUpAxis(); - - svg.select('.line') - .attr('d', this._d3line(this._memStatsData)); - - svg.select('.x-axis') - .call(this._d3xAxis); - - svg.select('.y-axis') - .call(this._d3yAxis); - }, - - onSocketMessage: function(e) { - var textMsg; - if (typeof e.data === 'string') { - textMsg = e.data; - } - else { - textMsg = ''; - } - - - if (textMsg.startsWith('settings')) { - textMsg = textMsg.substring('settings '.length); - textMsg = textMsg.split(' '); - - //TODO: Add CPU statistics - var memStatsSize, memStatsInterval, cpuStatsSize, cpuStatsInterval; - var i, j, data; - memStatsSize = this._memStatsSize; - memStatsInterval = this._memStatsInterval; - cpuStatsSize = this._cpuStatsSize; - cpuStatsInterval = this._cpuStatsInterval; - for (i = 0; i < textMsg.length; i++) { - var setting = textMsg[i].split('='); - if (setting[0] === 'mem_stats_size') { - memStatsSize = parseInt(setting[1]); - } - else if (setting[0] === 'mem_stats_interval') { - memStatsInterval = parseInt(setting[1]); - } - else if (setting[0] === 'cpu_stats_size') { - cpuStatsSize = parseInt(setting[1]); - } - else if (setting[0] === 'cpu_stats_interval') { - cpuStatsInterval = parseInt(setting[1]); - } - } - - // Fix the axes according to changed data - if (memStatsInterval !== this._memStatsInterval) { - // We can possibly reuse the data with a bit of work - this._initMemStatsData(memStatsSize, memStatsInterval, true); - } - else if (memStatsSize > this._memStatsSize) { - this._initMemStatsData(memStatsSize - this._memStatsSize, memStatsInterval, false); - } - else { - // just strip the extra items - for (i = 0; i < this._memStatsSize - memStatsSize; i++) { - this._memStatsData.shift(); - } - } - - this._memStatsSize = memStatsSize; - this._memStatsInterval = memStatsInterval; - this._cpuStatsSize = cpuStatsSize; - this._cpuStatsInterval = cpuStatsInterval; - } - else if (textMsg.startsWith('mem_stats') || - textMsg.startsWith('cpu_stats')) { - textMsg = textMsg.split(' ')[1]; - if (textMsg.endsWith(',')) { - // This is the result of query, not notification - data = textMsg.substring(0, textMsg.length - 1).split(','); - for (i = this._memStatsData.length - 1, j = data.length - 1; i >= 0 && j >= 0; i--, j--) { - this._memStatsData[i].value = parseInt(data[j]); - } - - //this._createMemData(data); - this._createMemGraph(); - } - else { - // this is a notification data; append to _memStatsData - data = textMsg.trim(); - this._addNewMemData(data); - this._updateMemGraph(); - } - } - }, - - onSocketClose: function() { - clearInterval(this._basicStatsIntervalId); - } -}); - - -/* - Socket to be intialized on opening the settings page in Admin console -*/ -/* global $ AdminSocketBase */ -var AdminSocketSettings = AdminSocketBase.extend({ - constructor: function(host) { - this.base(host); - this._init(); - }, - - _init: function() { - var socketSettings = this.socket; - $(document).ready(function() { - $('#admin_settings').on('submit', function(e) { - e.preventDefault(); - var memStatsSize = $('#mem_stats_size').val(); - var memStatsInterval = $('#mem_stats_interval').val(); - var cpuStatsSize = $('#cpu_stats_size').val(); - var cpuStatsInterval = $('#cpu_stats_interval').val(); - var command = 'set'; - command += ' mem_stats_size=' + memStatsSize; - command += ' mem_stats_interval=' + memStatsInterval; - command += ' cpu_stats_size=' + cpuStatsSize; - command += ' cpu_stats_interval=' + cpuStatsInterval; - socketSettings.send(command); - }); - }); - }, - - onSocketOpen: function() { - this.socket.send('subscribe settings'); - this.socket.send('settings'); - }, - - onSocketMessage: function(e) { - var textMsg; - if (typeof e.data === 'string') { - textMsg = e.data; - } - else { - textMsg = ''; - } - - if (textMsg.startsWith('settings')) { - textMsg = textMsg.substring('settings '.length); - var settings = textMsg.split(' '); - for (var i = 0; i < settings.length; i++) { - var setting = settings[i].split('='); - var settingKey = setting[0]; - var settingVal = setting[1]; - document.getElementById(settingKey).value = settingVal; - } - } - }, - - onSocketClose: function() { - clearInterval(this._basicStatsIntervalId); - } -}); - - diff --git a/loleaflet/dist/admin/adminAnalytics.html b/loleaflet/dist/admin/adminAnalytics.html deleted file mode 100644 index 5f4fb67..0000000 --- a/loleaflet/dist/admin/adminAnalytics.html +++ /dev/null @@ -1,100 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <meta http-equiv="X-UA-Compatible" content="IE=edge"> - <meta name="viewport" content="width=device-width, initial-scale=1"> - <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> - <meta name="description" content=""> - <meta name="author" content=""> - - <title>LibreOffice Online - Admin console</title> - - <!-- Bootstrap core CSS --> - <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet"> - - <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> - <link href="../bootstrap/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> - - <!-- Custom styles for this template --> - <link href="../bootstrap/dashboard.css" rel="stylesheet"> - - <link rel="stylesheet" href="../dialog/vex.css" /> - <link rel="stylesheet" href="../dialog/vex-theme-plain.css" /> - - <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> - <!--[if lt IE 9]> - <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> - <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> - <![endif]--> - </head> - - <body> - <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> - <script>window.jQuery || document.write('<script src="../bootstrap/assets/js/vendor/jquery.min.js"><\/script>')</script> - <script src="../dialog/vex.combined.min.js"></script> - <script>vex.defaultOptions.className = 'vex-theme-plain';</script> - <script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script> - <script src="admin-src.js"></script> - <script> - - host = 'wss://' + window.location.hostname + ':9989'; - new AdminSocketAnalytics(host); - - </script> - - <nav class="navbar navbar-inverse navbar-fixed-top"> - <div class="container-fluid"> - <div class="navbar-header"> - <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> - <span class="sr-only">Toggle navigation</span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - </button> - <a class="navbar-brand" href="#">LibreOffice Online - Admin console</a> - </div> - <div id="navbar" class="navbar-collapse collapse"> - <ul class="nav navbar-nav navbar-right"> - <li><a href="admin.html?host=ws://localhost:9989">Dashboard</a></li> - <li><a href="adminSettings.html?host=ws://localhost:9989">Settings</a></li> - <li><a href="#">Help</a></li> - </ul> - <form class="navbar-form navbar-right"> - <input type="text" class="form-control" placeholder="Search..."> - </form> - </div> - </div> - </nav> - - <div class="container-fluid"> - <div class="row"> - <div class="col-sm-3 col-md-2 sidebar"> - <ul class="nav nav-sidebar"> - <li><a href="admin.html">Overview <span class="sr-only">(current)</span></a></li> - <li class="active"><a href="adminAnalytics.html">Analytics</a></li> - </ul> - </div> - <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> - <h1 class="page-header">Graphs</h1> - <div class="graph-container"> - <div class="jumbotron"> - <svg id="visualisation" width="1000" height="500"></svg> - </div> - </div> - </div> - </div> - </div> - - <!-- Bootstrap core JavaScript - ================================================== --> - <!-- Placed at the end of the document so the pages load faster --> - <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> - <script>window.jQuery || document.write('<script src="../bootstrap/js/vendor/jquery.min.js"><\/script>')</script> - <script src="../bootstrap/js/bootstrap.min.js"></script> - <!-- Just to make our placeholder images work. Don't actually copy the next line! --> - <script src="../bootstrap/assets/js/vendor/holder.min.js"></script> - <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> - <script src="../bootstrap/assets/js/ie10-viewport-bug-workaround.js"></script> - </body> -</html> diff --git a/loleaflet/dist/admin/adminSettings.html b/loleaflet/dist/admin/adminSettings.html deleted file mode 100644 index 1db8279..0000000 --- a/loleaflet/dist/admin/adminSettings.html +++ /dev/null @@ -1,107 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <meta http-equiv="X-UA-Compatible" content="IE=edge"> - <meta name="viewport" content="width=device-width, initial-scale=1"> - <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> - <meta name="description" content=""> - <meta name="author" content=""> - - <title>LibreOffice Online - Admin console</title> - - <!-- Bootstrap core CSS --> - <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet"> - - <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> - <link href="../bootstrap/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> - - <!-- Custom styles for this template --> - <link href="../bootstrap/dashboard.css" rel="stylesheet"> - - <link rel="stylesheet" href="../dialog/vex.css" /> - <link rel="stylesheet" href="../dialog/vex-theme-plain.css" /> - - <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> - <!--[if lt IE 9]> - <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> - <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> - <![endif]--> - </head> - - <body> - <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> - <script>window.jQuery || document.write('<script src="../bootstrap/assets/js/vendor/jquery.min.js"><\/script>')</script> - <script src="../dialog/vex.combined.min.js"></script> - <script>vex.defaultOptions.className = 'vex-theme-plain';</script> - <script src="admin-src.js"></script> - <script> - - host = 'wss://' + window.location.hostname + ':9989'; - new AdminSocketSettings(host); - - </script> - - <nav class="navbar navbar-inverse navbar-fixed-top"> - <div class="container-fluid"> - <div class="navbar-header"> - <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> - <span class="sr-only">Toggle navigation</span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - </button> - <a class="navbar-brand" href="#">LibreOffice Online - Admin console</a> - </div> - <div id="navbar" class="navbar-collapse collapse"> - <ul class="nav navbar-nav navbar-right"> - <li><a href="admin.html">Dashboard</a></li> - <li><a href="adminSettings.html">Settings</a></li> - <li><a href="#">Help</a></li> - </ul> - <form class="navbar-form navbar-right"> - <input type="text" class="form-control" placeholder="Search..."> - </form> - </div> - </div> - </nav> - - <div class="container-fluid"> - <div class="row"> - <div class="col-sm-3 col-md-2 sidebar"> - <ul class="nav nav-sidebar"> - <li><a href="admin.html">Overview <span class="sr-only">(current)</span></a></li> - <li><a href="adminAnalytics.html">Analytics</a></li> - </ul> - </div> - <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> - <h1 class="page-header">Settings</h1> - <form id="admin_settings"> - <label for="mem_stats_size">Memory Stats Cache size</label> - <input type="text" id="mem_stats_size" name="Memory Stats Size"><br/> - <label for="mem_stats_interval">Memory Stats Interval (in ms)</label> - <input type="text" id="mem_stats_interval" name="Memory Stats Interval"><br/> - - <label for="cpu_stats_size">Cpu Stats Cache size</label> - <input type="text" id="cpu_stats_size" name="Cpu Stats Size"><br/> - <label for="cpu_stats_interval">Cpu Stats Interval (in ms)</label> - <input type="text" id="cpu_stats_interval" name="Cpu Stats Interval"><br/> - <input type="submit" value="Save"/><br/> - </form> - </div> - </div> - </div> - </div> - - <!-- Bootstrap core JavaScript - ================================================== --> - <!-- Placed at the end of the document so the pages load faster --> - <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> - <script>window.jQuery || document.write('<script src="../bootstrap/assets/js/vendor/jquery.min.js"><\/script>')</script> - <script src="../bootstrap/js/bootstrap.min.js"></script> - <!-- Just to make our placeholder images work. Don't actually copy the next line! --> - <script src="../bootstrap/assets/js/vendor/holder.min.js"></script> - <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> - <script src="../bootstrap/assets/js/ie10-viewport-bug-workaround.js"></script> - </body> -</html> commit 09d3c5f230602be75150570a1ee3eaae9dad6d2b Author: Tor Lillqvist <[email protected]> Date: Mon Mar 21 16:52:46 2016 +0200 Revert "loolwsd: Allow specifying custom file server root" This reverts commit a5f8ba44a2b9bb26ec9196a306f9f1b4d60afc79. diff --git a/loolwsd/FileServer.hpp b/loolwsd/FileServer.hpp index 102ace1..9c62e41 100644 --- a/loolwsd/FileServer.hpp +++ b/loolwsd/FileServer.hpp @@ -32,7 +32,6 @@ #include <Poco/Util/Timer.h> #include "Common.hpp" -#include "LOOLWSD.hpp" using Poco::Net::HTTPRequest; using Poco::Net::HTTPRequestHandler; @@ -56,8 +55,8 @@ public: std::vector<std::string> requestSegments; requestUri.getPathSegments(requestSegments); - // TODO: We might want to package all files from leaflet to some other dir and restrict - // file serving to it (?) + // FIXME: We might want to package all dist files from leaflet to some other dir (?) + const std::string loleafletPath = Poco::Path(Application::instance().commandPath()).parent().parent().toString() + "loleaflet"; const std::string endPoint = requestSegments[requestSegments.size() - 1]; if (request.getMethod() == HTTPRequest::HTTP_GET) @@ -80,7 +79,7 @@ public: Poco::Net::HTTPCookie cookie("jwt", jwtToken); response.addCookie(cookie); response.setContentType(htmlMimeType); - response.sendFile(LOOLWSD::FileServerRoot + requestUri.getPath(), htmlMimeType); + response.sendFile(loleafletPath + "/debug/document/" + endPoint, htmlMimeType); } else { @@ -88,12 +87,12 @@ public: throw Poco::Net::NotAuthenticatedException("Wrong credentials."); } } - else + else if (requestSegments.size() > 1 && requestSegments[0] == "dist") { const std::string filePath = requestUri.getPath(); const std::size_t extPoint = endPoint.find_last_of("."); if (extPoint == std::string::npos) - throw Poco::FileNotFoundException("Invalid file."); + return; const std::string fileType = endPoint.substr(extPoint + 1); std::string mimeType; @@ -101,13 +100,15 @@ public: mimeType = "application/javascript"; else if (fileType == "css") mimeType = "text/css"; - else if (fileType == "html") - mimeType = "text/html"; else mimeType = "text/plain"; response.setContentType(mimeType); - response.sendFile(LOOLWSD::FileServerRoot + requestUri.getPath(), mimeType); + response.sendFile(loleafletPath + request.getURI(), mimeType); + } + else + { + throw Poco::FileNotFoundException(""); } } } diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index eb499cc..ba30f41 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -935,7 +935,6 @@ std::string LOOLWSD::SysTemplate; std::string LOOLWSD::LoTemplate; std::string LOOLWSD::ChildRoot; std::string LOOLWSD::LoSubPath = "lo"; -std::string LOOLWSD::FileServerRoot; int LOOLWSD::NumPreSpawnedChildren = 10; bool LOOLWSD::DoTest = false; @@ -1010,11 +1009,6 @@ void LOOLWSD::defineOptions(OptionSet& optionSet) .repeatable(false) .argument("relative path")); - optionSet.addOption(Option("fileserverroot", "", "Path to the directory that should be considered root for the file server (default: '../loleaflet/').") - .required(false) - .repeatable(false) - .argument("directory")); - optionSet.addOption(Option("numprespawns", "", "Number of child processes to keep started in advance and waiting for new clients.") .required(false) .repeatable(false) @@ -1051,8 +1045,6 @@ void LOOLWSD::handleOption(const std::string& optionName, const std::string& val ChildRoot = value; else if (optionName == "losubpath") LoSubPath = value; - else if (optionName == "fileserverroot") - FileServerRoot = value; else if (optionName == "numprespawns") NumPreSpawnedChildren = std::stoi(value); else if (optionName == "test") @@ -1148,9 +1140,6 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) else if (ChildRoot[ChildRoot.size() - 1] != Path::separator()) ChildRoot += Path::separator(); - if (FileServerRoot.empty()) - FileServerRoot = Path(Application::instance().commandPath()).parent().parent().toString(); - if (ClientPortNumber == MASTER_PORT_NUMBER) throw IncompatibleOptionsException("port"); diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index 5504888..3fc2531 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -44,7 +44,6 @@ public: static std::string LoTemplate; static std::string ChildRoot; static std::string LoSubPath; - static std::string FileServerRoot; //static Auth AuthAgent; static const std::string PIDLOG; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
