From 6e01d57d7520934d81cb0aa01e4f78bcf8b37f20 Mon Sep 17 00:00:00 2001 From: jdgregson Date: Fri, 22 Jan 2021 22:54:07 -0800 Subject: [PATCH] Simplified VPN config cycling --- .../library/remote-access/openvpn/payload.sh | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/payloads/library/remote-access/openvpn/payload.sh b/payloads/library/remote-access/openvpn/payload.sh index a848ec6..4a8734a 100755 --- a/payloads/library/remote-access/openvpn/payload.sh +++ b/payloads/library/remote-access/openvpn/payload.sh @@ -60,6 +60,7 @@ function start() { # # If no numbered configs exist, the button functions as a way to reset the # VPN connection. + next=1 while true; do NO_LED=true BUTTON @@ -68,21 +69,15 @@ function start() { /etc/init.d/openvpn stop # Determine which config to load next - configpath=$(uci get openvpn.vpn.config) - configfile=$(echo "${configpath}" | grep -Eo "config[0-9]*") - confignumber=$(echo "${configfile}" | grep -Eo "[0-9]*") - if [ -z "${confignumber}" ]; then - confignumber="0" - fi - nextconfignumber="$(($confignumber + 1))" - if [ -f "${DIR}/config${nextconfignumber}.ovpn" ]; then - uci set openvpn.vpn.config="${DIR}/config${nextconfignumber}.ovpn" + if [ -f "${DIR}/config${next}.ovpn" ]; then + uci set openvpn.vpn.config="${DIR}/config${next}.ovpn" + uci commit + next=$(($next + 1)) elif [ -f "${DIR}/config1.ovpn" ]; then uci set openvpn.vpn.config="${DIR}/config1.ovpn" - else - uci set openvpn.vpn.config="${DIR}/config.ovpn" + uci commit + next=1 fi - uci commit # Start openvpn and update the LED /etc/init.d/openvpn start