Implemented feature request from issue #942 (WireGuard)

This commit is contained in:
Orazio 2020-02-07 18:07:15 +01:00
parent bf0015c303
commit 3f616d9254
4 changed files with 28 additions and 5 deletions

View file

@ -14,6 +14,7 @@
pivpnGitUrl="https://github.com/pivpn/pivpn.git" pivpnGitUrl="https://github.com/pivpn/pivpn.git"
setupVars="/etc/pivpn/setupVars.conf" setupVars="/etc/pivpn/setupVars.conf"
pivpnFilesDir="/etc/.pivpn" pivpnFilesDir="/etc/.pivpn"
dnsmasqConfig="/etc/dnsmasq.d/02-pivpn.conf"
### PKG Vars ### ### PKG Vars ###
PKG_MANAGER="apt-get" PKG_MANAGER="apt-get"
@ -1417,8 +1418,10 @@ askClientDNS(){
# Detect and offer to use Pi-hole # Detect and offer to use Pi-hole
if command -v pihole > /dev/null; then if command -v pihole > /dev/null; then
if (whiptail --backtitle "Setup PiVPN" --title "Pi-hole" --yesno "We have detected a Pi-hole installation, do you want to use it as the DNS server for the VPN, so you get ad blocking on the go?" ${r} ${c}); then if (whiptail --backtitle "Setup PiVPN" --title "Pi-hole" --yesno "We have detected a Pi-hole installation, do you want to use it as the DNS server for the VPN, so you get ad blocking on the go?" ${r} ${c}); then
echo "interface=$pivpnDEV" | $SUDO tee "$dnsmasqConfig" > /dev/null
echo "addn-hosts=/etc/pivpn/hosts.$VPN" | $SUDO tee -a "$dnsmasqConfig" > /dev/null
$SUDO bash -c "> /etc/pivpn/hosts.$VPN"
pivpnDNS1="$vpnGw" pivpnDNS1="$vpnGw"
echo "interface=$pivpnDEV" | $SUDO tee /etc/dnsmasq.d/02-pivpn.conf > /dev/null
echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf
echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf
return return
@ -2078,7 +2081,7 @@ restartServices(){
;; ;;
esac esac
if [ -f /etc/dnsmasq.d/02-pivpn.conf ]; then if [ -f "$dnsmasqConfig" ]; then
$SUDO pihole restartdns $SUDO pihole restartdns
fi fi
} }

View file

@ -7,6 +7,7 @@
PKG_MANAGER="apt-get" PKG_MANAGER="apt-get"
UPDATE_PKG_CACHE="${PKG_MANAGER} update" UPDATE_PKG_CACHE="${PKG_MANAGER} update"
subnetClass="24" subnetClass="24"
dnsmasqConfig="/etc/dnsmasq.d/02-pivpn.conf"
setupVars="/etc/pivpn/setupVars.conf" setupVars="/etc/pivpn/setupVars.conf"
if [ ! -f "${setupVars}" ]; then if [ ! -f "${setupVars}" ]; then
@ -176,8 +177,8 @@ removeAll(){
# Removing pivpn files # Removing pivpn files
echo "::: Removing pivpn system files..." echo "::: Removing pivpn system files..."
if [ -f /etc/dnsmasq.d/02-pivpn.conf ]; then if [ -f "$dnsmasqConfig" ]; then
rm -f /etc/dnsmasq.d/02-pivpn.conf rm -f "$dnsmasqConfig"
pihole restartdns pihole restartdns
fi fi

View file

@ -113,6 +113,15 @@ AllowedIPs = 10.6.0.${COUNT}/32
# end ${CLIENT_NAME}" >> wg0.conf # end ${CLIENT_NAME}" >> wg0.conf
echo "::: Updated server config" echo "::: Updated server config"
if [ -f /etc/pivpn/hosts.wireguard ]; then
echo "10.6.0.${COUNT} ${CLIENT_NAME}.pivpn" >> /etc/pivpn/hosts.wireguard
if killall -SIGHUP pihole-FTL; then
echo "::: Updated hosts file for Pi-hole"
else
echo "::: Failed to reload pihole-FTL configuration"
fi
fi
if systemctl restart wg-quick@wg0; then if systemctl restart wg-quick@wg0; then
echo "::: WireGuard restarted" echo "::: WireGuard restarted"
else else

View file

@ -101,9 +101,19 @@ for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do
fi fi
done done
((DELETED_COUNT++))
echo "::: Successfully deleted ${CLIENT_NAME}" echo "::: Successfully deleted ${CLIENT_NAME}"
((DELETED_COUNT++)) # If using Pi-hole, remove the client from the hosts file
if [ -f /etc/pivpn/hosts.wireguard ]; then
sed "\#10.6.0.${COUNT} ${CLIENT_NAME}.pivpn#d" -i /etc/pivpn/hosts.wireguard
if killall -SIGHUP pihole-FTL; then
echo "::: Updated hosts file for Pi-hole"
else
echo "::: Failed to reload pihole-FTL configuration"
fi
fi
fi fi
fi fi