Fix issue pivpn#281

This commit is contained in:
Hìr0 2020-06-01 00:39:18 +02:00
parent ad363b717b
commit 46c463d1d5
2 changed files with 59 additions and 48 deletions

View file

@ -20,7 +20,7 @@ source "${setupVars}"
helpFunc() { helpFunc() {
echo "::: Create a client ovpn profile, optional nopass" echo "::: Create a client ovpn profile, optional nopass"
echo ":::" echo ":::"
echo "::: Usage: pivpn <-a|add> [-n|--name <arg>] [-p|--password <arg>]|[nopass] [-d|--days <number>] [-b|--bitwarden] [-i|--iOS] [-h|--help]" echo "::: Usage: pivpn <-a|add> [-n|--name <arg>] [-p|--password <arg>]|[nopass] [-d|--days <number>] [-b|--bitwarden] [-i|--iOS] [-c|--config-file] [-h|--help]"
echo ":::" echo ":::"
echo "::: Commands:" echo "::: Commands:"
echo "::: [none] Interactive mode" echo "::: [none] Interactive mode"
@ -30,6 +30,7 @@ helpFunc() {
echo "::: -d,--days Expire the certificate after specified number of days (default: 1080)" echo "::: -d,--days Expire the certificate after specified number of days (default: 1080)"
echo "::: -b,--bitwarden Create and save a client through Bitwarden" echo "::: -b,--bitwarden Create and save a client through Bitwarden"
echo "::: -i,--iOS Generate a certificate that leverages iOS keychain" echo "::: -i,--iOS Generate a certificate that leverages iOS keychain"
echo "::: -c,--config-file Generate .ovpn configuration file for an existing client"
echo "::: -h,--help Show this help dialog" echo "::: -h,--help Show this help dialog"
} }
@ -97,6 +98,10 @@ do
echo "Bitwarden not found, please install bitwarden" echo "Bitwarden not found, please install bitwarden"
exit 1 exit 1
fi fi
;;
-c|--config-file)
GENOVPNONLY=1
;; ;;
*) *)
echo "Error: Got an unexpected argument '$1'" echo "Error: Got an unexpected argument '$1'"
@ -248,6 +253,10 @@ if [[ -z "${NAME}" ]]; then
exit 1 exit 1
fi fi
if [ "${GENOVPNONLY}" == "1" ]; then
# Generate .ovpn configuration file
cd /etc/openvpn/easy-rsa/pki || exit
else
# Check if name is already in use # Check if name is already in use
while read -r line || [ -n "${line}" ]; do while read -r line || [ -n "${line}" ]; do
STATUS=$(echo "$line" | awk '{print $1}') STATUS=$(echo "$line" | awk '{print $1}')
@ -282,7 +291,6 @@ if [[ ! "$DAYS" =~ ^[0-9]+$ ]] || [ "$DAYS" -lt 1 ] || [ "$DAYS" -gt 3650 ]; the
#The CRL lasts 3650 days so it doesn't make much sense that certificates would last longer #The CRL lasts 3650 days so it doesn't make much sense that certificates would last longer
echo "Please input a valid number of days, between 1 and 3650 inclusive." echo "Please input a valid number of days, between 1 and 3650 inclusive."
exit 1 exit 1
fi fi
cd /etc/openvpn/easy-rsa || exit cd /etc/openvpn/easy-rsa || exit
@ -297,6 +305,7 @@ if [[ "${NO_PASS}" =~ "1" ]]; then
else else
keyPASS keyPASS
fi fi
fi
#1st Verify that clients Public Key Exists #1st Verify that clients Public Key Exists
if [ ! -f "issued/${NAME}${CRT}" ]; then if [ ! -f "issued/${NAME}${CRT}" ]; then

View file

@ -73,6 +73,7 @@ function helpFunc {
echo "::: -c, clients List any connected clients to the server" echo "::: -c, clients List any connected clients to the server"
echo "::: -d, debug Start a debugging session if having trouble" echo "::: -d, debug Start a debugging session if having trouble"
echo "::: -l, list List all valid and revoked certificates" echo "::: -l, list List all valid and revoked certificates"
echo "::: -o, ovpn Generate a .ovpn config file for an existing client"
echo "::: -r, revoke Revoke a client ovpn profile" echo "::: -r, revoke Revoke a client ovpn profile"
echo "::: -h, help Show this help dialog" echo "::: -h, help Show this help dialog"
echo "::: -u, uninstall Uninstall PiVPN from your system!" echo "::: -u, uninstall Uninstall PiVPN from your system!"
@ -91,6 +92,7 @@ case "$1" in
"-c" | "clients" ) listClientsFunc "$@";; "-c" | "clients" ) listClientsFunc "$@";;
"-d" | "debug" ) debugFunc;; "-d" | "debug" ) debugFunc;;
"-l" | "list" ) listOVPNFunc;; "-l" | "list" ) listOVPNFunc;;
"-o" | "ovpn" ) makeOVPNFunc "$@" -c;;
"-r" | "revoke" ) removeOVPNFunc "$@";; "-r" | "revoke" ) removeOVPNFunc "$@";;
"-h" | "help" ) helpFunc;; "-h" | "help" ) helpFunc;;
"-u" | "uninstall" ) uninstallFunc;; "-u" | "uninstall" ) uninstallFunc;;