mirror of
https://github.com/angristan/wireguard-install.git
synced 2024-11-28 07:36:03 +03:00
Allow headless user revokation by CLIENT_NAME
This commit is contained in:
parent
8a97759803
commit
be360d410b
13
README.md
13
README.md
@ -82,6 +82,19 @@ export CLIENT_DOT="3"
|
|||||||
./wireguard-install.sh
|
./wireguard-install.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Headless User Revokation
|
||||||
|
|
||||||
|
It's also possible to automate the revokation of an existing user. Here, the key is to provide the (string) value of the `MENU_OPTION` variable along with the remaining mandatory variables before invoking the script.
|
||||||
|
|
||||||
|
The following Bash script revokes an user `foo` from an existing WireGuard configuration
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
export MENU_OPTION="2"
|
||||||
|
export CLIENT_NAME="foo"
|
||||||
|
./wireguard-install.sh
|
||||||
|
```
|
||||||
|
|
||||||
## Providers
|
## Providers
|
||||||
|
|
||||||
I recommend these cheap cloud providers for your VPN server:
|
I recommend these cheap cloud providers for your VPN server:
|
||||||
|
@ -336,8 +336,10 @@ function revokeClient() {
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Select the existing client you want to revoke"
|
echo "Select the existing client you want to revoke"
|
||||||
|
|
||||||
|
if [[ -z ${CLIENT_NAME} ]]; then
|
||||||
grep -E "^### Client" "/etc/wireguard/${SERVER_WG_NIC}.conf" | cut -d ' ' -f 3 | nl -s ') '
|
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
|
until [[ ${CLIENT_NUMBER} -ge 1 && ${CLIENT_NUMBER} -le ${NUMBER_OF_CLIENTS} ]] || [[ -n ${CLIENT_NAME} ]]; do
|
||||||
if [[ ${CLIENT_NUMBER} == '1' ]]; then
|
if [[ ${CLIENT_NUMBER} == '1' ]]; then
|
||||||
read -rp "Select one client [1]: " CLIENT_NUMBER
|
read -rp "Select one client [1]: " CLIENT_NUMBER
|
||||||
else
|
else
|
||||||
@ -347,7 +349,16 @@ function revokeClient() {
|
|||||||
|
|
||||||
# match the selected number to a client name
|
# 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)
|
CLIENT_NAME=$(grep -E "^### Client" "/etc/wireguard/${SERVER_WG_NIC}.conf" | cut -d ' ' -f 3 | sed -n "${CLIENT_NUMBER}"p)
|
||||||
|
else
|
||||||
|
CLIENT_EXISTS=$(grep -c -E "^### Client ${CLIENT_NAME}\$" "/etc/wireguard/${SERVER_WG_NIC}.conf")
|
||||||
|
|
||||||
|
if [[ ${CLIENT_EXISTS} == '1' ]]; then
|
||||||
|
echo ""
|
||||||
|
echo "The client with the specified name doesn't exists."
|
||||||
|
echo ""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
# remove [Peer] block matching $CLIENT_NAME
|
# remove [Peer] block matching $CLIENT_NAME
|
||||||
sed -i "/^### Client ${CLIENT_NAME}\$/,/^$/d" "/etc/wireguard/${SERVER_WG_NIC}.conf"
|
sed -i "/^### Client ${CLIENT_NAME}\$/,/^$/d" "/etc/wireguard/${SERVER_WG_NIC}.conf"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user