aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElie Obeid <elieobeid7@users.noreply.github.com>2023-01-22 13:22:49 +0400
committerGitHub <noreply@github.com>2023-01-22 10:22:49 +0100
commit0a405eb03e22a6834bfa61fa3dfb0fe1f1d7b2e9 (patch)
tree57deb30d6e43f924517f493dd157f684860ee4e1
parent7a1b3c04edfe42ad9d2135f555da7b0b20ecd553 (diff)
Added listClients which lists all the wireguard profile names (#312)
Co-authored-by: Stanislas Lange <git@slange.me>
-rw-r--r--wireguard-install.sh29
1 files 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