diff --git a/net/wireguard/src/opnsense/scripts/OPNsense/Wireguard/resolve-dns.bash b/net/wireguard/src/opnsense/scripts/OPNsense/Wireguard/resolve-dns.bash index 881ef276f..b7faf881a 100755 --- a/net/wireguard/src/opnsense/scripts/OPNsense/Wireguard/resolve-dns.bash +++ b/net/wireguard/src/opnsense/scripts/OPNsense/Wireguard/resolve-dns.bash @@ -8,40 +8,38 @@ shopt -s nocasematch shopt -s extglob export LC_ALL=C -for CONFIG_FILE in /usr/local/etc/wireguard/*.conf -do +for CONFIG_FILE in /usr/local/etc/wireguard/*.conf; do -[[ $CONFIG_FILE =~ /?([a-zA-Z0-9_=+.-]{1,15})\.conf$ ]] -INTERFACE="${BASH_REMATCH[1]}" + [[ $CONFIG_FILE =~ /?([a-zA-Z0-9_=+.-]{1,15})\.conf$ ]] + INTERFACE="${BASH_REMATCH[1]}" -process_peer() { + process_peer() { [[ $PEER_SECTION -ne 1 || -z $PUBLIC_KEY || -z $ENDPOINT ]] && return 0 - [[ $(wg show "$INTERFACE" latest-handshakes) =~ ${PUBLIC_KEY//+/\\+}\ ([0-9]+) ]] || return 0 + [[ $(wg show "$INTERFACE" latest-handshakes) =~ ${PUBLIC_KEY//+/\\+}\ ([0-9]+) ]] || return 0 (( ($EPOCHSECONDS - ${BASH_REMATCH[1]}) > 135 )) || return 0 wg set "$INTERFACE" peer "$PUBLIC_KEY" endpoint "$ENDPOINT" reset_peer_section -} + } -reset_peer_section() { + reset_peer_section() { PEER_SECTION=0 PUBLIC_KEY="" ENDPOINT="" -} + } -reset_peer_section -while read -r line || [[ -n $line ]]; do + reset_peer_section + while read -r line || [[ -n $line ]]; do stripped="${line%%\#*}" key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}" value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}" [[ $key == "["* ]] && { process_peer; reset_peer_section; } [[ $key == "[Peer]" ]] && PEER_SECTION=1 if [[ $PEER_SECTION -eq 1 ]]; then - case "$key" in + case "$key" in PublicKey) PUBLIC_KEY="$value"; continue ;; Endpoint) ENDPOINT="$value"; continue ;; - esac + esac fi -done < "$CONFIG_FILE" -process_peer - + done < "$CONFIG_FILE" + process_peer done diff --git a/net/wireguard/src/opnsense/service/conf/actions.d/actions_wireguard.conf b/net/wireguard/src/opnsense/service/conf/actions.d/actions_wireguard.conf index c132c16b8..ac9d353e8 100644 --- a/net/wireguard/src/opnsense/service/conf/actions.d/actions_wireguard.conf +++ b/net/wireguard/src/opnsense/service/conf/actions.d/actions_wireguard.conf @@ -27,8 +27,8 @@ description: Restart WireGuard command:/usr/local/opnsense/scripts/OPNsense/Wireguard/resolve-dns.bash parameters: type:script -message:Renew DNS for Wireguard -description:Renew DNS for Wireguard on stale connections +message:Renew DNS for WireGuard +description:Renew DNS for WireGuard on stale connections [genkey] command:/usr/local/opnsense/scripts/OPNsense/Wireguard/genkey.sh