Simplified VPN config cycling

pull/35/head
jdgregson 2021-01-22 22:54:07 -08:00
parent 9d2b2615a5
commit 6e01d57d75
1 changed files with 7 additions and 12 deletions

View File

@ -60,6 +60,7 @@ function start() {
# #
# If no numbered configs exist, the button functions as a way to reset the # If no numbered configs exist, the button functions as a way to reset the
# VPN connection. # VPN connection.
next=1
while true; do while true; do
NO_LED=true BUTTON NO_LED=true BUTTON
@ -68,21 +69,15 @@ function start() {
/etc/init.d/openvpn stop /etc/init.d/openvpn stop
# Determine which config to load next # Determine which config to load next
configpath=$(uci get openvpn.vpn.config) if [ -f "${DIR}/config${next}.ovpn" ]; then
configfile=$(echo "${configpath}" | grep -Eo "config[0-9]*") uci set openvpn.vpn.config="${DIR}/config${next}.ovpn"
confignumber=$(echo "${configfile}" | grep -Eo "[0-9]*") uci commit
if [ -z "${confignumber}" ]; then next=$(($next + 1))
confignumber="0"
fi
nextconfignumber="$(($confignumber + 1))"
if [ -f "${DIR}/config${nextconfignumber}.ovpn" ]; then
uci set openvpn.vpn.config="${DIR}/config${nextconfignumber}.ovpn"
elif [ -f "${DIR}/config1.ovpn" ]; then elif [ -f "${DIR}/config1.ovpn" ]; then
uci set openvpn.vpn.config="${DIR}/config1.ovpn" uci set openvpn.vpn.config="${DIR}/config1.ovpn"
else uci commit
uci set openvpn.vpn.config="${DIR}/config.ovpn" next=1
fi fi
uci commit
# Start openvpn and update the LED # Start openvpn and update the LED
/etc/init.d/openvpn start /etc/init.d/openvpn start