mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59: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/lodash-es": "^4.17.12",
|
||||
"@types/node": "^20.10.2",
|
||||
"@types/react": "^18.2.40",
|
||||
"@types/react": "^18.2.41",
|
||||
"@types/react-dom": "^18.2.17",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"alova": "^2.15.0",
|
||||
|
||||
@@ -168,20 +168,24 @@ const MqttSettingsForm: FC = () => {
|
||||
<MenuItem value={2}>2</MenuItem>
|
||||
</TextField>
|
||||
</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>
|
||||
{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
|
||||
control={<Checkbox name="clean_session" checked={data.clean_session} onChange={updateFormValue} />}
|
||||
|
||||
@@ -323,7 +323,8 @@ const de: Translation = {
|
||||
WRITEABLE: 'Schreibbar',
|
||||
SHOWING: 'Anzeigen von',
|
||||
SEARCH: 'Suche',
|
||||
CERT: 'TLS Zertifikat (Freilassen um TLS zu deaktivieren)',
|
||||
CERT: 'TLS Zertifikat (Freilassen für unsichere Verbindung)',
|
||||
ENABLE_TLS: 'Aktiviere TLS',
|
||||
ON: 'An',
|
||||
OFF: 'Aus',
|
||||
POLARITY: 'Polarität',
|
||||
|
||||
@@ -323,7 +323,8 @@ const en: Translation = {
|
||||
WRITEABLE: 'Writeable',
|
||||
SHOWING: 'Showing',
|
||||
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',
|
||||
OFF: 'Off',
|
||||
POLARITY: 'Polarity',
|
||||
|
||||
@@ -323,7 +323,8 @@ const fr: Translation = {
|
||||
WRITEABLE: 'Writeable', // TODO translate
|
||||
SHOWING: 'Showing', // 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
|
||||
OFF: 'Off', // TODO translate
|
||||
POLARITY: 'Polarity', // TODO translate
|
||||
|
||||
@@ -325,7 +325,8 @@ const it: Translation = {
|
||||
WRITEABLE: 'Scrivibile',
|
||||
SHOWING: 'Visualizza',
|
||||
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
|
||||
OFF: 'Off', // TODO translate
|
||||
POLARITY: 'Polarity', // TODO translate
|
||||
|
||||
@@ -323,7 +323,8 @@ const nl: Translation = {
|
||||
WRITEABLE: 'Beschrijfbare',
|
||||
SHOWING: 'Tonen',
|
||||
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
|
||||
OFF: 'Off', // TODO translate
|
||||
POLARITY: 'Polarity', // TODO translate
|
||||
|
||||
@@ -323,7 +323,8 @@ const no: Translation = {
|
||||
WRITEABLE: 'Writeable', // TODO translate
|
||||
SHOWING: 'Showing', // 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
|
||||
OFF: 'Off', // TODO translate
|
||||
POLARITY: 'Polarity', // TODO translate
|
||||
|
||||
@@ -323,7 +323,8 @@ const pl: BaseTranslation = {
|
||||
WRITEABLE: 'zapisywalna',
|
||||
SHOWING: 'Wyświetlane',
|
||||
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',
|
||||
OFF: 'wyłączony',
|
||||
POLARITY: 'Typ przekaźnika',
|
||||
|
||||
@@ -323,7 +323,8 @@ const sv: Translation = {
|
||||
WRITEABLE: 'Writeable', // TODO translate
|
||||
SHOWING: 'Showing', // 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
|
||||
OFF: 'Off', // TODO translate
|
||||
POLARITY: 'Polarity', // TODO translate
|
||||
|
||||
@@ -323,7 +323,8 @@ const tr: Translation = {
|
||||
WRITEABLE: 'Writeable', // TODO translate
|
||||
SHOWING: 'Showing', // 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
|
||||
OFF: 'Off', // TODO translate
|
||||
POLARITY: 'Polarity', // TODO translate
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface MqttSettings {
|
||||
port: number;
|
||||
base: string;
|
||||
rootCA?: string;
|
||||
enableTLS?: boolean;
|
||||
username: string;
|
||||
password: string;
|
||||
client_id: string;
|
||||
|
||||
@@ -1606,14 +1606,14 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/react@npm:^18.2.40":
|
||||
version: 18.2.40
|
||||
resolution: "@types/react@npm:18.2.40"
|
||||
"@types/react@npm:^18.2.41":
|
||||
version: 18.2.41
|
||||
resolution: "@types/react@npm:18.2.41"
|
||||
dependencies:
|
||||
"@types/prop-types": "npm:*"
|
||||
"@types/scheduler": "npm:*"
|
||||
csstype: "npm:^3.0.2"
|
||||
checksum: 323c319461482ad17b4813fec8641a4167361f42164757b64dbe27db379ae8fd98f3811a301f4abce0c17ce53a83c549db3ba3008e54d2a422a0656bddd72440
|
||||
checksum: 31a498a56ad3e825ae13799355fe49042c0cdbbe6f40003f39b6b9cf847ba1669393c22ba60e97b1072cf1c002b15432082cdd17e47c948430bdc1f0864829b9
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1794,7 +1794,7 @@ __metadata:
|
||||
"@types/imagemin": "npm:^8.0.5"
|
||||
"@types/lodash-es": "npm:^4.17.12"
|
||||
"@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-router-dom": "npm:^5.3.3"
|
||||
"@typescript-eslint/eslint-plugin": "npm:^6.13.1"
|
||||
|
||||
@@ -51,13 +51,13 @@ void MqttSettingsService::startClient() {
|
||||
static bool isSecure = false;
|
||||
if (_mqttClient != nullptr) {
|
||||
// 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;
|
||||
}
|
||||
delete _mqttClient;
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
if (_state.rootCA.length() > 0) {
|
||||
if (_state.enableTLS) {
|
||||
isSecure = true;
|
||||
_mqttClient = static_cast<MqttClient *>(new espMqttClientSecure(espMqttClientTypes::UseInternalTask::NO));
|
||||
if (_state.rootCA == "insecure") {
|
||||
@@ -100,7 +100,7 @@ const char * MqttSettingsService::getClientId() {
|
||||
|
||||
void MqttSettingsService::setWill(const char * topic) {
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
if (_state.rootCA.length() > 0) {
|
||||
if (_state.enableTLS) {
|
||||
static_cast<espMqttClientSecure *>(_mqttClient)->setWill(topic, 1, true, "offline");
|
||||
return;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ void MqttSettingsService::setWill(const char * topic) {
|
||||
|
||||
void MqttSettingsService::onMessage(espMqttClientTypes::OnMessageCallback callback) {
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
if (_state.rootCA.length() > 0) {
|
||||
if (_state.enableTLS) {
|
||||
static_cast<espMqttClientSecure *>(_mqttClient)->onMessage(callback);
|
||||
return;
|
||||
}
|
||||
@@ -181,7 +181,7 @@ bool MqttSettingsService::configureMqtt() {
|
||||
if (_state.enabled && emsesp::EMSESP::system_.network_connected() && !_state.host.isEmpty()) {
|
||||
_reconfigureMqtt = false;
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
if (_state.rootCA.length() > 0) {
|
||||
if (_state.enableTLS) {
|
||||
// emsesp::EMSESP::logger().info("Start secure MQTT with rootCA");
|
||||
static_cast<espMqttClientSecure *>(_mqttClient)->setServer(retainCstr(_state.host.c_str(), &_retainedHost), _state.port);
|
||||
if (_state.username.length() > 0) {
|
||||
@@ -217,7 +217,8 @@ bool MqttSettingsService::configureMqtt() {
|
||||
|
||||
void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
root["rootCA"] = settings.rootCA;
|
||||
root["enableTLS"] = settings.enableTLS;
|
||||
root["rootCA"] = settings.rootCA;
|
||||
#endif
|
||||
root["enabled"] = settings.enabled;
|
||||
root["host"] = settings.host;
|
||||
@@ -253,7 +254,8 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
||||
bool changed = false;
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
newSettings.rootCA = root["rootCA"] | "";
|
||||
newSettings.enableTLS = root["enableTLS"] | false;
|
||||
newSettings.rootCA = root["rootCA"] | "";
|
||||
#endif
|
||||
newSettings.enabled = root["enabled"] | FACTORY_MQTT_ENABLED;
|
||||
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("-----END CERTIFICATE-----", "");
|
||||
newSettings.rootCA.replace(" ", "");
|
||||
if (newSettings.rootCA.length() == 0 && newSettings.port > 8800) {
|
||||
if (newSettings.rootCA.length() == 0 && newSettings.enableTLS) {
|
||||
newSettings.rootCA = "insecure";
|
||||
}
|
||||
if (newSettings.rootCA != settings.rootCA) {
|
||||
if (newSettings.enableTLS != settings.enableTLS || newSettings.rootCA != settings.rootCA) {
|
||||
changed = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -64,6 +64,7 @@ class MqttSettings {
|
||||
String host;
|
||||
uint16_t port;
|
||||
String rootCA;
|
||||
bool enableTLS;
|
||||
|
||||
// username and password
|
||||
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