From 9c76c9f79c1ee4b0af9c1b727d0d0320a49953ee Mon Sep 17 00:00:00 2001 From: Andreas Brett Date: Sun, 27 Aug 2023 13:53:49 +0200 Subject: [PATCH 1/3] update parameters - add verifyssl (should be an option to pass to pyunify.controller) - remove protocol (not used in pyunify.controller) --- front/plugins/unifi_import/script.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/front/plugins/unifi_import/script.py b/front/plugins/unifi_import/script.py index 4bc9bc96..8935c43b 100755 --- a/front/plugins/unifi_import/script.py +++ b/front/plugins/unifi_import/script.py @@ -2,7 +2,7 @@ # Inspired by https://github.com/stevehoek/Pi.Alert # Example call -# python3 /home/pi/pialert/front/plugins/unifi_import/script.py username=pialert password=passw0rd host=192.168.1.1 site=default protocol=https:// port=8443 +# python3 /home/pi/pialert/front/plugins/unifi_import/script.py username=pialert password=passw0rd host=192.168.1.1 site=sdefault port=8443 verifyssl=false version=v5 from __future__ import unicode_literals from time import sleep, time, strftime @@ -31,8 +31,7 @@ last_run = curPath + '/last_result.log' def main(): # init global variables - global UNIFI_USERNAME, UNIFI_PASSWORD, UNIFI_HOST - global UNIFI_SITES, PORT, PROTOCOL, VERSION + global UNIFI_USERNAME, UNIFI_PASSWORD, UNIFI_HOST, UNIFI_SITES, PORT, VERIFYSSL, VERSION last_run_logfile = open(last_run, 'a') @@ -45,8 +44,8 @@ def main(): parser.add_argument('password', action="store", help="Password used to login into the UNIFI controller") parser.add_argument('host', action="store", help="Host url or IP address where the UNIFI controller is hosted (excluding http://)") parser.add_argument('sites', action="store", help="Name of the sites (usually 'default', check the URL in your UniFi controller UI). Separated by comma (,) if passing multiple sites") - parser.add_argument('protocol', action="store", help="https:// or http://") parser.add_argument('port', action="store", help="Usually 8443") + parser.add_argument('verifyssl', action="store", help="verify SSL certificate [true|false]") parser.add_argument('version', action="store", help="The base version of the controller API [v4|v5|unifiOS|UDMP-unifiOS]") values = parser.parse_args() @@ -60,8 +59,8 @@ def main(): UNIFI_PASSWORD = values.password.split('=')[1] UNIFI_HOST = values.host.split('=')[1] UNIFI_SITES = values.sites.split('=')[1] - PROTOCOL = values.protocol.split('=')[1] PORT = values.port.split('=')[1] + VERIFYSSL = values.verifyssl.split('=')[1] VERSION = values.version.split('=')[1] newEntries = get_entries(newEntries) @@ -75,6 +74,7 @@ def main(): # ----------------------------------------------------------------------------- def get_entries(newEntries): + global VERIFYSSL sites = [] @@ -84,10 +84,14 @@ def get_entries(newEntries): else: sites.append(UNIFI_SITES) + if (VERIFYSSL.upper() == "TRUE"): + VERIFYSSL = True + else: + VERIFYSSL = False for site in sites: - c = Controller(UNIFI_HOST, UNIFI_USERNAME, UNIFI_PASSWORD, version=VERSION, ssl_verify=False, site_id=site ) + c = Controller(UNIFI_HOST, UNIFI_USERNAME, UNIFI_PASSWORD, port=PORT, version=VERSION, ssl_verify=VERIFYSSL, site_id=site ) for ap in c.get_aps(): From 396416ad2941f0eadbc75067317bbe3fa6134492 Mon Sep 17 00:00:00 2001 From: Andreas Brett Date: Sun, 27 Aug 2023 14:07:36 +0200 Subject: [PATCH 2/3] Update config.json --- front/plugins/unifi_import/config.json | 58 +++++++++++++------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/front/plugins/unifi_import/config.json b/front/plugins/unifi_import/config.json index d1ec3d85..7fd44907 100755 --- a/front/plugins/unifi_import/config.json +++ b/front/plugins/unifi_import/config.json @@ -60,16 +60,16 @@ "type" : "setting", "value" : "UNFIMP_sites" }, - { - "name" : "protocol", - "type" : "setting", - "value" : "UNFIMP_protocol" - }, { "name" : "port", "type" : "setting", "value" : "UNFIMP_port" }, + { + "name" : "verifyssl", + "type" : "setting", + "value" : "UNFIMP_verifyssl" + }, { "name" : "version", "type" : "setting", @@ -348,7 +348,7 @@ { "function": "CMD", "type": "text", - "default_value":"python3 /home/pi/pialert/front/plugins/unifi_import/script.py username={username} password={password} host={host} sites={sites} protocol={protocol} port={port} version={version}", + "default_value":"python3 /home/pi/pialert/front/plugins/unifi_import/script.py username={username} password={password} host={host} sites={sites} port={port} verifyssl={verifyssl} version={version}", "options": [], "localized": ["name", "description"], "name" : [{ @@ -414,29 +414,6 @@ "string" : "La contraseña utilizada para iniciar sesión en su controlador UNIFI." }] }, - { - "function": "protocol", - "type": "text.select", - "default_value":"https://", - "options": ["https://", "http://"], - "localized": ["name", "description"], - "name" : [{ - "language_code":"en_us", - "string" : "Protocol" - }, - { - "language_code":"es_es", - "string" : "Protocolo" - }], - "description": [{ - "language_code":"en_us", - "string" : "The protocol to use to access the controller." - }, - { - "language_code":"es_es", - "string" : "El protocolo a utilizar para acceder al controlador." - }] - }, { "function": "host", "type": "text", @@ -483,6 +460,29 @@ "string" : "El número de puerto donde se ejecuta el controlador UNIFI. Normalmente es 8443." }] }, + { + "function": "verifyssl", + "type": "text", + "default_value":"false", + "options": [], + "localized": ["name", "description"], + "name" : [{ + "language_code":"en_us", + "string" : "verify SSL" + }, + { + "language_code": "es_es", + "string": "verificar SSL" + }], + "description": [{ + "language_code":"en_us", + "string" : "verify SSL certificate validity true|false." + }, + { + "language_code":"es_es", + "string" : "verificar la validez del certificado SSL true|false." + }] + }, { "function": "version", "type": "text", From eb7282201b34f4c4d9b6979606410e79de370954 Mon Sep 17 00:00:00 2001 From: Andreas Brett Date: Sun, 27 Aug 2023 14:14:55 +0200 Subject: [PATCH 3/3] typo parameter is `sites` not `site` --- front/plugins/unifi_import/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/plugins/unifi_import/script.py b/front/plugins/unifi_import/script.py index 8935c43b..f5c61519 100755 --- a/front/plugins/unifi_import/script.py +++ b/front/plugins/unifi_import/script.py @@ -2,7 +2,7 @@ # Inspired by https://github.com/stevehoek/Pi.Alert # Example call -# python3 /home/pi/pialert/front/plugins/unifi_import/script.py username=pialert password=passw0rd host=192.168.1.1 site=sdefault port=8443 verifyssl=false version=v5 +# python3 /home/pi/pialert/front/plugins/unifi_import/script.py username=pialert password=passw0rd host=192.168.1.1 sites=sdefault port=8443 verifyssl=false version=v5 from __future__ import unicode_literals from time import sleep, time, strftime