Skip to content

Commit 90017ee

Browse files
committed
Option to disable API for MQTT
1 parent c5bada6 commit 90017ee

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

include/mqtt/mqtt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ private slots:
5656
QTimer* _retryTimer;
5757
bool _initialized;
5858
QJsonArray _resultArray;
59+
bool _disableApiAccess;
5960

6061
Logger* _log;
6162
QMQTT::Client* _clientInstance;

sources/base/schema/schema-mqtt.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
},
3939
"password" : {
4040
"type": "string",
41+
"format": "password",
4142
"title":"edt_conf_mqtt_password_title",
4243
"required" : true,
4344
"default" : "",
@@ -74,6 +75,15 @@
7475
"default" : "",
7576
"propertyOrder" : 8
7677
},
78+
"disableApiAccess" :
79+
{
80+
"type" : "boolean",
81+
"format": "checkbox",
82+
"title" : "edt_conf_mqtt_disableApiAccess_title",
83+
"default" : false,
84+
"required" : true,
85+
"propertyOrder" : 9
86+
},
7787
"maxRetry":
7888
{
7989
"type" : "integer",
@@ -84,7 +94,7 @@
8494
"maximum" : 120,
8595
"default" : 0,
8696
"required" : true,
87-
"propertyOrder" : 9
97+
"propertyOrder" : 10
8898
}
8999
},
90100
"additionalProperties" : false

sources/mqtt/mqtt.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mqtt::mqtt(const QJsonDocument& mqttConfig)
2424
, _currentRetry(0)
2525
, _retryTimer(nullptr)
2626
, _initialized(false)
27+
, _disableApiAccess(false)
2728
, _log(Logger::getInstance("MQTT"))
2829
, _clientInstance(nullptr)
2930
{
@@ -210,6 +211,7 @@ void mqtt::handleSettingsUpdate(settings::type type, const QJsonDocument& config
210211
_is_ssl = obj["is_ssl"].toBool(false);
211212
_ignore_ssl_errors = obj["ignore_ssl_errors"].toBool(true);
212213
_maxRetry = obj["maxRetry"].toInt(120);
214+
_disableApiAccess = obj["disableApiAccess"].toBool(false);
213215

214216
_customTopic = obj["custom_topic"].toString().trimmed();
215217
if (_customTopic.isEmpty())
@@ -233,7 +235,13 @@ void mqtt::begin()
233235
}
234236

235237
void mqtt::executeJson(QString origin, const QJsonDocument& input, QJsonDocument& result)
236-
{
238+
{
239+
if (_disableApiAccess)
240+
{
241+
Error(_log, "API access is disabled in MQTT configuration");
242+
return;
243+
}
244+
237245
HyperAPI* _hyperAPI = new HyperAPI(origin, _log, true, this);
238246

239247
_resultArray = QJsonArray();

www/i18n/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,5 +1269,7 @@
12691269
"select_ha_intro": "Select Home Assistant",
12701270
"edt_dev_spec_constantBrightness_title": "Constant brightness",
12711271
"edt_conf_reorder_displays_title": "Reorder displays",
1272-
"edt_conf_reorder_displays_expl": "Manipulate the order (permutations) of the displays until you get the correct one in multi-monitor mode"
1272+
"edt_conf_reorder_displays_expl": "Manipulate the order (permutations) of the displays until you get the correct one in multi-monitor mode",
1273+
"edt_conf_mqtt_disableApiAccess_title" : "Disable API access",
1274+
"edt_conf_mqtt_disableApiAccess_expl" : "Block execution of API commands sent via MQTT"
12731275
}

0 commit comments

Comments
 (0)