From 98b770afa1891d39181e8cacc0f842831e274702 Mon Sep 17 00:00:00 2001 From: Sheppy Date: Sun, 1 Jan 2023 18:02:13 +0100 Subject: [PATCH] feat: auto add ssh forward ports --- main.py | 2 ++ vm.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/main.py b/main.py index 5b14e3e..a0ecfa1 100644 --- a/main.py +++ b/main.py @@ -43,6 +43,8 @@ if __name__ == "__main__": with open("/etc/nginx/stream_include.conf", "w") as f: for vmo in vmList: [ f.write(c) for c in vmo.dumpStreamComponents()] + for vmo in set(vmList): + [ f.write(c) for c in vmo.dumpSshFowardsNginx()] with open("/etc/nginx/http_include.conf", "w") as f: for vmo in vmList: diff --git a/vm.py b/vm.py index 906d50d..fe9c3ec 100644 --- a/vm.py +++ b/vm.py @@ -16,6 +16,7 @@ class VM: self.isExternal = args.get("external") self.noTerminateACME = args.get("no-terminate-acme") self.ansible = not args.get("noansible") + self.sshOutsidePort = None if self.isExternal: self.lease = None @@ -74,6 +75,21 @@ class VM: return components + def dumpSshFowardsNginx(self): + + components = [] + template = self.environment.get_template("nginx_stream_block.conf.j2") + if not self.isExternal: + self.sshOutsidePort = 7000 + int(self.ip.split(".")[-1]) + component = template.render(targetip=self.ip, udp=False, + portstring=self.sshOutsidePort, + targetportoverwrite=7000, + transparent=False, proxy_timeout="24h", + comment="ssh-{}".format(self.hostname)) + components.append(component) + + return components + def dumpIptables(self, remove=False): entries = []