change tunnelier config format
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
CONFDIR="$HOME/.config/ssh-tunnelier"
|
CONFDIR="$HOME/.config/ssh-tunnelier"
|
||||||
CONF="$CONFDIR/config"
|
CONF="$CONFDIR/tunnels.conf"
|
||||||
# Just over a year in minutes
|
# Just over a year in minutes
|
||||||
MAGIC_TIME=525601
|
MAGIC_TIME=525601
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ If run with arguments, runs an ssh tunnel with arguments:
|
|||||||
ssh-tunnelier hostname [local-port] remote-port
|
ssh-tunnelier hostname [local-port] remote-port
|
||||||
|
|
||||||
If local port missing, the same port assumed in local
|
If local port missing, the same port assumed in local
|
||||||
"
|
"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +37,9 @@ done
|
|||||||
[[ -f "$CONF" ]] || {
|
[[ -f "$CONF" ]] || {
|
||||||
echo No config file.
|
echo No config file.
|
||||||
echo "$CONF" each line like:
|
echo "$CONF" each line like:
|
||||||
echo -L 8888:localhost:8888 servername
|
echo "servername: 8888,8889:8989,8890:host:9090"
|
||||||
mkdir -p "$CONFDIR"
|
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]+$'
|
number_re='^[0-9]+$'
|
||||||
# import qolop
|
# import qolop
|
||||||
@@ -62,10 +62,31 @@ function get_id() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_command() {
|
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\""
|
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() {
|
function get_pid() {
|
||||||
pgrep -f "$MAGIC_TIME.*echo tunnelier $1" | head -n 1
|
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} 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} (q)uit (e)dit (l)ist ssh (i)nstant tunnel${colZ}\n"
|
||||||
printf "${colTitle}=============================================\n"
|
printf "${colTitle}=============================================\n"
|
||||||
printf "${colRow}ID PID command\n"
|
printf "${colRow}ID PID host: ports\n"
|
||||||
read_config
|
read_config
|
||||||
printf "$colZ"
|
printf "$colZ"
|
||||||
read -t 600 input
|
read -t 600 input
|
||||||
|
|||||||
Reference in New Issue
Block a user