Added listClients which lists all the wireguard profile names (#312)

Co-authored-by: Stanislas Lange <git@slange.me>
This commit is contained in:
Elie Obeid 2023-01-22 13:22:49 +04:00 committed by GitHub
parent 7a1b3c04ed
commit 0a405eb03e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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" 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() { function revokeClient() {
NUMBER_OF_CLIENTS=$(grep -c -E "^### Client" "/etc/wireguard/${SERVER_WG_NIC}.conf") NUMBER_OF_CLIENTS=$(grep -c -E "^### Client" "/etc/wireguard/${SERVER_WG_NIC}.conf")
if [[ ${NUMBER_OF_CLIENTS} == '0' ]]; then if [[ ${NUMBER_OF_CLIENTS} == '0' ]]; then
@ -438,23 +449,27 @@ function manageMenu() {
echo "" echo ""
echo "What do you want to do?" echo "What do you want to do?"
echo " 1) Add a new user" echo " 1) Add a new user"
echo " 2) Revoke existing user" echo " 2) List all users"
echo " 3) Uninstall WireGuard" echo " 3) Revoke existing user"
echo " 4) Exit" echo " 4) Uninstall WireGuard"
until [[ ${MENU_OPTION} =~ ^[1-4]$ ]]; do echo " 5) Exit"
read -rp "Select an option [1-4]: " MENU_OPTION until [[ ${MENU_OPTION} =~ ^[1-5]$ ]]; do
read -rp "Select an option [1-5]: " MENU_OPTION
done done
case "${MENU_OPTION}" in case "${MENU_OPTION}" in
1) 1)
newClient newClient
;; ;;
2) 2)
revokeClient listClients
;; ;;
3) 3)
uninstallWg revokeClient
;; ;;
4) 4)
uninstallWg
;;
5)
exit 0 exit 0
;; ;;
esac esac