From 313ebef2e2a6e71df369a278dd7e8ee3d4f7e6a5 Mon Sep 17 00:00:00 2001 From: codewithvk Date: Wed, 27 Nov 2024 16:21:55 +0530 Subject: [PATCH] WIP: export admin setting iframe Signed-off-by: codewithvk Change-Id: Ic1ce7cb70a499b76b13c5c74424f6bf2cde9b8f9 --- browser/html/admin-settings.html | 83 ++++++++++++++++++++++++++++++++ wsd/FileServer.cpp | 48 ++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 browser/html/admin-settings.html diff --git a/browser/html/admin-settings.html b/browser/html/admin-settings.html new file mode 100644 index 000000000000..276ca6329124 --- /dev/null +++ b/browser/html/admin-settings.html @@ -0,0 +1,83 @@ + + + + + Admin Setting Iframe + + + +

Admin Setting Iframe

+
+
+
+ + +

+
+ + + + diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index c094e211d37c..d41a6f4693ab 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -600,6 +600,54 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, } } + if (endPoint == "admin-settings.html") + { + try + { + std::string templatePath = COOLWSD::FileServerRoot + "/browser/dist/admin-settings.html"; + + std::string htmlContent = readFileToString(templatePath); + if (htmlContent.empty()) + { + throw std::runtime_error("HTML file is empty or could not be read"); + } + + Poco::Net::HTTPResponse httpResponse(Poco::Net::HTTPResponse::HTTP_OK); + httpResponse.setContentType("text/html"); + httpResponse.setContentLength(htmlContent.size()); + + std::ostringstream headerStream; + headerStream << "HTTP/1.1 " << httpResponse.getStatus() << " " << httpResponse.getReason() + << "\r\nContent-Type: " << httpResponse.getContentType() + << "\r\nContent-Length: " << httpResponse.getContentLength() << "\r\n\r\n"; + std::string headers = headerStream.str(); + + socket->send(headers.data(), headers.size()); + + socket->send(htmlContent.data(), htmlContent.size()); + } + catch (const std::exception& e) + { + Poco::Net::HTTPResponse errorResponse(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); + errorResponse.setContentType("text/plain"); + + std::string errorMessage = "Error: " + std::string(e.what()); + errorResponse.setContentLength(errorMessage.size()); + + std::ostringstream errorHeaderStream; + errorHeaderStream << "HTTP/1.1 " << errorResponse.getStatus() << " " << errorResponse.getReason() + << "\r\nContent-Type: " << errorResponse.getContentType() + << "\r\nContent-Length: " << errorResponse.getContentLength() << "\r\n\r\n"; + std::string errorHeaders = errorHeaderStream.str(); + + socket->send(errorHeaders.data(), errorHeaders.size()); + + socket->send(errorMessage.data(), errorMessage.size()); + } + + return; + } + // Is this a file we read at startup - if not; it's not for serving. if (FileHash.find(relPath) == FileHash.end() && FileHash.find(relPath + ".br") == FileHash.end())