Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
os-wireguard: add script to enable cron renewal of DNS for stale conn…
…ections (#2956)
- Loading branch information
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
net/wireguard/src/opnsense/scripts/OPNsense/Wireguard/resolve-dns.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/local/bin/bash | ||
# SPDX-License-Identifier: GPL-2.0 | ||
# | ||
# Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. | ||
|
||
set -e | ||
shopt -s nocasematch | ||
shopt -s extglob | ||
export LC_ALL=C | ||
|
||
for CONFIG_FILE in /usr/local/etc/wireguard/*.conf | ||
do | ||
|
||
[[ $CONFIG_FILE =~ /?([a-zA-Z0-9_=+.-]{1,15})\.conf$ ]] | ||
INTERFACE="${BASH_REMATCH[1]}" | ||
|
||
process_peer() { | ||
[[ $PEER_SECTION -ne 1 || -z $PUBLIC_KEY || -z $ENDPOINT ]] && 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() { | ||
PEER_SECTION=0 | ||
PUBLIC_KEY="" | ||
ENDPOINT="" | ||
} | ||
|
||
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%%*([[:spa | ||
ce:]])}" | ||
[[ $key == "["* ]] && { process_peer; reset_peer_section; } | ||
[[ $key == "[Peer]" ]] && PEER_SECTION=1 | ||
if [[ $PEER_SECTION -eq 1 ]]; then | ||
case "$key" in | ||
PublicKey) PUBLIC_KEY="$value"; continue ;; | ||
Endpoint) ENDPOINT="$value"; continue ;; | ||
esac | ||
fi | ||
done < "$CONFIG_FILE" | ||
process_peer | ||
|
||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters