[packages] sshtunnel: update to version 2
git-svn-id: svn://svn.openwrt.org/openwrt/packages@23263 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
0c8a8a5434
commit
1a7a3dc9cd
@ -8,21 +8,22 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=sshtunnel
|
PKG_NAME:=sshtunnel
|
||||||
PKG_VERSION:=1
|
PKG_VERSION:=2
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=2
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|
||||||
define Package/sshtunnel
|
define Package/sshtunnel
|
||||||
SECTION:=net
|
SECTION:=net
|
||||||
CATEGORY:=Network
|
CATEGORY:=Network
|
||||||
|
SUBMENU:=SSH
|
||||||
TITLE:=Manages Local and Remote openssh ssh(1) tunnels
|
TITLE:=Manages Local and Remote openssh ssh(1) tunnels
|
||||||
MAINTAINER:=Nuno Goncalves <nunojpg@gmail.com>
|
MAINTAINER:=Nuno Goncalves <nunojpg@gmail.com>
|
||||||
DEPENDS:=+openssh-client
|
DEPENDS:=+openssh-client
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/sshtunnel/description
|
define Package/sshtunnel/description
|
||||||
Creates openssh ssh(1) Local and Remote tunnels configured in UCI file. Can be user to allow remote connections, possibly over NATed connections or without public IP/DNS
|
Creates openssh ssh(1) Local and Remote tunnels configured in UCI file. Can be used to allow remote connections, possibly over NATed connections or without public IP/DNS
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/sshtunnel/conffiles
|
define Package/sshtunnel/conffiles
|
||||||
|
@ -1,30 +1,44 @@
|
|||||||
#
|
#
|
||||||
# only authentication supported is public key with indentity file specified
|
# password authentication is not possible, publick key authentication must be used.
|
||||||
|
# set "option IdentityFile" to he file from which the identity (private key) for RSA or DSA authentication is read.
|
||||||
|
# The default is ~/.ssh/identity for protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for protocol version 2.
|
||||||
|
# ssh will also try to load certificate information from the filename obtained by appending -cert.pub to identity filenames.
|
||||||
# pkcs11 support soon
|
# pkcs11 support soon
|
||||||
#
|
#
|
||||||
|
|
||||||
|
config server disney
|
||||||
|
option user mourinho
|
||||||
|
option hostname server.disney.com
|
||||||
|
# option port 22
|
||||||
|
# option retrydelay 1
|
||||||
|
# option CheckHostIP yes
|
||||||
|
# option Compression no
|
||||||
|
# option CompressionLevel 6
|
||||||
|
# option IdentityFile ~/.ssh/id_rsa
|
||||||
|
# option LogLevel INFO
|
||||||
|
# option ServerAliveCountMax 3
|
||||||
|
# option ServerAliveInterval 0
|
||||||
|
# option StrictHostKeyChecking ask
|
||||||
|
# option TCPKeepAlive yes
|
||||||
|
# option VerifyHostKeyDNS yes
|
||||||
|
|
||||||
|
|
||||||
# tunnelR(emote) - when the connection will be initiated to the R(emote) endpoint at
|
# tunnelR(emote) - when the connection will be initiated to the R(emote) endpoint at
|
||||||
# remoteaddress:remoteport and then forward to localaddress:localport
|
# remoteaddress:remoteport and then forward to localaddress:localport
|
||||||
#
|
#
|
||||||
config tunnelR http
|
config tunnelR http
|
||||||
option user mourinho
|
option server disney
|
||||||
option hostname server.disney.com
|
|
||||||
option identity /root/.ssh/id_rsa
|
|
||||||
option remoteaddress *
|
option remoteaddress *
|
||||||
option remoteport 9009
|
option remoteport 9009
|
||||||
option localaddress 192.168.1.13
|
option localaddress 192.168.1.13
|
||||||
option localport 80
|
option localport 80
|
||||||
option options '-o ServerAliveCountMax=3 -o ServerAliveInterval=20 -o StrictHostKeyChecking=false'
|
|
||||||
|
|
||||||
# tunnelL(ocal) - when the connection will be initiated to the L(ocal) endpoint at
|
# tunnelL(ocal) - when the connection will be initiated to the L(ocal) endpoint at
|
||||||
# localaddress:localport and then forward to remoteaddress:remoteport
|
# localaddress:localport and then forward to remoteaddress:remoteport
|
||||||
#
|
#
|
||||||
config tunnelL test
|
config tunnelL test
|
||||||
option user mourinho
|
option server disney
|
||||||
option hostname server.disney.com
|
|
||||||
option identity /root/.ssh/id_rsa
|
|
||||||
option localaddress *
|
option localaddress *
|
||||||
option localport 1022
|
option localport 1022
|
||||||
option remoteaddress secretserver.disney.com
|
option remoteaddress secretserver.disney.com
|
||||||
option remoteport 22
|
option remoteport 22
|
||||||
option options '-o ServerAliveCountMax=3 -o ServerAliveInterval=20 -o StrictHostKeyChecking=false'
|
|
||||||
|
@ -5,40 +5,82 @@ STOP=01
|
|||||||
|
|
||||||
PIDFILE="/tmp/run/sshtunnel"
|
PIDFILE="/tmp/run/sshtunnel"
|
||||||
|
|
||||||
load_tunnel() {
|
load_server() {
|
||||||
config_get user $1 user
|
server="$1"
|
||||||
config_get hostname $1 hostname
|
|
||||||
config_get identity $1 identity
|
|
||||||
config_get remoteport $1 remoteport
|
|
||||||
config_get localport $1 localport
|
|
||||||
config_get options $1 options '-o ServerAliveCountMax=3 -o ServerAliveInterval=20 -o StrictHostKeyChecking=false'
|
|
||||||
config_get retrydelay $1 retrydelay "10"
|
|
||||||
[ "$cfgtype" = "tunnelL" ] && {
|
|
||||||
config_get localaddress $1 localaddress "127.0.0.1"
|
|
||||||
config_get remoteaddress $1 remoteaddress "*"
|
|
||||||
}
|
|
||||||
[ "$cfgtype" = "tunnelR" ] && {
|
|
||||||
config_get localaddress $1 localaddress "*"
|
|
||||||
config_get remoteaddress $1 remoteaddress "127.0.0.1"
|
|
||||||
}
|
|
||||||
|
|
||||||
local error
|
config_get user $1 user
|
||||||
[ -f "$identity" ] || error="Identity file $identity not accessible"
|
config_get hostname $1 hostname
|
||||||
[ -n "$user" ] || error="please set user option"
|
config_get debuglevel $1 debuglevel "0"
|
||||||
[ -n "$hostname" ] || error="please set hostname option"
|
config_get retrydelay $1 retrydelay "10"
|
||||||
[ "$remoteport" -gt 0 -a "$localport" -gt 0 -a "$retrydelay" -ge 0 ] || error="invalid configuration"
|
config_get CheckHostIP $1 CheckHostIP
|
||||||
[ -n "$error" ] && { logger -p user.err -t "sshtunnel" "$cfgtype $1 not started - $error"; return; }
|
config_get Compression $1 Compression
|
||||||
|
config_get CompressionLevel $1 CompressionLevel
|
||||||
[ "$cfgtype" = "tunnelL" ] && {
|
config_get IdentityFile $1 IdentityFile
|
||||||
args="-N -i $identity -o PasswordAuthentication=no -o ExitOnForwardFailure=yes $options -L $localaddress:$localport:$remoteaddress:$remoteport $user@$hostname"
|
config_get LogLevel $1 LogLevel
|
||||||
}
|
config_get ServerAliveCountMax $1 ServerAliveCountMax
|
||||||
[ "$cfgtype" = "tunnelR" ] && {
|
config_get ServerAliveInterval $1 ServerAliveInterval
|
||||||
args="-N -i $identity -o PasswordAuthentication=no -o ExitOnForwardFailure=yes $options -R $remoteaddress:$remoteport:$localaddress:$localport $user@$hostname"
|
config_get StrictHostKeyChecking $1 StrictHostKeyChecking
|
||||||
}
|
config_get TCPKeepAlive $1 TCPKeepAlive
|
||||||
|
config_get VerifyHostKeyDNS $1 VerifyHostKeyDNS
|
||||||
|
|
||||||
/usr/bin/sshtunnel.sh "$args" "$retrydelay" &
|
error=""
|
||||||
|
[ -n "$user" ] || error="user is not set"
|
||||||
|
[ -n "$hostname" ] || error="${error:+$error; }hostname is not set"
|
||||||
|
[ "$retrydelay" -ge 0 ] || error="${error:+$error; }retrydelay must be a positive integer"
|
||||||
|
#[ -f "$IdentityFile" ] || error="${error:+$error; }IdentityFile $IdentityFile not accessible"
|
||||||
|
#add validation for the rest of the parameters
|
||||||
|
[ -n "$error" ] && { logger -p user.err -t "sshtunnel" "tunnels to $server not started - $error"; return; }
|
||||||
|
|
||||||
|
tunnels_cmd=""
|
||||||
|
count=0
|
||||||
|
config_foreach load_tunnel tunnelR && config_foreach load_tunnel tunnelL
|
||||||
|
[ -n "$error" ] && { logger -p user.err -t "sshtunnel" "tunnels to $server not started - $error"; return; }
|
||||||
|
[ "$count" -eq 0 ] && { logger -p user.err -t "sshtunnel" "tunnels to $server not started - no tunnels defined"; return; }
|
||||||
|
|
||||||
|
cmd="${CheckHostIP:+-o CheckHostIP=$CheckHostIP }"
|
||||||
|
cmd="$cmd${CheckHostIP:+-o CheckHostIP=$CheckHostIP }"
|
||||||
|
cmd="$cmd${Compression:+-o Compression=$Compression }"
|
||||||
|
cmd="$cmd${CompressionLevel:+-o CompressionLevel=$CompressionLevel }"
|
||||||
|
cmd="$cmd${IdentityFile:+-o IdentityFile=$IdentityFile }"
|
||||||
|
cmd="$cmd${LogLevel:+-o LogLevel=$LogLevel }"
|
||||||
|
cmd="$cmd${ServerAliveCountMax:+-o ServerAliveCountMax=$ServerAliveCountMax }"
|
||||||
|
cmd="$cmd${ServerAliveInterval:+-o ServerAliveInterval=$ServerAliveInterval }"
|
||||||
|
cmd="$cmd${StrictHostKeyChecking:+-o StrictHostKeyChecking=$StrictHostKeyChecking }"
|
||||||
|
cmd="$cmd${TCPKeepAlive:+-o TCPKeepAlive=$TCPKeepAlive }"
|
||||||
|
cmd="$cmd${VerifyHostKeyDNS:+-o VerifyHostKeyDNS=$VerifyHostKeyDNS }"
|
||||||
|
cmd="$cmd""-o ExitOnForwardFailure=yes -o BatchMode=yes -nN $tunnels_cmd $user@$hostname"
|
||||||
|
|
||||||
|
/usr/bin/sshtunnel.sh "$cmd" "$retrydelay" "$server" &
|
||||||
echo $! >> "$PIDFILE".pids
|
echo $! >> "$PIDFILE".pids
|
||||||
logger -p user.info -t "sshtunnel" "started new $cfgtype $1 (pid=$!;retrydelay=$retrydelay)"
|
logger -p user.info -t "sshtunnel" "started tunnels to $server (pid=$!;retrydelay=$retrydelay)"
|
||||||
|
}
|
||||||
|
|
||||||
|
load_tunnel() {
|
||||||
|
config_get section_server $1 server
|
||||||
|
[ "$server" = "$section_server" ] || return 0 # continue to read next section if this is not for the current server
|
||||||
|
let count++ # count nr of valid sections to make sure there are at least one
|
||||||
|
|
||||||
|
config_get remoteport $1 remoteport
|
||||||
|
config_get localport $1 localport
|
||||||
|
[ "$cfgtype" = "tunnelL" ] && {
|
||||||
|
config_get localaddress $1 localaddress "*"
|
||||||
|
config_get remoteaddress $1 remoteaddress
|
||||||
|
}
|
||||||
|
[ "$cfgtype" = "tunnelR" ] && {
|
||||||
|
config_get localaddress $1 localaddress
|
||||||
|
config_get remoteaddress $1 remoteaddress "*"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "$remoteport" -gt 0 ] || error="remoteport must be a positive integer"
|
||||||
|
[ "$localport" -gt 0 ] || error="${error:+$error; }localpost must be a positive integer"
|
||||||
|
[ -n "$error" ] && return 1
|
||||||
|
|
||||||
|
[ "$cfgtype" = "tunnelL" ] && {
|
||||||
|
tunnels_cmd="${tunnels_cmd:+$tunnels_cmd }-L $localaddress:$localport:$remoteaddress:$remoteport"
|
||||||
|
}
|
||||||
|
[ "$cfgtype" = "tunnelR" ] && {
|
||||||
|
tunnels_cmd="${tunnels_cmd:+$tunnels_cmd }-R $remoteaddress:$remoteport:$localaddress:$localport"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
@ -51,10 +93,11 @@ stop() {
|
|||||||
start-stop-daemon -K -p "$PIDFILE"_"$pid".pid
|
start-stop-daemon -K -p "$PIDFILE"_"$pid".pid
|
||||||
kill $pid
|
kill $pid
|
||||||
logger -p daemon.info -t "sshtunnel[$pid]" "tunnel stopped"
|
logger -p daemon.info -t "sshtunnel[$pid]" "tunnel stopped"
|
||||||
|
rm "$PIDFILE"_"$pid".pid
|
||||||
done < "$PIDFILE".pids
|
done < "$PIDFILE".pids
|
||||||
|
|
||||||
rm "$PIDFILE".pids
|
rm "$PIDFILE".pids
|
||||||
|
|
||||||
logger -p user.info -t "sshtunnel" "all tunnels stopped"
|
logger -p user.info -t "sshtunnel" "all tunnels stopped"
|
||||||
else
|
else
|
||||||
logger -p user.info -t "sshtunnel" "no tunnels running"
|
logger -p user.info -t "sshtunnel" "no tunnels running"
|
||||||
@ -64,11 +107,13 @@ stop() {
|
|||||||
start() {
|
start() {
|
||||||
[ -f "$PIDFILE".pids ] && stop
|
[ -f "$PIDFILE".pids ] && stop
|
||||||
|
|
||||||
logger -p user.info -t "sshtunnel" "starting all tunnels"
|
config_load sshtunnel
|
||||||
|
if [ -n "$(uci show sshtunnel.@server[0])" ] # at least one server section exists
|
||||||
config_load sshtunnel
|
then
|
||||||
config_foreach load_tunnel tunnelR
|
logger -p user.info -t "sshtunnel" "starting all tunnels"
|
||||||
config_foreach load_tunnel tunnelL
|
config_foreach load_server server
|
||||||
|
logger -p user.info -t "sshtunnel" "all tunnels started"
|
||||||
logger -p user.info -t "sshtunnel" "all tunnels started"
|
else
|
||||||
|
logger -p user.info -t "sshtunnel" "no servers defined"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,19 @@
|
|||||||
|
|
||||||
PIDFILE="/tmp/run/sshtunnel"
|
PIDFILE="/tmp/run/sshtunnel"
|
||||||
|
|
||||||
args=$1
|
args="$1"
|
||||||
retrydelay=$2
|
retrydelay="$2"
|
||||||
|
server="$3"
|
||||||
|
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
logger -p daemon.info -t "sshtunnel[$$]" "connecting: ssh $args"
|
logger -p daemon.info -t "sshtunnel[$$][$server]" "connection started"
|
||||||
|
|
||||||
start-stop-daemon -S -p "$PIDFILE"_"$$".pid -mx ssh -- $args &>/tmp/log/sshtunnel_$$
|
start-stop-daemon -S -p "$PIDFILE"_"$$".pid -mx ssh -- $args &>/tmp/log/sshtunnel_$$
|
||||||
logger -p daemon.err -t "sshtunnel[$$]" < /tmp/log/sshtunnel_$$
|
|
||||||
rm /tmp/log/sshtunnel_$$
|
|
||||||
|
|
||||||
logger -p daemon.info -t "sshtunnel[$$]" "ssh exited with code $?, retrying in $retrydelay seconds"
|
logger -p daemon.err -t "sshtunnel[$$][$server]" < /tmp/log/sshtunnel_$$
|
||||||
|
rm /tmp/log/sshtunnel_$$
|
||||||
|
logger -p daemon.info -t "sshtunnel[$$][$server]" "ssh exited with code $?, retrying in $retrydelay seconds"
|
||||||
|
|
||||||
sleep "$retrydelay" & wait
|
sleep "$retrydelay" & wait
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user