mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Harmonize hostname, username and password length
This commit is contained in:
parent
86cfbc98da
commit
09ae100b27
@ -11,6 +11,17 @@
|
|||||||
// language specific defines
|
// language specific defines
|
||||||
#include "lang/lang.h"
|
#include "lang/lang.h"
|
||||||
|
|
||||||
|
// Lengths
|
||||||
|
#ifndef MAX_PASSWORD_LENGTH
|
||||||
|
#define MAX_PASSWORD_LENGTH 64
|
||||||
|
#endif
|
||||||
|
#ifndef MAX_USERNAME_LENGTH
|
||||||
|
#define MAX_USERNAME_LENGTH 32
|
||||||
|
#endif
|
||||||
|
#ifndef MAX_HOSTNAME_LENGTH
|
||||||
|
#define MAX_HOSTNAME_LENGTH 128
|
||||||
|
#endif
|
||||||
|
|
||||||
// TFT defines
|
// TFT defines
|
||||||
#ifndef TFT_BACKLIGHT_ON
|
#ifndef TFT_BACKLIGHT_ON
|
||||||
#define TFT_BACKLIGHT_ON HIGH
|
#define TFT_BACKLIGHT_ON HIGH
|
||||||
|
@ -2063,19 +2063,22 @@ static hasp_attribute_type_t attribute_common_bool(lv_obj_t* obj, uint16_t attr_
|
|||||||
|
|
||||||
void attr_out_str(lv_obj_t* obj, const char* attribute, const char* data)
|
void attr_out_str(lv_obj_t* obj, const char* attribute, const char* data)
|
||||||
{
|
{
|
||||||
|
const size_t size = 64 + strlen(data);
|
||||||
uint8_t pageid;
|
uint8_t pageid;
|
||||||
uint8_t objid;
|
uint8_t objid;
|
||||||
|
|
||||||
if(!attribute || !hasp_find_id_from_obj(obj, &pageid, &objid)) return;
|
if(!attribute || !hasp_find_id_from_obj(obj, &pageid, &objid)) return;
|
||||||
|
char payload[size];
|
||||||
|
|
||||||
StaticJsonDocument<32> doc; // Total (recommended) size
|
{
|
||||||
|
StaticJsonDocument<size> doc; // Total (recommended) size
|
||||||
if(data)
|
if(data)
|
||||||
doc[attribute].set(data);
|
doc[attribute].set(data);
|
||||||
else
|
else
|
||||||
doc[attribute].set(nullptr);
|
doc[attribute].set(nullptr);
|
||||||
|
|
||||||
char payload[MQTT_MAX_PACKET_SIZE];
|
|
||||||
serializeJson(doc, payload, MQTT_MAX_PACKET_SIZE);
|
serializeJson(doc, payload, MQTT_MAX_PACKET_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
object_dispatch_state(pageid, objid, payload);
|
object_dispatch_state(pageid, objid, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +66,9 @@ bool mqttHAautodiscover = true;
|
|||||||
std::recursive_mutex dispatch_mtx;
|
std::recursive_mutex dispatch_mtx;
|
||||||
std::recursive_mutex publish_mtx;
|
std::recursive_mutex publish_mtx;
|
||||||
|
|
||||||
char mqttServer[16] = MQTT_HOST;
|
char mqttServer[MAX_HOSTNAME_LENGTH] = MQTT_HOST;
|
||||||
char mqttUser[23] = MQTT_USER;
|
char mqttUser[MAX_USERNAME_LENGTH] = MQTT_USER;
|
||||||
char mqttPassword[32] = MQTT_PASSW;
|
char mqttPassword[MAX_PASSWORD_LENGTH] = MQTT_PASSW;
|
||||||
// char mqttNodeName[16] = MQTT_NODENAME;
|
// char mqttNodeName[16] = MQTT_NODENAME;
|
||||||
char mqttGroupName[16] = MQTT_GROUPNAME;
|
char mqttGroupName[16] = MQTT_GROUPNAME;
|
||||||
uint16_t mqttPort = MQTT_PORT;
|
uint16_t mqttPort = MQTT_PORT;
|
||||||
|
@ -54,9 +54,9 @@ uint32_t mqttPublishCount;
|
|||||||
uint32_t mqttReceiveCount;
|
uint32_t mqttReceiveCount;
|
||||||
uint32_t mqttFailedCount;
|
uint32_t mqttFailedCount;
|
||||||
|
|
||||||
char mqttServer[16] = MQTT_HOST;
|
char mqttServer[MAX_USERNAME_LENGTH] = MQTT_HOST;
|
||||||
char mqttUser[23] = MQTT_USER;
|
char mqttUsername[MAX_USERNAME_LENGTH] = MQTT_USER;
|
||||||
char mqttPassword[32] = MQTT_PASSW;
|
char mqttPassword[MAX_PASSWORD_LENGTH] = MQTT_PASSW;
|
||||||
// char mqttNodeName[16] = MQTT_NODENAME;
|
// char mqttNodeName[16] = MQTT_NODENAME;
|
||||||
char mqttGroupName[16] = MQTT_GROUPNAME;
|
char mqttGroupName[16] = MQTT_GROUPNAME;
|
||||||
uint16_t mqttPort = MQTT_PORT;
|
uint16_t mqttPort = MQTT_PORT;
|
||||||
@ -241,7 +241,7 @@ void mqttStart()
|
|||||||
|
|
||||||
haspProgressMsg(F(D_MQTT_CONNECTING));
|
haspProgressMsg(F(D_MQTT_CONNECTING));
|
||||||
haspProgressVal(mqttReconnectCount * 5);
|
haspProgressVal(mqttReconnectCount * 5);
|
||||||
if(!mqttClient.connect(mqttClientId, mqttUser, mqttPassword, buffer, 0, true, lastWillPayload, true)) {
|
if(!mqttClient.connect(mqttClientId, mqttUsername, mqttPassword, buffer, 0, true, lastWillPayload, true)) {
|
||||||
// Retry until we give up and restart after connectTimeout seconds
|
// Retry until we give up and restart after connectTimeout seconds
|
||||||
mqttReconnectCount++;
|
mqttReconnectCount++;
|
||||||
|
|
||||||
@ -383,7 +383,7 @@ void mqtt_get_info(JsonDocument& doc)
|
|||||||
|
|
||||||
JsonObject info = doc.createNestedObject(F("MQTT"));
|
JsonObject info = doc.createNestedObject(F("MQTT"));
|
||||||
info[F(D_INFO_SERVER)] = mqttServer;
|
info[F(D_INFO_SERVER)] = mqttServer;
|
||||||
info[F(D_INFO_USERNAME)] = mqttUser;
|
info[F(D_INFO_USERNAME)] = mqttUsername;
|
||||||
|
|
||||||
mac = halGetMacAddress(3, "");
|
mac = halGetMacAddress(3, "");
|
||||||
mac.toLowerCase();
|
mac.toLowerCase();
|
||||||
@ -437,8 +437,8 @@ bool mqttGetConfig(const JsonObject& settings)
|
|||||||
if(mqttPort != settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
if(mqttPort != settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_PORT)] = mqttPort;
|
settings[FPSTR(FP_CONFIG_PORT)] = mqttPort;
|
||||||
|
|
||||||
if(strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
if(strcmp(mqttUsername, settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_USER)] = mqttUser;
|
settings[FPSTR(FP_CONFIG_USER)] = mqttUsername;
|
||||||
|
|
||||||
if(strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
if(strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_PASS)] = mqttPassword;
|
settings[FPSTR(FP_CONFIG_PASS)] = mqttPassword;
|
||||||
@ -493,8 +493,8 @@ bool mqttSetConfig(const JsonObject& settings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) {
|
if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) {
|
||||||
changed |= strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)]) != 0;
|
changed |= strcmp(mqttUsername, settings[FPSTR(FP_CONFIG_USER)]) != 0;
|
||||||
strncpy(mqttUser, settings[FPSTR(FP_CONFIG_USER)], sizeof(mqttUser));
|
strncpy(mqttUsername, settings[FPSTR(FP_CONFIG_USER)], sizeof(mqttUsername));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!settings[FPSTR(FP_CONFIG_PASS)].isNull() &&
|
if(!settings[FPSTR(FP_CONFIG_PASS)].isNull() &&
|
||||||
|
@ -38,20 +38,16 @@ SPIClass espSPI(ESPSPI_MOSI, ESPSPI_MISO, ESPSPI_SCLK); // SPI port where esp is
|
|||||||
#endif
|
#endif
|
||||||
//#include "DNSserver.h"
|
//#include "DNSserver.h"
|
||||||
|
|
||||||
// #ifdef USE_CONFIG_OVERRIDE
|
#ifndef WIFI_SSID
|
||||||
// #include "user_config_override.h"
|
#define WIFI_SSID ""
|
||||||
// #endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIFI_SSID
|
#ifndef WIFI_PASSW
|
||||||
char wifiSsid[32] = WIFI_SSID;
|
#define WIFI_PASSW ""
|
||||||
#else
|
|
||||||
char wifiSsid[32] = "";
|
|
||||||
#endif
|
|
||||||
#ifdef WIFI_PASSW
|
|
||||||
char wifiPassword[64] = WIFI_PASSW;
|
|
||||||
#else
|
|
||||||
char wifiPassword[64] = "";
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char wifiSsid[MAX_USERNAME_LENGTH] = WIFI_SSID;
|
||||||
|
char wifiPassword[MAX_PASSWORD_LENGTH] = WIFI_PASSW;
|
||||||
char wifiIpAddress[16] = "";
|
char wifiIpAddress[16] = "";
|
||||||
uint16_t wifiReconnectCounter = 0;
|
uint16_t wifiReconnectCounter = 0;
|
||||||
bool wifiOnline = false;
|
bool wifiOnline = false;
|
||||||
|
@ -64,7 +64,7 @@ static void console_process_line(const char* input)
|
|||||||
0x01); // Hide characters
|
0x01); // Hide characters
|
||||||
bufferedSerialClient->print(buffer);
|
bufferedSerialClient->print(buffer);
|
||||||
#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
|
#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
|
||||||
consoleLoginState = strcmp(input, http_config.user) == 0 ? CONSOLE_USERNAME_OK : CONSOLE_USERNAME_NOK;
|
consoleLoginState = strcmp(input, http_config.username) == 0 ? CONSOLE_USERNAME_OK : CONSOLE_USERNAME_NOK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CONSOLE_USERNAME_OK:
|
case CONSOLE_USERNAME_OK:
|
||||||
|
@ -87,10 +87,6 @@ IPAddress apIP(192, 168, 4, 1);
|
|||||||
#endif // DNS_PORT
|
#endif // DNS_PORT
|
||||||
#endif // HASP_USE_CAPTIVE_PORTAL
|
#endif // HASP_USE_CAPTIVE_PORTAL
|
||||||
|
|
||||||
// bool httpEnable = true;
|
|
||||||
// uint16_t httpPort = 80;
|
|
||||||
// char httpUser[32] = "";
|
|
||||||
// char httpPassword[32] = "";
|
|
||||||
hasp_http_config_t http_config;
|
hasp_http_config_t http_config;
|
||||||
|
|
||||||
#define HTTP_PAGE_SIZE (6 * 256)
|
#define HTTP_PAGE_SIZE (6 * 256)
|
||||||
@ -207,7 +203,7 @@ static void webHandleHaspConfig();
|
|||||||
bool httpIsAuthenticated()
|
bool httpIsAuthenticated()
|
||||||
{
|
{
|
||||||
if(http_config.password[0] != '\0') { // Request HTTP auth if httpPassword is set
|
if(http_config.password[0] != '\0') { // Request HTTP auth if httpPassword is set
|
||||||
if(!webServer.authenticate(http_config.user, http_config.password)) {
|
if(!webServer.authenticate(http_config.username, http_config.password)) {
|
||||||
webServer.requestAuthentication();
|
webServer.requestAuthentication();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -568,211 +564,6 @@ static void webHandleInfoJson()
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/*
|
|
||||||
static void webHandleInfo()
|
|
||||||
{ // http://plate01/
|
|
||||||
if(!httpIsAuthenticated(F("info"))) return;
|
|
||||||
|
|
||||||
{ // Send Content
|
|
||||||
char size_buf[32];
|
|
||||||
String httpMessage((char*)0);
|
|
||||||
httpMessage.reserve(HTTP_PAGE_SIZE);
|
|
||||||
httpMessage += F("<h1>");
|
|
||||||
httpMessage += haspDevice.get_hostname();
|
|
||||||
httpMessage += F("</h1><hr>");
|
|
||||||
|
|
||||||
// HASP Stats
|
|
||||||
httpMessage += F("<b>HASP Version: </b>");
|
|
||||||
httpMessage += haspDevice.get_version();
|
|
||||||
httpMessage += F("<br/><b>Build DateTime: </b>");
|
|
||||||
httpMessage += __DATE__;
|
|
||||||
httpMessage += F(" ");
|
|
||||||
httpMessage += __TIME__;
|
|
||||||
httpMessage += F(" UTC<br/><b>Uptime: </b>"); // Github buildservers are in UTC
|
|
||||||
|
|
||||||
unsigned long time = millis() / 1000;
|
|
||||||
uint16_t day = time / 86400;
|
|
||||||
time = time % 86400;
|
|
||||||
uint8_t hour = time / 3600;
|
|
||||||
time = time % 3600;
|
|
||||||
uint8_t min = time / 60;
|
|
||||||
time = time % 60;
|
|
||||||
uint8_t sec = time;
|
|
||||||
|
|
||||||
if(day > 0) {
|
|
||||||
httpMessage += String(day);
|
|
||||||
httpMessage += F("d ");
|
|
||||||
}
|
|
||||||
if(day > 0 || hour > 0) {
|
|
||||||
httpMessage += String(hour);
|
|
||||||
httpMessage += F("h ");
|
|
||||||
}
|
|
||||||
if(day > 0 || hour > 0 || min > 0) {
|
|
||||||
httpMessage += String(min);
|
|
||||||
httpMessage += F("m ");
|
|
||||||
}
|
|
||||||
httpMessage += String(sec);
|
|
||||||
httpMessage += F("s");
|
|
||||||
|
|
||||||
httpMessage += F("<br/><b>Free Memory: </b>");
|
|
||||||
Parser::format_bytes(haspDevice.get_free_heap(), size_buf, sizeof(size_buf));
|
|
||||||
httpMessage += size_buf;
|
|
||||||
httpMessage += F("<br/><b>Memory Fragmentation: </b>");
|
|
||||||
httpMessage += String(haspDevice.get_heap_fragmentation());
|
|
||||||
|
|
||||||
#if ARDUINO_ARCH_ESP32
|
|
||||||
if(psramFound()) {
|
|
||||||
httpMessage += F("<br/><b>Free PSRam: </b>");
|
|
||||||
Parser::format_bytes(ESP.getFreePsram(), size_buf, sizeof(size_buf));
|
|
||||||
httpMessage += size_buf;
|
|
||||||
httpMessage += F("<br/><b>PSRam Size: </b>");
|
|
||||||
Parser::format_bytes(ESP.getPsramSize(), size_buf, sizeof(size_buf));
|
|
||||||
httpMessage += size_buf;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// LVGL Stats
|
|
||||||
lv_mem_monitor_t mem_mon;
|
|
||||||
lv_mem_monitor(&mem_mon);
|
|
||||||
httpMessage += F("</p><p><b>LVGL Memory: </b>");
|
|
||||||
Parser::format_bytes(mem_mon.total_size, size_buf, sizeof(size_buf));
|
|
||||||
httpMessage += size_buf;
|
|
||||||
httpMessage += F("<br/><b>LVGL Free: </b>");
|
|
||||||
Parser::format_bytes(mem_mon.free_size, size_buf, sizeof(size_buf));
|
|
||||||
httpMessage += size_buf;
|
|
||||||
httpMessage += F("<br/><b>LVGL Fragmentation: </b>");
|
|
||||||
httpMessage += mem_mon.frag_pct;
|
|
||||||
|
|
||||||
// httpMessage += F("<br/><b>LCD Model: </b>")) + String(LV_HASP_HOR_RES_MAX) + " x " +
|
|
||||||
// String(LV_HASP_VER_RES_MAX); httpMessage += F("<br/><b>LCD Version: </b>")) +
|
|
||||||
// String(lcdVersion);
|
|
||||||
httpMessage += F("</p/><p><b>LCD Active Page: </b>");
|
|
||||||
httpMessage += String(haspPages.get());
|
|
||||||
|
|
||||||
// Wifi Stats
|
|
||||||
#if HASP_USE_WIFI > 0
|
|
||||||
httpMessage += F("</p/><p><b>SSID: </b>");
|
|
||||||
httpMessage += String(WiFi.SSID());
|
|
||||||
httpMessage += F("</br><b>Signal Strength: </b>");
|
|
||||||
|
|
||||||
int8_t rssi = WiFi.RSSI();
|
|
||||||
httpMessage += String(rssi);
|
|
||||||
httpMessage += F("dBm (");
|
|
||||||
|
|
||||||
if(rssi >= -50) {
|
|
||||||
httpMessage += F("Excellent)");
|
|
||||||
} else if(rssi >= -60) {
|
|
||||||
httpMessage += F("Good)");
|
|
||||||
} else if(rssi >= -70) {
|
|
||||||
httpMessage += F("Fair)");
|
|
||||||
} else if(rssi >= -80) {
|
|
||||||
httpMessage += F("Weak)");
|
|
||||||
} else {
|
|
||||||
httpMessage += F("Very Bad)");
|
|
||||||
}
|
|
||||||
#if defined(STM32F4xx)
|
|
||||||
byte mac[6];
|
|
||||||
WiFi.macAddress(mac);
|
|
||||||
char macAddress[16];
|
|
||||||
snprintf_P(macAddress, sizeof(macAddress), PSTR("%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4],
|
|
||||||
mac[5]);
|
|
||||||
httpMessage += F("</br><b>IP Address: </b>");
|
|
||||||
httpMessage += String(WiFi.localIP());
|
|
||||||
httpMessage += F("</br><b>Gateway: </b>");
|
|
||||||
httpMessage += String(WiFi.gatewayIP());
|
|
||||||
httpMessage += F("</br><b>MAC Address: </b>");
|
|
||||||
httpMessage += String(macAddress);
|
|
||||||
#else
|
|
||||||
httpMessage += F("</br><b>IP Address: </b>");
|
|
||||||
httpMessage += String(WiFi.localIP().toString());
|
|
||||||
httpMessage += F("</br><b>Gateway: </b>");
|
|
||||||
httpMessage += String(WiFi.gatewayIP().toString());
|
|
||||||
httpMessage += F("</br><b>DNS Server: </b>");
|
|
||||||
httpMessage += String(WiFi.dnsIP().toString());
|
|
||||||
httpMessage += F("</br><b>MAC Address: </b>");
|
|
||||||
httpMessage += String(WiFi.macAddress());
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if HASP_USE_ETHERNET > 0
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
httpMessage += F("</p/><p><b>Ethernet: </b>");
|
|
||||||
httpMessage += String(ETH.linkSpeed());
|
|
||||||
httpMessage += F(" Mbps");
|
|
||||||
if(ETH.fullDuplex()) {
|
|
||||||
httpMessage += F(" " D_INFO_FULL_DUPLEX);
|
|
||||||
}
|
|
||||||
httpMessage += F("</br><b>IP Address: </b>");
|
|
||||||
httpMessage += String(ETH.localIP().toString());
|
|
||||||
httpMessage += F("</br><b>Gateway: </b>");
|
|
||||||
httpMessage += String(ETH.gatewayIP().toString());
|
|
||||||
httpMessage += F("</br><b>DNS Server: </b>");
|
|
||||||
httpMessage += String(ETH.dnsIP().toString());
|
|
||||||
httpMessage += F("</br><b>MAC Address: </b>");
|
|
||||||
httpMessage += String(ETH.macAddress());
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Mqtt Stats
|
|
||||||
#if HASP_USE_MQTT > 0
|
|
||||||
httpMessage += F("</p/><p><b>MQTT Status: </b>");
|
|
||||||
if(mqttIsConnected()) { // Check MQTT connection
|
|
||||||
httpMessage += F("Connected");
|
|
||||||
} else {
|
|
||||||
httpMessage += F("<font color='red'><b>Disconnected</b></font>, return code: ");
|
|
||||||
// +String(mqttClient.returnCode());
|
|
||||||
}
|
|
||||||
httpMessage += F("<br/><b>MQTT ClientID: </b>");
|
|
||||||
|
|
||||||
{
|
|
||||||
char mqttClientId[64];
|
|
||||||
String mac = halGetMacAddress(3, "");
|
|
||||||
mac.toLowerCase();
|
|
||||||
snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%s"), haspDevice.get_hostname(), mac.c_str());
|
|
||||||
httpMessage += mqttClientId;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // MQTT
|
|
||||||
|
|
||||||
// ESP Stats
|
|
||||||
httpMessage += F("</p/><p><b>MCU Model: </b>");
|
|
||||||
httpMessage += haspDevice.get_chip_model();
|
|
||||||
httpMessage += F("<br/><b>CPU Frequency: </b>");
|
|
||||||
httpMessage += String(haspDevice.get_cpu_frequency());
|
|
||||||
httpMessage += F("MHz");
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
httpMessage += F("<br/><b>Flash Chip Size: </b>");
|
|
||||||
Parser::format_bytes(ESP.getFlashChipSize(), size_buf, sizeof(size_buf));
|
|
||||||
httpMessage += size_buf;
|
|
||||||
|
|
||||||
httpMessage += F("</br><b>Program Size Used: </b>");
|
|
||||||
Parser::format_bytes(ESP.getSketchSize(), size_buf, sizeof(size_buf));
|
|
||||||
httpMessage += size_buf;
|
|
||||||
|
|
||||||
httpMessage += F("<br/><b>Program Size Free: </b>");
|
|
||||||
Parser::format_bytes(ESP.getFreeSketchSpace(), size_buf, sizeof(size_buf));
|
|
||||||
httpMessage += size_buf;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
// httpMessage += F("<br/><b>ESP SDK version: </b>");
|
|
||||||
// httpMessage += String(ESP.getSdkVersion());
|
|
||||||
//#else
|
|
||||||
httpMessage += F("<br/><b>Core version: </b>");
|
|
||||||
httpMessage += haspDevice.get_core_version();
|
|
||||||
//#endif
|
|
||||||
httpMessage += F("<br/><b>Last Reset: </b>");
|
|
||||||
// httpMessage += halGetResetInfo();
|
|
||||||
|
|
||||||
httpMessage += FPSTR(MAIN_MENU_BUTTON);
|
|
||||||
|
|
||||||
webSendHeader(haspDevice.get_hostname(), httpMessage.length(), false);
|
|
||||||
webServer.sendContent(httpMessage);
|
|
||||||
}
|
|
||||||
webSendFooter();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* String urldecode(String str)
|
/* String urldecode(String str)
|
||||||
{
|
{
|
||||||
String encodedString = "";
|
String encodedString = "";
|
||||||
@ -2563,8 +2354,8 @@ bool httpGetConfig(const JsonObject& settings)
|
|||||||
if(http_config.port != settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
if(http_config.port != settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_PORT)] = http_config.port;
|
settings[FPSTR(FP_CONFIG_PORT)] = http_config.port;
|
||||||
|
|
||||||
if(strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
if(strcmp(http_config.username, settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_USER)] = http_config.user;
|
settings[FPSTR(FP_CONFIG_USER)] = http_config.username;
|
||||||
|
|
||||||
if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_PASS)] = http_config.password;
|
settings[FPSTR(FP_CONFIG_PASS)] = http_config.password;
|
||||||
@ -2589,8 +2380,8 @@ bool httpSetConfig(const JsonObject& settings)
|
|||||||
changed |= configSet(http_config.port, settings[FPSTR(FP_CONFIG_PORT)], F("httpPort"));
|
changed |= configSet(http_config.port, settings[FPSTR(FP_CONFIG_PORT)], F("httpPort"));
|
||||||
|
|
||||||
if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) {
|
if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) {
|
||||||
changed |= strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)]) != 0;
|
changed |= strcmp(http_config.username, settings[FPSTR(FP_CONFIG_USER)]) != 0;
|
||||||
strncpy(http_config.user, settings[FPSTR(FP_CONFIG_USER)], sizeof(http_config.user));
|
strncpy(http_config.username, settings[FPSTR(FP_CONFIG_USER)], sizeof(http_config.username));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!settings[FPSTR(FP_CONFIG_PASS)].isNull()) {
|
if(!settings[FPSTR(FP_CONFIG_PASS)].isNull()) {
|
||||||
|
@ -11,8 +11,8 @@ struct hasp_http_config_t
|
|||||||
bool enable = true;
|
bool enable = true;
|
||||||
uint16_t port = 80;
|
uint16_t port = 80;
|
||||||
|
|
||||||
char user[32] = "";
|
char username[MAX_USERNAME_LENGTH] = "";
|
||||||
char password[32] = "";
|
char password[MAX_PASSWORD_LENGTH] = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
void httpSetup();
|
void httpSetup();
|
||||||
|
@ -58,7 +58,7 @@ bool webServerStarted = false;
|
|||||||
// bool httpEnable = true;
|
// bool httpEnable = true;
|
||||||
// uint16_t httpPort = 80;
|
// uint16_t httpPort = 80;
|
||||||
// char httpUser[32] = "";
|
// char httpUser[32] = "";
|
||||||
// char httpPassword[32] = "";
|
// char httpPassword[MAX_PASSWORD_LENGTH] = "";
|
||||||
hasp_http_config_t http_config;
|
hasp_http_config_t http_config;
|
||||||
|
|
||||||
#define HTTP_PAGE_SIZE (6 * 256)
|
#define HTTP_PAGE_SIZE (6 * 256)
|
||||||
@ -219,7 +219,7 @@ void webHandleHaspConfig(AsyncWebServerRequest* request);
|
|||||||
bool httpIsAuthenticated()
|
bool httpIsAuthenticated()
|
||||||
{
|
{
|
||||||
if(http_config.password[0] != '\0') { // Request HTTP auth if httpPassword is set
|
if(http_config.password[0] != '\0') { // Request HTTP auth if httpPassword is set
|
||||||
// if(!webServer.authenticate(http_config.user, http_config.password)) {
|
// if(!webServer.authenticate(http_config.username, http_config.password)) {
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
@ -2347,8 +2347,8 @@ bool httpGetConfig(const JsonObject& settings)
|
|||||||
if(http_config.port != settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
if(http_config.port != settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_PORT)] = http_config.port;
|
settings[FPSTR(FP_CONFIG_PORT)] = http_config.port;
|
||||||
|
|
||||||
if(strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
if(strcmp(http_config.username, settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_USER)] = http_config.user;
|
settings[FPSTR(FP_CONFIG_USER)] = http_config.username;
|
||||||
|
|
||||||
if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_PASS)] = http_config.password;
|
settings[FPSTR(FP_CONFIG_PASS)] = http_config.password;
|
||||||
@ -2373,8 +2373,8 @@ bool httpSetConfig(const JsonObject& settings)
|
|||||||
changed |= configSet(http_config.port, settings[FPSTR(FP_CONFIG_PORT)], F("httpPort"));
|
changed |= configSet(http_config.port, settings[FPSTR(FP_CONFIG_PORT)], F("httpPort"));
|
||||||
|
|
||||||
if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) {
|
if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) {
|
||||||
changed |= strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)]) != 0;
|
changed |= strcmp(http_config.username, settings[FPSTR(FP_CONFIG_USER)]) != 0;
|
||||||
strncpy(http_config.user, settings[FPSTR(FP_CONFIG_USER)], sizeof(http_config.user));
|
strncpy(http_config.username, settings[FPSTR(FP_CONFIG_USER)], sizeof(http_config.username));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!settings[FPSTR(FP_CONFIG_PASS)].isNull()) {
|
if(!settings[FPSTR(FP_CONFIG_PASS)].isNull()) {
|
||||||
|
@ -103,7 +103,7 @@ void telnetAcceptClient()
|
|||||||
// telnetClient.print((char)0x1B);
|
// telnetClient.print((char)0x1B);
|
||||||
|
|
||||||
#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
|
#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
|
||||||
if(strlen(http_config.user) != 0 || strlen(http_config.password) != 0) {
|
if(strlen(http_config.username) != 0 || strlen(http_config.password) != 0) {
|
||||||
telnetClient.println(F("\r\n" D_USERNAME " "));
|
telnetClient.println(F("\r\n" D_USERNAME " "));
|
||||||
telnetLoginState = TELNET_UNAUTHENTICATED;
|
telnetLoginState = TELNET_UNAUTHENTICATED;
|
||||||
} else
|
} else
|
||||||
@ -123,7 +123,7 @@ static inline void telnetProcessLine()
|
|||||||
case TELNET_UNAUTHENTICATED: {
|
case TELNET_UNAUTHENTICATED: {
|
||||||
telnetClient.printf(PSTR(D_PASSWORD" %c%c%c"), 0xFF, 0xFB, 0x01); // Hide characters
|
telnetClient.printf(PSTR(D_PASSWORD" %c%c%c"), 0xFF, 0xFB, 0x01); // Hide characters
|
||||||
#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
|
#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
|
||||||
telnetLoginState = strcmp(telnetInputBuffer, http_config.user) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK;
|
telnetLoginState = strcmp(telnetInputBuffer, http_config.username) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TELNET_USERNAME_OK:
|
case TELNET_USERNAME_OK:
|
||||||
@ -209,7 +209,7 @@ static void telnetProcessLine(const char* input)
|
|||||||
0x01); // Hide characters
|
0x01); // Hide characters
|
||||||
telnetClient.print(buffer);
|
telnetClient.print(buffer);
|
||||||
#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
|
#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
|
||||||
telnetLoginState = strcmp(input, http_config.user) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK;
|
telnetLoginState = strcmp(input, http_config.username) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TELNET_USERNAME_OK:
|
case TELNET_USERNAME_OK:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user