- Delete obsolete users

- Alter pairing credentials to allow panel pairing
- Start working on panel workflow
This commit is contained in:
Dorian Zedler 2021-08-23 13:59:38 +02:00
parent 23f4d4ced9
commit c8d5b4a7f3
Signed by: dozedler
GPG key ID: 989DE36109AFA354
7 changed files with 89 additions and 16 deletions

View file

@ -90,6 +90,21 @@ class MaDbHelper:
return users
def deleteUser(self, username):
if not self.userExists(username):
return False
query = "DELETE FROM `vmq_auth_acl` WHERE username=%s;"
self.mysqlCur.execute(
query,
(username)
)
self.mysqlConn.commit()
return True
def _updateUser(self, username, password, publishAclPatterns, subscribeAclPatterns):
query = """

17
backend/mlmAccess.py Normal file → Executable file
View file

@ -1,3 +1,5 @@
#!/usr/bin/python3
import paho.mqtt.client as mqtt
from dbHelper import MaDbHelper
from pairingHandler import MaPairingHandler
@ -23,13 +25,17 @@ class MlmAccess:
self._db = MaDbHelper(self._config)
initUsers = [
("backend", self._config["MQTT_BACKEND_PASSWORD"], ["mlmAccess/#"], ["mlmAccess/#"]),
("pair-actor", self._config["PAIR_SECRET"], ["mlmAccess/pair/request/actor"], ["mlmAccess/pair/response/actor"])
("pair", self._config["PAIR_SECRET"], ["mlmAccess/pair/request/#"], ["mlmAccess/pair/response/#"])
]
for username, password, publishAclPatterns, subscribeAclPatterns in initUsers:
if not self._db.addUser(username, password, publishAclPatterns, subscribeAclPatterns):
self._db.updateUser(username, password, publishAclPatterns, subscribeAclPatterns)
obsoleteSystemUsers = ["pair-actor"]
for username in obsoleteSystemUsers:
self._db.deleteUser(username)
def _initMqtt(self):
logging.info("Initializing MQTT")
self._mqtt = client = mqtt.Client(client_id="backend")
@ -51,8 +57,13 @@ class MlmAccess:
for user in self._db.getAllUsers():
if user.startswith("actor-"):
actorSubject = f"mlmAccess/actor/{user.replace('actor-', '')}/status"
logging.info(f"* {actorSubject}")
client.subscribe(actorSubject)
elif user.startswith("panel-"):
actorSubject = "mlmAccess/panel"
else:
continue
logging.info(f"* {actorSubject}")
client.subscribe(actorSubject)
# call hooks of child objects
self._pairingHanlder._mqttOnConnect(client, userdata, flags, rc)

View file

@ -8,6 +8,9 @@ class MaPairingHandler:
def handlePairingRequest(self, topic, message):
if "actor" in topic:
self._handleActorPairRequest(message)
elif "panel" in topic:
pass
#self.
else:
logging.warn(f"Invalid pairing request: {topic}, {message}, Device type not know.")