mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-19 11:20:15 +00:00
Multiple fixes and Shellcheck complaiance
fixes for Issue #1306, qrcode now defaults to ansiutf8, added flag -a256 or --ansi256 if their fonts are having trouble Shellcheck compliance #1233 for qrcodeCONF.sh, LIST array is now created with mapfile instead quoted multiple variables. fixes for Issue #1307, User creation won't allow user creation with name starting with "-", qrcodeCONF.sh won't accept wrong options or users starting with "-" and exit with error code 1
This commit is contained in:
parent
9de9f84ff0
commit
4a5804a24c
2 changed files with 20 additions and 6 deletions
|
@ -64,6 +64,11 @@ if [[ "${CLIENT_NAME}" =~ [^a-zA-Z0-9.@_-] ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "${CLIENT_NAME:0:1}" == "-" ]]; then
|
||||||
|
echo "Name cannot start with -"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "${CLIENT_NAME}" =~ ^[0-9]+$ ]]; then
|
if [[ "${CLIENT_NAME}" =~ ^[0-9]+$ ]]; then
|
||||||
echo "Names cannot be integers."
|
echo "Names cannot be integers."
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
helpFunc(){
|
helpFunc(){
|
||||||
echo "::: Show the qrcode of a client for use with the mobile app"
|
echo "::: Show the qrcode of a client for use with the mobile app"
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo "::: Usage: pivpn <-qr|qrcode> [-h|--help] [<client-1>] ... [<client-n>] ..."
|
echo "::: Usage: pivpn <-qr|qrcode> [-h|--help] [Options] [<client-1>] ... [<client-n>] ..."
|
||||||
echo ":::"
|
echo ":::"
|
||||||
|
echo "::: Options:"
|
||||||
|
echo "::: -a256|ansi256 Shows QR Code in ansi256 characters"
|
||||||
echo "::: Commands:"
|
echo "::: Commands:"
|
||||||
echo "::: [none] Interactive mode"
|
echo "::: [none] Interactive mode"
|
||||||
echo "::: <client> Client(s) to show"
|
echo "::: <client> Client(s) to show"
|
||||||
|
@ -12,6 +14,7 @@ helpFunc(){
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse input arguments
|
# Parse input arguments
|
||||||
|
encoding="ansiutf8"
|
||||||
while test $# -gt 0
|
while test $# -gt 0
|
||||||
do
|
do
|
||||||
_key="$1"
|
_key="$1"
|
||||||
|
@ -20,6 +23,9 @@ do
|
||||||
helpFunc
|
helpFunc
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
-a256|--ansi256)
|
||||||
|
encoding="ansi256"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
CLIENTS_TO_SHOW+=("$1")
|
CLIENTS_TO_SHOW+=("$1")
|
||||||
;;
|
;;
|
||||||
|
@ -33,14 +39,14 @@ if [ ! -s clients.txt ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LIST=($(awk '{print $1}' clients.txt))
|
mapfile -t 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::"
|
||||||
len=${#LIST[@]}
|
len=${#LIST[@]}
|
||||||
COUNTER=1
|
COUNTER=1
|
||||||
while [ $COUNTER -le ${len} ]; do
|
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++))
|
((COUNTER++))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -54,13 +60,16 @@ fi
|
||||||
|
|
||||||
for CLIENT_NAME in "${CLIENTS_TO_SHOW[@]}"; do
|
for CLIENT_NAME in "${CLIENTS_TO_SHOW[@]}"; do
|
||||||
re='^[0-9]+$'
|
re='^[0-9]+$'
|
||||||
if [[ ${CLIENT_NAME} =~ $re ]] ; then
|
if [[ ${CLIENT_NAME:0:1} == "-" ]]; then
|
||||||
|
echo "${CLIENT_NAME} is not a valid client name or option"
|
||||||
|
exit 1
|
||||||
|
elif [[ ${CLIENT_NAME} =~ $re ]] ; then
|
||||||
CLIENT_NAME=${LIST[$((CLIENT_NAME -1))]}
|
CLIENT_NAME=${LIST[$((CLIENT_NAME -1))]}
|
||||||
fi
|
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 "====================================================================="
|
||||||
qrencode -t ansi256 < "${CLIENT_NAME}.conf"
|
qrencode -t "${encoding}" < "${CLIENT_NAME}.conf"
|
||||||
echo "====================================================================="
|
echo "====================================================================="
|
||||||
else
|
else
|
||||||
echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist"
|
echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist"
|
||||||
|
|
Loading…
Reference in a new issue