From 4fc2561df2786be3be09148cda78c1270db8cca4 Mon Sep 17 00:00:00 2001 From: wwwqr <83577933+wwwqr-000@users.noreply.github.com> Date: Tue, 7 May 2024 15:59:15 +0200 Subject: [PATCH] Folder index file fix --- whiteavocado-web-server/classes/Website.hpp | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/whiteavocado-web-server/classes/Website.hpp b/whiteavocado-web-server/classes/Website.hpp index bbfbcd8..7bfe755 100644 --- a/whiteavocado-web-server/classes/Website.hpp +++ b/whiteavocado-web-server/classes/Website.hpp @@ -51,11 +51,14 @@ class Website : Server { return res; } - std::string getFilenameExtention(const std::string &path) {//Get the extention name from a path if it has one + std::string getFilenameExtention(std::string path) {//Get the extention name from a path if it has one if (path.back() == '/') { - std::string Fol = "folder"; - std::reverse(Fol.begin(), Fol.end()); - return Fol; + if (path == "/") { + path = this->indexFile; + } + else { + path += this->indexFile; + } } bool isValid = false; std::string ext = ""; @@ -330,9 +333,16 @@ class Website : Server { std::string bufStr(&buffer); std::string normalResp = ""; std::string requestPath = getClientPath(bufStr); + bool whiteListed = isWhitelisted(requestPath); + if (getFilenameExtention(requestPath) == "enon") { + requestPath += "/"; + requestPath += this->indexFile; + } + if (!whiteListed) {//If index file inside folder is fully typed out, check the whitelist + whiteListed = isWhitelisted(requestPath); + } std::string extention = getFilenameExtention(requestPath); std::string cct = getContentType(extention); - bool whiteListed = isWhitelisted(requestPath); if (requestPath == "/" || whiteListed) { std::cout << getCurrentDateTime() << " => " << requestPath << " -> " + this->clientIP + "\n"; @@ -419,4 +429,4 @@ class Website : Server { void startup() { start(); } -}; \ No newline at end of file +};