mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-09-27 20:16:22 +02:00
committed by
rootzoll
parent
ee257c6170
commit
cdfdb365e1
@@ -11,8 +11,8 @@ import sys
|
||||
# display config script info
|
||||
if len(sys.argv) <= 1 or sys.argv[1] == "-h" or sys.argv[1] == "help":
|
||||
print("forward ports from another server to raspiblitz with reverse SSH tunnel")
|
||||
print("internet.sshtunnel.py [on|off|restore] [USER]@[SERVER:PORT] \"[INTERNAL-PORT]<[EXTERNAL-PORT]\"")
|
||||
print("note that [INTERNAL-PORT]<[EXTERNAL-PORT] can one or multiple forwardings")
|
||||
print("internet.sshtunnel.py on|off|restore USER@SERVER:PORT [--m:MONITORINGPORT] \"INTERNAL-PORT<EXTERNAL-PORT\"")
|
||||
print("note that INTERNAL-PORT<EXTERNAL-PORT can one or multiple forwardings")
|
||||
sys.exit(1)
|
||||
|
||||
#
|
||||
@@ -31,7 +31,7 @@ After=network.target
|
||||
User=root
|
||||
Group=root
|
||||
Environment="AUTOSSH_GATETIME=0"
|
||||
ExecStart=/usr/bin/autossh -M 0 -N -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=2 [PLACEHOLDER]
|
||||
ExecStart=/usr/bin/autossh [MONITORING-PORT] -N -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=2 [PLACEHOLDER]
|
||||
StandardOutput=journal
|
||||
|
||||
[Install]
|
||||
@@ -77,11 +77,24 @@ def on(restore_on_update=False):
|
||||
|
||||
# generate additional parameter for autossh (forwarding ports)
|
||||
if len(sys.argv) < 4:
|
||||
print("[INTERNAL-PORT]<[EXTERNAL-PORT] missing")
|
||||
print("missing parameters")
|
||||
sys.exit(1)
|
||||
|
||||
# check for optional monitoring port parameter
|
||||
i = 3
|
||||
monitoringPort="-M 0"
|
||||
optionalParameter=""
|
||||
if sys.argv[3].count("--m:") > 0:
|
||||
# get monitoring port number
|
||||
monitoringPort = sys.argv[3][4:]
|
||||
optionalParameter= "--m:{} ".format(monitoringPort)
|
||||
monitoringPort = "-M {}".format(monitoringPort)
|
||||
print("# found optional monitoring port: {}".format(monitoringPort))
|
||||
# port forwadings start one parameter later
|
||||
i = 4
|
||||
|
||||
ssh_ports = ""
|
||||
additional_parameters = ""
|
||||
i = 3
|
||||
while i < len(sys.argv):
|
||||
|
||||
# check forwarding format
|
||||
@@ -122,7 +135,8 @@ def on(restore_on_update=False):
|
||||
|
||||
# generate custom service config
|
||||
service_data = SERVICE_TEMPLATE.replace("[PLACEHOLDER]", additional_parameters)
|
||||
|
||||
service_data = service_data.replace("[MONITORING-PORT]", monitoringPort)
|
||||
|
||||
# debug print out service
|
||||
print()
|
||||
print("*** New systemd service: {}".format(SERVICE_NAME))
|
||||
@@ -157,7 +171,7 @@ def on(restore_on_update=False):
|
||||
file_content = f.read()
|
||||
if file_content.count("sshtunnel=") == 0:
|
||||
file_content = file_content + "\nsshtunnel=''"
|
||||
file_content = re.sub("sshtunnel=.*", "sshtunnel='%s %s'" % (ssh_server, ssh_ports), file_content)
|
||||
file_content = re.sub("sshtunnel=.*", "sshtunnel='%s %s%s'" % (ssh_server, optionalParameter, ssh_ports), file_content)
|
||||
|
||||
if not restore_on_update:
|
||||
server_domain = ssh_server.split("@")[1]
|
||||
|
Reference in New Issue
Block a user