diff --git a/scripts/wireguard/makeCONF.sh b/scripts/wireguard/makeCONF.sh index 09ee2db..e919e4a 100755 --- a/scripts/wireguard/makeCONF.sh +++ b/scripts/wireguard/makeCONF.sh @@ -108,12 +108,12 @@ Endpoint = ${pivpnHOST}:${pivpnPORT} AllowedIPs = 0.0.0.0/0, ::0/0" >> "configs/${CLIENT_NAME}.conf" echo "::: Client config generated" -echo "# begin ${CLIENT_NAME} +echo "### begin ${CLIENT_NAME} ### [Peer] PublicKey = $(cat "keys/${CLIENT_NAME}_pub") PresharedKey = $(cat "keys/${CLIENT_NAME}_psk") AllowedIPs = ${NET_REDUCED}.${COUNT}/32 -# end ${CLIENT_NAME}" >> wg0.conf +### end ${CLIENT_NAME} ###" >> wg0.conf echo "::: Updated server config" if [ -f /etc/pivpn/hosts.wireguard ]; then diff --git a/scripts/wireguard/removeCONF.sh b/scripts/wireguard/removeCONF.sh index 7b44e35..345a670 100755 --- a/scripts/wireguard/removeCONF.sh +++ b/scripts/wireguard/removeCONF.sh @@ -64,7 +64,7 @@ DELETED_COUNT=0 for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do - if ! grep -qw "${CLIENT_NAME}" configs/clients.txt; then + if ! grep -q "^${CLIENT_NAME} " configs/clients.txt; then echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist" else REQUESTED="$(sha256sum "configs/${CLIENT_NAME}.conf" | cut -c 1-64)" @@ -73,17 +73,17 @@ for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do if [[ $REPLY =~ ^[Yy]$ ]]; then # Grab the least significant octed of the client IP address - COUNT=$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $4}') + COUNT=$(grep "^${CLIENT_NAME} " configs/clients.txt | awk '{print $4}') # The creation date of the client - CREATION_DATE="$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $3}')" + CREATION_DATE="$(grep "^${CLIENT_NAME} " configs/clients.txt | awk '{print $3}')" # And its public key - PUBLIC_KEY="$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $2}')" + PUBLIC_KEY="$(grep "^${CLIENT_NAME} " configs/clients.txt | awk '{print $2}')" # Then remove the client matching the variables above sed "\#${CLIENT_NAME} ${PUBLIC_KEY} ${CREATION_DATE} ${COUNT}#d" -i configs/clients.txt # Remove the peer section from the server config - sed "/# begin ${CLIENT_NAME}/,/# end ${CLIENT_NAME}/d" -i wg0.conf + sed "/### begin ${CLIENT_NAME} ###/,/### end ${CLIENT_NAME} ###/d" -i wg0.conf echo "::: Updated server config" rm "configs/${CLIENT_NAME}.conf"