Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/helpermodules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,11 @@ def addConsumer(self, connection_id: str, payload: dict) -> None:
Pub().pub(f"openWB/set/consumer/{new_id}/usage", asdict(Usage(type=consumer_default["usage"][0])))
self.max_id_hierarchy = new_id
Pub().pub("openWB/set/command/max_id/hierarchy", new_id)
# add ACL roles for consumer access, if user management is active
if SubData.system_data["system"].data["security"]["user_management_active"]:
add_acl_role("consumer-<id>-access", new_id)
if consumer_default["type"] == "mqtt":
add_acl_role("consumer-<id>-write-access", new_id)
pub_user_message(
payload, connection_id,
f'Neues Gerät vom Typ \'{payload["data"]["type"]}\' mit ID \'{new_id}\' hinzugefügt.',
Expand All @@ -1224,6 +1229,10 @@ def removeConsumer(self, connection_id: str, payload: dict) -> None:
Pub().pub("openWB/set/counter/get/hierarchy", SubData.counter_all_data.data.get.hierarchy)
SubData.counter_all_data.remove_loadmanagement_prio_item(ComponentType.CONSUMER, payload["data"]["consumer_id"])
Pub().pub("openWB/set/counter/get/loadmanagement_prios", SubData.counter_all_data.data.get.loadmanagement_prios)
# remove ACL roles for consumer access, if user management is active
if SubData.system_data["system"].data["security"]["user_management_active"]:
remove_acl_role("consumer-<id>-access", payload["data"]["consumer_id"])
remove_acl_role("consumer-<id>-write-access", payload["data"]["consumer_id"])
pub_user_message(payload, connection_id,
f'Verbraucher mit ID \'{payload["data"]["consumer_id"]}\' gelöscht.', MessageType.SUCCESS)

Expand Down
4 changes: 4 additions & 0 deletions packages/helpermodules/mosquitto_dynsec/mosquitto_dynsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ def check_roles_at_start():
add_acl_role("vehicle-<id>-access", ev.num)
if ev.soc_module is not None and ev.soc_module.vehicle_config.type == "mqtt":
add_acl_role("vehicle-<id>-write-access", ev.num)
for consumer in SubData.consumer_data.values():
add_acl_role("consumer-<id>-access", consumer.num)
if consumer.data.module is not None and consumer.data.module.type == "mqtt":
add_acl_role("consumer-<id>-write-access", consumer.num)
Comment on lines +146 to +149
for io_action in SubData.io_actions.actions.values():
add_acl_role("io-action-<id>-access", io_action.config.id)
for key, value in SubData.system_data.items():
Expand Down
23 changes: 22 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from helpermodules.measurement_logging.process_log import get_default_charge_log_columns, get_totals
from helpermodules.measurement_logging.write_log import get_names
from helpermodules.messaging import MessageType, pub_system_message
from helpermodules.mosquitto_dynsec.role_handler import add_acl_role, remove_acl_role
from helpermodules.pub import Pub
from helpermodules.utils.json_file_handler import write_and_check
from helpermodules.utils.run_command import run_command
Expand Down Expand Up @@ -58,7 +59,7 @@

class UpdateConfig:

DATASTORE_VERSION = 148
DATASTORE_VERSION = 149

valid_topic = [
"^openWB/bat/config/bat_control_activated$",
Expand Down Expand Up @@ -3864,3 +3865,23 @@ def upgrade(topic: str, payload) -> Optional[dict]:
return {topic: NO_MODULE}
self._loop_all_received_topics(upgrade)
self._append_datastore_version(148)

def upgrade_datastore_149(self) -> None:
user_management_active = decode_payload(
self.all_received_topics.get("openWB/system/security/user_management_active")
)
if user_management_active is True:
for topic, payload in self.all_received_topics.items():
match = re.search(r"^openWB/consumer/(\d+)/module$", topic)
if match is None:
continue
consumer_id = int(match.group(1))
consumer_module = decode_payload(payload)
consumer_type = consumer_module.get("type") if isinstance(consumer_module, dict) else None

add_acl_role("consumer-<id>-access", consumer_id)
if consumer_type == "mqtt":
add_acl_role("consumer-<id>-write-access", consumer_id)
else:
remove_acl_role("consumer-<id>-write-access", consumer_id)
self._append_datastore_version(149)
Loading