diff --git a/src/cc/Httpd.cpp b/src/cc/Httpd.cpp index 887c6261..79cb7054 100644 --- a/src/cc/Httpd.cpp +++ b/src/cc/Httpd.cpp @@ -96,19 +96,19 @@ std::string Httpd::readFile(const std::string &fileName) unsigned Httpd::tokenAuth(struct MHD_Connection* connection, const std::string& clientIp) { if (!m_options->ccToken()) { - LOG_WARN("[%s] AccessToken not set. Access Granted!", clientIp.c_str()); + LOG_WARN("[%s] 200 OK - WARNING AccessToken not set!", clientIp.c_str()); return MHD_HTTP_OK; } const char* header = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_AUTHORIZATION); if (m_options->ccToken() && !header) { - LOG_WARN("[%s] No auth header. Access Forbidden!", clientIp.c_str()); + LOG_WARN("[%s] 401 UNAUTHORIZED", clientIp.c_str()); return MHD_HTTP_UNAUTHORIZED; } const size_t size = strlen(header); if (size < 8 || strlen(m_options->ccToken()) != size - 7 || memcmp("Bearer ", header, 7) != 0) { - LOG_ERR("[%s] AccessToken wrong. Access Forbidden!", clientIp.c_str()); + LOG_ERR("[%s] 403 FORBIDDEN - AccessToken wrong!", clientIp.c_str()); return MHD_HTTP_FORBIDDEN; } @@ -124,7 +124,7 @@ unsigned Httpd::basicAuth(struct MHD_Connection* connection, const std::string& "Please configure admin user and pass to view this Page." ""); - LOG_WARN("[%s] Admin user/password not set. Access Forbidden!", clientIp.c_str()); + LOG_ERR("[%s] 403 FORBIDDEN - Admin user/password not set!", clientIp.c_str()); result = MHD_HTTP_FORBIDDEN; } else { @@ -137,7 +137,7 @@ unsigned Httpd::basicAuth(struct MHD_Connection* connection, const std::string& if (user == nullptr || strcmp(user, m_options->ccAdminUser()) != 0 || pass == nullptr || strcmp(pass, m_options->ccAdminPass()) != 0) { - LOG_ERR("[%s] Admin user/password wrong. Access Forbidden!", clientIp.c_str()); + LOG_ERR("[%s] 403 FORBIDDEN - Admin user/password wrong!", clientIp.c_str()); result = MHD_HTTP_UNAUTHORIZED; } @@ -149,7 +149,7 @@ unsigned Httpd::basicAuth(struct MHD_Connection* connection, const std::string& free(pass); } } else { - LOG_WARN("[%s] No auth header. Access Forbidden!", clientIp.c_str()); + LOG_WARN("[%s] 401 UNAUTHORIZED", clientIp.c_str()); result = MHD_HTTP_UNAUTHORIZED; } } @@ -199,7 +199,7 @@ int Httpd::handler(void* httpd, MHD_Connection* connection, const char* url, con } if (strcmp(method, MHD_HTTP_METHOD_GET) != 0 && strcmp(method, MHD_HTTP_METHOD_POST) != 0) { - LOG_ERR("[%s] HTTP_METHOD_NOT_ALLOWED (%s)", clientIp.c_str(), method); + LOG_ERR("[%s] 405 METHOD NOT ALLOWED (%s)", clientIp.c_str(), method); return sendResponse(connection, MHD_HTTP_METHOD_NOT_ALLOWED, nullptr, CONTENT_TYPE_HTML); } @@ -225,8 +225,6 @@ int Httpd::handler(void* httpd, MHD_Connection* connection, const char* url, con } else { return handlePOST(static_cast(httpd), connection, clientIp, url, upload_data, upload_data_size, con_cls); } - - return MHD_NO; } int Httpd::handleGET(const Httpd* httpd, struct MHD_Connection* connection, const std::string& clientIp, const char* urlPtr) diff --git a/src/cc/Service.cpp b/src/cc/Service.cpp index e02e584f..9131ee31 100644 --- a/src/cc/Service.cpp +++ b/src/cc/Service.cpp @@ -90,11 +90,12 @@ unsigned Service::handleGET(const Options* options, const std::string& url, cons } else if (url.rfind("/admin/getClientLog", 0) == 0) { resultCode = getClientLog(clientId, resp); } else { - LOG_WARN("[%s] METHOD_NOT_FOUND (%s)", clientIp.c_str(), url.c_str()); + LOG_WARN("[%s] 404 NOT FOUND (%s)", clientIp.c_str(), url.c_str()); } } else { - LOG_ERR("[%s] Request does not contain clientId: %s", clientIp.c_str(), url.c_str()); + resultCode = MHD_HTTP_BAD_REQUEST; + LOG_ERR("[%s] 400 BAD REQUEST - Request does not contain clientId (%s)", clientIp.c_str(), url.c_str()); } } @@ -128,13 +129,13 @@ unsigned Service::handlePOST(const Options* options, const std::string& url, con } else if (url.rfind("/admin/setClientCommand", 0) == 0) { resultCode = setClientCommand(clientId, data, resp); } else { - LOG_WARN("[%s] METHOD_NOT_FOUND (%s)", clientIp.c_str(), url.c_str()); + LOG_WARN("[%s] 400 BAD REQUEST - Request does not contain clientId (%s)", clientIp.c_str(), url.c_str()); } } else { if (url.rfind("/admin/resetClientStatusList", 0) == 0) { resultCode = resetClientStatusList(data, resp); } else { - LOG_WARN("[%s] METHOD_NOT_FOUND (%s)", clientIp.c_str(), url.c_str()); + LOG_WARN("[%s] 404 NOT FOUND (%s)", clientIp.c_str(), url.c_str()); } }