From 934aff8871cd3d1eb9077b6177007e98cbd2937e Mon Sep 17 00:00:00 2001 From: GizMoCuz Date: Wed, 8 Jul 2020 15:32:19 +0200 Subject: [PATCH 1/5] Add Index for Wireguard remove/qr commands --- scripts/wireguard/qrcodeCONF.sh | 15 ++++++++++----- scripts/wireguard/removeCONF.sh | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/scripts/wireguard/qrcodeCONF.sh b/scripts/wireguard/qrcodeCONF.sh index 0420eb5..2927da9 100755 --- a/scripts/wireguard/qrcodeCONF.sh +++ b/scripts/wireguard/qrcodeCONF.sh @@ -33,17 +33,18 @@ if [ ! -s clients.txt ]; then exit 1 fi +LIST=($(awk '{print $1}' clients.txt)) if [ "${#CLIENTS_TO_SHOW[@]}" -eq 0 ]; then echo -e "::\e[4m Client list \e[0m::" - LIST=($(awk '{print $1}' clients.txt)) + len=${#LIST[@]} COUNTER=1 - while [ $COUNTER -le ${#LIST[@]} ]; do - echo "• ${LIST[(($COUNTER-1))]}" + while [ $COUNTER -le ${len} ]; do + printf "• [%0${#len}s] %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} ((COUNTER++)) done - read -r -p "Please enter the Name of the Client to show: " CLIENTS_TO_SHOW + read -r -p "Please enter the Index/Name of the Client to show: " CLIENTS_TO_SHOW if [ -z "${CLIENTS_TO_SHOW}" ]; then echo "::: You can not leave this blank!" @@ -52,6 +53,10 @@ if [ "${#CLIENTS_TO_SHOW[@]}" -eq 0 ]; then fi for CLIENT_NAME in "${CLIENTS_TO_SHOW[@]}"; do + re='^[0-9]+$' + if [[ ${CLIENT_NAME} =~ $re ]] ; then + CLIENT_NAME=${LIST[$(($CLIENT_NAME -1))]} + fi if grep -qw "${CLIENT_NAME}" clients.txt; then echo -e "::: Showing client \e[1m${CLIENT_NAME}\e[0m below" echo "=====================================================================" @@ -60,4 +65,4 @@ for CLIENT_NAME in "${CLIENTS_TO_SHOW[@]}"; do else echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist" fi -done \ No newline at end of file +done diff --git a/scripts/wireguard/removeCONF.sh b/scripts/wireguard/removeCONF.sh index 345a670..7a72328 100755 --- a/scripts/wireguard/removeCONF.sh +++ b/scripts/wireguard/removeCONF.sh @@ -42,17 +42,17 @@ if [ ! -s configs/clients.txt ]; then exit 1 fi +LIST=($(awk '{print $1}' configs/clients.txt)) if [ "${#CLIENTS_TO_REMOVE[@]}" -eq 0 ]; then - echo -e "::\e[4m Client list \e[0m::" - LIST=($(awk '{print $1}' configs/clients.txt)) + len=${#LIST[@]} COUNTER=1 - while [ $COUNTER -le ${#LIST[@]} ]; do - echo "• ${LIST[(($COUNTER-1))]}" + while [ $COUNTER -le ${len} ]; do + printf "• [%0${#len}s] %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} ((COUNTER++)) done - read -r -p "Please enter the Name of the Client to be removed from the list above: " CLIENTS_TO_REMOVE + read -r -p "Please enter the Index/Name of the Client to be removed from the list above: " CLIENTS_TO_REMOVE if [ -z "${CLIENTS_TO_REMOVE}" ]; then echo "::: You can not leave this blank!" @@ -64,6 +64,11 @@ DELETED_COUNT=0 for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do + re='^[0-9]+$' + if [[ ${CLIENT_NAME} =~ $re ]] ; then + CLIENT_NAME=${LIST[$(($CLIENT_NAME -1))]} + fi + if ! grep -q "^${CLIENT_NAME} " configs/clients.txt; then echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist" else From c00e208286547e7c494b09e6868340b8d83e1039 Mon Sep 17 00:00:00 2001 From: GizMoCuz Date: Wed, 8 Jul 2020 16:36:23 +0200 Subject: [PATCH 2/5] Add Index for OpenVPN remover command --- scripts/openvpn/removeOVPN.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/openvpn/removeOVPN.sh b/scripts/openvpn/removeOVPN.sh index 4f79385..79a5936 100755 --- a/scripts/openvpn/removeOVPN.sh +++ b/scripts/openvpn/removeOVPN.sh @@ -52,17 +52,23 @@ if [[ -z "${CERTS_TO_REVOKE}" ]]; then STATUS=$(echo "$line" | awk '{print $1}') if [[ "${STATUS}" = "V" ]]; then NAME=$(echo "$line" | sed -e 's:.*/CN=::') - CERTS[$i]=${NAME} if [ "$i" != 0 ]; then # Prevent printing "server" certificate - printf " %s\n" "$NAME" + CERTS[$i]=${NAME} fi let i=i+1 fi done <${INDEX} + + i=1 + len=${#CERTS[@]} + while [ $i -le ${len} ]; do + printf "[%0${#len}s] %s\r\n" ${i} ${CERTS[(($i))]} + ((i++)) + done printf "\n" - echo -n "::: Please enter the Name of the client to be revoked from the list above: " + echo -n "::: Please enter the Index/Name of the client to be revoked from the list above: " read -r NAME if [[ -z "${NAME}" ]]; then @@ -70,6 +76,10 @@ if [[ -z "${CERTS_TO_REVOKE}" ]]; then exit 1 fi + if [[ ${NAME} =~ $re ]] ; then + NAME=${CERTS[$(($NAME))]} + fi + for((x=1;x<=i;++x)); do if [ "${CERTS[$x]}" = "${NAME}" ]; then VALID=1 From 7aa91fc67af28d5d64b07c7b0ef101283530b45b Mon Sep 17 00:00:00 2001 From: GizMoCuz Date: Wed, 8 Jul 2020 16:36:50 +0200 Subject: [PATCH 3/5] Removed middle-dot in print function --- scripts/wireguard/qrcodeCONF.sh | 2 +- scripts/wireguard/removeCONF.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/wireguard/qrcodeCONF.sh b/scripts/wireguard/qrcodeCONF.sh index 2927da9..0000a69 100755 --- a/scripts/wireguard/qrcodeCONF.sh +++ b/scripts/wireguard/qrcodeCONF.sh @@ -40,7 +40,7 @@ if [ "${#CLIENTS_TO_SHOW[@]}" -eq 0 ]; then len=${#LIST[@]} COUNTER=1 while [ $COUNTER -le ${len} ]; do - printf "• [%0${#len}s] %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} + printf "[%0${#len}s] %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} ((COUNTER++)) done diff --git a/scripts/wireguard/removeCONF.sh b/scripts/wireguard/removeCONF.sh index 7a72328..5cd325c 100755 --- a/scripts/wireguard/removeCONF.sh +++ b/scripts/wireguard/removeCONF.sh @@ -48,7 +48,7 @@ if [ "${#CLIENTS_TO_REMOVE[@]}" -eq 0 ]; then len=${#LIST[@]} COUNTER=1 while [ $COUNTER -le ${len} ]; do - printf "• [%0${#len}s] %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} + printf "[%0${#len}s] %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} ((COUNTER++)) done From e6b081e0f9ce6d6529ec568930ff71f46e4681c2 Mon Sep 17 00:00:00 2001 From: GizMoCuz Date: Wed, 8 Jul 2020 16:43:32 +0200 Subject: [PATCH 4/5] Added missing regex --- scripts/openvpn/removeOVPN.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/openvpn/removeOVPN.sh b/scripts/openvpn/removeOVPN.sh index 79a5936..d8e1061 100755 --- a/scripts/openvpn/removeOVPN.sh +++ b/scripts/openvpn/removeOVPN.sh @@ -76,6 +76,7 @@ if [[ -z "${CERTS_TO_REVOKE}" ]]; then exit 1 fi + re='^[0-9]+$' if [[ ${NAME} =~ $re ]] ; then NAME=${CERTS[$(($NAME))]} fi From 960a0848666fc90c67f88df686e23b76da1be0fb Mon Sep 17 00:00:00 2001 From: Rob Peters Date: Tue, 14 Jul 2020 13:27:40 +0200 Subject: [PATCH 5/5] Better list presentation --- scripts/openvpn/removeOVPN.sh | 2 +- scripts/wireguard/qrcodeCONF.sh | 2 +- scripts/wireguard/removeCONF.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/openvpn/removeOVPN.sh b/scripts/openvpn/removeOVPN.sh index d8e1061..475140a 100755 --- a/scripts/openvpn/removeOVPN.sh +++ b/scripts/openvpn/removeOVPN.sh @@ -63,7 +63,7 @@ if [[ -z "${CERTS_TO_REVOKE}" ]]; then i=1 len=${#CERTS[@]} while [ $i -le ${len} ]; do - printf "[%0${#len}s] %s\r\n" ${i} ${CERTS[(($i))]} + printf "%0${#len}s) %s\r\n" ${i} ${CERTS[(($i))]} ((i++)) done printf "\n" diff --git a/scripts/wireguard/qrcodeCONF.sh b/scripts/wireguard/qrcodeCONF.sh index 0000a69..6d980fe 100755 --- a/scripts/wireguard/qrcodeCONF.sh +++ b/scripts/wireguard/qrcodeCONF.sh @@ -40,7 +40,7 @@ if [ "${#CLIENTS_TO_SHOW[@]}" -eq 0 ]; then len=${#LIST[@]} COUNTER=1 while [ $COUNTER -le ${len} ]; do - printf "[%0${#len}s] %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} + printf "%0${#len}s) %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} ((COUNTER++)) done diff --git a/scripts/wireguard/removeCONF.sh b/scripts/wireguard/removeCONF.sh index 5cd325c..33967b9 100755 --- a/scripts/wireguard/removeCONF.sh +++ b/scripts/wireguard/removeCONF.sh @@ -48,7 +48,7 @@ if [ "${#CLIENTS_TO_REMOVE[@]}" -eq 0 ]; then len=${#LIST[@]} COUNTER=1 while [ $COUNTER -le ${len} ]; do - printf "[%0${#len}s] %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} + printf "%0${#len}s) %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} ((COUNTER++)) done