27 lines
684 B
Python
Executable file
27 lines
684 B
Python
Executable file
#! /usr/bin/env python3
|
|
# encoding: utf-8
|
|
|
|
import jsmin
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) == 2:
|
|
cfg_path = sys.argv[1]
|
|
else:
|
|
cfg_path = "/etc/safe-harbor/config.json"
|
|
|
|
with open(cfg_path) as f:
|
|
cfg = json.loads(jsmin.jsmin(f.read()))
|
|
|
|
command = ["/usr/bin/ssh", "-o", "ServerAliveInterval 45", "-o", "ServerAliveCountMax 2", "-o", "ExitOnForwardFailure yes", "-N"]
|
|
|
|
for m in cfg["mapping"]:
|
|
command.append("-R")
|
|
command.append("%d:localhost:%d" %(m["remote"], m["local"]))
|
|
|
|
command.append("%s@%s" %(cfg["user"], cfg["host"]))
|
|
|
|
# replace this process, systemd will restart us if needed
|
|
subprocess.run(command)
|