From 4124fa9148c09bd6b50ea1569a24d546a6059418 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Wed, 7 Oct 2020 16:17:28 +0200 Subject: [PATCH] Typo fixes for webcode error type Add ping function to check status --- esp3d/src/modules/http/handles/handle-command.cpp | 9 ++++++++- esp3d/src/modules/http/http_server.cpp | 2 +- esp3d/src/modules/http/http_server.h | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/esp3d/src/modules/http/handles/handle-command.cpp b/esp3d/src/modules/http/handles/handle-command.cpp index dfd3ecd0..f23041a5 100644 --- a/esp3d/src/modules/http/handles/handle-command.cpp +++ b/esp3d/src/modules/http/handles/handle-command.cpp @@ -34,6 +34,10 @@ void HTTP_Server::handle_web_command () { level_authenticate_type auth_level = AuthenticationService::authenticated_level(); + if (auth_level == LEVEL_GUEST) { + _webserver->send (401, "text/plain", "Wrong authentication!"); + return; + } //log_esp3d("Authentication = %d", auth_level); String cmd = ""; if (_webserver->hasArg ("cmd")) { @@ -43,7 +47,10 @@ void HTTP_Server::handle_web_command () cmd+="\n"; //need to validate command } esp3d_commands.process((uint8_t*)cmd.c_str(), cmd.length(), &output, auth_level); - } else { + } else if (_webserver->hasArg ("ping")) { + _webserver->send (200); + } + else { _webserver->send (400, "text/plain", "Invalid command"); } return; diff --git a/esp3d/src/modules/http/http_server.cpp b/esp3d/src/modules/http/http_server.cpp index e7a549df..ee364860 100644 --- a/esp3d/src/modules/http/http_server.cpp +++ b/esp3d/src/modules/http/http_server.cpp @@ -146,7 +146,7 @@ bool HTTP_Server::StreamSDFile(const char* filename, const char * contentType) } #endif //SD_DEVICE -void HTTP_Server::pushError(int code, const char * st, bool web_error, uint16_t timeout) +void HTTP_Server::pushError(int code, const char * st, uint8_t web_error, uint16_t timeout) { if (websocket_terminal_server.started() && st) { String s = "ERROR:" + String(code) + ":"; diff --git a/esp3d/src/modules/http/http_server.h b/esp3d/src/modules/http/http_server.h index 5e609eee..3f43d70c 100644 --- a/esp3d/src/modules/http/http_server.h +++ b/esp3d/src/modules/http/http_server.h @@ -57,7 +57,7 @@ public: return _port; } private: - static void pushError(int code, const char * st, bool web_error = 500, uint16_t timeout = 1000); + static void pushError(int code, const char * st, uint8_t web_error = 500, uint16_t timeout = 1000); static void cancelUpload(); static bool _started; static WEBSERVER * _webserver;