raspiblitz/home.admin/config.scripts/internet.sshtunnel.py

39 lines
1,001 B
Python
Raw Normal View History

2019-04-01 22:49:53 +01:00
#!/usr/bin/python3
2019-04-01 23:21:47 +01:00
2019-04-02 00:05:37 +01:00
import sys, subprocess
2019-04-01 23:31:42 +01:00
2019-04-02 00:05:37 +01:00
# display config script info
if len(sys.argv) <= 1 or sys.argv[1] == "-h" or sys.argv[1] == "help":
2019-04-01 23:43:21 +01:00
print("forward ports from another server to raspiblitz with reverse SSH tunnel")
print("internet.sshtunnel.py [on|off] [USER]@[SERVER] [INTERNAL-PORT]:[EXTERNAL-PORT]")
print("note that [INTERNAL-PORT]:[EXTERNAL-PORT] can one or multiple forwardings")
sys.exit(1)
2019-04-02 00:05:37 +01:00
#
# SWITCHING ON
#
if sys.argv[1] == "on":
# check if already running -> systemctl is-enabled autossh-tunnel.service
alreadyRunning = subprocess.check_output(['systemctl','is-enabled','autossh-tunnel.service'],shell=True)
if alreadyRunning == "enabled":
print("already running - run 'internet.sshtunnel.py off' first")
sys.exit(1)
print ("TODO: Switch ON")
#
# SWITCHING OFF
#
elif sys.argv[1] == "off":
print ("TODO: Switch OFF")
#
# UNKOWN PARAMETER
#
else:
print ("unkown parameter - use 'internet.sshtunnel.py -h' for help")