mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-18 19:00:15 +00:00
Merge pull request #1087 from gizmocuz/ft-index
Feature: Add Index based option for remove/qr commands
This commit is contained in:
commit
4b239cfdc6
3 changed files with 34 additions and 13 deletions
|
@ -56,17 +56,23 @@ if [[ -z "${CERTS_TO_REVOKE}" ]]; then
|
||||||
STATUS=$(echo "$line" | awk '{print $1}')
|
STATUS=$(echo "$line" | awk '{print $1}')
|
||||||
if [[ "${STATUS}" = "V" ]]; then
|
if [[ "${STATUS}" = "V" ]]; then
|
||||||
NAME=$(echo "$line" | sed -e 's:.*/CN=::')
|
NAME=$(echo "$line" | sed -e 's:.*/CN=::')
|
||||||
CERTS[$i]=${NAME}
|
|
||||||
if [ "$i" != 0 ]; then
|
if [ "$i" != 0 ]; then
|
||||||
# Prevent printing "server" certificate
|
# Prevent printing "server" certificate
|
||||||
printf " %s\n" "$NAME"
|
CERTS[$i]=${NAME}
|
||||||
fi
|
fi
|
||||||
let i=i+1
|
let i=i+1
|
||||||
fi
|
fi
|
||||||
done <${INDEX}
|
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"
|
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
|
read -r NAME
|
||||||
|
|
||||||
if [[ -z "${NAME}" ]]; then
|
if [[ -z "${NAME}" ]]; then
|
||||||
|
@ -74,6 +80,11 @@ if [[ -z "${CERTS_TO_REVOKE}" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
re='^[0-9]+$'
|
||||||
|
if [[ ${NAME} =~ $re ]] ; then
|
||||||
|
NAME=${CERTS[$(($NAME))]}
|
||||||
|
fi
|
||||||
|
|
||||||
for((x=1;x<=i;++x)); do
|
for((x=1;x<=i;++x)); do
|
||||||
if [ "${CERTS[$x]}" = "${NAME}" ]; then
|
if [ "${CERTS[$x]}" = "${NAME}" ]; then
|
||||||
VALID=1
|
VALID=1
|
||||||
|
|
|
@ -33,17 +33,18 @@ if [ ! -s clients.txt ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
LIST=($(awk '{print $1}' clients.txt))
|
||||||
if [ "${#CLIENTS_TO_SHOW[@]}" -eq 0 ]; then
|
if [ "${#CLIENTS_TO_SHOW[@]}" -eq 0 ]; then
|
||||||
|
|
||||||
echo -e "::\e[4m Client list \e[0m::"
|
echo -e "::\e[4m Client list \e[0m::"
|
||||||
LIST=($(awk '{print $1}' clients.txt))
|
len=${#LIST[@]}
|
||||||
COUNTER=1
|
COUNTER=1
|
||||||
while [ $COUNTER -le ${#LIST[@]} ]; do
|
while [ $COUNTER -le ${len} ]; do
|
||||||
echo "• ${LIST[(($COUNTER-1))]}"
|
printf "%0${#len}s) %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]}
|
||||||
((COUNTER++))
|
((COUNTER++))
|
||||||
done
|
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
|
if [ -z "${CLIENTS_TO_SHOW}" ]; then
|
||||||
echo "::: You can not leave this blank!"
|
echo "::: You can not leave this blank!"
|
||||||
|
@ -52,6 +53,10 @@ if [ "${#CLIENTS_TO_SHOW[@]}" -eq 0 ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for CLIENT_NAME in "${CLIENTS_TO_SHOW[@]}"; do
|
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
|
if grep -qw "${CLIENT_NAME}" clients.txt; then
|
||||||
echo -e "::: Showing client \e[1m${CLIENT_NAME}\e[0m below"
|
echo -e "::: Showing client \e[1m${CLIENT_NAME}\e[0m below"
|
||||||
echo "====================================================================="
|
echo "====================================================================="
|
||||||
|
@ -60,4 +65,4 @@ for CLIENT_NAME in "${CLIENTS_TO_SHOW[@]}"; do
|
||||||
else
|
else
|
||||||
echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist"
|
echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
@ -46,17 +46,17 @@ if [ ! -s configs/clients.txt ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
LIST=($(awk '{print $1}' configs/clients.txt))
|
||||||
if [ "${#CLIENTS_TO_REMOVE[@]}" -eq 0 ]; then
|
if [ "${#CLIENTS_TO_REMOVE[@]}" -eq 0 ]; then
|
||||||
|
|
||||||
echo -e "::\e[4m Client list \e[0m::"
|
echo -e "::\e[4m Client list \e[0m::"
|
||||||
LIST=($(awk '{print $1}' configs/clients.txt))
|
len=${#LIST[@]}
|
||||||
COUNTER=1
|
COUNTER=1
|
||||||
while [ $COUNTER -le ${#LIST[@]} ]; do
|
while [ $COUNTER -le ${len} ]; do
|
||||||
echo "• ${LIST[(($COUNTER-1))]}"
|
printf "%0${#len}s) %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]}
|
||||||
((COUNTER++))
|
((COUNTER++))
|
||||||
done
|
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
|
if [ -z "${CLIENTS_TO_REMOVE}" ]; then
|
||||||
echo "::: You can not leave this blank!"
|
echo "::: You can not leave this blank!"
|
||||||
|
@ -68,6 +68,11 @@ DELETED_COUNT=0
|
||||||
|
|
||||||
for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do
|
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
|
if ! grep -q "^${CLIENT_NAME} " configs/clients.txt; then
|
||||||
echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist"
|
echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue