From eff5a1ee1cd8a681f436945a48bbda46be416d9c Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 29 May 2020 12:24:07 +0200 Subject: Authentication for webbox --- plugins/webbox/webbox.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'plugins/webbox/webbox.cpp') diff --git a/plugins/webbox/webbox.cpp b/plugins/webbox/webbox.cpp index de8df85..37ddde2 100644 --- a/plugins/webbox/webbox.cpp +++ b/plugins/webbox/webbox.cpp @@ -40,6 +40,7 @@ namespace { std::unordered_map status_map { { "301", "Moved Permanently" }, { "400", "Bad Request"}, + { "401", "Unauthorized"}, { "403", "Forbidden" }, { "404", "Not Found" }, { "500", "Internal Server Error" } @@ -176,6 +177,11 @@ public: // call interface std::string execute(CommandParameters& p) { + // Authentication + if (m_needsAuthentication && p.m_GetRequestParam("is_authenticated") == "0") { + return HttpStatus("401", "Not authorized", p); + } + // check if this webbox is writable and enforce this if (p.webboxReadOnly && m_isWriteCommand) { return HttpStatus("400", "Webbox is Read-Only", p); @@ -205,7 +211,7 @@ protected: std::string m_commandName; std::string m_requestMethod; bool m_isWriteCommand; // if true, command must be prevented if p.webboxReadOnly - + bool m_needsAuthentication{true}; }; class GetCommand: public Command @@ -841,6 +847,7 @@ public: { m_commandName = "static-html"; m_isWriteCommand = false; + m_needsAuthentication = false; } protected: -- cgit v1.2.3