mirror of
https://github.com/simbelmas/gotify-dunst.git
synced 2026-01-19 14:35:23 +01:00
option to support unsecure protocols
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
[server]
|
[server]
|
||||||
|
ssl=true
|
||||||
domain=push.example.com
|
domain=push.example.com
|
||||||
token=C2Un.92TZBzsukg
|
token=C2Un.92TZBzsukg
|
||||||
|
|||||||
17
main.py
17
main.py
@@ -27,6 +27,7 @@ if domain in [ "push.example.com", None]:
|
|||||||
|
|
||||||
token = config.get('server','token')
|
token = config.get('server','token')
|
||||||
|
|
||||||
|
ssl = "true" == config.get('server','ssl', fallback='false').lower()
|
||||||
|
|
||||||
path = "{}/.cache/gotify-dunst".format(home)
|
path = "{}/.cache/gotify-dunst".format(home)
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
@@ -37,13 +38,18 @@ def get_picture(appid):
|
|||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
return imgPath
|
return imgPath
|
||||||
else:
|
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")
|
req.add_header("User-Agent", "Mozilla/5.0")
|
||||||
r = json.loads(urlopen(req).read())
|
r = json.loads(urlopen(req).read())
|
||||||
for i in r:
|
for i in r:
|
||||||
if i['id'] == appid:
|
if i['id'] == appid:
|
||||||
with open(imgPath, "wb") as f:
|
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")
|
req.add_header("User-Agent", "Mozilla/5.0")
|
||||||
f.write(urlopen(req).read())
|
f.write(urlopen(req).read())
|
||||||
return imgPath
|
return imgPath
|
||||||
@@ -69,7 +75,12 @@ def on_close(ws):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
websocket.enableTrace(True)
|
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_message = on_message,
|
||||||
on_error = on_error,
|
on_error = on_error,
|
||||||
on_close = on_close)
|
on_close = on_close)
|
||||||
|
|||||||
Reference in New Issue
Block a user