update tunnelier again

This commit is contained in:
Q
2024-03-02 17:35:57 +02:00
parent fb0543dfe4
commit 2ce8bc5fd8
2 changed files with 30 additions and 23 deletions

View File

@@ -23,6 +23,6 @@ setup(
]
},
install_requires=[
"psutil",
"psutil", "pyyaml"
],
)

View File

@@ -9,32 +9,33 @@ import sys
from argparse import ArgumentError, ArgumentParser
import psutil
import yaml
__version__ = "2024.01.07"
__version__ = "2024.03.02"
CONFDIR = os.path.expanduser("~/.config/ssh-tunnelier")
CONF = os.path.join(CONFDIR, "tunnels.json")
CONF_OLD = os.path.join(CONFDIR, "tunnels.json")
CONF = os.path.join(CONFDIR, "tunnels.yaml")
# Just over a year in minutes
MAGIC_TIME = 525601
LOCALHOSTSYMBOL = "💻"
EXAMPLE_CONFIG = """{
"test": {
"host": "host to connect, or defaults to name",
"options": "-4 and other ssh options",
"auto-connect": false,
"tunnels": [
{
"local_port": 1111,
"remote_port": 8080,
"remote_address": "localhost",
"reverse": false,
"comment": "`comment`, `reverse` and `remote_address` are not required"
}
]
}
EXAMPLE_CONFIG = {
"test": {
"host": "host to connect, or defaults to name",
"options": "-4 and other ssh options",
"auto-connect": False,
"tunnels": [
{
"local_port": 1111,
"remote_port": 8080,
"remote_address": "localhost",
"reverse": False,
"comment": "`comment`, `reverse` and `remote_address` are not required",
}
],
}
}
"""
def args():
@@ -106,11 +107,17 @@ def load_config():
try:
os.makedirs(CONFDIR, exist_ok=True)
if not os.path.exists(CONF):
print("Creating example config: " + CONF)
with open(CONF, "w") as fp:
fp.write(EXAMPLE_CONFIG)
if os.path.exists(CONF_OLD):
with open(CONF_OLD, "r") as fp:
config = json.load(fp)
with open(CONF, "w") as fp:
yaml.dump(config, fp, sort_keys=False)
else:
print("Creating example config: " + CONF)
with open(CONF, "w") as fp:
yaml.dump(EXAMPLE_CONFIG, fp)
with open(CONF, "r") as fp:
config = json.load(fp)
config = yaml.safe_load(fp)
for name in config:
config[name]["host"] = config[name].get("host", name)