fastd-2-uci and fix start/stop #219

Closed
rohammer wants to merge 2 commits from rohammer:fastd-2-uci into master
2 changed files with 16 additions and 21 deletions

View File

@ -1,34 +1,25 @@
protocol=fastd
fastd_clear() {
rm /tmp/fastd_fff_peers/*
while uci -q delete fastd.@peer[0];do :; done
}
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"
uci add fastd peer
uci set fastd.@peer[-1].enabled=1
uci set fastd.@peer[-1].net=fff
uci set fastd.@peer[-1].key="$key"
uci add_list fastd.@peer[-1].remote="\"$address\" port $port"
uci set fastd.@peer[-1].float=1
}
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
uci commit
[ "$0" = "/usr/sbin/vpn-stop" ] && /etc/init.d/fastd stop && return
[ "$new_hoodfile" = "yes" ] && /etc/init.d/fastd restart && return
/etc/init.d/fastd start
}

View File

@ -86,6 +86,8 @@ if [ -s "$hoodfiletmp" ]; then
if [ "$sumnew" != "$sumold" ] ; then
echo "New file detected, we reconfigure the Node";
export new_hoodfile="yes"
json_select hood
json_get_var hood name
@ -174,6 +176,8 @@ if [ -s "$hoodfiletmp" ]; then
/etc/init.d/alfred restart
else
echo "We have no new file. We do nothing. We try it again in 5 minutes...";
export new_hoodfile="no"
fi
# and now we get to vpn-select script and load VPNs directly from /tmp/keyxchangev2data