From 805b265c8d3285ee17269d94260af6a7090d4423 Mon Sep 17 00:00:00 2001 From: koopa1338 Date: Mon, 19 Apr 2021 19:36:10 +0200 Subject: [PATCH] option to support unsecure protocols --- gotify-dunst.conf | 1 + main.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gotify-dunst.conf b/gotify-dunst.conf index c9e1373..e500dfc 100644 --- a/gotify-dunst.conf +++ b/gotify-dunst.conf @@ -1,3 +1,4 @@ [server] +ssl=true domain=push.example.com token=C2Un.92TZBzsukg diff --git a/main.py b/main.py index fb2b953..2e4a6bf 100644 --- a/main.py +++ b/main.py @@ -27,6 +27,7 @@ if domain in [ "push.example.com", None]: token = config.get('server','token') +ssl = "true" == config.get('server','ssl', fallback='false').lower() path = "{}/.cache/gotify-dunst".format(home) if not os.path.isdir(path): @@ -37,13 +38,18 @@ def get_picture(appid): if os.path.isfile(path): return imgPath else: - req = Request("https://{}/application?token={}".format(domain, token)) + if ssl: + protocol = 'https' + else: + protocol = 'http' + + req = Request("{}://{}/application?token={}".format(protocol, domain, token)) req.add_header("User-Agent", "Mozilla/5.0") r = json.loads(urlopen(req).read()) for i in r: if i['id'] == appid: with open(imgPath, "wb") as f: - req = Request("https://{}/{}?token={}".format(domain, i['image'], token)) + req = Request("{}://{}/{}?token={}".format(protocol, domain, i['image'], token)) req.add_header("User-Agent", "Mozilla/5.0") f.write(urlopen(req).read()) return imgPath @@ -69,7 +75,12 @@ def on_close(ws): if __name__ == "__main__": websocket.enableTrace(True) - ws = websocket.WebSocketApp("wss://{}/stream?token={}".format(domain, token), + if ssl: + protocol = 'wss' + else: + protocol = 'ws' + + ws = websocket.WebSocketApp("{}://{}/stream?token={}".format(protocol, domain, token), on_message = on_message, on_error = on_error, on_close = on_close)