mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-19 03:10:16 +00:00
Less fragile way to add and remove clients (issue #1050)
This commit is contained in:
parent
b829bc09f1
commit
de127173dd
2 changed files with 7 additions and 7 deletions
|
@ -108,12 +108,12 @@ Endpoint = ${pivpnHOST}:${pivpnPORT}
|
||||||
AllowedIPs = 0.0.0.0/0, ::0/0" >> "configs/${CLIENT_NAME}.conf"
|
AllowedIPs = 0.0.0.0/0, ::0/0" >> "configs/${CLIENT_NAME}.conf"
|
||||||
echo "::: Client config generated"
|
echo "::: Client config generated"
|
||||||
|
|
||||||
echo "# begin ${CLIENT_NAME}
|
echo "### begin ${CLIENT_NAME} ###
|
||||||
[Peer]
|
[Peer]
|
||||||
PublicKey = $(cat "keys/${CLIENT_NAME}_pub")
|
PublicKey = $(cat "keys/${CLIENT_NAME}_pub")
|
||||||
PresharedKey = $(cat "keys/${CLIENT_NAME}_psk")
|
PresharedKey = $(cat "keys/${CLIENT_NAME}_psk")
|
||||||
AllowedIPs = ${NET_REDUCED}.${COUNT}/32
|
AllowedIPs = ${NET_REDUCED}.${COUNT}/32
|
||||||
# end ${CLIENT_NAME}" >> wg0.conf
|
### end ${CLIENT_NAME} ###" >> wg0.conf
|
||||||
echo "::: Updated server config"
|
echo "::: Updated server config"
|
||||||
|
|
||||||
if [ -f /etc/pivpn/hosts.wireguard ]; then
|
if [ -f /etc/pivpn/hosts.wireguard ]; then
|
||||||
|
|
|
@ -64,7 +64,7 @@ DELETED_COUNT=0
|
||||||
|
|
||||||
for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do
|
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"
|
echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist"
|
||||||
else
|
else
|
||||||
REQUESTED="$(sha256sum "configs/${CLIENT_NAME}.conf" | cut -c 1-64)"
|
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
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
|
||||||
# Grab the least significant octed of the client IP address
|
# 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
|
# 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
|
# 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
|
# Then remove the client matching the variables above
|
||||||
sed "\#${CLIENT_NAME} ${PUBLIC_KEY} ${CREATION_DATE} ${COUNT}#d" -i configs/clients.txt
|
sed "\#${CLIENT_NAME} ${PUBLIC_KEY} ${CREATION_DATE} ${COUNT}#d" -i configs/clients.txt
|
||||||
|
|
||||||
# Remove the peer section from the server config
|
# 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"
|
echo "::: Updated server config"
|
||||||
|
|
||||||
rm "configs/${CLIENT_NAME}.conf"
|
rm "configs/${CLIENT_NAME}.conf"
|
||||||
|
|
Loading…
Reference in a new issue