Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
add enable/disable client feature
Browse files Browse the repository at this point in the history
  • Loading branch information
finzzz committed Jul 6, 2021
1 parent 2be7468 commit e0a9368
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ wgzero list
wgzero add clientname
wgzero del clientname
wgzero qr clientname
wgzero enable clientname
wgzero disable clientname
```

# FAQ, troubleshoot, etc.
Expand Down
30 changes: 30 additions & 0 deletions wgzero
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Run(){
Add "$@" ;;
"del")
Del "$@" ;;
"enable")
Enable "$@" ;;
"disable")
Disable "$@" ;;
"qr")
QR "$2" ;;
*)
Expand Down Expand Up @@ -308,4 +312,30 @@ Del(){
fi
}

ModifyClientEntry(){
CFG="$CONFIGFOLDER/$1"
if [ -d "$CFG" ]; then
PUBKEY=$(cat "$CFG"/pub.key)
LINENUM=$(grep -n "$PUBKEY" "$WG0" | cut -d ':' -f 1)

if [ ! "$LINENUM" ]; then
Print "Cannot find public key in $WG0\\n" "red" && exit
fi

sed -i -e "$LINENUM $2" -e "$(expr "$LINENUM" + 1) $2" -e "$(expr "$LINENUM" - 1) $2" "$WG0"
wg set wg0 peer "$(cat "$CFG/pub.key")" remove
wg addconf wg0 <(wg-quick strip wg0)
else
Print "Client doesn't exist\\n" "red"
fi
}

Disable(){
ModifyClientEntry $2 "s/./#&/"
}

Enable(){
ModifyClientEntry $2 "s/^#//"
}

Run "$@"

0 comments on commit e0a9368

Please sign in to comment.