mirror of
https://github.com/luc-github/ESP3D.git
synced 2025-10-31 11:56:48 -07:00
Add setting to unsecure the serial when authentication is on
This commit is contained in:
@@ -178,6 +178,8 @@ ESP_AUTO_NOTIFICATION 1022 //1 byte = flag
|
||||
ESP_VERBOSE_BOOT 1023 //1 byte = flag
|
||||
ESP_WEBDAV_ON 1024 //1 byte = flag
|
||||
ESP_WEBDAV_PORT 1025 //4 bytes = int
|
||||
ESP_STA_DNS_VALUE 1029 //4 bytes= int
|
||||
ESP_SECURE_SERIAL 1033 //1 byte = flag
|
||||
|
||||
* Get/Set Check update at boot state which can be ON, OFF
|
||||
[ESP402]<state>pwd=<admin password>
|
||||
|
||||
@@ -253,7 +253,7 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
//do not overwrite previous authetic <time=YYYY-MM-DD#H24:MM:SS>ation level
|
||||
if (auth_type == LEVEL_GUEST) {
|
||||
String pwd=get_param (cmd_params, "pwd=");
|
||||
auth_type = AuthenticationService::authenticated_level(pwd.c_str());
|
||||
auth_type = AuthenticationService::authenticated_level(pwd.c_str(), output);
|
||||
}
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
//log_esp3d("Authentication = %d", auth_type);
|
||||
|
||||
@@ -53,7 +53,7 @@ bool Commands::ESP103(const char* cmd_params, level_authenticate_type auth_type,
|
||||
res += Settings_ESP3D::read_IP_String(ESP_STA_GATEWAY_VALUE);
|
||||
res += ", MSK:";
|
||||
res += Settings_ESP3D::read_IP_String(ESP_STA_MASK_VALUE);
|
||||
res += ", DNS:";
|
||||
res += ", DNS:";
|
||||
res += Settings_ESP3D::read_IP_String(ESP_STA_DNS_VALUE);
|
||||
output->printMSG (res.c_str());
|
||||
} else { //set
|
||||
|
||||
@@ -209,6 +209,13 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->print ("\",\"H\":\"session timeout\",\"M\":\"");
|
||||
output->print (Settings_ESP3D::get_min_byte(ESP_SESSION_TIMEOUT));
|
||||
output->print ("\"}");
|
||||
|
||||
//Secure Serial
|
||||
output->print (",{\"F\":\"security/security\",\"P\":\"");
|
||||
output->print (ESP_SECURE_SERIAL);
|
||||
output->print ("\",\"T\":\"B\",\"V\":\"");
|
||||
output->print (Settings_ESP3D::read_byte(ESP_SECURE_SERIAL));
|
||||
output->print ("\",\"H\":\"serial\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
|
||||
#ifdef HTTP_FEATURE
|
||||
|
||||
@@ -85,6 +85,9 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
|
||||
case ESP_TARGET_FW:
|
||||
Settings_ESP3D::GetFirmwareTarget(true);
|
||||
break;
|
||||
case ESP_SECURE_SERIAL:
|
||||
serial_service.setParameters();
|
||||
break;
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
case ESP_SESSION_TIMEOUT:
|
||||
AuthenticationService::setSessionTimeout(1000*60*sval.toInt());
|
||||
|
||||
@@ -118,6 +118,7 @@
|
||||
#define DEFAULT_NOTIFICATION_TOKEN2 ""
|
||||
#define DEFAULT_NOTIFICATION_SETTINGS ""
|
||||
#define DEFAULT_AUTO_NOTIFICATION_STATE 1
|
||||
#define DEFAULT_SECURE_SERIAL 1
|
||||
|
||||
|
||||
//default int values
|
||||
@@ -239,6 +240,9 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
|
||||
{
|
||||
uint8_t res;
|
||||
switch(pos) {
|
||||
case ESP_SECURE_SERIAL:
|
||||
res = DEFAULT_SECURE_SERIAL;
|
||||
break;
|
||||
case ESP_RADIO_MODE:
|
||||
res = DEFAULT_ESP_RADIO_MODE;
|
||||
break;
|
||||
@@ -1068,7 +1072,7 @@ bool Settings_ESP3D::reset(bool networkonly)
|
||||
Settings_ESP3D::write_IP(ESP_STA_GATEWAY_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_GATEWAY_VALUE));
|
||||
//STA static Mask
|
||||
Settings_ESP3D::write_IP(ESP_STA_MASK_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_MASK_VALUE));
|
||||
//STA static DNS
|
||||
//STA static DNS
|
||||
Settings_ESP3D::write_IP(ESP_STA_DNS_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_DNS_VALUE));
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE
|
||||
if (networkonly) {
|
||||
@@ -1095,7 +1099,8 @@ bool Settings_ESP3D::reset(bool networkonly)
|
||||
Settings_ESP3D::write_byte(ESP_SETUP,Settings_ESP3D::get_default_byte_value(ESP_SETUP));
|
||||
//Verbose boot
|
||||
Settings_ESP3D::write_byte(ESP_VERBOSE_BOOT,Settings_ESP3D::get_default_byte_value(ESP_VERBOSE_BOOT));
|
||||
|
||||
//Secure Serial
|
||||
Settings_ESP3D::write_byte(ESP_SECURE_SERIAL,Settings_ESP3D::get_default_byte_value(ESP_SECURE_SERIAL));
|
||||
#if defined(DISPLAY_DEVICE) && defined(DISPLAY_TOUCH_DRIVER)
|
||||
//Calibration done (internal only)
|
||||
Settings_ESP3D::write_byte(ESP_CALIBRATION,Settings_ESP3D::get_default_byte_value(ESP_CALIBRATION));
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
#define ESP_WEBDAV_ON 1024 //1 byte = flag
|
||||
#define ESP_WEBDAV_PORT 1025 //4 bytes= int
|
||||
#define ESP_STA_DNS_VALUE 1029 //4 bytes= int
|
||||
#define ESP_SECURE_SERIAL 1033 //1 byte = flag
|
||||
|
||||
|
||||
//Hidden password
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "3.0.0.a90"
|
||||
#define FW_VERSION "3.0.0.a91"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
||||
@@ -48,7 +48,7 @@ uint8_t AuthenticationService::_current_nb_ip = 0;
|
||||
//#define ALLOW_MULTIPLE_SESSIONS
|
||||
|
||||
//check authentification
|
||||
level_authenticate_type AuthenticationService::authenticated_level(const char * pwd)
|
||||
level_authenticate_type AuthenticationService::authenticated_level(const char * pwd, ESP3DOutput * output)
|
||||
{
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
level_authenticate_type auth_type = LEVEL_GUEST;
|
||||
@@ -60,7 +60,13 @@ level_authenticate_type AuthenticationService::authenticated_level(const char *
|
||||
if (isuser (pwd) && (auth_type != LEVEL_ADMIN)) {
|
||||
auth_type = LEVEL_USER;
|
||||
}
|
||||
return auth_type;
|
||||
} else {
|
||||
if(output) {
|
||||
if (output->client() !=ESP_HTTP_CLIENT) {
|
||||
return auth_type;
|
||||
}
|
||||
}
|
||||
#if defined (HTTP_FEATURE)
|
||||
if (_webserver) {
|
||||
if (_webserver->hasHeader ("Authorization") ) {
|
||||
@@ -92,6 +98,7 @@ level_authenticate_type AuthenticationService::authenticated_level(const char *
|
||||
return auth_type;
|
||||
#else
|
||||
(void)pwd;
|
||||
(void)output;
|
||||
return LEVEL_ADMIN;
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ const char DEFAULT_ADMIN_LOGIN [] = "admin";
|
||||
const char DEFAULT_USER_LOGIN [] = "user";
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#if defined (AUTHENTICATION_FEATURE)
|
||||
#if defined (HTTP_FEATURE)
|
||||
#include <IPAddress.h>
|
||||
@@ -58,7 +59,7 @@ typedef void Authwebserver;
|
||||
class AuthenticationService
|
||||
{
|
||||
public:
|
||||
static level_authenticate_type authenticated_level(const char * pwd = nullptr);
|
||||
static level_authenticate_type authenticated_level(const char * pwd = nullptr, ESP3DOutput * output= nullptr);
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
static bool begin(Authwebserver * webserver);
|
||||
static void end();
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#if COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#include "../mks/mks_service.h"
|
||||
#endif //COMMUNICATION_PROTOCOL == MKS_SERIAL
|
||||
#include "../authentication/authentication_service.h"
|
||||
|
||||
//Serial Parameters
|
||||
#define ESP_SERIAL_PARAM SERIAL_8N1
|
||||
@@ -59,6 +60,7 @@ SerialService::SerialService()
|
||||
{
|
||||
_buffer_size = 0;
|
||||
_started = false;
|
||||
_needauthentication = true;
|
||||
}
|
||||
|
||||
//Destructor
|
||||
@@ -79,12 +81,23 @@ void ESP3DSerialTaskfn( void * parameter )
|
||||
}
|
||||
#endif //ARDUINO_ARCH_ESP32
|
||||
|
||||
//extra parameters that do not need a begin
|
||||
void SerialService::setParameters()
|
||||
{
|
||||
#if defined (AUTHENTICATION_FEATURE)
|
||||
_needauthentication = (Settings_ESP3D::read_byte (ESP_SECURE_SERIAL)==0)?false:true;
|
||||
#else
|
||||
_needauthentication = false;
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
}
|
||||
|
||||
//Setup Serial
|
||||
bool SerialService::begin()
|
||||
{
|
||||
_lastflush = millis();
|
||||
//read from settings
|
||||
long br = Settings_ESP3D::read_uint32(ESP_BAUD_RATE);
|
||||
setParameters();
|
||||
_buffer_size = 0;
|
||||
//change only if different from current
|
||||
if (br != baudRate() || (ESP_RX_PIN != -1) || (ESP_TX_PIN != -1)) {
|
||||
@@ -197,7 +210,7 @@ void SerialService::flushbuffer()
|
||||
ESP3DOutput output(ESP_SERIAL_CLIENT);
|
||||
_buffer[_buffer_size] = 0x0;
|
||||
//dispatch command
|
||||
esp3d_commands.process(_buffer, _buffer_size, &output);
|
||||
esp3d_commands.process(_buffer, _buffer_size, &output,_needauthentication?LEVEL_GUEST:LEVEL_ADMIN);
|
||||
_lastflush = millis();
|
||||
_buffer_size = 0;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class SerialService : public Print
|
||||
public:
|
||||
SerialService();
|
||||
~SerialService();
|
||||
void setParameters();
|
||||
bool begin();
|
||||
bool end();
|
||||
void updateBaudRate(long br);
|
||||
@@ -73,6 +74,7 @@ public:
|
||||
}
|
||||
private:
|
||||
bool _started;
|
||||
bool _needauthentication;
|
||||
uint32_t _lastflush;
|
||||
uint8_t _buffer[ESP3D_SERIAL_BUFFER_SIZE + 1]; //keep space of 0x0 terminal
|
||||
size_t _buffer_size;
|
||||
|
||||
@@ -148,7 +148,8 @@ const char * SysboolKeysVal[] = {"Active_Printer_LCD",
|
||||
"Active_WebSocket",
|
||||
"Active_Telnet",
|
||||
"Active_BT",
|
||||
"Boot_verbose"
|
||||
"Boot_verbose",
|
||||
"Secure_serial"
|
||||
} ;
|
||||
|
||||
const uint16_t SysboolKeysPos[] = {ESP_PRINTER_LCD_FLAG,
|
||||
@@ -157,7 +158,8 @@ const uint16_t SysboolKeysPos[] = {ESP_PRINTER_LCD_FLAG,
|
||||
ESP_WEBSOCKET_FLAG,
|
||||
ESP_TELNET_FLAG,
|
||||
ESP_BT_FLAG,
|
||||
ESP_VERBOSE_BOOT
|
||||
ESP_VERBOSE_BOOT,
|
||||
ESP_SECURE_SERIAL
|
||||
} ;
|
||||
|
||||
const char * NetbyteKeysVal[] = {
|
||||
|
||||
Reference in New Issue
Block a user