From 2781209eb0f69a010e9067a57a9cce00dc0ded30 Mon Sep 17 00:00:00 2001 From: Martin Sekera Date: Sat, 26 Oct 2019 00:08:41 +0200 Subject: [PATCH] Added support for SSH ports other than 22. --- config.json.example | 8 ++++++++ lib/safe-harbor.py | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config.json.example b/config.json.example index 570e320..0127798 100644 --- a/config.json.example +++ b/config.json.example @@ -1,7 +1,15 @@ { + // host and port of the SSH server that's going to act as the proxy "host": "rusty.wafe.eu", + "port": 10022, + + // username I'm allowed to use on that server "user": "tunnel", + + // a list of associations "mapping": [ + + // local port 22 will be available as port 39999 on the above server { "remote": 39999, "local": 22 diff --git a/lib/safe-harbor.py b/lib/safe-harbor.py index 8ad2a01..3865997 100755 --- a/lib/safe-harbor.py +++ b/lib/safe-harbor.py @@ -10,6 +10,16 @@ def load_cfg(path): with open(path) as f: return json.loads(jsmin.jsmin(f.read())) +def safe_get(d, k, alt): + """ + Returns d[k] or alt + """ + + if k in d: + return d[k] + else: + return alt + if __name__ == "__main__": # try config files in the order they are passed to us # first one wins @@ -23,13 +33,12 @@ if __name__ == "__main__": break except Exception as e: print("! cfg file %s failed to load (%s)" %(path, e)) - if not cfg: print("! unable to load any configuration") sys.exit(1) - command = ["/usr/bin/ssh", "-o", "ServerAliveInterval 45", "-o", "ServerAliveCountMax 2", "-o", "ExitOnForwardFailure yes", "-N"] + command = ["/usr/bin/ssh", "-o", "ServerAliveInterval 45", "-o", "ServerAliveCountMax 2", "-o", "ExitOnForwardFailure yes", "-N", "-p", safe_get(cfg, "port", 22)] for m in cfg["mapping"]: command.append("-R")