mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
add checkbox for MQTT-TLS, fix #1474
This commit is contained in:
@@ -30,7 +30,7 @@
|
|||||||
"@types/imagemin": "^8.0.5",
|
"@types/imagemin": "^8.0.5",
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^20.10.2",
|
"@types/node": "^20.10.2",
|
||||||
"@types/react": "^18.2.40",
|
"@types/react": "^18.2.41",
|
||||||
"@types/react-dom": "^18.2.17",
|
"@types/react-dom": "^18.2.17",
|
||||||
"@types/react-router-dom": "^5.3.3",
|
"@types/react-router-dom": "^5.3.3",
|
||||||
"alova": "^2.15.0",
|
"alova": "^2.15.0",
|
||||||
|
|||||||
@@ -168,20 +168,24 @@ const MqttSettingsForm: FC = () => {
|
|||||||
<MenuItem value={2}>2</MenuItem>
|
<MenuItem value={2}>2</MenuItem>
|
||||||
</TextField>
|
</TextField>
|
||||||
</Grid>
|
</Grid>
|
||||||
{data.rootCA !== undefined && (
|
|
||||||
<Grid item xs={12} sm={6}>
|
|
||||||
<ValidatedPasswordField
|
|
||||||
name="rootCA"
|
|
||||||
label={LL.CERT()}
|
|
||||||
fullWidth
|
|
||||||
variant="outlined"
|
|
||||||
value={data.rootCA}
|
|
||||||
onChange={updateFormValue}
|
|
||||||
margin="normal"
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
)}
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
{data.enableTLS !== undefined && (
|
||||||
|
<BlockFormControlLabel
|
||||||
|
control={<Checkbox name="enableTLS" checked={data.enableTLS} onChange={updateFormValue} />}
|
||||||
|
label={LL.ENABLE_TLS()}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{data.enableTLS === true && (
|
||||||
|
<ValidatedPasswordField
|
||||||
|
name="rootCA"
|
||||||
|
label={LL.CERT()}
|
||||||
|
fullWidth
|
||||||
|
variant="outlined"
|
||||||
|
value={data.rootCA}
|
||||||
|
onChange={updateFormValue}
|
||||||
|
margin="normal"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<BlockFormControlLabel
|
<BlockFormControlLabel
|
||||||
control={<Checkbox name="clean_session" checked={data.clean_session} onChange={updateFormValue} />}
|
control={<Checkbox name="clean_session" checked={data.clean_session} onChange={updateFormValue} />}
|
||||||
|
|||||||
@@ -323,7 +323,8 @@ const de: Translation = {
|
|||||||
WRITEABLE: 'Schreibbar',
|
WRITEABLE: 'Schreibbar',
|
||||||
SHOWING: 'Anzeigen von',
|
SHOWING: 'Anzeigen von',
|
||||||
SEARCH: 'Suche',
|
SEARCH: 'Suche',
|
||||||
CERT: 'TLS Zertifikat (Freilassen um TLS zu deaktivieren)',
|
CERT: 'TLS Zertifikat (Freilassen für unsichere Verbindung)',
|
||||||
|
ENABLE_TLS: 'Aktiviere TLS',
|
||||||
ON: 'An',
|
ON: 'An',
|
||||||
OFF: 'Aus',
|
OFF: 'Aus',
|
||||||
POLARITY: 'Polarität',
|
POLARITY: 'Polarität',
|
||||||
|
|||||||
@@ -323,7 +323,8 @@ const en: Translation = {
|
|||||||
WRITEABLE: 'Writeable',
|
WRITEABLE: 'Writeable',
|
||||||
SHOWING: 'Showing',
|
SHOWING: 'Showing',
|
||||||
SEARCH: 'Search',
|
SEARCH: 'Search',
|
||||||
CERT: 'TLS root certificate (leave blank to disable TLS)',
|
CERT: 'TLS root certificate (leave blank for insecure)',
|
||||||
|
ENABLE_TLS: 'Enable TLS',
|
||||||
ON: 'On',
|
ON: 'On',
|
||||||
OFF: 'Off',
|
OFF: 'Off',
|
||||||
POLARITY: 'Polarity',
|
POLARITY: 'Polarity',
|
||||||
|
|||||||
@@ -323,7 +323,8 @@ const fr: Translation = {
|
|||||||
WRITEABLE: 'Writeable', // TODO translate
|
WRITEABLE: 'Writeable', // TODO translate
|
||||||
SHOWING: 'Showing', // TODO translate
|
SHOWING: 'Showing', // TODO translate
|
||||||
SEARCH: 'Search', // TODO translate
|
SEARCH: 'Search', // TODO translate
|
||||||
CERT: 'TLS root certificate (leave blank to disable TLS)', // TODO translate
|
CERT: 'TLS root certificate (leave blank for insecure)', // TODO translate
|
||||||
|
ENABLE_TLS: 'Activer TLS',
|
||||||
ON: 'On', // TODO translate
|
ON: 'On', // TODO translate
|
||||||
OFF: 'Off', // TODO translate
|
OFF: 'Off', // TODO translate
|
||||||
POLARITY: 'Polarity', // TODO translate
|
POLARITY: 'Polarity', // TODO translate
|
||||||
|
|||||||
@@ -325,7 +325,8 @@ const it: Translation = {
|
|||||||
WRITEABLE: 'Scrivibile',
|
WRITEABLE: 'Scrivibile',
|
||||||
SHOWING: 'Visualizza',
|
SHOWING: 'Visualizza',
|
||||||
SEARCH: 'Ricerca',
|
SEARCH: 'Ricerca',
|
||||||
CERT: 'TLS root certificate (leave blank to disable TLS)', // TODO translate
|
CERT: 'TLS root certificate (leave blank for insecure)', // TODO translate
|
||||||
|
ENABLE_TLS: 'Abilita TLS',
|
||||||
ON: 'On', // TODO translate
|
ON: 'On', // TODO translate
|
||||||
OFF: 'Off', // TODO translate
|
OFF: 'Off', // TODO translate
|
||||||
POLARITY: 'Polarity', // TODO translate
|
POLARITY: 'Polarity', // TODO translate
|
||||||
|
|||||||
@@ -323,7 +323,8 @@ const nl: Translation = {
|
|||||||
WRITEABLE: 'Beschrijfbare',
|
WRITEABLE: 'Beschrijfbare',
|
||||||
SHOWING: 'Tonen',
|
SHOWING: 'Tonen',
|
||||||
SEARCH: 'Zoek',
|
SEARCH: 'Zoek',
|
||||||
CERT: 'TLS rootcertificaat (laat leeg om TLS uit te schakelen)',
|
CERT: 'TLS rootcertificaat (laat leeg om TLS-insecure)', // TODO translate
|
||||||
|
ENABLE_TLS: 'Activeer TLS',
|
||||||
ON: 'On', // TODO translate
|
ON: 'On', // TODO translate
|
||||||
OFF: 'Off', // TODO translate
|
OFF: 'Off', // TODO translate
|
||||||
POLARITY: 'Polarity', // TODO translate
|
POLARITY: 'Polarity', // TODO translate
|
||||||
|
|||||||
@@ -323,7 +323,8 @@ const no: Translation = {
|
|||||||
WRITEABLE: 'Writeable', // TODO translate
|
WRITEABLE: 'Writeable', // TODO translate
|
||||||
SHOWING: 'Showing', // TODO translate
|
SHOWING: 'Showing', // TODO translate
|
||||||
SEARCH: 'Search', // TODO translate
|
SEARCH: 'Search', // TODO translate
|
||||||
CERT: 'TLS root certificate (leave blank to disable TLS)', // TODO translate
|
CERT: 'TLS root certificate (leave blank for insecure)', // TODO translate
|
||||||
|
ENABLE_TLS: 'Aktiviser TLS',
|
||||||
ON: 'On', // TODO translate
|
ON: 'On', // TODO translate
|
||||||
OFF: 'Off', // TODO translate
|
OFF: 'Off', // TODO translate
|
||||||
POLARITY: 'Polarity', // TODO translate
|
POLARITY: 'Polarity', // TODO translate
|
||||||
|
|||||||
@@ -323,7 +323,8 @@ const pl: BaseTranslation = {
|
|||||||
WRITEABLE: 'zapisywalna',
|
WRITEABLE: 'zapisywalna',
|
||||||
SHOWING: 'Wyświetlane',
|
SHOWING: 'Wyświetlane',
|
||||||
SEARCH: 'Szukaj',
|
SEARCH: 'Szukaj',
|
||||||
CERT: 'Certyfikat główny TLS (pozostaw puste zby wyłączyć TLS)',
|
CERT: 'Certyfikat główny TLS (pozostaw puste zby wyłączyć TLS-insecure)',
|
||||||
|
ENABLE_TLS: 'Włącz wsparcie dla TLS',
|
||||||
ON: 'włączony',
|
ON: 'włączony',
|
||||||
OFF: 'wyłączony',
|
OFF: 'wyłączony',
|
||||||
POLARITY: 'Typ przekaźnika',
|
POLARITY: 'Typ przekaźnika',
|
||||||
|
|||||||
@@ -323,7 +323,8 @@ const sv: Translation = {
|
|||||||
WRITEABLE: 'Writeable', // TODO translate
|
WRITEABLE: 'Writeable', // TODO translate
|
||||||
SHOWING: 'Showing', // TODO translate
|
SHOWING: 'Showing', // TODO translate
|
||||||
SEARCH: 'Search', // TODO translate
|
SEARCH: 'Search', // TODO translate
|
||||||
CERT: 'TLS root certificate (leave blank to disable TLS)', // TODO translate
|
CERT: 'TLS root certificate (leave blank for insecure)', // TODO translate
|
||||||
|
ENABLE_TLS: 'Aktivera TLS',
|
||||||
ON: 'On', // TODO translate
|
ON: 'On', // TODO translate
|
||||||
OFF: 'Off', // TODO translate
|
OFF: 'Off', // TODO translate
|
||||||
POLARITY: 'Polarity', // TODO translate
|
POLARITY: 'Polarity', // TODO translate
|
||||||
|
|||||||
@@ -323,7 +323,8 @@ const tr: Translation = {
|
|||||||
WRITEABLE: 'Writeable', // TODO translate
|
WRITEABLE: 'Writeable', // TODO translate
|
||||||
SHOWING: 'Showing', // TODO translate
|
SHOWING: 'Showing', // TODO translate
|
||||||
SEARCH: 'Search', // TODO translate
|
SEARCH: 'Search', // TODO translate
|
||||||
CERT: 'TLS root certificate (leave blank to disable TLS)', // TODO translate
|
CERT: 'TLS root certificate (leave blank for insecure)',
|
||||||
|
ENABLE_TLS: 'TLS deveye al',
|
||||||
ON: 'On', // TODO translate
|
ON: 'On', // TODO translate
|
||||||
OFF: 'Off', // TODO translate
|
OFF: 'Off', // TODO translate
|
||||||
POLARITY: 'Polarity', // TODO translate
|
POLARITY: 'Polarity', // TODO translate
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export interface MqttSettings {
|
|||||||
port: number;
|
port: number;
|
||||||
base: string;
|
base: string;
|
||||||
rootCA?: string;
|
rootCA?: string;
|
||||||
|
enableTLS?: boolean;
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
client_id: string;
|
client_id: string;
|
||||||
|
|||||||
@@ -1606,14 +1606,14 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@types/react@npm:^18.2.40":
|
"@types/react@npm:^18.2.41":
|
||||||
version: 18.2.40
|
version: 18.2.41
|
||||||
resolution: "@types/react@npm:18.2.40"
|
resolution: "@types/react@npm:18.2.41"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/prop-types": "npm:*"
|
"@types/prop-types": "npm:*"
|
||||||
"@types/scheduler": "npm:*"
|
"@types/scheduler": "npm:*"
|
||||||
csstype: "npm:^3.0.2"
|
csstype: "npm:^3.0.2"
|
||||||
checksum: 323c319461482ad17b4813fec8641a4167361f42164757b64dbe27db379ae8fd98f3811a301f4abce0c17ce53a83c549db3ba3008e54d2a422a0656bddd72440
|
checksum: 31a498a56ad3e825ae13799355fe49042c0cdbbe6f40003f39b6b9cf847ba1669393c22ba60e97b1072cf1c002b15432082cdd17e47c948430bdc1f0864829b9
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -1794,7 +1794,7 @@ __metadata:
|
|||||||
"@types/imagemin": "npm:^8.0.5"
|
"@types/imagemin": "npm:^8.0.5"
|
||||||
"@types/lodash-es": "npm:^4.17.12"
|
"@types/lodash-es": "npm:^4.17.12"
|
||||||
"@types/node": "npm:^20.10.2"
|
"@types/node": "npm:^20.10.2"
|
||||||
"@types/react": "npm:^18.2.40"
|
"@types/react": "npm:^18.2.41"
|
||||||
"@types/react-dom": "npm:^18.2.17"
|
"@types/react-dom": "npm:^18.2.17"
|
||||||
"@types/react-router-dom": "npm:^5.3.3"
|
"@types/react-router-dom": "npm:^5.3.3"
|
||||||
"@typescript-eslint/eslint-plugin": "npm:^6.13.1"
|
"@typescript-eslint/eslint-plugin": "npm:^6.13.1"
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ void MqttSettingsService::startClient() {
|
|||||||
static bool isSecure = false;
|
static bool isSecure = false;
|
||||||
if (_mqttClient != nullptr) {
|
if (_mqttClient != nullptr) {
|
||||||
// do we need to change the client?
|
// do we need to change the client?
|
||||||
if ((isSecure && _state.rootCA.length() > 0) || (!isSecure && _state.rootCA.length() == 0)) {
|
if ((isSecure && _state.enableTLS) || (!isSecure && _state.enableTLS)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete _mqttClient;
|
delete _mqttClient;
|
||||||
}
|
}
|
||||||
#if CONFIG_IDF_TARGET_ESP32S3
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
if (_state.rootCA.length() > 0) {
|
if (_state.enableTLS) {
|
||||||
isSecure = true;
|
isSecure = true;
|
||||||
_mqttClient = static_cast<MqttClient *>(new espMqttClientSecure(espMqttClientTypes::UseInternalTask::NO));
|
_mqttClient = static_cast<MqttClient *>(new espMqttClientSecure(espMqttClientTypes::UseInternalTask::NO));
|
||||||
if (_state.rootCA == "insecure") {
|
if (_state.rootCA == "insecure") {
|
||||||
@@ -100,7 +100,7 @@ const char * MqttSettingsService::getClientId() {
|
|||||||
|
|
||||||
void MqttSettingsService::setWill(const char * topic) {
|
void MqttSettingsService::setWill(const char * topic) {
|
||||||
#if CONFIG_IDF_TARGET_ESP32S3
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
if (_state.rootCA.length() > 0) {
|
if (_state.enableTLS) {
|
||||||
static_cast<espMqttClientSecure *>(_mqttClient)->setWill(topic, 1, true, "offline");
|
static_cast<espMqttClientSecure *>(_mqttClient)->setWill(topic, 1, true, "offline");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ void MqttSettingsService::setWill(const char * topic) {
|
|||||||
|
|
||||||
void MqttSettingsService::onMessage(espMqttClientTypes::OnMessageCallback callback) {
|
void MqttSettingsService::onMessage(espMqttClientTypes::OnMessageCallback callback) {
|
||||||
#if CONFIG_IDF_TARGET_ESP32S3
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
if (_state.rootCA.length() > 0) {
|
if (_state.enableTLS) {
|
||||||
static_cast<espMqttClientSecure *>(_mqttClient)->onMessage(callback);
|
static_cast<espMqttClientSecure *>(_mqttClient)->onMessage(callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ bool MqttSettingsService::configureMqtt() {
|
|||||||
if (_state.enabled && emsesp::EMSESP::system_.network_connected() && !_state.host.isEmpty()) {
|
if (_state.enabled && emsesp::EMSESP::system_.network_connected() && !_state.host.isEmpty()) {
|
||||||
_reconfigureMqtt = false;
|
_reconfigureMqtt = false;
|
||||||
#if CONFIG_IDF_TARGET_ESP32S3
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
if (_state.rootCA.length() > 0) {
|
if (_state.enableTLS) {
|
||||||
// emsesp::EMSESP::logger().info("Start secure MQTT with rootCA");
|
// emsesp::EMSESP::logger().info("Start secure MQTT with rootCA");
|
||||||
static_cast<espMqttClientSecure *>(_mqttClient)->setServer(retainCstr(_state.host.c_str(), &_retainedHost), _state.port);
|
static_cast<espMqttClientSecure *>(_mqttClient)->setServer(retainCstr(_state.host.c_str(), &_retainedHost), _state.port);
|
||||||
if (_state.username.length() > 0) {
|
if (_state.username.length() > 0) {
|
||||||
@@ -217,7 +217,8 @@ bool MqttSettingsService::configureMqtt() {
|
|||||||
|
|
||||||
void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
|
void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
|
||||||
#if CONFIG_IDF_TARGET_ESP32S3
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
root["rootCA"] = settings.rootCA;
|
root["enableTLS"] = settings.enableTLS;
|
||||||
|
root["rootCA"] = settings.rootCA;
|
||||||
#endif
|
#endif
|
||||||
root["enabled"] = settings.enabled;
|
root["enabled"] = settings.enabled;
|
||||||
root["host"] = settings.host;
|
root["host"] = settings.host;
|
||||||
@@ -253,7 +254,8 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
|||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
#if CONFIG_IDF_TARGET_ESP32S3
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
newSettings.rootCA = root["rootCA"] | "";
|
newSettings.enableTLS = root["enableTLS"] | false;
|
||||||
|
newSettings.rootCA = root["rootCA"] | "";
|
||||||
#endif
|
#endif
|
||||||
newSettings.enabled = root["enabled"] | FACTORY_MQTT_ENABLED;
|
newSettings.enabled = root["enabled"] | FACTORY_MQTT_ENABLED;
|
||||||
newSettings.host = root["host"] | FACTORY_MQTT_HOST;
|
newSettings.host = root["host"] | FACTORY_MQTT_HOST;
|
||||||
@@ -377,10 +379,10 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
|||||||
newSettings.rootCA.replace("-----BEGIN CERTIFICATE-----", "");
|
newSettings.rootCA.replace("-----BEGIN CERTIFICATE-----", "");
|
||||||
newSettings.rootCA.replace("-----END CERTIFICATE-----", "");
|
newSettings.rootCA.replace("-----END CERTIFICATE-----", "");
|
||||||
newSettings.rootCA.replace(" ", "");
|
newSettings.rootCA.replace(" ", "");
|
||||||
if (newSettings.rootCA.length() == 0 && newSettings.port > 8800) {
|
if (newSettings.rootCA.length() == 0 && newSettings.enableTLS) {
|
||||||
newSettings.rootCA = "insecure";
|
newSettings.rootCA = "insecure";
|
||||||
}
|
}
|
||||||
if (newSettings.rootCA != settings.rootCA) {
|
if (newSettings.enableTLS != settings.enableTLS || newSettings.rootCA != settings.rootCA) {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ class MqttSettings {
|
|||||||
String host;
|
String host;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
String rootCA;
|
String rootCA;
|
||||||
|
bool enableTLS;
|
||||||
|
|
||||||
// username and password
|
// username and password
|
||||||
String username;
|
String username;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define EMSESP_APP_VERSION "3.6.5-dev.2"
|
#define EMSESP_APP_VERSION "3.6.5-dev.3"
|
||||||
|
|||||||
Reference in New Issue
Block a user