From d02a29f0ff33279268e675aae0856f3f8cf9d939 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 10 Jan 2023 14:22:47 +0100 Subject: Configurable Websocket für HTTPS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/websocket/websocket.cpp | 80 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 plugins/websocket/websocket.cpp (limited to 'plugins/websocket/websocket.cpp') diff --git a/plugins/websocket/websocket.cpp b/plugins/websocket/websocket.cpp new file mode 100644 index 0000000..884f691 --- /dev/null +++ b/plugins/websocket/websocket.cpp @@ -0,0 +1,80 @@ +#include "websocket.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace std::string_literals; +namespace bp = boost::process; +namespace fs = std::filesystem; + +namespace { + + // Used to return errors by generating response page and HTTP status code + std::string HttpStatus(std::string status, std::string message, std::function& SetResponseHeader) + { + SetResponseHeader("status", status); + SetResponseHeader("content_type", "text/html"); + return status + " " + message; + } + +} // anonymous namespace + +std::string websocket_plugin::name() +{ + return "websocket"; +} + +websocket_plugin::websocket_plugin() +{ + //std::cout << "Plugin constructor" << std::endl; +} + +websocket_plugin::~websocket_plugin() +{ + //std::cout << "Plugin destructor" << std::endl; +} + +std::string websocket_plugin::generate_page( + std::function& GetServerParam, + std::function& GetRequestParam, // request including body (POST...) + std::function& SetResponseHeader // to be added to result string +) +{ + try { + // Request path must not contain "..". + std::string rel_target{GetRequestParam("rel_target")}; + size_t query_pos{rel_target.find("?")}; + if (query_pos != rel_target.npos) + rel_target = rel_target.substr(0, query_pos); + + std::string target{GetRequestParam("target")}; + if (rel_target.find("..") != std::string::npos) { + return HttpStatus("400", "Illegal request: "s + target, SetResponseHeader); + } + + try { + return "Dummy"; + } catch (const std::exception& ex) { + return HttpStatus("500", "Internal Server Error: "s + ex.what(), SetResponseHeader); + } + + } catch (const std::exception& ex) { + return HttpStatus("500", "Unknown Error: "s + ex.what(), SetResponseHeader); + } +} + +bool websocket_plugin::has_own_authentication() +{ + return false; +} + -- cgit v1.2.3