change tunnelier config format

This commit is contained in:
Ville Rantanen
2023-01-13 14:45:11 +02:00
parent 8b475a5409
commit 115f631743

View File

@@ -1,7 +1,7 @@
#!/bin/bash
CONFDIR="$HOME/.config/ssh-tunnelier"
CONF="$CONFDIR/config"
CONF="$CONFDIR/tunnels.conf"
# Just over a year in minutes
MAGIC_TIME=525601
@@ -37,9 +37,9 @@ done
[[ -f "$CONF" ]] || {
echo No config file.
echo "$CONF" each line like:
echo -L 8888:localhost:8888 servername
echo "servername: 8888,8889:8989,8890:host:9090"
mkdir -p "$CONFDIR"
echo -e "# example:\n -L 8888:localhost:8888 servername" > "$CONF"
echo -e "# example:\nservername: 8888,8889:8989,8890:host:9090" > "$CONF"
}
number_re='^[0-9]+$'
# import qolop
@@ -62,10 +62,31 @@ function get_id() {
}
function get_command() {
switches=$( echo "$1" | $UNBASE )
switches=$( echo "$1" | $UNBASE | parse_switches )
echo -n "ssh -f -n $switches \"nice /bin/bash -c 'for ((i=1;i<$MAGIC_TIME;i++)); do cut -f4 -d \\\" \\\" /proc/\\\$PPID/stat | xargs kill -0 || exit ; sleep 60;done'; echo tunnelier $1\""
}
function parse_switches() {
python3 -c "
import sys
host, tunnels = sys.stdin.read(1024*10).split(':',1)
for i, tunnel in enumerate(tunnels.split(',')):
tunnel = tunnel.strip().split(':')
thost='localhost'
if len(tunnel) == 1:
tport=tunnel[0]
if len(tunnel) == 2:
tport=tunnel[1]
if len(tunnel) == 3:
thost=tunnel[1]
tport=tunnel[2]
sys.stdout.write('-L {}:{}:{} '.format(tunnel[0], thost, tport))
sys.stderr.write('Generated tunnel {}: http://localhost:{} -> {}:{}\n'.format(i+1,tunnel[0],thost, tport))
sys.stdout.write(host)
"
}
function get_pid() {
pgrep -f "$MAGIC_TIME.*echo tunnelier $1" | head -n 1
}
@@ -147,7 +168,7 @@ while true; do
printf "${colTitle} List of tunnels: (${LOCALHOSTSYMBOL}=localhost) [%s]${colZ}\n" $( date +%H:%M )
printf "${colTitle} (q)uit (e)dit (l)ist ssh (i)nstant tunnel${colZ}\n"
printf "${colTitle}=============================================\n"
printf "${colRow}ID PID command\n"
printf "${colRow}ID PID host: ports\n"
read_config
printf "$colZ"
read -t 600 input