import
This commit is contained in:
commit
747b4fbcf8
3 changed files with 53 additions and 0 deletions
27
bin/safe-harbor.py
Executable file
27
bin/safe-harbor.py
Executable file
|
@ -0,0 +1,27 @@
|
|||
#! /usr/bin/env python3
|
||||
# encoding: utf-8
|
||||
|
||||
import jsmin
|
||||
import json
|
||||
import os
|
||||
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", "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
|
||||
os.execl(*command)
|
Loading…
Add table
Add a link
Reference in a new issue