1
1
mirror of https://github.com/angristan/wireguard-install.git synced 2024-06-06 05:20:49 +00:00

Add revokeClient()

A lot of additions but it's the same code as the openvpn-install repo
This commit is contained in:
randomshell 2020-07-02 17:26:15 +00:00
parent a5faeb1968
commit b5509d5192

View File

@ -96,6 +96,41 @@ AllowedIPs = $CLIENT_WG_IPV4/32,$CLIENT_WG_IPV6/128" >>"/etc/wireguard/$SERVER_W
echo "It is also available in $HOME/$SERVER_WG_NIC-client-$CLIENT_NAME.conf"
}
function revokeClient() {
# Load params
source /etc/wireguard/params
NUMBER_OF_CLIENTS=$(grep -c -E "^### Client" "/etc/wireguard/$SERVER_WG_NIC.conf")
if [[ $NUMBER_OF_CLIENTS == '0' ]]; then
echo ""
echo "You have no existing clients!"
exit 1
fi
echo ""
echo "Select the existing client you want to revoke"
grep -E "^### Client" "/etc/wireguard/$SERVER_WG_NIC.conf" | cut -d ' ' -f 3 | nl -s ') '
until [[ $CLIENT_NUMBER -ge 1 && $CLIENT_NUMBER -le $NUMBER_OF_CLIENTS ]]; do
if [[ $CLIENT_NUMBER == '1' ]]; then
read -rp "Select one client [1]: " CLIENT_NUMBER
else
read -rp "Select one client [1-$NUMBER_OF_CLIENTS]: " CLIENT_NUMBER
fi
done
# match the selected number to a client name
CLIENT_NAME=$(grep -E "^### Client" "/etc/wireguard/$SERVER_WG_NIC.conf" | cut -d ' ' -f 3 | sed -n "$CLIENT_NUMBER"p)
# remove [Peer] block matching $CLIENT_NAME
sed -i "/^### Client ${CLIENT_NAME}\$/,/^$/d" "/etc/wireguard/$SERVER_WG_NIC.conf"
# remove generated client file
rm -f "$HOME/$SERVER_WG_NIC-client-$CLIENT_NAME.conf"
# restart wireguard to apply changes
systemctl restart "wg-quick@$SERVER_WG_NIC"
}
if [ "$EUID" -ne 0 ]; then
echo "You need to run this script as root"
exit 1
@ -123,6 +158,14 @@ if [[ $1 == "add-client" ]]; then
echo "Please install and configure WireGuard first."
exit 1
fi
elif [[ $1 == "revoke-client" ]]; then
if [[ -e /etc/wireguard/params ]]; then
revokeClient
exit 0
else
echo "Please install and configure WireGuard first."
exit 1
fi
elif [[ -e /etc/wireguard/params ]]; then
echo "WireGuard is already installed. Run with 'add-client' to add a client."
exit 1