fff-vpn-select: Make vpn-select modular
This rewrite makes vpn-select modular to easely add new vpn-protocols. The stuff dependent on the vpn-protocol is outsourced to files in /usr/lib/vpn-select.d/ and comes in with the respective vpn package. In this way it is easy to select or deselect vpnprotocols to be build in. vpn-stop is removed to use the protocol independent start/stop mechanism of vpn-select. Instead, a symlink is used. Signed-off-by: Robert Langhammer <rlanghammer@web.de> Reviewed-by: Fabian Bläse <fabian@blaese.de>
This commit is contained in:
parent
feeead6c43
commit
1febd2a9b2
|
@ -1,7 +1,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=fff-fastd
|
PKG_NAME:=fff-fastd
|
||||||
PKG_RELEASE:=3
|
PKG_RELEASE:=4
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
protocol=fastd
|
||||||
|
|
||||||
|
fastd_clear() {
|
||||||
|
rm /tmp/fastd_fff_peers/*
|
||||||
|
}
|
||||||
|
|
||||||
|
fastd_addpeer() {
|
||||||
|
[ -d /tmp/fastd_fff_peers ] || mkdir /tmp/fastd_fff_peers
|
||||||
|
|
||||||
|
# write fastd-config
|
||||||
|
json_get_var servername name
|
||||||
|
filename="/etc/fastd/fff/peers/$servername"
|
||||||
|
echo "#name \"${servername}\";" > "$filename"
|
||||||
|
json_get_var key key
|
||||||
|
echo "key \"${key}\";" >> "$filename"
|
||||||
|
json_get_var address address
|
||||||
|
json_get_var port port
|
||||||
|
echo "remote \"${address}\" port ${port};" >> "$filename"
|
||||||
|
echo "" >> "$filename"
|
||||||
|
echo "float yes;" >> "$filename"
|
||||||
|
}
|
||||||
|
|
||||||
|
fastd_start_stop() {
|
||||||
|
/etc/init.d/fastd reload # does nothing if fastd was not running
|
||||||
|
|
||||||
|
# fastd start/stop for various situations
|
||||||
|
# this is needed for first start and if fastd comes up or disappears in hoodfile
|
||||||
|
pidfile="/tmp/run/fastd.fff.pid"
|
||||||
|
if [ "$(ls /etc/fastd/fff/peers/* 2>/dev/null)" ]; then
|
||||||
|
([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) || /etc/init.d/fastd start
|
||||||
|
else
|
||||||
|
([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) && /etc/init.d/fastd stop
|
||||||
|
fi
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=fff-vpn-select
|
PKG_NAME:=fff-vpn-select
|
||||||
PKG_RELEASE:=5
|
PKG_RELEASE:=6
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|
||||||
|
|
|
@ -1,65 +1,45 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Usage: vpn-select <path-to-hood-file>
|
# Usage: vpn-select <path-to-hood-file>
|
||||||
|
# To add a new protocol, put a file with three functions to /usr/lib/vpn-select.d/ .
|
||||||
|
# The file must start with protocol=name. It is most important to use the same name here and in hoodfile.
|
||||||
|
# The old config can be cleared in function ${protocol}_clear(). It is called first once per installed protocol.
|
||||||
|
# The function ${protocol}_addpeer() is called for every selected peer in hoodfile.
|
||||||
|
# The function ${protocol}_start_stop() is called at the end once per installed protocol.
|
||||||
|
|
||||||
. /usr/share/libubox/jshn.sh
|
. /usr/share/libubox/jshn.sh
|
||||||
|
|
||||||
hoodfile="$1"
|
hoodfile="$1"
|
||||||
|
|
||||||
make_config() {
|
# source functions
|
||||||
# remove old config
|
for file in /usr/lib/vpn-select.d/*; do
|
||||||
rm /tmp/fastd_fff_peers/*
|
[ -f $file ] && . "$file"
|
||||||
|
supported_protocols="$supported_protocols $protocol"
|
||||||
|
done
|
||||||
|
|
||||||
# prepare
|
# clear old config
|
||||||
Index=1
|
for protocol in $supported_protocols; do
|
||||||
|
"${protocol}_clear"
|
||||||
|
done
|
||||||
|
|
||||||
|
# configure vpn
|
||||||
|
|
||||||
|
if [ -n "$hoodfile" ] && [ -s "$hoodfile" ] ; then
|
||||||
json_load "$(cat "$hoodfile")"
|
json_load "$(cat "$hoodfile")"
|
||||||
|
json_select hood
|
||||||
|
json_get_var id id
|
||||||
|
json_select ".."
|
||||||
json_select vpn
|
json_select vpn
|
||||||
|
json_get_keys vpn_keys
|
||||||
# get fastd peers
|
for key in $vpn_keys; do
|
||||||
while json_select "$Index" > /dev/null
|
json_select $key
|
||||||
do
|
|
||||||
json_get_var protocol protocol
|
json_get_var protocol protocol
|
||||||
if [ "$protocol" = "fastd" ]; then
|
"${protocol}_addpeer"
|
||||||
# set up fastd
|
|
||||||
json_get_var servername name
|
|
||||||
filename="/etc/fastd/fff/peers/$servername"
|
|
||||||
echo "#name \"${servername}\";" > "$filename"
|
|
||||||
json_get_var key key
|
|
||||||
echo "key \"${key}\";" >> "$filename"
|
|
||||||
json_get_var address address
|
|
||||||
json_get_var port port
|
|
||||||
echo "remote \"${address}\" port ${port};" >> "$filename"
|
|
||||||
echo "" >> "$filename"
|
|
||||||
echo "float yes;" >> "$filename"
|
|
||||||
fi
|
|
||||||
json_select ".." # back to vpn
|
json_select ".." # back to vpn
|
||||||
Index=$(( Index + 1 ))
|
|
||||||
done
|
done
|
||||||
json_select ".." # back to root
|
|
||||||
}
|
|
||||||
|
|
||||||
# Only do something if file is there and not empty; otherwise exit 1
|
|
||||||
if [ -s "$hoodfile" ]; then
|
|
||||||
if [ ! -d /tmp/fastd_fff_peers ]; then
|
|
||||||
# first run after reboot
|
|
||||||
mkdir /tmp/fastd_fff_peers
|
|
||||||
make_config
|
|
||||||
# start fastd only if there are some peers
|
|
||||||
[ "$(ls /etc/fastd/fff/peers/* 2>/dev/null)" ] && /etc/init.d/fastd start
|
|
||||||
else
|
|
||||||
make_config
|
|
||||||
/etc/init.d/fastd reload
|
|
||||||
|
|
||||||
# fastd start/stop for various situations
|
|
||||||
pidfile="/tmp/run/fastd.fff.pid"
|
|
||||||
if [ "$(ls /etc/fastd/fff/peers/* 2>/dev/null)" ]; then
|
|
||||||
([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) || /etc/init.d/fastd start
|
|
||||||
else
|
|
||||||
([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) && /etc/init.d/fastd stop
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo "vpn-select: Hood file not found or empty!"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# start/restart/stop vpnservices
|
||||||
|
for protocol in $supported_protocols; do
|
||||||
|
"${protocol}_start_stop"
|
||||||
|
done
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
rm /tmp/fastd_fff_peers/*
|
|
||||||
/etc/init.d/fastd stop
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
vpn-select
|
Loading…
Reference in New Issue