#!/bin/sh
if ! [ "root" = "$(id -u -n)" ]; then
echo "ERROR: ${0} must be run as root!"; exit 1
fi
echo "**********************************************************"
echo "* *"
echo "* Are you sure you want to RESET your VPN server? *"
echo "* *"
echo "* ALL DATA AND LOCALLY ADDED USERS WILL BE LOST! *"
echo "* *"
echo "* ALL CONFIGURATION WILL BE KEPT! *"
echo "* *"
echo "* THIS CAN *NOT* BE UNDONE! *"
echo "* *"
echo "**********************************************************"
echo
printf "Continue? (y/n) [n]: "; read -r CONFIRM
if ! [ "${CONFIRM}" = "y" ] && ! [ "${CONFIRM}" = "Y" ]; then
exit 1
fi
for CONFIG_NAME in $(systemctl list-units "openvpn-server@*" --no-legend | awk '{print $1}')
do
systemctl disable --now "${CONFIG_NAME}"
done
for CONFIG_NAME in $(systemctl list-units "wg-quick@*" --no-legend | awk '{print $1}')
do
systemctl disable --now "${CONFIG_NAME}"
done
rm -rf /etc/openvpn/server/*
rm -rf /etc/wireguard/*
if [ -f /etc/redhat-release ]; then
# Fedora, CentOS, RHEL
systemctl stop httpd
systemctl stop php-fpm
rm -rf /var/lib/vpn-user-portal/*
rm -rf /etc/vpn-user-portal/keys
rm -rf /etc/vpn-server-node/keys
rm -rf /var/lib/php/session/*
/usr/libexec/vpn-user-portal/generate-secrets
/usr/libexec/vpn-server-node/generate-secrets
cp /etc/vpn-user-portal/keys/node.0.key /etc/vpn-server-node/keys/node.key
systemctl start php-fpm
systemctl start httpd
/usr/libexec/vpn-server-node/server-config
elif [ -f /etc/debian_version ]; then
# Debian, Ubuntu
PHP_VERSION=$(/usr/sbin/phpquery -V)
systemctl stop apache2
systemctl stop "php${PHP_VERSION}-fpm"
rm -rf /var/lib/vpn-user-portal/*
rm -rf /etc/vpn-user-portal/keys
rm -rf /etc/vpn-server-node/keys
rm -rf /var/lib/php/sessions/*
/usr/libexec/vpn-user-portal/generate-secrets
/usr/libexec/vpn-server-node/generate-secrets
cp /etc/vpn-user-portal/keys/node.0.key /etc/vpn-server-node/keys/node.key
systemctl start "php${PHP_VERSION}-fpm"
systemctl start apache2
/usr/libexec/vpn-server-node/server-config
else
echo "ERROR: OS not supported!"
exit 1
fi
# Enable & Start OpenVPN
for F in /etc/openvpn/server/*
do
case ${F} in
*.conf)
CONFIG_NAME=$(basename "${F}" .conf)
systemctl enable --now "openvpn-server@${CONFIG_NAME}"
;;
esac
done
# Enable & Start WireGuard
for F in /etc/wireguard/*
do
case ${F} in
*.conf)
CONFIG_NAME=$(basename "${F}" .conf)
systemctl enable --now "wg-quick@${CONFIG_NAME}"
;;
esac
done