From dea112f50f722d7e8a24cad13618425d5942b478 Mon Sep 17 00:00:00 2001 From: Kaladin Light <0.kaladin@gmail.com> Date: Thu, 5 May 2016 21:04:57 -0400 Subject: [PATCH] Fixes #23, enhance 'pivpn add', minor bug fixes & other enhancements --- auto_install/install.sh | 3 +++ scripts/makeOVPN.sh | 5 +++++ scripts/removeOVPN.sh | 27 +++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index a42029c..ddb9d26 100644 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -63,6 +63,8 @@ else PLAT="raspbian" fi +echo "${PLAT}" > /tmp/DET_PLATFORM + ####### FUNCTIONS ########## spinner() { @@ -733,6 +735,7 @@ confNetwork() { confOVPN() { IPv4pub=$(dig +short myip.opendns.com @resolver1.opendns.com) $SUDO cp /tmp/pivpnUSR /etc/pivpn/INSTALL_USER + $SUDO cp /tmp/DET_PLATFORM /etc/pivpn/DET_PLATFORM # Set status that no certs have been revoked echo 0 > /tmp/REVOKE_STATUS diff --git a/scripts/makeOVPN.sh b/scripts/makeOVPN.sh index ab8c3e9..bb3290e 100644 --- a/scripts/makeOVPN.sh +++ b/scripts/makeOVPN.sh @@ -90,6 +90,11 @@ EOF printf "Enter a Name for the Client: " read NAME +if [[ -z "$NAME" ]]; then + printf '%s\n' "::: You can not leave this blank!" + exit 1 +fi + cd /etc/openvpn/easy-rsa source /etc/openvpn/easy-rsa/vars diff --git a/scripts/removeOVPN.sh b/scripts/removeOVPN.sh index cc9ba2c..54efd43 100644 --- a/scripts/removeOVPN.sh +++ b/scripts/removeOVPN.sh @@ -3,6 +3,7 @@ INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER) REVOKE_STATUS=$(cat /etc/pivpn/REVOKE_STATUS) +PLAT=$(cat /etc/pivpn/DET_PLATFORM) INDEX="/etc/openvpn/easy-rsa/keys/index.txt" if [ ! -f $INDEX ]; then @@ -14,12 +15,14 @@ fi printf "\n" printf " ::\e[4m Certificate List \e[0m:: \n" +i=0 while read -r line || [[ -n "$line" ]]; do status=$(echo $line | awk '{print $1}') if [[ $status = "V" ]]; then var=$(echo $line | awk '{print $5}' | cut -d'/' -f7) var=${var#CN=} - if [ "$var" != "server" ]; then + certs[$i]=$var + if [ "$i" != 0 ]; then printf " $var\n" fi fi @@ -29,6 +32,22 @@ printf "\n" echo "::: Please enter the Name of the client to be revoked from the list above:" read NAME +if [[ -z "$NAME" ]]; then + printf '%s\n' "::: You can not leave this blank!" + exit 1 +fi + +for((x=1;x<=$y;++x)) do + if [[ ${certs[$x]} = ${NAME} ]]; then + Valid=1 + fi +done + +if [[ -z "$Valid" ]]; then + printf "::: You didn't enter a valid cert name!\n" + exit 1 +fi + cd /etc/openvpn/easy-rsa source /etc/openvpn/easy-rsa/vars @@ -43,5 +62,9 @@ if [ $REVOKE_STATUS == 0 ]; then printf "\nThis seems to be the first time you have revoked a cert.\n" printf "We are adding the CRL to the server.conf and restarting openvpn.\n" sed -i '/#crl-verify/c\crl-verify /etc/openvpn/crl.pem' /etc/openvpn/server.conf - systemctl restart openvpn.service + if [[ ${PLAT} == "ubuntu" ]]; then + service openvpn restart + else + systemctl restart openvpn.service + fi fi