diff --git a/runs/lt-armv7l_ELF b/runs/lt-armv7l_ELF new file mode 100755 index 0000000000..d53698cd56 Binary files /dev/null and b/runs/lt-armv7l_ELF differ diff --git a/runs/lt-x86_64_ELF b/runs/lt-x86_64_ELF new file mode 100755 index 0000000000..76fc264192 Binary files /dev/null and b/runs/lt-x86_64_ELF differ diff --git a/runs/remoteSupport/remoteSupport.py b/runs/remoteSupport/remoteSupport.py index 14c2060dfa..513f37a719 100755 --- a/runs/remoteSupport/remoteSupport.py +++ b/runs/remoteSupport/remoteSupport.py @@ -4,15 +4,18 @@ from subprocess import Popen from pathlib import Path import paho.mqtt.client as mqtt +import platform BASE_PATH = Path(__file__).resolve().parents[2] RAMDISK_PATH = BASE_PATH / "ramdisk" +RUNS_PATH = BASE_PATH / "runs" BASE_TOPIC = "openWB-remote/" REMOTE_SUPPORT_TOPIC = BASE_TOPIC + "support" REMOTE_PARTNER_TOPIC = BASE_TOPIC + "partner" +CLOUD_TOPIC = BASE_TOPIC + "cloud" support_tunnel: Popen = None partner_tunnel: Popen = None - +cloud_tunnel: Popen = None logging.basicConfig( filename=str(RAMDISK_PATH / "remote_support.log"), level=logging.INFO, format='%(asctime)s: %(message)s' @@ -51,6 +54,7 @@ def is_tunnel_closed(tunnel: Popen) -> bool: global support_tunnel global partner_tunnel + global cloud_tunnel payload = msg.payload.decode("utf-8") if len(payload) > 0: log.debug("Topic: %s, Message: %s", msg.topic, payload) @@ -101,6 +105,47 @@ def is_tunnel_closed(tunnel: Popen) -> bool: log.info(f"tunnel running with pid {partner_tunnel.pid}") else: log.info("unknown message: " + payload) + elif msg.topic == CLOUD_TOPIC: + if payload == 'stop': + if cloud_tunnel is None: + log.error("received stop cloud message but tunnel is not running") + else: + log.info("stop cloud tunnel") + cloud_tunnel.terminate() + cloud_tunnel.wait(timeout=3) + cloud_tunnel = None + elif re.match(r'^([^;]+)(?:;([a-zA-Z0-9]+)(?:;([a-zA-Z0-9]+))?)?$', payload): + if is_tunnel_closed(cloud_tunnel): + splitted = payload.split(";") + if len(splitted) != 3: + log.error("invalid number of settings received!") + else: + token = splitted[0] + cloud_node = splitted[1] + user = splitted[2] + + machine = platform.machine() + bits, linkage = platform.architecture() + lt_executable = f"lt-{machine}_{linkage}" + + log.info("System Info:") + log.info(f"Architecture: ({(bits, linkage)})") + log.info(f"Machine: {machine}") + log.info(f"Node: {platform.node()}") + log.info(f"Platform: {platform.platform()}") + log.info(f"System: {platform.system()}") + log.info(f"Release: {platform.release()}") + log.info(f"using binary: '{lt_executable}'") + + log.info("start cloud tunnel" + token + cloud_node) + try: + cloud_tunnel = Popen([f"{RUNS_PATH}/{lt_executable}", "-h", + "https://" + cloud_node + ".openwb.de/", "-p", "80", "-s", token]) + log.info(f"cloud tunnel running with pid {cloud_tunnel.pid}") + except FileNotFoundError: + log.exception(f"executable '{lt_executable}' does not exist!") + else: + log.info("unknown message: " + payload) # clear topic client.publish(msg.topic, "", qos=2, retain=True)