From a74ffff976965548283b3917883b2e37ee9c1444 Mon Sep 17 00:00:00 2001 From: Daniel Perna Date: Fri, 6 Jul 2018 22:20:21 +0200 Subject: [PATCH] Support for custom notification services --- README.md | 2 ++ changelog.txt | 1 + configurator.py | 13 ++++++++++--- settings.conf | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1747e48..80fe163 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,8 @@ If set to _somesecretkeynobodycanguess_, you can browse to `https://your.configu HTTP requests include the hostname to which the request has been made. To improve security you can set this parameter to `yourdomain.example.com`. This will check if the hostname within the request matches the one you are expecting. If it does not match, a `403 Forbidden` response will be sent. As a result attackers that scan your IP address won't be able to connect unless they know the correct hostname. Be careful with this option though, because it prohibits you from accessing the configurator directly via IP. #### ENV_PREFIX (string) To modify the default prefix for settings passed as environment variables (`HC_`) change this setting to another value that meets your demands. +#### NOTIFY_SERVICE (string) +Define a notification service from your Home Assistant setup that should be used to send notifications, e.g. `notify.mytelegram`. The default is `persistent_notification.create`. Do __NOT__ change the value of the `NOTIFY_SERVICE_DEFAULT` variable! __Note regarding `ALLOWED_NETWORKS`, `BANNED_IPS` and `BANLIMIT`__: The way this is implemented works in the following order: diff --git a/changelog.txt b/changelog.txt index b20a0fb..dbc552d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ Version 0.3.0 (2018-) - Allow passing settings via environment variables (Issue #100) @danielperna84 - Added basic git stash functionality (Issue #16) @danielperna84 - Logging warnings if used passwords are insecure (Issue #100) @danielperna84 +- Added NOTIFY_SERVICE option @danielperna84 Version 0.2.9 (2018-06-22) - Material Icons and HASS-help now open in new tab instead of modal (Issues #85 and #34) @danielperna84 diff --git a/configurator.py b/configurator.py index 2ca2667..85c54e8 100755 --- a/configurator.py +++ b/configurator.py @@ -68,6 +68,9 @@ SESAME = None VERIFY_HOSTNAME = None # Prefix for environment variables ENV_PREFIX = "HC_" +# Notification service like `notify.mytelegram`. Default is `persistent_notification.create` +NOTIFY_SERVICE_DEFAULT = "persistent_notification.create" +NOTIFY_SERVICE = NOTIFY_SERVICE_DEFAULT ### End of options LOGLEVEL = logging.INFO @@ -3386,7 +3389,7 @@ def load_settings(settingsfile): global LISTENIP, LISTENPORT, BASEPATH, SSL_CERTIFICATE, SSL_KEY, HASS_API, \ HASS_API_PASSWORD, CREDENTIALS, ALLOWED_NETWORKS, BANNED_IPS, BANLIMIT, \ DEV, IGNORE_PATTERN, DIRSFIRST, SESAME, VERIFY_HOSTNAME, ENFORCE_BASEPATH, \ - ENV_PREFIX + ENV_PREFIX, NOTIFY_SERVICE settings = {} if settingsfile: try: @@ -3429,6 +3432,7 @@ def load_settings(settingsfile): DIRSFIRST = settings.get("DIRSFIRST", DIRSFIRST) SESAME = settings.get("SESAME", SESAME) VERIFY_HOSTNAME = settings.get("VERIFY_HOSTNAME", VERIFY_HOSTNAME) + NOTIFY_SERVICE = settings.get("NOTIFY_SERVICE", NOTIFY_SERVICE_DEFAULT) def is_safe_path(basedir, path, follow_symlinks=True): if basedir is None: @@ -4537,7 +4541,7 @@ class SimpleServer(socketserver.ThreadingMixIn, socketserver.TCPServer): def __init__(self, server_address, RequestHandlerClass): socketserver.TCPServer.__init__(self, server_address, RequestHandlerClass) -def notify(service="persistent_notification.create", +def notify(service=NOTIFY_SERVICE, title="HASS Configurator", message="Notification by HASS Configurator", notification_id=None): @@ -4550,7 +4554,7 @@ def notify(service="persistent_notification.create", "title": title, "message": message } - if notification_id: + if notification_id and NOTIFY_SERVICE == NOTIFY_SERVICE_DEFAULT: data["notification_id"] = notification_id if HASS_API_PASSWORD: headers["x-ha-access"] = HASS_API_PASSWORD @@ -4579,6 +4583,7 @@ def main(args): problems = password_problems(HASS_API_PASSWORD, "HASS_API_PASSWORD") if problems: data = { + "service": NOTIFY_SERVICE, "title": "HASS Configurator - Password warning", "message": "Your HASS API password seems insecure (%i). " \ "Refer to the HASS configurator logs for further information." % problems, @@ -4591,6 +4596,7 @@ def main(args): problems = password_problems(SESAME, "SESAME") if problems: data = { + "service": NOTIFY_SERVICE, "title": "HASS Configurator - Password warning", "message": "Your SESAME seems insecure (%i). " \ "Refer to the HASS configurator logs for further information." % problems, @@ -4603,6 +4609,7 @@ def main(args): problems = password_problems(":".join(CREDENTIALS.split(":")[1:]), "CREDENTIALS") if problems: data = { + "service": NOTIFY_SERVICE, "title": "HASS Configurator - Password warning", "message": "Your CREDENTIALS seems insecure (%i). " \ "Refer to the HASS configurator logs for further information." % problems, diff --git a/settings.conf b/settings.conf index f06c747..5075e07 100644 --- a/settings.conf +++ b/settings.conf @@ -15,5 +15,6 @@ "DIRSFIRST": false, "SESAME": null, "VERIFY_HOSTNAME": null, - "ENV_PREFIX": "HC_" + "ENV_PREFIX": "HC_", + "NOTIFY_SERVICE": "persistent_notification.create" }