This commit is contained in:
Martin 2019-09-13 18:50:01 +02:00
commit 747b4fbcf8
3 changed files with 53 additions and 0 deletions

27
bin/safe-harbor.py Executable file
View 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)

14
config.json.example Normal file
View file

@ -0,0 +1,14 @@
{
"host": "decade.cz",
"user": "tunnel",
"mapping": [
{
"remote": 50022,
"local": 22
},
{
"remote": 8000,
"local": 80
}
]
}

View file

@ -0,0 +1,12 @@
[Unit]
Description=Safe Harbor SSH tunnel
After=network.target
[Service]
User=$i
ExecStart=/usr/bin/python3 /usr/lib/safe-harbor/safe-harbor.py
Restart=always
RestartSec=90
[Install]
WantedBy=multi-user.target