mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-18 19:00:15 +00:00
added -n and -p options to pivpn add
::: Create a client ovpn profile, optional nopass ::: ::: Usage: pivpn <-a|add> [-n|--name <arg>] [-p|--password <arg>]|[nopass] [-h|--help] ::: ::: Commands: ::: nopass Create a client without a password ::: -n,--name Name for the Client (default: 'raspberrypi') ::: -p,--password Password for the Client (no default) ::: -h,--help Show this help dialog
This commit is contained in:
parent
277a212a8f
commit
7a65f083c4
1 changed files with 81 additions and 21 deletions
|
@ -10,6 +10,59 @@ TA="ta.key"
|
||||||
INDEX="/etc/openvpn/easy-rsa/pki/index.txt"
|
INDEX="/etc/openvpn/easy-rsa/pki/index.txt"
|
||||||
INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER)
|
INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER)
|
||||||
|
|
||||||
|
helpFunc() {
|
||||||
|
echo "::: Create a client ovpn profile, optional nopass"
|
||||||
|
echo ":::"
|
||||||
|
echo "::: Usage: pivpn <-a|add> [-n|--name <arg>] [-p|--password <arg>]|[nopass] [-h|--help]"
|
||||||
|
echo ":::"
|
||||||
|
echo "::: Commands:"
|
||||||
|
echo "::: nopass Create a client without a password"
|
||||||
|
echo "::: -n,--name Name for the Client (default: '"$(hostname)"')"
|
||||||
|
echo "::: -p,--password Password for the Client (no default)"
|
||||||
|
echo "::: -h,--help Show this help dialog"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Parse input arguments
|
||||||
|
while test $# -gt 0
|
||||||
|
do
|
||||||
|
_key="$1"
|
||||||
|
case "$_key" in
|
||||||
|
-n|--name|--name=*)
|
||||||
|
_val="${_key##--name=}"
|
||||||
|
if test "$_val" = "$_key"
|
||||||
|
then
|
||||||
|
test $# -lt 2 && echo "Missing value for the optional argument '$_key'." && exit 1
|
||||||
|
_val="$2"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
NAME="$_val"
|
||||||
|
;;
|
||||||
|
-p|--password|--password=*)
|
||||||
|
_val="${_key##--password=}"
|
||||||
|
if test "$_val" = "$_key"
|
||||||
|
then
|
||||||
|
test $# -lt 2 && echo "Missing value for the optional argument '$_key'." && exit 1
|
||||||
|
_val="$2"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
PASSWD="$_val"
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
helpFunc
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
nopass)
|
||||||
|
NO_PASS="1"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error: Got an unexpected argument '$1'"
|
||||||
|
helpFunc
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
# Functions def
|
# Functions def
|
||||||
|
|
||||||
function keynoPASS() {
|
function keynoPASS() {
|
||||||
|
@ -27,25 +80,27 @@ EOF
|
||||||
|
|
||||||
function keyPASS() {
|
function keyPASS() {
|
||||||
|
|
||||||
stty -echo
|
|
||||||
while true
|
|
||||||
do
|
|
||||||
printf "Enter the password for the client: "
|
|
||||||
read -r PASSWD
|
|
||||||
printf "\n"
|
|
||||||
printf "Enter the password again to verify: "
|
|
||||||
read -r PASSWD2
|
|
||||||
printf "\n"
|
|
||||||
[ "${PASSWD}" = "${PASSWD2}" ] && break
|
|
||||||
printf "Passwords do not match! Please try again.\n"
|
|
||||||
done
|
|
||||||
stty echo
|
|
||||||
if [[ -z "${PASSWD}" ]]; then
|
if [[ -z "${PASSWD}" ]]; then
|
||||||
echo "You left the password blank"
|
stty -echo
|
||||||
echo "If you don't want a password, please run:"
|
while true
|
||||||
echo "pivpn add nopass"
|
do
|
||||||
exit 1
|
printf "Enter the password for the client: "
|
||||||
fi
|
read -r PASSWD
|
||||||
|
printf "\n"
|
||||||
|
printf "Enter the password again to verify: "
|
||||||
|
read -r PASSWD2
|
||||||
|
printf "\n"
|
||||||
|
[ "${PASSWD}" = "${PASSWD2}" ] && break
|
||||||
|
printf "Passwords do not match! Please try again.\n"
|
||||||
|
done
|
||||||
|
stty echo
|
||||||
|
if [[ -z "${PASSWD}" ]]; then
|
||||||
|
echo "You left the password blank"
|
||||||
|
echo "If you don't want a password, please run:"
|
||||||
|
echo "pivpn add nopass"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
if [ ${#PASSWD} -lt 4 ] || [ ${#PASSWD} -gt 1024 ]
|
if [ ${#PASSWD} -lt 4 ] || [ ${#PASSWD} -gt 1024 ]
|
||||||
then
|
then
|
||||||
echo "Password must be between from 4 to 1024 characters"
|
echo "Password must be between from 4 to 1024 characters"
|
||||||
|
@ -69,8 +124,10 @@ EOF
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf "Enter a Name for the Client: "
|
if [ -z "${NAME}" ]; then
|
||||||
read -r NAME
|
printf "Enter a Name for the Client: "
|
||||||
|
read -r NAME
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "${NAME}" =~ [^a-zA-Z0-9] ]]; then
|
if [[ "${NAME}" =~ [^a-zA-Z0-9] ]]; then
|
||||||
echo "Name can only contain alphanumeric characters."
|
echo "Name can only contain alphanumeric characters."
|
||||||
|
@ -109,8 +166,11 @@ fi
|
||||||
|
|
||||||
cd /etc/openvpn/easy-rsa || exit
|
cd /etc/openvpn/easy-rsa || exit
|
||||||
|
|
||||||
if [[ "$@" =~ "nopass" ]]; then
|
if [[ "${NO_PASS}" =~ "1" ]]; then
|
||||||
keynoPASS
|
keynoPASS
|
||||||
|
elif [[ -n "${PASSWD}" ]]; then
|
||||||
|
echo "Both nopass and password arguments passed to the script. Please use either one."
|
||||||
|
exit 1
|
||||||
else
|
else
|
||||||
keyPASS
|
keyPASS
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue