Skip to content

Commit

Permalink
Merge pull request #38 from hibo98/nm-wireguard-unused-time
Browse files Browse the repository at this point in the history
Add config option to specify time when unused wg keys where delete
  • Loading branch information
cremesk authored Oct 27, 2021
2 parents a421946 + 0fead38 commit 121bc07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions salt/freifunk/base/wireguard/usr/local/bin/wg-backbone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ start_wg()
public=$(echo "$secret" | wg pubkey)
uci -q set ffdd.wireguard.public="$public"

# set unused days delete timeout
if [ -z "$(uci -q get ffdd.wireguard.unused_days)" ]; then
uci -q set ffdd.wireguard.unused_days=30
fi

# save config
uci commit

Expand Down
7 changes: 4 additions & 3 deletions salt/freifunk/base/wireguard/usr/local/bin/wg-check-peers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ wg_ifname='tbb_wg'
peers_dir='/etc/wireguard-backbone/peers'

current_date=$(date +%s)
days30=60*60*24*30
unused_days=$(uci -qX get ffdd.wireguard.unused_days || echo 30)
unused_days_sec=60*60*24*$unused_days

get_peer_file()
{
Expand Down Expand Up @@ -49,8 +50,8 @@ clean_peers()
lastseen=$(grep lastseen $file | sed 's#lastseen\s*##')
if [ ! -z $lastseen ];
then
current_days30=$(($(($current_date))-$(($days30))))
if [ $(($lastseen)) -lt $(($current_days30)) ];
current_unused_date=$(($(($current_date))-$(($unused_days_sec))))
if [ $(($lastseen)) -lt $(($current_unused_date)) ];
then
wg set "$wg_ifname" peer "$key" remove
rm "$file"
Expand Down

0 comments on commit 121bc07

Please sign in to comment.