From 0a405eb03e22a6834bfa61fa3dfb0fe1f1d7b2e9 Mon Sep 17 00:00:00 2001 From: Elie Obeid Date: Sun, 22 Jan 2023 13:22:49 +0400 Subject: [PATCH] Added listClients which lists all the wireguard profile names (#312) Co-authored-by: Stanislas Lange --- wireguard-install.sh | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/wireguard-install.sh b/wireguard-install.sh index a190d01..87aac32 100644 --- a/wireguard-install.sh +++ b/wireguard-install.sh @@ -338,6 +338,17 @@ AllowedIPs = ${CLIENT_WG_IPV4}/32,${CLIENT_WG_IPV6}/128" >>"/etc/wireguard/${SER echo "It is also available in ${HOME_DIR}/${SERVER_WG_NIC}-client-${CLIENT_NAME}.conf" } +function listClients() { + NUMBER_OF_CLIENTS=$(grep -c -E "^### Client" "/etc/wireguard/${SERVER_WG_NIC}.conf") + if [[ ${NUMBER_OF_CLIENTS} -eq 0 ]]; then + echo "" + echo "You have no existing clients!" + exit 1 + fi + + grep -E "^### Client" "/etc/wireguard/${SERVER_WG_NIC}.conf" | cut -d ' ' -f 3 | nl -s ') ' +} + function revokeClient() { NUMBER_OF_CLIENTS=$(grep -c -E "^### Client" "/etc/wireguard/${SERVER_WG_NIC}.conf") if [[ ${NUMBER_OF_CLIENTS} == '0' ]]; then @@ -438,23 +449,27 @@ function manageMenu() { echo "" echo "What do you want to do?" echo " 1) Add a new user" - echo " 2) Revoke existing user" - echo " 3) Uninstall WireGuard" - echo " 4) Exit" - until [[ ${MENU_OPTION} =~ ^[1-4]$ ]]; do - read -rp "Select an option [1-4]: " MENU_OPTION + echo " 2) List all users" + echo " 3) Revoke existing user" + echo " 4) Uninstall WireGuard" + echo " 5) Exit" + until [[ ${MENU_OPTION} =~ ^[1-5]$ ]]; do + read -rp "Select an option [1-5]: " MENU_OPTION done case "${MENU_OPTION}" in 1) newClient ;; 2) - revokeClient + listClients ;; 3) - uninstallWg + revokeClient ;; 4) + uninstallWg + ;; + 5) exit 0 ;; esac