mirror of https://github.com/arendst/Tasmota.git
Phase 2/2 Ethernet IP address config
Phase 2 of 2 Ethernet IP address config based on PR (#14385)
This commit is contained in:
parent
2a644b1718
commit
e6e5d5174f
|
@ -570,12 +570,26 @@ void CmndStatus(void)
|
|||
}
|
||||
|
||||
if ((0 == payload) || (5 == payload)) {
|
||||
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS5_NETWORK "\":{\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%_I\",\""
|
||||
D_JSON_GATEWAY "\":\"%_I\",\"" D_JSON_SUBNETMASK "\":\"%_I\",\"" D_JSON_DNSSERVER "1\":\"%_I\",\"" D_JSON_DNSSERVER "2\":\"%_I\",\""
|
||||
D_JSON_MAC "\":\"%s\",\"" D_CMND_WEBSERVER "\":%d,\"HTTP_API\":%d,\"" D_CMND_WIFICONFIG "\":%d,\"" D_CMND_WIFIPOWER "\":%s}}"),
|
||||
NetworkHostname(), (uint32_t)NetworkAddress(),
|
||||
Settings->ipv4_address[1], Settings->ipv4_address[2], Settings->ipv4_address[3], Settings->ipv4_address[4],
|
||||
NetworkMacAddress().c_str(), Settings->webserver, Settings->flag5.disable_referer_chk, Settings->sta_config, WifiGetOutputPower().c_str());
|
||||
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS5_NETWORK "\":{\"" D_CMND_HOSTNAME "\":\"%s\",\""
|
||||
D_CMND_IPADDRESS "\":\"%_I\",\"" D_JSON_GATEWAY "\":\"%_I\",\"" D_JSON_SUBNETMASK "\":\"%_I\",\""
|
||||
D_JSON_DNSSERVER "1\":\"%_I\",\"" D_JSON_DNSSERVER "2\":\"%_I\",\""
|
||||
D_JSON_MAC "\":\"%s\""),
|
||||
TasmotaGlobal.hostname,
|
||||
(uint32_t)WiFi.localIP(), Settings->ipv4_address[1], Settings->ipv4_address[2],
|
||||
Settings->ipv4_address[3], Settings->ipv4_address[4],
|
||||
WiFi.macAddress().c_str());
|
||||
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET)
|
||||
ResponseAppend_P(PSTR(",\"Ethernet\":{\"" D_CMND_HOSTNAME "\":\"%s\",\""
|
||||
D_CMND_IPADDRESS "\":\"%_I\",\"" D_JSON_GATEWAY "\":\"%_I\",\"" D_JSON_SUBNETMASK "\":\"%_I\",\""
|
||||
D_JSON_DNSSERVER "1\":\"%_I\",\"" D_JSON_DNSSERVER "2\":\"%_I\",\""
|
||||
D_JSON_MAC "\":\"%s\"}"),
|
||||
EthernetHostname(),
|
||||
(uint32_t)EthernetLocalIP(), Settings->eth_ipv4_address[1], Settings->eth_ipv4_address[2],
|
||||
Settings->eth_ipv4_address[3], Settings->eth_ipv4_address[4],
|
||||
EthernetMacAddress().c_str());
|
||||
#endif // USE_ETHERNET
|
||||
ResponseAppend_P(PSTR(",\"" D_CMND_WEBSERVER "\":%d,\"HTTP_API\":%d,\"" D_CMND_WIFICONFIG "\":%d,\"" D_CMND_WIFIPOWER "\":%s}}"),
|
||||
Settings->webserver, Settings->flag5.disable_referer_chk, Settings->sta_config, WifiGetOutputPower().c_str());
|
||||
CmndStatusResponse(5);
|
||||
}
|
||||
|
||||
|
@ -1635,7 +1649,7 @@ void CmndIpAddress(void)
|
|||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 5)) {
|
||||
char network_address[22];
|
||||
ext_snprintf_P(network_address, sizeof(network_address), PSTR(" (%_I)"), (uint32_t)NetworkAddress());
|
||||
ext_snprintf_P(network_address, sizeof(network_address), PSTR(" (%_I)"), (uint32_t)WiFi.localIP());
|
||||
if (!XdrvMailbox.usridx) {
|
||||
ResponseClear();
|
||||
for (uint32_t i = 0; i < 5; i++) {
|
||||
|
|
|
@ -683,11 +683,18 @@ bool HttpCheckPriviledgedAccess(bool autorequestauth = true)
|
|||
String referer = Webserver->header(F("Referer")); // http://demo/? or http://192.168.2.153/?
|
||||
if (referer.length()) {
|
||||
referer.toUpperCase();
|
||||
String hostname = NetworkHostname();
|
||||
String hostname = TasmotaGlobal.hostname;
|
||||
hostname.toUpperCase();
|
||||
if ((referer.indexOf(hostname) == 7) || (referer.indexOf(NetworkAddress().toString()) == 7)) {
|
||||
if ((referer.indexOf(hostname) == 7) || (referer.indexOf(WiFi.localIP().toString()) == 7)) {
|
||||
return true;
|
||||
}
|
||||
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET)
|
||||
hostname = EthernetHostname();
|
||||
hostname.toUpperCase();
|
||||
if ((referer.indexOf(hostname) == 7) || (referer.indexOf(EthernetLocalIP().toString()) == 7)) {
|
||||
return true;
|
||||
}
|
||||
#endif // USE_ETHERNET
|
||||
}
|
||||
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_HTTP "Referer '%s' denied. Use 'SO128 1' for HTTP API commands. 'Webpassword' is recommended."), referer.c_str());
|
||||
return false;
|
||||
|
@ -2313,16 +2320,12 @@ void HandleInformation(void)
|
|||
WSContentSend_P(PSTR("}1" D_FRIENDLY_NAME " %d}2%s"), i +1, SettingsText(SET_FRIENDLYNAME1 +i));
|
||||
}
|
||||
WSContentSend_P(PSTR("}1}2 ")); // Empty line
|
||||
#ifdef ESP32
|
||||
#ifdef USE_ETHERNET
|
||||
if (static_cast<uint32_t>(EthernetLocalIP()) != 0) {
|
||||
WSContentSend_P(PSTR("}1" D_HOSTNAME "}2%s%s"), EthernetHostname(), (Mdns.begun) ? PSTR(".local") : "");
|
||||
WSContentSend_P(PSTR("}1" D_MAC_ADDRESS "}2%s"), EthernetMacAddress().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_IP_ADDRESS " (eth)}2%_I"), (uint32_t)EthernetLocalIP());
|
||||
if ((WiFi.getMode() >= WIFI_AP) && (static_cast<uint32_t>(WiFi.softAPIP()) != 0)) {
|
||||
WSContentSend_P(PSTR("}1" D_MAC_ADDRESS "}2%s"), WiFi.softAPmacAddress().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_IP_ADDRESS " (AP)}2%_I"), (uint32_t)WiFi.softAPIP());
|
||||
WSContentSend_P(PSTR("}1" D_GATEWAY "}2%_I"), (uint32_t)WiFi.softAPIP());
|
||||
WSContentSend_P(PSTR("}1<hr/>}2<hr/>"));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (Settings->flag4.network_wifi) {
|
||||
int32_t rssi = WiFi.RSSI();
|
||||
WSContentSend_P(PSTR("}1" D_AP "%d " D_SSID " (" D_RSSI ")}2%s (%d%%, %d dBm) 11%c"), Settings->sta_active +1, HtmlEscape(SettingsText(SET_STASSID1 + Settings->sta_active)).c_str(), WifiGetRssiAsQuality(rssi), rssi, pgm_read_byte(&kWifiPhyMode[WiFi.getPhyMode() & 0x3]) );
|
||||
|
@ -2332,11 +2335,10 @@ void HandleInformation(void)
|
|||
if (ipv6_addr != "") {
|
||||
WSContentSend_P(PSTR("}1 IPv6 Address }2%s"), ipv6_addr.c_str());
|
||||
}
|
||||
#endif
|
||||
#endif // LWIP_IPV6 = 1
|
||||
if (static_cast<uint32_t>(WiFi.localIP()) != 0) {
|
||||
WSContentSend_P(PSTR("}1" D_MAC_ADDRESS "}2%s"), WiFi.macAddress().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_IP_ADDRESS " (wifi)}2%_I"), (uint32_t)WiFi.localIP());
|
||||
WSContentSend_P(PSTR("}1<hr/>}2<hr/>"));
|
||||
}
|
||||
}
|
||||
if (!TasmotaGlobal.global_state.network_down) {
|
||||
|
@ -2345,12 +2347,20 @@ void HandleInformation(void)
|
|||
WSContentSend_P(PSTR("}1" D_DNS_SERVER "1}2%_I"), Settings->ipv4_address[3]);
|
||||
WSContentSend_P(PSTR("}1" D_DNS_SERVER "2}2%_I"), Settings->ipv4_address[4]);
|
||||
}
|
||||
if ((WiFi.getMode() >= WIFI_AP) && (static_cast<uint32_t>(WiFi.softAPIP()) != 0)) {
|
||||
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET)
|
||||
if (static_cast<uint32_t>(EthernetLocalIP()) != 0) {
|
||||
WSContentSend_P(PSTR("}1<hr/>}2<hr/>"));
|
||||
WSContentSend_P(PSTR("}1" D_MAC_ADDRESS "}2%s"), WiFi.softAPmacAddress().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_IP_ADDRESS " (AP)}2%_I"), (uint32_t)WiFi.softAPIP());
|
||||
WSContentSend_P(PSTR("}1" D_GATEWAY "}2%_I"), (uint32_t)WiFi.softAPIP());
|
||||
WSContentSend_P(PSTR("}1" D_HOSTNAME "}2%s%s"), EthernetHostname(), (Mdns.begun) ? PSTR(".local") : "");
|
||||
WSContentSend_P(PSTR("}1" D_MAC_ADDRESS "}2%s"), EthernetMacAddress().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_IP_ADDRESS " (eth)}2%_I"), (uint32_t)EthernetLocalIP());
|
||||
}
|
||||
if (!TasmotaGlobal.global_state.network_down) {
|
||||
WSContentSend_P(PSTR("}1" D_GATEWAY "}2%_I"), Settings->eth_ipv4_address[1]);
|
||||
WSContentSend_P(PSTR("}1" D_SUBNET_MASK "}2%_I"), Settings->eth_ipv4_address[2]);
|
||||
WSContentSend_P(PSTR("}1" D_DNS_SERVER "1}2%_I"), Settings->eth_ipv4_address[3]);
|
||||
WSContentSend_P(PSTR("}1" D_DNS_SERVER "2}2%_I"), Settings->eth_ipv4_address[4]);
|
||||
}
|
||||
#endif // USE_ETHERNET
|
||||
WSContentSend_P(PSTR("}1}2 ")); // Empty line
|
||||
WSContentSend_P(PSTR("}1" D_HTTP_API "}2%s"), Settings->flag5.disable_referer_chk ? PSTR(D_ENABLED) : PSTR(D_DISABLED)); // SetOption 128
|
||||
WSContentSend_P(PSTR("}1}2 ")); // Empty line
|
||||
|
|
|
@ -917,13 +917,22 @@ void MqttConnected(void) {
|
|||
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_INFO "1"), Settings->flag5.mqtt_info_retain);
|
||||
#ifdef USE_WEBSERVER
|
||||
if (Settings->webserver) {
|
||||
Response_P(PSTR("{\"Info2\":{\"" D_JSON_WEBSERVER_MODE "\":\"%s\""),
|
||||
(2 == Settings->webserver) ? PSTR(D_ADMIN) : PSTR(D_USER));
|
||||
if (static_cast<uint32_t>(WiFi.localIP()) != 0) {
|
||||
ResponseAppend_P(PSTR(",\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%_I\""),
|
||||
TasmotaGlobal.hostname, WiFi.localIP());
|
||||
#if LWIP_IPV6
|
||||
Response_P(PSTR("{\"Info2\":{\"" D_JSON_WEBSERVER_MODE "\":\"%s\",\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%s\",\"IPv6Address\":\"%s\"}}"),
|
||||
(2 == Settings->webserver) ? PSTR(D_ADMIN) : PSTR(D_USER), NetworkHostname(), NetworkAddress().toString().c_str(), WifiGetIPv6().c_str(), Settings->flag5.mqtt_info_retain);
|
||||
#else
|
||||
Response_P(PSTR("{\"Info2\":{\"" D_JSON_WEBSERVER_MODE "\":\"%s\",\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%s\"}}"),
|
||||
(2 == Settings->webserver) ? PSTR(D_ADMIN) : PSTR(D_USER), NetworkHostname(), NetworkAddress().toString().c_str(), Settings->flag5.mqtt_info_retain);
|
||||
#endif // LWIP_IPV6 = 1
|
||||
ResponseAppend_P(PSTR(",\"IPv6Address\":\"%s\""), WifiGetIPv6().c_str());
|
||||
#endif // LWIP_IPV6 = 1
|
||||
}
|
||||
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET)
|
||||
if (static_cast<uint32_t>(EthernetLocalIP()) != 0) {
|
||||
ResponseAppend_P(PSTR(",\"Ethernet\":{\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%_I\"}"),
|
||||
EthernetHostname(), (uint32_t)EthernetLocalIP());
|
||||
}
|
||||
#endif // USE_ETHERNET
|
||||
ResponseJsonEndEnd();
|
||||
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_INFO "2"), Settings->flag5.mqtt_info_retain);
|
||||
}
|
||||
#endif // USE_WEBSERVER
|
||||
|
|
|
@ -1002,7 +1002,7 @@ void RulesEvery50ms(void)
|
|||
TasmotaGlobal.rules_flag.eth_disconnected = 0;
|
||||
strncpy_P(json_event, PSTR("{\"ETH\":{\"Disconnected\":1}}"), sizeof(json_event));
|
||||
}
|
||||
#endif
|
||||
#endif // USE_ETHERNET
|
||||
else if (TasmotaGlobal.rules_flag.http_init) {
|
||||
TasmotaGlobal.rules_flag.http_init = 0;
|
||||
strncpy_P(json_event, PSTR("{\"HTTP\":{\"Initialized\":1}}"), sizeof(json_event));
|
||||
|
|
|
@ -193,11 +193,11 @@ void EthernetConfigChange(void) {
|
|||
|
||||
const char kEthernetCommands[] PROGMEM = "Eth|" // Prefix
|
||||
"ernet|" D_CMND_ETHADDRESS "|" D_CMND_ETHTYPE "|" D_CMND_ETHCLOCKMODE "|"
|
||||
D_CMND_ETHIPADDRESS "|" D_CMND_ETHGATEWAY "|" D_CMND_ETHNETMASK "|" D_CMND_ETHDNS "|Ipconfig" ;
|
||||
D_CMND_ETHIPADDRESS "|" D_CMND_ETHGATEWAY "|" D_CMND_ETHNETMASK "|" D_CMND_ETHDNS ;
|
||||
|
||||
void (* const EthernetCommand[])(void) PROGMEM = {
|
||||
&CmndEthernet, &CmndEthAddress, &CmndEthType, &CmndEthClockMode,
|
||||
&CmndEthSetIpConfig, &CmndEthSetIpConfig, &CmndEthSetIpConfig, &CmndEthSetIpConfig, &CmndEthIpConfig };
|
||||
&CmndEthSetIpConfig, &CmndEthSetIpConfig, &CmndEthSetIpConfig, &CmndEthSetIpConfig };
|
||||
|
||||
#define ETH_PARAM_OFFSET 4 // Offset of command index in above table of first CmndEthIpConfig
|
||||
|
||||
|
@ -262,18 +262,6 @@ void CmndEthSetIpConfig(void) {
|
|||
Response_P(PSTR("{\"%s%s\":\"%_I%s\"}"), XdrvMailbox.command, cmnd_idx, Settings->eth_ipv4_address[param_id], network_address);
|
||||
}
|
||||
|
||||
void CmndEthIpConfig(void) {
|
||||
char network_address[22] = { 0 };
|
||||
if (!Settings->eth_ipv4_address[0]) {
|
||||
ext_snprintf_P(network_address, sizeof(network_address), PSTR(" (%_I)"), (uint32_t)ETH.localIP());
|
||||
}
|
||||
Response_P(PSTR("{\"EthIpAddress\":\"%_I%s\""), Settings->eth_ipv4_address[0], network_address);
|
||||
ResponseAppend_P(PSTR(",\"EthGateway\":\"%_I\""), Settings->eth_ipv4_address[1]);
|
||||
ResponseAppend_P(PSTR(",\"EthSubNetmask\":\"%_I\""), Settings->eth_ipv4_address[2]);
|
||||
ResponseAppend_P(PSTR(",\"EthDnsServer1\":\"%_I\""), Settings->eth_ipv4_address[3]);
|
||||
ResponseAppend_P(PSTR(",\"EthDnsServer2\":\"%_I\"}"), Settings->eth_ipv4_address[4]);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue