Skip to content

Commit 051de32

Browse files
committed
cloud client
1 parent b27d1a3 commit 051de32

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

runs/lt

6.79 MB
Binary file not shown.

runs/remoteSupport/remoteSupport.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
BASE_TOPIC = "openWB-remote/"
1111
REMOTE_SUPPORT_TOPIC = BASE_TOPIC + "support"
1212
REMOTE_PARTNER_TOPIC = BASE_TOPIC + "partner"
13+
CLOUD_TOPIC = BASE_TOPIC + "cloud"
1314
support_tunnel: Popen = None
1415
partner_tunnel: Popen = None
1516

@@ -51,6 +52,7 @@ def is_tunnel_closed(tunnel: Popen) -> bool:
5152

5253
global support_tunnel
5354
global partner_tunnel
55+
global cloud_tunnel
5456
payload = msg.payload.decode("utf-8")
5557
if len(payload) > 0:
5658
log.debug("Topic: %s, Message: %s", msg.topic, payload)
@@ -75,7 +77,6 @@ def is_tunnel_closed(tunnel: Popen) -> bool:
7577
f"{port}:localhost:22", f"{user}@remotesupport.openwb.de"])
7678
log.info(f"tunnel running with pid {support_tunnel.pid}")
7779
else:
78-
log.info("unknown message: " + payload)
7980
elif msg.topic == REMOTE_PARTNER_TOPIC:
8081
if payload == 'stop':
8182
if partner_tunnel is None:
@@ -101,6 +102,31 @@ def is_tunnel_closed(tunnel: Popen) -> bool:
101102
log.info(f"tunnel running with pid {partner_tunnel.pid}")
102103
else:
103104
log.info("unknown message: " + payload)
105+
elif msg.topic == CLOUD_TOPIC:
106+
log.info("1")
107+
if payload == 'stop':
108+
if cloud_tunnel is None:
109+
log.error("received stop cloud message but tunnel is not running")
110+
else:
111+
log.info("stop cloud tunnel")
112+
cloud_tunnel.terminate()
113+
cloud_tunnel.wait(timeout=3)
114+
cloud_tunnel = None
115+
elif re.match(r'^([^;]+)(?:;([a-zA-Z0-9]+)(?:;([a-zA-Z0-9]+))?)?$', payload):
116+
#elif payload != 'stio':
117+
if is_tunnel_closed(partner_tunnel):
118+
splitted = payload.split(";")
119+
if len(splitted) != 3:
120+
log.error("invalid number of settings received!")
121+
else:
122+
token = splitted[0]
123+
cloudnode = splitted[1]
124+
user = splitted[2]
125+
log.info("start cloud tunnel" + token + cloudnode)
126+
cloud_tunnel = Popen(["/var/www/html/openWB/runs/lt", "-h", "https://" + cloudnode + ".openwb.de/", "-p", "80", "-s", token])
127+
log.info(f"cloud tunnel running with pid {cloud_tunnel.pid}")
128+
else:
129+
log.info("unknown message: " + payload)
104130
# clear topic
105131
client.publish(msg.topic, "", qos=2, retain=True)
106132

0 commit comments

Comments
 (0)