address review

This commit is contained in:
Diavolo 2024-01-20 13:57:59 +01:00
parent 2d7ec9d6d9
commit c6762826dc
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
2 changed files with 9 additions and 13 deletions

View File

@ -435,7 +435,7 @@ namespace Components
MongooseLogBuffer.push_back(c);
}
void Download::ReplyError(mg_connection* connection, int code)
void Download::ReplyError(mg_connection* connection, int code, std::string messageOverride)
{
std::string msg{};
switch(code)
@ -453,6 +453,11 @@ namespace Components
break;
}
if (!messageOverride.empty())
{
msg = message;
}
mg_http_reply(connection, code, "Content-Type: text/plain\r\n", "%s", msg.c_str());
}
@ -471,25 +476,16 @@ namespace Components
char buffer[128]{};
const auto len = mg_http_get_var(&hm->query, "password", buffer, sizeof(buffer));
const auto reply = [&c](const char* s) -> void
{
mg_printf(c, "%s", "HTTP/1.1 403 Forbidden\r\n");
mg_printf(c, "%s", "Content-Type: text/plain\r\n");
mg_printf(c, "Connection: close\r\n");
mg_printf(c, "%s", "\r\n");
mg_printf(c, "%s", s);
};
if (len <= 0)
{
reply("Password Required");
ReplyError(connection, 403, "Password Required");
return false;
}
const auto password = std::string(buffer, len);
if (password != Utils::String::DumpHex(Utils::Cryptography::SHA256::Compute(g_password), ""))
{
reply("Invalid Password");
ReplyError(connection, 403, "Invalid Password");
return false;
}

View File

@ -105,7 +105,7 @@ namespace Components
static bool DownloadFile(ClientDownload* download, unsigned int index);
static void LogFn(char c, void* param);
static void ReplyError(mg_connection* connection, int code);
static void ReplyError(mg_connection* connection, int code, std::string messageOverride = {});
static void Reply(mg_connection* connection, const std::string& contentType, const std::string& data);
static std::optional<std::string> FileHandler(mg_connection* c, const mg_http_message* hm);