address review
This commit is contained in:
parent
2d7ec9d6d9
commit
c6762826dc
@ -435,7 +435,7 @@ namespace Components
|
|||||||
MongooseLogBuffer.push_back(c);
|
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{};
|
std::string msg{};
|
||||||
switch(code)
|
switch(code)
|
||||||
@ -453,6 +453,11 @@ namespace Components
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!messageOverride.empty())
|
||||||
|
{
|
||||||
|
msg = message;
|
||||||
|
}
|
||||||
|
|
||||||
mg_http_reply(connection, code, "Content-Type: text/plain\r\n", "%s", msg.c_str());
|
mg_http_reply(connection, code, "Content-Type: text/plain\r\n", "%s", msg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,25 +476,16 @@ namespace Components
|
|||||||
char buffer[128]{};
|
char buffer[128]{};
|
||||||
const auto len = mg_http_get_var(&hm->query, "password", buffer, sizeof(buffer));
|
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)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
reply("Password Required");
|
ReplyError(connection, 403, "Password Required");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto password = std::string(buffer, len);
|
const auto password = std::string(buffer, len);
|
||||||
if (password != Utils::String::DumpHex(Utils::Cryptography::SHA256::Compute(g_password), ""))
|
if (password != Utils::String::DumpHex(Utils::Cryptography::SHA256::Compute(g_password), ""))
|
||||||
{
|
{
|
||||||
reply("Invalid Password");
|
ReplyError(connection, 403, "Invalid Password");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ namespace Components
|
|||||||
static bool DownloadFile(ClientDownload* download, unsigned int index);
|
static bool DownloadFile(ClientDownload* download, unsigned int index);
|
||||||
|
|
||||||
static void LogFn(char c, void* param);
|
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 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);
|
static std::optional<std::string> FileHandler(mg_connection* c, const mg_http_message* hm);
|
||||||
|
Loading…
Reference in New Issue
Block a user