cleaned up removeOVPN.sh

This commit is contained in:
redfast00 2016-10-04 21:02:02 +02:00
parent d8d89c758b
commit a68435e6c3
No known key found for this signature in database
GPG key ID: B7DD106EAC545F95

View file

@ -6,9 +6,8 @@ REVOKE_STATUS=$(cat /etc/pivpn/REVOKE_STATUS)
PLAT=$(cat /etc/pivpn/DET_PLATFORM) PLAT=$(cat /etc/pivpn/DET_PLATFORM)
INDEX="/etc/openvpn/easy-rsa/keys/index.txt" INDEX="/etc/openvpn/easy-rsa/keys/index.txt"
if [ ! -f $INDEX ]; then if [ ! -f "$INDEX" ]; then
printf "The file: $INDEX \n" printf "The file: %s was not found\n" "$INDEX"
printf "Was not Found!\n"
exit 1 exit 1
fi fi
@ -16,49 +15,49 @@ printf "\n"
printf " ::\e[4m Certificate List \e[0m:: \n" printf " ::\e[4m Certificate List \e[0m:: \n"
i=0 i=0
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}')
if [[ $status = "V" ]]; then if [[ "$STATUS" = "V" ]]; then
var=$(echo $line | sed -e 's/^.*CN=\([^/]*\)\/.*/\1/') NAME=$(echo "$line" | sed -e 's/^.*CN=\([^/]*\)\/.*/\1/')
certs[$i]=$var CERTS[$i]=$NAME
if [ "$i" != 0 ]; then if [ "$i" != 0 ]; then
printf " $var\n" # Prevent printing "server" certificate
printf " %s\n" "$NAME"
fi fi
let i=i+1 let i=i+1
y=$i
fi fi
done <$INDEX done <$INDEX
printf "\n" printf "\n"
echo "::: Please enter the Name of the client to be revoked from the list above:" echo "::: Please enter the Name of the client to be revoked from the list above:"
read NAME read -r NAME
if [[ -z "$NAME" ]]; then if [[ -z "$NAME" ]]; then
printf '%s\n' "::: You can not leave this blank!" echo "::: You can not leave this blank!"
exit 1 exit 1
fi fi
for((x=1;x<=$y;++x)); do for((x=1;x<=i;++x)); do
if [[ ${certs[$x]} = ${NAME} ]]; then if [ "${CERTS[$x]}" = "${NAME}" ]; then
Valid=1 VALID=1
fi fi
done done
if [[ -z "$Valid" ]]; then if [ -z "$VALID" ]; then
printf "::: You didn't enter a valid cert name!\n" printf "::: You didn't enter a valid cert name!\n"
exit 1 exit 1
fi fi
cd /etc/openvpn/easy-rsa cd /etc/openvpn/easy-rsa || exit
source /etc/openvpn/easy-rsa/vars source /etc/openvpn/easy-rsa/vars
./revoke-full $NAME ./revoke-full "$NAME"
echo "::: Certificate revoked, removing ovpns from /home/$INSTALL_USER/ovpns" echo "::: Certificate revoked, removing ovpns from /home/$INSTALL_USER/ovpns"
rm /home/$INSTALL_USER/ovpns/$NAME.ovpn rm "/home/$INSTALL_USER/ovpns/$NAME.ovpn"
cp /etc/openvpn/easy-rsa/keys/crl.pem /etc/openvpn/crl.pem cp /etc/openvpn/easy-rsa/keys/crl.pem /etc/openvpn/crl.pem
echo "::: Completed!" echo "::: Completed!"
if [ $REVOKE_STATUS == 0 ]; then if [ "$REVOKE_STATUS" == 0 ]; then
echo 1 > /etc/pivpn/REVOKE_STATUS echo 1 > /etc/pivpn/REVOKE_STATUS
printf "\nThis seems to be the first time you have revoked a cert.\n" 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" printf "We are adding the CRL to the server.conf and restarting openvpn.\n"