1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pihole_ynh.git synced 2024-09-03 20:05:58 +02:00

Ajouts hooks domain et conf_regen

This commit is contained in:
Maniack Crudelis 2017-08-11 00:56:26 +02:00
parent 1ef78e092b
commit d66ce429eb
8 changed files with 96 additions and 1 deletions

48
conf/dnsmasq_regenconf_hook Executable file
View file

@ -0,0 +1,48 @@
#!/bin/bash
force=${2:-0} # 0/1 --force argument
dryrun=${3:-0} # 0/1 --dry-run argument
pending_conf=$4 # Path of the pending conf file
temp_dir=/tmp/pi-hole.bck
do_pre_regen() {
if [ $dryrun -eq 0 ]
then
# Créer une sauvegarde des config dnsmasq de pi-hole. Que la regen-conf va sauvagement supprimer
mkdir $temp_dir
cp -a "/etc/dnsmasq.d/01-pihole.conf" "$temp_dir"
test -e "/etc/dnsmasq.d/02-pihole-dhcp.conf" && cp -a "/etc/dnsmasq.d/02-pihole-dhcp.conf" "$temp_dir"
test -e "/etc/dnsmasq.d/03-pihole-wildcard.conf" && cp -a "/etc/dnsmasq.d/03-pihole-wildcard.conf" "$temp_dir"
fi
}
do_post_regen() {
# Restaure la config dnsmasq de pi-hole
cp -a "$temp_dir/01-pihole.conf" "/etc/dnsmasq.d/"
test -e "$temp_dir/02-pihole-dhcp.conf" && cp -a "$temp_dir/02-pihole-dhcp.conf" "/etc/dnsmasq.d/"
test -e "$temp_dir/03-pihole-wildcard.conf" && cp -a "$temp_dir/03-pihole-wildcard.conf" "/etc/dnsmasq.d/"
# Supprime le dossier temporaire
test -n $temp_dir && rm -r $temp_dir
# Commente le cache-size de la config par défaut
sed --in-place "s/^cache-size=/#pihole# cache-size=/g" /etc/dnsmasq.conf
# Reload dnsmasq
systemctl reload dnsmasq
}
case "$1" in
pre)
do_pre_regen
;;
post)
do_post_regen
;;
*)
echo "Hook called with unknown argument \`$1'" >&2
exit 1
;;
esac
exit 0

15
hooks/post_domain_add Normal file
View file

@ -0,0 +1,15 @@
#!/bin/bash
domain=$1
# Trouve l'interface réseau par défaut
main_iface=$(route | grep default | awk '{print $8;}' | head -n1)
# Trouve l'ipv4 associée à l'interface trouvée
localipv4=$(ifconfig | grep -A 1 "$main_iface" | tail -1 | awk '{print $2;}' | cut -d: -f2)
# Commente les résolutions du domaine sur 127.0.0.1, qui risquerait de bloquer la résolution sur le réseau local
sed -i "s/^127.0.0.1.*$domain/#Commented by pihole# &/g" /etc/hosts
# Et ajoute une résolution sur l'ip local à la place, si elle n'existe pas déjà
grep -q "^$localipv4.*$domain" /etc/hosts || \
echo "$localipv4 $domain #Added by pihole#" >> /etc/hosts

10
hooks/post_domain_remove Normal file
View file

@ -0,0 +1,10 @@
#!/bin/bash
domain=$1
# Restaure les résolutions qui avaient été commentées par pihole pour ce domaine
sed -i "s/#Commented by pihole# \(.*domain1\)/\1/g" /etc/hosts
# On utilise ici les sous-expressions sed pour supprimer seulement le début de la ligne.
# Et supprime les lignes ajoutées par pihole pour ce domaine
sed -i "/$domain #Added by pihole#/d" /etc/hosts

View file

@ -90,3 +90,5 @@ fi
if test -e "/etc/dnsmasq.d/03-pihole-wildcard.conf"; then if test -e "/etc/dnsmasq.d/03-pihole-wildcard.conf"; then
ynh_backup "/etc/dnsmasq.d/03-pihole-wildcard.conf" "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/03-pihole-wildcard.conf" ynh_backup "/etc/dnsmasq.d/03-pihole-wildcard.conf" "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/03-pihole-wildcard.conf"
fi fi
ynh_backup "/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" "${YNH_APP_BACKUP_DIR}/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"

View file

@ -256,6 +256,12 @@ SUPPRESS_WARNING /opt/pihole/gravity.sh
systemctl start pihole-FTL systemctl start pihole-FTL
#=================================================
# SET UP THE CONF_REGEN HOOK
#=================================================
cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
#================================================= #=================================================
# GENERIC FINALISATION # GENERIC FINALISATION
#================================================= #=================================================

View file

@ -35,7 +35,7 @@ fi
#================================================= #=================================================
systemctl stop pihole-FTL systemctl stop pihole-FTL
systemctl disable pihole-FTL SUPPRESS_WARNING systemctl disable pihole-FTL
rm -f "/etc/init.d/pihole-FTL" "/usr/bin/pihole-FTL" "/var/run/pihole-FTL.pid" "/var/run/pihole-FTL.port" rm -f "/etc/init.d/pihole-FTL" "/usr/bin/pihole-FTL" "/var/run/pihole-FTL.pid" "/var/run/pihole-FTL.port"
#================================================= #=================================================
@ -125,6 +125,12 @@ sed -i "/#Added by pihole#/d" /etc/hosts
systemctl start dnsmasq systemctl start dnsmasq
#=================================================
# REMOVE THE CONF_REGEN HOOK
#=================================================
rm /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
#================================================= #=================================================
# GENERIC FINALISATION # GENERIC FINALISATION
#================================================= #=================================================

View file

@ -123,6 +123,8 @@ ynh_restore_file "/usr/bin/pihole-FTL"
ynh_restore_file "/var/run/pihole-FTL.pid" ynh_restore_file "/var/run/pihole-FTL.pid"
ynh_restore_file "/var/run/pihole-FTL.port" ynh_restore_file "/var/run/pihole-FTL.port"
ynh_restore_file "/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
#================================================= #=================================================
# RESTORE OF DNSMASQ CONFIG # RESTORE OF DNSMASQ CONFIG
#================================================= #=================================================

View file

@ -164,6 +164,12 @@ systemctl start pihole-FTL
systemctl start pihole-FTL systemctl start pihole-FTL
#=================================================
# UPDATE THE CONF_REGEN HOOK
#=================================================
cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================