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

Work in progress...

This commit is contained in:
Maniack Crudelis 2020-06-17 21:54:05 +02:00
parent 445dcfec6a
commit 0c0316a443
28 changed files with 1000 additions and 951 deletions

View file

@ -11,7 +11,7 @@ If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to
## Overview ## Overview
Network-wide ad blocking via your own Linux hardware Network-wide ad blocking via your own Linux hardware
**Shipped version:** 3.3.1 **Shipped version:** 3.3.1 or 5.0
## Screenshots ## Screenshots
@ -41,7 +41,7 @@ Use the admin panel of your Pi-hole to configure this app. You may also need to
* x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/pihole%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/pihole/) * x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/pihole%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/pihole/)
* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/pihole%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/pihole/) * ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/pihole%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/pihole/)
* Jessie x86-64b - [![](https://ci-stretch.nohost.me/ci/logs/pihole%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/pihole/) * Buster x86-64b - [![](https://ci-buster.nohost.me/ci/logs/pihole%20%28Apps%29.svg)](https://ci-buster.nohost.me/ci/apps/pihole/)
## Limitations ## Limitations
@ -66,7 +66,7 @@ Please do your pull request to the [testing branch](https://github.com/YunoHost-
To try the testing branch, please do the following: To try the testing branch, please do the following:
``` ```
sudo yunohost app install https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --debug sudo yunohost app install https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --force --debug
or or
sudo yunohost app upgrade pihole -u https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --debug sudo yunohost app upgrade pihole -u https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --debug
``` ```

View file

@ -11,7 +11,7 @@ Si vous n'avez pas YunoHost, merci de regarder [ici](https://yunohost.org/#/inst
## Résumé ## Résumé
Blocage des publicités sur l'ensemble du réseau via votre propre matériel Linux Blocage des publicités sur l'ensemble du réseau via votre propre matériel Linux
**Version embarquée:** 3.3.1 **Version embarquée:** 3.3.1 ou 5.0
## Captures d'écran ## Captures d'écran
@ -42,7 +42,7 @@ Utiliser le panneau d'administration de votre Pi-hole pour configurer cette appl
* x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/pihole%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/pihole/) * x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/pihole%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/pihole/)
* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/pihole%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/pihole/) * ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/pihole%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/pihole/)
* Jessie x86-64b - [![](https://ci-stretch.nohost.me/ci/logs/pihole%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/pihole/) * Buster x86-64b - [![](https://ci-buster.nohost.me/ci/logs/pihole%20%28Apps%29.svg)](https://ci-buster.nohost.me/ci/apps/pihole/)
## Limitations ## Limitations
@ -67,7 +67,7 @@ Merci de faire vos pull request sur la [branche testing](https://github.com/Yuno
Pour tester la branche testing, merci de procéder ainsi. Pour tester la branche testing, merci de procéder ainsi.
``` ```
sudo yunohost app install https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --debug sudo yunohost app install https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --force --debug
ou ou
sudo yunohost app upgrade pihole -u https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --debug sudo yunohost app upgrade pihole -u https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --debug
``` ```

View file

@ -15,3 +15,41 @@ command = "/bin/bash scripts/actions/reset_default_config \"pihole-FTL.conf\""
# accepted_return_codes = [0, 1, 2, 3] # optional # accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0] accepted_return_codes = [0]
description = "Reset the config file pihole-FTL.conf." description = "Reset the config file pihole-FTL.conf."
[reset_default_dnsmasq]
name = "Reset the config file and restore a default one."
command = "/bin/bash scripts/actions/reset_default_config \"01-pihole.conf\""
# user = "root" # optional
# cwd = "/" # optional
# accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Reset the config file dnsmasq.d/01-pihole.conf."
[reset_default_nginx]
name = "Reset the nginx config for this app."
command = "/bin/bash scripts/actions/reset_default_system nginx"
# user = "root" # optional
# cwd = "/" # optional
# accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Reset the nginx config for this app."
[reset_default_phpfpm]
name = "Reset the php-fpm config for this app."
command = "/bin/bash scripts/actions/reset_default_system phpfpm"
# user = "root" # optional
# cwd = "/" # optional
# accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Reset the php-fpm config for this app."
[reset_default_app]
name = "Reset the app with a default configuration."
command = "/bin/bash scripts/actions/reset_default_app"
# user = "root" # optional
# cwd = "/" # optional
# accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Reset the app to its default configuration to try to fix potential issues.<br>This action won't remove any data added to the app.<br>However, if you have modified any configuration, it will be overwritten."

View file

@ -1,28 +1,56 @@
;; Test complet ;; Test version last version
; Manifest ; Manifest
domain="domain.tld" (DOMAIN) domain="domain.tld" (DOMAIN)
path="/path" (PATH) path="/path" (PATH)
admin="john" (USER) admin="john" (USER)
query_logging="1" query_logging=1
; Checks enable_dhcp=0
pkg_linter=1 pihole_version="Last available"
setup_sub_dir=1 ; Config_panel
setup_root=1 main.overwrite_files.overwrite_setupvars=0|1
setup_nourl=0 main.overwrite_files.overwrite_ftl=0|1
setup_private=1 main.overwrite_files.overwrite_nginx=0|1
setup_public=0 main.overwrite_files.overwrite_phpfpm=0|1
upgrade=1 main.global_config.email_type=0|1
upgrade=1 from_commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932 main.php_fpm_config.footprint=low|medium|high
backup_restore=1 main.php_fpm_config.free_footprint=20
multi_instance=0 main.php_fpm_config.usage=low|medium|high
port_already_use=1 (4711) main.php_fpm_config.force_max_children=20|0
change_url=1 ; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=0
upgrade=1
backup_restore=1
multi_instance=0
port_already_use=1 (4711)
change_url=1
actions=1
config_panel=1
;; Test version 3
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
admin="john" (USER)
query_logging=1
enable_dhcp=0
pihole_version="Last 3.X"
; Checks
setup_sub_dir=1
setup_root=0
upgrade=1
upgrade=1 from_commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932
backup_restore=1
actions=1
;;; Levels ;;; Levels
Level 5=auto Level 5=auto
;;; Options ;;; Options
Email= Email=
Notification=change Notification=change
;;; Upgrade options ;;; Upgrade options
; commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932 ; commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932
name= Stretch fix name= Stretch fix
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&query_logging=1& manifest_arg=domain=DOMAIN&path=PATH&admin=USER&query_logging=1&

View file

@ -1,9 +1,6 @@
SOURCE_URL=https://github.com/pi-hole/FTL/archive/v2.13.2.tar.gz SOURCE_URL=https://github.com/pi-hole/FTL/archive/v3.0.tar.gz
SOURCE_SUM=07383d2b3de1ef31526b090603e783b3 SOURCE_SUM=45fd33e4498b2ab9403d96e1251abb8c
SOURCE_SUM_PRG=md5sum SOURCE_SUM_PRG=md5sum
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true
SOURCE_FILENAME= SOURCE_FILENAME=
# Be carrefull, the version 3.0 isn't compatible with the version of dnsmasq available on Jessie.
# So, we need to stay stick on the version 2.13.2.

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/pi-hole/FTL/archive/v4.3.1.tar.gz SOURCE_URL=https://github.com/pi-hole/FTL/archive/v5.0.tar.gz
SOURCE_SUM=1c0df5fa42e7f7b89c7e704fdc1b5154 SOURCE_SUM=a405fee9a924324eefe6bfb832180c3d
SOURCE_SUM_PRG=md5sum SOURCE_SUM_PRG=md5sum
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/pi-hole/AdminLTE/archive/v4.3.3.tar.gz SOURCE_URL=https://github.com/pi-hole/AdminLTE/archive/v5.0.tar.gz
SOURCE_SUM=3f9da0e1f9134393758b7a1425ca66f6 SOURCE_SUM=9402041b365e78a02a95942bdd3c3c05
SOURCE_SUM_PRG=md5sum SOURCE_SUM_PRG=md5sum
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/pi-hole/pi-hole/archive/v4.4.tar.gz SOURCE_URL=https://github.com/pi-hole/pi-hole/archive/v5.0.tar.gz
SOURCE_SUM=970013bf8e273b868dd184ac2ffb1348 SOURCE_SUM=0f19aeefad3063c44f421de1ad21b233
SOURCE_SUM_PRG=md5sum SOURCE_SUM_PRG=md5sum
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true

10
conf/dns-servers.conf Normal file
View file

@ -0,0 +1,10 @@
(FR) FDN;80.67.169.12;80.67.169.40;2001:910:800::12;2001:910:800::40
(FR) LDN;80.67.188.188;2001:913::8
(FR) ARN;89.234.141.66;2a00:5881:8100:1000::3
(FR) Aquilenet;185.233.100.100;185.233.100.101;2a0c:e300::100;2a0c:e300::101
(FR) gozmail / grifon;80.67.190.200;80.67.190.200;2a00:5884:8218::1;2a00:5884:8218::1
(DE) FoeBud / Digital Courage;85.214.20.141;85.214.20.141
(DE) CCC Berlin;195.160.173.53;195.160.173.53
(DE) AS250;194.150.168.168;194.150.168.168;2001:4ce8::53;2001:4ce8::53
(DE) Ideal-Hosting;84.200.69.80;84.200.70.40;2001:1608:10:25::1c04:b12f;2001:1608:10:25::9249:d69b
(DK) censurfridns;91.239.100.100;89.233.43.71;2001:67c:28a4::;2a01:3a0:53:53::

View file

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

View file

@ -1,31 +1,31 @@
# Listen only for local socket connections or permit all connections ; Listen only for local socket connections or permit all connections
# localonly|all ; localonly|all
SOCKET_LISTENING=localonly SOCKET_LISTENING=localonly
# Display all queries? Set to no to hide query display ; Display all queries? Set to no to hide query display
# yes|no ; yes|no
QUERY_DISPLAY=yes QUERY_DISPLAY=yes
# Allow FTL to analyze AAAA queries from pihole.log? ; Allow FTL to analyze AAAA queries from pihole.log?
# yes|no ; yes|no
AAAA_QUERY_ANALYSIS=yes AAAA_QUERY_ANALYSIS=yes
# How long should queries be stored in the database? Setting this to 0 disables the database altogether ; How long should queries be stored in the database? Setting this to 0 disables the database altogether
MAXDBDAYS=365 MAXDBDAYS=365
# Should FTL try to resolve IPv6 addresses to host names? ; Should FTL try to resolve IPv6 addresses to host names?
# yes|no ; yes|no
RESOLVE_IPV6=yes RESOLVE_IPV6=yes
# Should FTL try to resolve IPv4 addresses to host names? ; Should FTL try to resolve IPv4 addresses to host names?
# yes|no ; yes|no
RESOLVE_IPV4=yes RESOLVE_IPV4=yes
# How often do we store queries in FTL's database [minutes]? ; How often do we store queries in FTL's database [minutes]?
DBINTERVAL=1.0 DBINTERVAL=1.0
# Specify path and filename of FTL's SQLite long-term database. Setting this to DBFILE= disables the database altogether ; Specify path and filename of FTL's SQLite long-term database. Setting this to DBFILE= disables the database altogether
DBFILE=/etc/pihole/pihole-FTL.db DBFILE=/etc/pihole/pihole-FTL.db
# Up to how many hours of queries should be imported from the database and logs? Maximum is 744 (31 days) ; Up to how many hours of queries should be imported from the database and logs? Maximum is 744 (31 days)
MAXLOGAGE=24.0 MAXLOGAGE=24.0

View file

@ -62,3 +62,9 @@ name = "PiHole configuration"
choices = ["low", "medium", "high"] choices = ["low", "medium", "high"]
default = "low" default = "low"
help = "low: Personal usage, behind the sso. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.<br>medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.<br>high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding." help = "low: Personal usage, behind the sso. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.<br>medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.<br>high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding."
[main.php_fpm_config.force_max_children]
ask = "Force the value of pm.max_children ?"
type = "number"
default = "0"
help = "Do not change this value unless you're sure about what you're doing !<br>pm.max_children is automatically defined by this formula: $max_ram / 2 / $footprint<br>You can force that value, and ignore the formula by changing the value here.<br>To reset to the default value, set to 0."

View file

@ -1,96 +1,96 @@
{ {
"name": "Pi-hole", "name": "Pi-hole",
"id": "pihole", "id": "pihole",
"packaging_format": 1, "packaging_format": 1,
"description": { "description": {
"en": "Network-wide ad blocking via your own DNS server.", "en": "Network-wide ad blocking via your own DNS server.",
"fr": "Filtrage publicitaire sur l'ensemble du réseau via votre propre serveur DNS." "fr": "Filtrage publicitaire sur l'ensemble du réseau via votre propre serveur DNS."
}, },
"version": "3.3.1~ynh6", "version": "5.0~ynh1",
"url": "https://pi-hole.net/", "url": "https://pi-hole.net/",
"license": "EUPL-1.2", "license": "EUPL-1.2",
"maintainer": { "maintainer": {
"name": "Maniack Crudelis", "name": "Maniack Crudelis",
"email": "maniackc_dev@crudelis.fr" "email": "maniackc_dev@crudelis.fr"
}, },
"requirements": { "requirements": {
"yunohost": ">= 3.6" "yunohost": ">= 3.8"
}, },
"multi_instance": false, "multi_instance": false,
"services": [ "services": [
"nginx", "nginx",
"php7.0-fpm" "php7.0-fpm"
], ],
"arguments": { "arguments": {
"install" : [ "install" : [
{ {
"name": "domain", "name": "domain",
"type": "domain", "type": "domain",
"ask": { "ask": {
"en": "Choose a domain for the admin interface of Pi-hole", "en": "Choose a domain for the admin interface of Pi-hole",
"fr": "Choisissez un domaine pour l'interface admin de Pi-hole" "fr": "Choisissez un domaine pour l'interface admin de Pi-hole"
}, },
"example": "domain.org" "example": "domain.org"
}, },
{ {
"name": "path", "name": "path",
"type": "path", "type": "path",
"ask": { "ask": {
"en": "Choose a path for the admin interface of Pi-hole", "en": "Choose a path for the admin interface of Pi-hole",
"fr": "Choisissez un chemin pour l'interface admin de Pi-hole" "fr": "Choisissez un chemin pour l'interface admin de Pi-hole"
}, },
"example": "/pihole", "example": "/pihole",
"default": "/pihole" "default": "/pihole"
}, },
{ {
"name": "admin", "name": "admin",
"type": "user", "type": "user",
"ask": { "ask": {
"en": "Choose the Pi-hole administrator (must be an existing YunoHost user)", "en": "Choose the Pi-hole administrator (must be an existing YunoHost user)",
"fr": "Administrateur de Pi-hole (doit être un utilisateur YunoHost existant)" "fr": "Administrateur de Pi-hole (doit être un utilisateur YunoHost existant)"
}, },
"example": "john" "example": "john"
}, },
{ {
"name": "query_logging", "name": "query_logging",
"type": "boolean", "type": "boolean",
"ask": { "ask": {
"en": "Do you want to log queries ?", "en": "Do you want to log queries ?",
"fr": "Voulez-vous enregistrer les requêtes dns ?" "fr": "Voulez-vous enregistrer les requêtes dns ?"
}, },
"help": { "help": {
"en": "Keeping this option deactivate will render graphs on the admin page useless. But will respect the privacy of the other users.", "en": "Keeping this option deactivate will render graphs on the admin page useless. But will respect the privacy of the other users.",
"fr": "Garder cette option désactivée rendra les graphiques sur la page d'administration inutiles. Mais respectera la vie privée des autres utilisateurs." "fr": "Garder cette option désactivée rendra les graphiques sur la page d'administration inutiles. Mais respectera la vie privée des autres utilisateurs."
}, },
"default": false "default": false
}, },
{ {
"name": "enable_dhcp", "name": "enable_dhcp",
"type": "boolean", "type": "boolean",
"ask": { "ask": {
"en": "Do you want to set Pi-hole as your DHCP server ?", "en": "Do you want to set Pi-hole as your DHCP server ?",
"fr": "Voulez-vous utiliser Pi-hole an tant que serveur DHCP ?" "fr": "Voulez-vous utiliser Pi-hole an tant que serveur DHCP ?"
}, },
"help": { "help": {
"en": "If you want to do that, <a href=https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md target=_blank>you really have to read this before</a> !", "en": "If you want to do that, <a href=https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md target=_blank>you really have to read this before</a> !",
"fr": "Si vous voulez faire ça, <a href=https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md target=_blank>vous devez vraiment lire cela avant</a> !" "fr": "Si vous voulez faire ça, <a href=https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md target=_blank>vous devez vraiment lire cela avant</a> !"
}, },
"default": false "default": false
}, },
{ {
"name": "pihole_version", "name": "pihole_version",
"type": "string", "type": "string",
"ask": { "ask": {
"en": "Which version of Pi-Hole do you want to install ?", "en": "Which version of Pi-Hole do you want to install ?",
"fr": "Quelle version de Pi-Hole voulez-vous installer ?" "fr": "Quelle version de Pi-Hole voulez-vous installer ?"
}, },
"help": { "help": {
"en": "The last 3.X version is the last version available with the Debian version of dnsmasq.", "en": "The last 3.X version is the last version available with the Debian version of dnsmasq.",
"fr": "The last available version will replace the Debian version of dnsmasq by FTLDNS.<br>See the readme for more information." "fr": "The last available version will replace the Debian version of dnsmasq by FTLDNS.<br>See the readme for more information."
}, },
"choices" : ["Last 3.X","Last available"], "choices": ["Last 3.X","Last available"],
"default": "Last 3.X" "default": "Last 3.X"
} }
] ]
} }
} }

View file

@ -1,44 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# BACKUP
#=================================================
HUMAN_SIZE () { # Transforme une taille en Ko en une taille lisible pour un humain
human=$(numfmt --to=iec --from-unit=1K $1)
echo $human
}
CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant
file_to_analyse=$1
backup_size=$(du --summarize "$file_to_analyse" | cut -f1)
free_space=$(df --output=avail "/home/yunohost.backup" | sed 1d)
if [ $free_space -le $backup_size ]
then
ynh_print_err "Espace insuffisant pour sauvegarder $file_to_analyse."
ynh_print_err "Espace disponible: $(HUMAN_SIZE $free_space)"
ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)"
fi
}
#=================================================
# PACKAGE CHECK BYPASSING...
#=================================================
IS_PACKAGE_CHECK () {
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]
then
return 0
else
return 1
fi
}
#================================================= #=================================================
# FUTUR OFFICIAL HELPERS # FUTUR OFFICIAL HELPERS
#================================================= #=================================================
@ -265,30 +226,6 @@ __PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/service
#================================================= #=================================================
ynh_debian_release () {
lsb_release --codename --short
}
is_stretch () {
if [ "$(ynh_debian_release)" == "stretch" ]
then
return 0
else
return 1
fi
}
is_jessie () {
if [ "$(ynh_debian_release)" == "jessie" ]
then
return 0
else
return 1
fi
}
#=================================================
ynh_maintenance_mode_ON () { ynh_maintenance_mode_ON () {
# Load value of $path_url and $domain from the config if their not set # Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then if [ -z $path_url ]; then
@ -508,237 +445,9 @@ ynh_app_changelog () {
#================================================= #=================================================
# Check the amount of available RAM
#
# usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram]
# | arg: -r, --required= - Amount of RAM required in Mb. The helper will return 0 is there's enough RAM, or 1 otherwise.
# If --required isn't set, the helper will print the amount of RAM, in Mb.
# | arg: -s, --no_swap - Ignore swap
# | arg: -o, --only_swap - Ignore real RAM, consider only swap.
# | arg: -f, --free_ram - Count only free RAM, not the total amount of RAM available.
ynh_check_ram () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [r]=required= [s]=no_swap [o]=only_swap [f]=free_ram )
local required
local no_swap
local only_swap
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
required=${required:-}
no_swap=${no_swap:-0}
only_swap=${only_swap:-0}
local total_ram=$(vmstat --stats --unit M | grep "total memory" | awk '{print $1}')
local total_swap=$(vmstat --stats --unit M | grep "total swap" | awk '{print $1}')
local total_ram_swap=$(( total_ram + total_swap ))
local free_ram=$(vmstat --stats --unit M | grep "free memory" | awk '{print $1}')
local free_swap=$(vmstat --stats --unit M | grep "free swap" | awk '{print $1}')
local free_ram_swap=$(( free_ram + free_swap ))
# Use the total amount of ram
local ram=$total_ram_swap
if [ $free_ram -eq 1 ]
then
# Use the total amount of free ram
ram=$free_ram_swap
if [ $no_swap -eq 1 ]
then
# Use only the amount of free ram
ram=$free_ram
elif [ $only_swap -eq 1 ]
then
# Use only the amount of free swap
ram=$free_swap
fi
else
if [ $no_swap -eq 1 ]
then
# Use only the amount of free ram
ram=$total_ram
elif [ $only_swap -eq 1 ]
then
# Use only the amount of free swap
ram=$total_swap
fi
fi
if [ -n "$required" ]
then
# Return 1 if the amount of ram isn't enough.
if [ $ram -lt $required ]
then
return 1
else
return 0
fi
# If no RAM is required, return the amount of available ram.
else
echo $ram
fi
}
#=================================================
# Define the values to configure php-fpm
#
# usage: ynh_get_scalable_phpfpm --usage=usage --footprint=footprint [--print]
# | arg: -f, --footprint - Memory footprint of the service (low/medium/high).
# low - Less than 20Mb of ram by pool.
# medium - Between 20Mb and 40Mb of ram by pool.
# high - More than 40Mb of ram by pool.
# Or specify exactly the footprint, the load of the service as Mb by pool instead of having a standard value.
# To have this value, use the following command and stress the service.
# watch -n0.5 ps -o user,cmd,%cpu,rss -u APP
#
# | arg: -u, --usage - Expected usage of the service (low/medium/high).
# low - Personal usage, behind the sso.
# medium - Low usage, few people or/and publicly accessible.
# high - High usage, frequently visited website.
#
# | arg: -p, --print - Print the result
#
#
#
# The footprint of the service will be used to defined the maximum footprint we can allow, which is half the maximum RAM.
# So it will be used to defined 'pm.max_children'
# A lower value for the footprint will allow more children for 'pm.max_children'. And so for
# 'pm.start_servers', 'pm.min_spare_servers' and 'pm.max_spare_servers' which are defined from the
# value of 'pm.max_children'
# NOTE: 'pm.max_children' can't exceed 4 times the number of processor's cores.
#
# The usage value will defined the way php will handle the children for the pool.
# A value set as 'low' will set the process manager to 'ondemand'. Children will start only if the
# service is used, otherwise no child will stay alive. This config gives the lower footprint when the
# service is idle. But will use more proc since it has to start a child as soon it's used.
# Set as 'medium', the process manager will be at dynamic. If the service is idle, a number of children
# equal to pm.min_spare_servers will stay alive. So the service can be quick to answer to any request.
# The number of children can grow if needed. The footprint can stay low if the service is idle, but
# not null. The impact on the proc is a little bit less than 'ondemand' as there's always a few
# children already available.
# Set as 'high', the process manager will be set at 'static'. There will be always as many children as
# 'pm.max_children', the footprint is important (but will be set as maximum a quarter of the maximum
# RAM) but the impact on the proc is lower. The service will be quick to answer as there's always many
# children ready to answer.
ynh_get_scalable_phpfpm () {
local legacy_args=ufp
# Declare an array to define the options of this helper.
declare -Ar args_array=( [u]=usage= [f]=footprint= [p]=print )
local usage
local footprint
local print
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Set all characters as lowercase
footprint=${footprint,,}
usage=${usage,,}
print=${print:-0}
if [ "$footprint" = "low" ]
then
footprint=20
elif [ "$footprint" = "medium" ]
then
footprint=35
elif [ "$footprint" = "high" ]
then
footprint=50
fi
# Define the way the process manager handle child processes.
if [ "$usage" = "low" ]
then
php_pm=ondemand
elif [ "$usage" = "medium" ]
then
php_pm=dynamic
elif [ "$usage" = "high" ]
then
php_pm=static
else
ynh_die --message="Does not recognize '$usage' as an usage value."
fi
# Get the total of RAM available, except swap.
local max_ram=$(ynh_check_ram --no_swap)
less0() {
# Do not allow value below 1
if [ $1 -le 0 ]
then
echo 1
else
echo $1
fi
}
# Define pm.max_children
# The value of pm.max_children is the total amount of ram divide by 2 and divide again by the footprint of a pool for this app.
# So if php-fpm start the maximum of children, it won't exceed half of the ram.
php_max_children=$(( $max_ram / 2 / $footprint ))
# If process manager is set as static, use half less children.
# Used as static, there's always as many children as the value of pm.max_children
if [ "$php_pm" = "static" ]
then
php_max_children=$(( $php_max_children / 2 ))
fi
php_max_children=$(less0 $php_max_children)
# To not overload the proc, limit the number of children to 4 times the number of cores.
local core_number=$(nproc)
local max_proc=$(( $core_number * 4 ))
if [ $php_max_children -gt $max_proc ]
then
php_max_children=$max_proc
fi
if [ "$php_pm" = "dynamic" ]
then
# Define pm.start_servers, pm.min_spare_servers and pm.max_spare_servers for a dynamic process manager
php_min_spare_servers=$(( $php_max_children / 8 ))
php_min_spare_servers=$(less0 $php_min_spare_servers)
php_max_spare_servers=$(( $php_max_children / 2 ))
php_max_spare_servers=$(less0 $php_max_spare_servers)
php_start_servers=$(( $php_min_spare_servers + ( $php_max_spare_servers - $php_min_spare_servers ) /2 ))
php_start_servers=$(less0 $php_start_servers)
else
php_min_spare_servers=0
php_max_spare_servers=0
php_start_servers=0
fi
if [ $print -eq 1 ]
then
ynh_debug --message="Footprint=${footprint}Mb by pool."
ynh_debug --message="Process manager=$php_pm"
ynh_debug --message="Max RAM=${max_ram}Mb"
if [ "$php_pm" != "static" ]; then
ynh_debug --message="\nMax estimated footprint=$(( $php_max_children * $footprint ))"
ynh_debug --message="Min estimated footprint=$(( $php_min_spare_servers * $footprint ))"
fi
if [ "$php_pm" = "dynamic" ]; then
ynh_debug --message="Estimated average footprint=$(( $php_max_spare_servers * $footprint ))"
elif [ "$php_pm" = "static" ]; then
ynh_debug --message="Estimated footprint=$(( $php_max_children * $footprint ))"
fi
ynh_debug --message="\nRaw php-fpm values:"
ynh_debug --message="pm.max_children = $php_max_children"
if [ "$php_pm" = "dynamic" ]; then
ynh_debug --message="pm.start_servers = $php_start_servers"
ynh_debug --message="pm.min_spare_servers = $php_min_spare_servers"
ynh_debug --message="pm.max_spare_servers = $php_max_spare_servers"
fi
fi
}
#=================================================
# Execute a command as another user # Execute a command as another user
# usage: exec_as USER COMMAND [ARG ...] # usage: exec_as USER COMMAND [ARG ...]
exec_as() { ynh_exec_as() {
local USER=$1 local USER=$1
shift 1 shift 1

View file

@ -2,3 +2,14 @@
# Dependencies # Dependencies
app_depencencies="sqlite idn2 php7.0-sqlite3 nettle-dev libcap2-bin" app_depencencies="sqlite idn2 php7.0-sqlite3 nettle-dev libcap2-bin"
if [ "$YNH_APP_ARG_PIHOLE_VERSION" == "Last 3.X" ]
then
pihole_core_version=3.3.1
dashboard_version=3.3
FTL_version=3.0
else
pihole_core_version=5.0
dashboard_version=5.0
FTL_version=5.0
fi

View file

@ -1,132 +0,0 @@
#!/bin/bash
# Create a dedicated php-fpm config
#
# usage 1: ynh_add_fpm_config [--phpversion=7.X] [--use_template]
# | arg: -v, --phpversion - Version of php to use.
# | arg: -t, --use_template - Use this helper in template mode.
#
# -----------------------------------------------------------------------------
#
# usage 2: ynh_add_fpm_config [--phpversion=7.X] --usage=usage --footprint=footprint
# | arg: -v, --phpversion - Version of php to use.#
# | arg: -f, --footprint - Memory footprint of the service (low/medium/high).
# low - Less than 20Mb of ram by pool.
# medium - Between 20Mb and 40Mb of ram by pool.
# high - More than 40Mb of ram by pool.
# Or specify exactly the footprint, the load of the service as Mb by pool instead of having a standard value.
# To have this value, use the following command and stress the service.
# watch -n0.5 ps -o user,cmd,%cpu,rss -u APP
#
# | arg: -u, --usage - Expected usage of the service (low/medium/high).
# low - Personal usage, behind the sso.
# medium - Low usage, few people or/and publicly accessible.
# high - High usage, frequently visited website.
#
# Requires YunoHost version 2.7.2 or higher.
ynh_add_fpm_config () {
# Declare an array to define the options of this helper.
local legacy_args=vtuf
declare -Ar args_array=( [v]=phpversion= [t]=use_template [u]=usage= [f]=footprint= )
local phpversion
local use_template
local usage
local footprint
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# The default behaviour is to use the template.
use_template="${use_template:-1}"
usage="${usage:-}"
footprint="${footprint:-}"
if [ -n "$usage" ] || [ -n "$footprint" ]; then
use_template=0
fi
# Configure PHP-FPM 7.0 by default
phpversion="${phpversion:-7.0}"
local fpm_config_dir="/etc/php/$phpversion/fpm"
local fpm_service="php${phpversion}-fpm"
# Configure PHP-FPM 5 on Debian Jessie
if [ "$(ynh_get_debian_release)" == "jessie" ]; then
fpm_config_dir="/etc/php5/fpm"
fpm_service="php5-fpm"
fi
ynh_app_setting_set --app=$app --key=fpm_config_dir --value="$fpm_config_dir"
ynh_app_setting_set --app=$app --key=fpm_service --value="$fpm_service"
finalphpconf="$fpm_config_dir/pool.d/$app.conf"
ynh_backup_if_checksum_is_different --file="$finalphpconf"
if [ $use_template -eq 1 ]
then
# Usage 1, use the template in ../conf/php-fpm.conf
sudo cp ../conf/php-fpm.conf "$finalphpconf"
ynh_replace_string --match_string="__NAMETOCHANGE__" --replace_string="$app" --target_file="$finalphpconf"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalphpconf"
ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$finalphpconf"
ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file="$finalphpconf"
else
# Store settings
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$footprint
ynh_app_setting_set --app=$app --key=fpm_usage --value=$usage
# Usage 2, generate a php-fpm config file with ynh_get_scalable_phpfpm
ynh_get_scalable_phpfpm --usage=$usage --footprint=$footprint
# Copy the default file
sudo cp "$fpm_config_dir/pool.d/www.conf" "$finalphpconf"
# Replace standard variables into the default file
ynh_replace_string --match_string="^\[www\]" --replace_string="[$app]" --target_file="$finalphpconf"
ynh_replace_string --match_string=".*listen = .*" --replace_string="listen = /var/run/php/php7.0-fpm-$app.sock" --target_file="$finalphpconf"
ynh_replace_string --match_string="^user = .*" --replace_string="user = $app" --target_file="$finalphpconf"
ynh_replace_string --match_string="^group = .*" --replace_string="group = $app" --target_file="$finalphpconf"
ynh_replace_string --match_string=".*chdir = .*" --replace_string="chdir = $final_path" --target_file="$finalphpconf"
# Configure fpm children
ynh_replace_string --match_string=".*pm = .*" --replace_string="pm = $php_pm" --target_file="$finalphpconf"
ynh_replace_string --match_string=".*pm.max_children = .*" --replace_string="pm.max_children = $php_max_children" --target_file="$finalphpconf"
ynh_replace_string --match_string=".*pm.max_requests = .*" --replace_string="pm.max_requests = 500" --target_file="$finalphpconf"
ynh_replace_string --match_string=".*request_terminate_timeout = .*" --replace_string="request_terminate_timeout = 1d" --target_file="$finalphpconf"
if [ "$php_pm" = "dynamic" ]
then
ynh_replace_string --match_string=".*pm.start_servers = .*" --replace_string="pm.start_servers = $php_start_servers" --target_file="$finalphpconf"
ynh_replace_string --match_string=".*pm.min_spare_servers = .*" --replace_string="pm.min_spare_servers = $php_min_spare_servers" --target_file="$finalphpconf"
ynh_replace_string --match_string=".*pm.max_spare_servers = .*" --replace_string="pm.max_spare_servers = $php_max_spare_servers" --target_file="$finalphpconf"
elif [ "$php_pm" = "ondemand" ]
then
ynh_replace_string --match_string=".*pm.process_idle_timeout = .*" --replace_string="pm.process_idle_timeout = 10s" --target_file="$finalphpconf"
fi
# Comment unused parameters
if [ "$php_pm" != "dynamic" ]
then
ynh_replace_string --match_string=".*\(pm.start_servers = .*\)" --replace_string=";\1" --target_file="$finalphpconf"
ynh_replace_string --match_string=".*\(pm.min_spare_servers = .*\)" --replace_string=";\1" --target_file="$finalphpconf"
ynh_replace_string --match_string=".*\(pm.max_spare_servers = .*\)" --replace_string=";\1" --target_file="$finalphpconf"
fi
if [ "$php_pm" != "ondemand" ]
then
ynh_replace_string --match_string=".*\(pm.process_idle_timeout = .*\)" --replace_string=";\1" --target_file="$finalphpconf"
fi
# Concatene the extra config.
if [ -e ../conf/extra_php-fpm.conf ]; then
cat ../conf/extra_php-fpm.conf >> "$finalphpconf"
fi
fi
sudo chown root: "$finalphpconf"
ynh_store_file_checksum --file="$finalphpconf"
if [ -e "../conf/php-fpm.ini" ]
then
echo "Packagers ! Please do not use a separate php ini file, merge your directives in the pool file instead." >&2
finalphpini="$fpm_config_dir/conf.d/20-$app.ini"
ynh_backup_if_checksum_is_different "$finalphpini"
sudo cp ../conf/php-fpm.ini "$finalphpini"
sudo chown root: "$finalphpini"
ynh_store_file_checksum "$finalphpini"
fi
ynh_systemd_action --service_name=$fpm_service --action=reload
}

256
scripts/actions/reset_default_app Executable file
View file

@ -0,0 +1,256 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Load common variables for all scripts.
source scripts/_variables
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
path_url=$(ynh_app_setting_get --app=$app --key=path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
pihole_version="$(ynh_app_setting_get --app=$app --key=pihole_version)"
#=================================================
# SPECIFIC ACTION
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activating maintenance mode..." --time --weight=1
ynh_maintenance_mode_ON
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Resetting source files..." --time --weight=1
# Download, check integrity, uncompress and patch the source from app.src
pihole_local_repo="/etc/.pihole"
(cd scripts
if [ "$pihole_version" == "Last 3.X" ]
then
# Overwrite the version 3.3.1
YNH_CWD=$PWD ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_3
# Overwrite admin dashboard
YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard_3
else
# Overwrite the last version available
YNH_CWD=$PWD ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_last
# Overwrite admin dashboard
YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard_last
fi
)
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Resetting nginx web server configuration..." --time --weight=1
# Create a dedicated nginx config
yunohost app action run $app reset_default_nginx
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Resetting php-fpm configuration..." --time --weight=1
# Create a dedicated php-fpm config
yunohost app action run $app reset_default_phpfpm
#=================================================
# RECREATE DIRECTORIES
#=================================================
ynh_script_progression --message="Recreating and populating directories..." --time --weight=1
pihole_storage="/etc/pihole"
mkdir -p "$pihole_storage"
chown $app: -R "$pihole_storage"
pihole_dir="/opt/pihole"
mkdir -p "$pihole_dir"
# Make a copy of Pi-Hole scripts
cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/"
cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
# And copy this fucking COL_TABLE file...
cp -a "$pihole_local_repo/advanced/Scripts/COL_TABLE" "$pihole_dir/"
#=================================================
# COPY PI-HOLE MAIN SCRIPT
#=================================================
ynh_script_progression --message="Copying Pi-Hole main script..."
cp -a "$pihole_local_repo/pihole" /usr/local/bin/
cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.d/pihole
#=================================================
# RECREATE LOG FILES
#=================================================
touch /var/log/{pihole,pihole-FTL}.log
chmod 644 /var/log/{pihole,pihole-FTL}.log
dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
chown $dnsmasq_user:root /var/log/{pihole,pihole-FTL}.log
#=================================================
# RECREATE SUDOER FILE
#=================================================
# This sudoers config allow pihole to execute /usr/local/bin/pihole as root without password. Nothing more.
if [ "$pihole_version" == "Last 3.X" ]
then
cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole
else
cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
fi
echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
# echo "Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin" >> /etc/sudoers.d/pihole
chmod 0440 /etc/sudoers.d/pihole
#=================================================
# REINSTALL LOGROTATE SCRIPT FOR PI-HOLE
#=================================================
if [ "$pihole_version" == "Last 3.X" ]
then
cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate"
else
cp "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
fi
sed -i "/# su #/d;" "$pihole_storage/logrotate"
#=================================================
# REINSTALLATION OF PIHOLE-FTL
#=================================================
ynh_script_progression --message="Reinstalling PiHole-FTL..." --weight=30
# Get the source of Pi-Hole-FTL
FTL_temp_path=$(mktemp -d)
if [ "$pihole_version" == "Last 3.X" ]
then
# Install the version 3.3.1
ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL_3
else
# Install the last version available
ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL_last
fi
# Instead of downloading a binary file, we're going to compile it
( cd "$FTL_temp_path"
ynh_exec_warn_less make
ynh_exec_warn_less make install )
ynh_secure_remove --file="$FTL_temp_path"
cp "../conf/dns-servers.conf" "$pihole_storage"
# Restore the default pihole-FTL.conf
yunohost app action run $app reset_default_ftl
if [ "$pihole_version" == "Last 3.X" ]
then
# Version 3.3.1
cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
chmod +x /etc/init.d/pihole-FTL
ynh_exec_warn_less systemctl enable pihole-FTL
else
cp -a $pihole_local_repo/advanced/Templates/pihole-FTL.service /etc/init.d/pihole-FTL
chmod +x /etc/init.d/pihole-FTL
ynh_exec_warn_less systemctl enable pihole-FTL
# Reload systemd config
systemctl daemon-reload
fi
#=================================================
# RESET THE VARIABLES FILE
#=================================================
# Restore the default setupVars.conf
yunohost app action run $app reset_default_setupvars
#=================================================
# RESET DNSMASQ CONFIG
#=================================================
# Restore the default setupVars.conf
yunohost app action run $app reset_default_dnsmasq
#=================================================
# REINSTALL CRON JOB
#=================================================
if [ "$pihole_version" == "Last 3.X" ]
then
cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole
else
cp $pihole_local_repo/advanced/Templates/pihole.cron /etc/cron.d/pihole
fi
# Remove git usage for version. Which fails because we use here a release instead of master.
ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --target_file=/etc/cron.d/pihole
#=================================================
# REINSTALL CONF_REGEN HOOK
#=================================================
(cd scripts; cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app)
#=================================================
# RESTART PIHOLE-FTL
#=================================================
ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2
ynh_systemd_action --action=restart --service_name=pihole-FTL
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Disabling maintenance mode..." --time --weight=1
ynh_maintenance_mode_OFF
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --time --last

View file

@ -9,11 +9,18 @@
source scripts/_common.sh source scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#================================================= #=================================================
# RETRIEVE ARGUMENTS # RETRIEVE ARGUMENTS
#================================================= #=================================================
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} app=$YNH_APP_INSTANCE_NAME
query_logging=$(ynh_app_setting_get --app=$app --key=query_logging) query_logging=$(ynh_app_setting_get --app=$app --key=query_logging)
@ -24,9 +31,11 @@ query_logging=$(ynh_app_setting_get --app=$app --key=query_logging)
file="$1" file="$1"
if [ "$file" = "setupVars.conf" ]; then if [ "$file" = "setupVars.conf" ]; then
config_file="/etc/pihole/setupVars.conf" config_file="/etc/pihole/setupVars.conf"
elif [ "$file" = "pihole-FTL.conf" ]; then elif [ "$file" = "pihole-FTL.conf" ]; then
config_file="/etc/pihole/pihole-FTL.conf" config_file="/etc/pihole/pihole-FTL.conf"
elif [ "$file" = "01-pihole.conf" ]; then
config_file="/etc/dnsmasq.d/01-pihole.conf"
fi fi
#================================================= #=================================================
@ -39,33 +48,55 @@ ynh_script_progression --message="Resetting the config file $config_file..." --w
# Verify the checksum and backup the file if it's different # Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different --file="$config_file" ynh_backup_if_checksum_is_different --file="$config_file"
main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
if [ "$file" = "setupVars.conf" ] if [ "$file" = "setupVars.conf" ]
then then
# Recreate the default config # Recreate the default config
# Trouve l'interface réseau par défaut # Trouve l'interface réseau par défaut
main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}') echo "PIHOLE_INTERFACE=$main_iface" > "$config_file"
echo "PIHOLE_INTERFACE=$main_iface" > "$config_file" echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file"
echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file" echo "IPV6_ADDRESS=::1" >> "$config_file"
echo "IPV6_ADDRESS=::1" >> "$config_file" echo "PIHOLE_DNS_1=" >> "$config_file"
echo "PIHOLE_DNS_1=" >> "$config_file" echo "PIHOLE_DNS_2=" >> "$config_file"
echo "PIHOLE_DNS_2=" >> "$config_file" if [ $query_logging -eq 1 ]; then
if [ $query_logging -eq 1 ]; then query_logging=true
query_logging=true else
else query_logging=false
query_logging=false fi
fi echo "QUERY_LOGGING=$query_logging" >> "$config_file"
echo "QUERY_LOGGING=$query_logging" >> "$config_file" echo "INSTALL_WEB=true" >> "$config_file"
echo "INSTALL_WEB=true" >> "$config_file"
elif [ "$file" = "pihole-FTL.conf" ] elif [ "$file" = "pihole-FTL.conf" ]
then then
# Get the default file and overwrite the current config # Get the default file and overwrite the current config
cp /etc/yunohost/apps/$app/conf/pihole-FTL.conf "$config_file" cp /etc/yunohost/apps/$app/conf/pihole-FTL.conf "$config_file"
ynh_script_progression --message="Restarting PiHole..." --weight=2 ynh_script_progression --message="Restarting PiHole..." --weight=2
# Restart pihole-FTL # Restart pihole-FTL
ynh_systemd_action --action=restart --service_name=pihole-FTL ynh_systemd_action --action=restart --service_name=pihole-FTL
elif [ "$file" = "01-pihole.conf" ]
then
cp "$pihole_local_repo/advanced/01-pihole.conf" $config_file
# Use dns from /etc/resolv.dnsmasq.conf
ynh_replace_string --match_string="@DNS1@" --replace_string="" --target_file=$config_file
ynh_replace_string --match_string="@DNS2@" --replace_string="" --target_file=$config_file
ynh_replace_string --match_string="^no-resolv" --replace_string="#no-resolv" --target_file=$config_file
ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file=$config_file
if [ "$query_logging" = "true" ]; then
ynh_replace_string --match_string="^#log-queries" --replace_string="log-queries" --target_file=$config_file
else
ynh_replace_string --match_string="^log-queries" --replace_string="#log-queries" --target_file=$config_file
fi
# Fix a too recent option for our dnsmasq version.
ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file=$config_file
# To prevent any conflict with the original dnsmasq config, comment cache-size in the original config.
ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file=/etc/dnsmasq.conf
fi fi
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings

View file

@ -0,0 +1,64 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
type=$1
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# SPECIFIC ACTION
#=================================================
# RESET THE CONFIG FILE
#=================================================
if [ $type == nginx ]; then
name=Nginx
elif [ $type == phpfpm ]; then
name=PHP-FPM
else
ynh_die --message="The type $type is not recognized"
fi
ynh_script_progression --message="Resetting the specific configuration of $name for the app $app..." --weight=3
if [ $type == nginx ]
then
(cd scripts; ynh_add_nginx_config)
elif [ $type == phpfpm ]
then
(cd scripts; ynh_add_fpm_config --usage=low --footprint=low --dedicated_service)
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -27,6 +27,9 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
path_url=$(ynh_app_setting_get --app=$app --key=path) path_url=$(ynh_app_setting_get --app=$app --key=path)
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
# Get variable from ynh_add_fpm_config
fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir)
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#================================================= #=================================================
@ -34,16 +37,9 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
#================================================= #=================================================
ynh_script_progression --message="Backing up the main app directory..." --weight=5 ynh_script_progression --message="Backing up the main app directory..." --weight=5
CHECK_SIZE "$final_path"
ynh_backup --src_path="$final_path" ynh_backup --src_path="$final_path"
CHECK_SIZE "/etc/.pihole"
ynh_backup --src_path="/etc/.pihole" ynh_backup --src_path="/etc/.pihole"
CHECK_SIZE "/etc/pihole"
ynh_backup --src_path="/etc/pihole" ynh_backup --src_path="/etc/pihole"
CHECK_SIZE "/opt/pihole"
ynh_backup --src_path="/opt/pihole" ynh_backup --src_path="/opt/pihole"
#================================================= #=================================================
@ -58,7 +54,8 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
ynh_script_progression --message="Backing up php-fpm configuration..." ynh_script_progression --message="Backing up php-fpm configuration..."
ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" ynh_backup --src_path="$fpm_config_dir/php-fpm-$app.conf"
ynh_backup --src_path="$fpm_config_dir/pool.d/$app.conf"
#================================================= #=================================================
# SPECIFIC BACKUP # SPECIFIC BACKUP
@ -84,13 +81,13 @@ ynh_backup --src_path="/usr/bin/pihole-FTL"
ynh_backup --src_path="/etc/dnsmasq.d/01-pihole.conf" ynh_backup --src_path="/etc/dnsmasq.d/01-pihole.conf"
if test -e "/etc/dnsmasq.d/02-pihole-dhcp.conf"; then if test -e "/etc/dnsmasq.d/02-pihole-dhcp.conf"; then
ynh_backup --src_path="/etc/dnsmasq.d/02-pihole-dhcp.conf" ynh_backup --src_path="/etc/dnsmasq.d/02-pihole-dhcp.conf"
fi 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 --src_path="/etc/dnsmasq.d/03-pihole-wildcard.conf" ynh_backup --src_path="/etc/dnsmasq.d/03-pihole-wildcard.conf"
fi fi
if test -e "/etc/dnsmasq.d/04-pihole-static-dhcp.conf"; then if test -e "/etc/dnsmasq.d/04-pihole-static-dhcp.conf"; then
ynh_backup --src_path="/etc/dnsmasq.d/04-pihole-static-dhcp.conf" ynh_backup --src_path="/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
fi fi
ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"

View file

@ -36,11 +36,11 @@ ynh_script_progression --message="Backing up the app before changing its url (ma
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails # restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -61,13 +61,13 @@ ynh_maintenance_mode_ON
change_domain=0 change_domain=0
if [ "$old_domain" != "$new_domain" ] if [ "$old_domain" != "$new_domain" ]
then then
change_domain=1 change_domain=1
fi fi
change_path=0 change_path=0
if [ "$old_path" != "$new_path" ] if [ "$old_path" != "$new_path" ]
then then
change_path=1 change_path=1
fi fi
#================================================= #=================================================
@ -82,26 +82,26 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the nginx config file # Change the path in the nginx config file
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]
then then
# Make a backup of the original nginx config file if modified # Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path" ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper # Set global variables for nginx helper
domain="$old_domain" domain="$old_domain"
path_url="$new_path" path_url="$new_path"
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
fi fi
# Change the domain for nginx # Change the domain for nginx
if [ $change_domain -eq 1 ] if [ $change_domain -eq 1 ]
then then
# Delete file checksum for the old conf file location # Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path" ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location # Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi fi
#================================================= #=================================================

View file

@ -8,13 +8,14 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _ynh_add_fpm_config
#================================================= #=================================================
# RETRIEVE ARGUMENTS # RETRIEVE ARGUMENTS
#================================================= #=================================================
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} app=$YNH_APP_INSTANCE_NAME
fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir)
#================================================= #=================================================
# SPECIFIC CODE # SPECIFIC CODE
@ -69,24 +70,33 @@ free_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT:-$old_free_footp
old_fpm_usage="$(ynh_app_setting_get --app=$app --key=fpm_usage)" old_fpm_usage="$(ynh_app_setting_get --app=$app --key=fpm_usage)"
fpm_usage="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE:-$old_fpm_usage}" fpm_usage="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE:-$old_fpm_usage}"
# php_forced_max_children for php-fpm
old_php_forced_max_children="$(ynh_app_setting_get --app=$app --key=php_forced_max_children)"
# If php_forced_max_children isn't into settings.yml, get the current value from the fpm config
if [ -z "$old_php_forced_max_children" ]; then
old_php_forced_max_children="$(grep "^pm.max_children" "$fpm_config_dir/pool.d/$app.conf" | awk '{print $3}')"
fi
php_forced_max_children="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FORCE_MAX_CHILDREN:-$old_php_forced_max_children}"
#================================================= #=================================================
# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND # SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
#================================================= #=================================================
show_config() { show_config() {
# here you are supposed to read some config file/database/other then print the values # here you are supposed to read some config file/database/other then print the values
# ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value" # ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS=$overwrite_setupvars" ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS=$overwrite_setupvars"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL=$overwrite_ftl" ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL=$overwrite_ftl"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx" ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm" ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm"
ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html" ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT=$fpm_footprint" ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT=$fpm_footprint"
ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT=$free_footprint" ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT=$free_footprint"
ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE=$fpm_usage" ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE=$fpm_usage"
ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FORCE_MAX_CHILDREN=$php_forced_max_children"
} }
#================================================= #=================================================
@ -99,27 +109,30 @@ apply_config() {
# MODIFY OVERWRITTING SETTINGS # MODIFY OVERWRITTING SETTINGS
#================================================= #=================================================
# Set overwrite_setupvars # Set overwrite_setupvars
ynh_app_setting_set --app=$app --key=overwrite_setupvars --value="$overwrite_setupvars" ynh_app_setting_set --app=$app --key=overwrite_setupvars --value="$overwrite_setupvars"
# Set overwrite_ftl # Set overwrite_ftl
ynh_app_setting_set --app=$app --key=overwrite_ftl --value="$overwrite_ftl" ynh_app_setting_set --app=$app --key=overwrite_ftl --value="$overwrite_ftl"
# Set overwrite_nginx # Set overwrite_nginx
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx" ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
# Set overwrite_phpfpm # Set overwrite_phpfpm
ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value="$overwrite_phpfpm" ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value="$overwrite_phpfpm"
#================================================= #=================================================
# MODIFY EMAIL SETTING # MODIFY EMAIL SETTING
#================================================= #=================================================
# Set admin_mail_html # Set admin_mail_html
ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html" ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html"
#================================================= #=================================================
# RECONFIGURE PHP-FPM # RECONFIGURE PHP-FPM
#================================================= #=================================================
if [ "$fpm_usage" != "$old_fpm_usage" ] || [ "$fpm_footprint" != "$old_fpm_footprint" ] || [ "$free_footprint" != "$old_free_footprint" ] if [ "$fpm_usage" != "$old_fpm_usage" ] || \
[ "$fpm_footprint" != "$old_fpm_footprint" ] || \
[ "$free_footprint" != "$old_free_footprint" ] || \
[ "$php_forced_max_children" != "$old_php_forced_max_children" ]
then then
# If fpm_footprint is set to 'specific', use $free_footprint value. # If fpm_footprint is set to 'specific', use $free_footprint value.
if [ "$fpm_footprint" = "specific" ] if [ "$fpm_footprint" = "specific" ]
@ -127,9 +140,21 @@ apply_config() {
fpm_footprint=$free_footprint fpm_footprint=$free_footprint
fi fi
if [ "$php_forced_max_children" != "$old_php_forced_max_children" ]
then
# Set php_forced_max_children
if [ $php_forced_max_children -ne 0 ]
then
ynh_app_setting_set --app=$app --key=php_forced_max_children --value="$php_forced_max_children"
else
# If the value is set to 0, remove the setting
ynh_app_setting_delete --app=$app --key=php_forced_max_children
fi
fi
if [ "$fpm_footprint" != "0" ] if [ "$fpm_footprint" != "0" ]
then then
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --dedicated_service
else else
ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below." ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below."
fi fi
@ -143,6 +168,6 @@ apply_config() {
#================================================= #=================================================
case $1 in case $1 in
show) show_config;; show) show_config;;
apply) apply_config;; apply) apply_config;;
esac esac

View file

@ -6,12 +6,12 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers
source _ynh_add_fpm_config
# Load common variables for all scripts. # Load common variables for all scripts.
source _variables source _variables
source _common.sh
source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE FAILURE OF THE SCRIPT # MANAGE FAILURE OF THE SCRIPT
#================================================= #=================================================
@ -72,7 +72,7 @@ ynh_script_progression --message="Configuring firewall..." --weight=12
port=$(ynh_find_port --port=4711) port=$(ynh_find_port --port=4711)
if [ $port -gt 4720 ] if [ $port -gt 4720 ]
then then
ynh_die --message="The ports 4711 to 4720 are already in use. Pi-hole can't works on another port. Please try to free one of this ports." ynh_die --message="The ports 4711 to 4720 are already in use. Pi-hole can't works on another port. Please try to free one of this ports."
fi fi
# Open this port # Open this port
ynh_exec_fully_quiet yunohost firewall allow --no-upnp TCP $port ynh_exec_fully_quiet yunohost firewall allow --no-upnp TCP $port
@ -132,7 +132,7 @@ ynh_system_user_create --username=$app
ynh_script_progression --message="Configuring php-fpm..." --weight=2 ynh_script_progression --message="Configuring php-fpm..." --weight=2
# Create a dedicated php-fpm config # Create a dedicated php-fpm config
ynh_add_fpm_config --usage=low --footprint=low ynh_add_fpm_config --usage=low --footprint=low --dedicated_service
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
@ -167,10 +167,10 @@ cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.
# CREATE LOG FILES # CREATE LOG FILES
#================================================= #=================================================
touch /var/log/pihole.log touch /var/log/{pihole,pihole-FTL}.log
chmod 644 /var/log/pihole.log chmod 644 /var/log/{pihole,pihole-FTL}.log
dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2) dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
chown $dnsmasq_user:root /var/log/pihole.log chown $dnsmasq_user:root /var/log/{pihole,pihole-FTL}.log
#================================================= #=================================================
# CREATE SUDOER FILE # CREATE SUDOER FILE
@ -221,7 +221,9 @@ ynh_exec_warn_less make
ynh_exec_warn_less make install ) ynh_exec_warn_less make install )
ynh_secure_remove --file="$FTL_temp_path" ynh_secure_remove --file="$FTL_temp_path"
cp "../conf/dns-servers.conf" "$pihole_storage"
cp "../conf/pihole-FTL.conf" "$pihole_storage" cp "../conf/pihole-FTL.conf" "$pihole_storage"
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$pihole_storage/pihole-FTL.conf" ynh_store_file_checksum --file="$pihole_storage/pihole-FTL.conf"
@ -276,9 +278,9 @@ echo "IPV6_ADDRESS=::1" >> $setupVars
echo "PIHOLE_DNS_1=" >> $setupVars echo "PIHOLE_DNS_1=" >> $setupVars
echo "PIHOLE_DNS_2=" >> $setupVars echo "PIHOLE_DNS_2=" >> $setupVars
if [ $query_logging -eq 1 ]; then if [ $query_logging -eq 1 ]; then
query_logging=true query_logging=true
else else
query_logging=false query_logging=false
fi fi
echo "QUERY_LOGGING=$query_logging" >> $setupVars echo "QUERY_LOGGING=$query_logging" >> $setupVars
echo "INSTALL_WEB=true" >> $setupVars echo "INSTALL_WEB=true" >> $setupVars
@ -302,9 +304,9 @@ ynh_replace_string --match_string="^no-resolv" --replace_string="#no-resolv" --t
ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file=$pihole_dnsmasq_config ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file=$pihole_dnsmasq_config
if [ "$query_logging" = "true" ]; then if [ "$query_logging" = "true" ]; then
ynh_replace_string --match_string="^#log-queries" --replace_string="log-queries" --target_file=$pihole_dnsmasq_config ynh_replace_string --match_string="^#log-queries" --replace_string="log-queries" --target_file=$pihole_dnsmasq_config
else else
ynh_replace_string --match_string="^log-queries" --replace_string="#log-queries" --target_file=$pihole_dnsmasq_config ynh_replace_string --match_string="^log-queries" --replace_string="#log-queries" --target_file=$pihole_dnsmasq_config
fi fi
# Fix a too recent option for our dnsmasq version. # Fix a too recent option for our dnsmasq version.
@ -327,12 +329,12 @@ localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f
# List all YunoHost domains # List all YunoHost domains
while read perdomain while read perdomain
do do
# Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution. # Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution.
ynh_replace_string --match_string="^127.0.0.1.*$perdomain" --replace_string="#Commented by pihole# &" --target_file=/etc/hosts ynh_replace_string --match_string="^127.0.0.1.*$perdomain" --replace_string="#Commented by pihole# &" --target_file=/etc/hosts
# And add a resolution on the local IP instead # And add a resolution on the local IP instead
grep -q "^$localipv4.*$perdomain" /etc/hosts || \ grep -q "^$localipv4.*$perdomain" /etc/hosts || \
echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts
done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
#================================================= #=================================================
@ -341,38 +343,45 @@ done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
if [ $enable_dhcp -eq 1 ] if [ $enable_dhcp -eq 1 ]
then then
ynh_script_progression --message="Enabling dhcp server..." ynh_script_progression --message="Enabling dhcp server..."
max_dhcp_range=250 max_dhcp_range=250
dhcp_range=100 dhcp_range=100
# Define the dhcp range from the current ip # Define the dhcp range from the current ip
ip_beginning_part=$(echo "$localipv4" | cut -d. -f1-3) ip_beginning_part=$(echo "$localipv4" | cut -d. -f1-3)
ip_fourth_part=$(echo "$localipv4" | cut -d. -f4) ip_fourth_part=$(echo "$localipv4" | cut -d. -f4)
b_range=$(( $ip_fourth_part + $dhcp_range )) b_range=$(( $ip_fourth_part + $dhcp_range ))
if [ $b_range -gt $max_dhcp_range ]; then if [ $b_range -gt $max_dhcp_range ]; then
b_range=$max_dhcp_range b_range=$max_dhcp_range
fi fi
a_range=$(( $b_range - $dhcp_range )) a_range=$(( $b_range - $dhcp_range ))
# Get the gateway # Get the gateway
gateway=$(ip route | grep default | awk '{print $3;}') gateway=$(ip route | grep default | awk '{print $3;}')
# And the mac adress # And the mac adress
hw_adress=$(ip link | grep -A1 "$main_iface" | tail -n1 | awk '{print $2;}') hw_adress=$(ip link | grep -A1 "$main_iface" | tail -n1 | awk '{print $2;}')
# Copy the config file # Copy the config file
cp "../conf/02-pihole-dhcp.conf" "/etc/dnsmasq.d/" cp "../conf/02-pihole-dhcp.conf" "/etc/dnsmasq.d/"
# And set the config # And set the config
ynh_replace_string --match_string="__A_RANGE__" --replace_string="$ip_beginning_part.$a_range" --target_file="/etc/dnsmasq.d/02-pihole-dhcp.conf" ynh_replace_string --match_string="__A_RANGE__" --replace_string="$ip_beginning_part.$a_range" --target_file="/etc/dnsmasq.d/02-pihole-dhcp.conf"
ynh_replace_string --match_string="__B_RANGE__" --replace_string="$ip_beginning_part.$b_range" --target_file="/etc/dnsmasq.d/02-pihole-dhcp.conf" ynh_replace_string --match_string="__B_RANGE__" --replace_string="$ip_beginning_part.$b_range" --target_file="/etc/dnsmasq.d/02-pihole-dhcp.conf"
ynh_replace_string --match_string="__GATEWAY__" --replace_string="$gateway" --target_file="/etc/dnsmasq.d/02-pihole-dhcp.conf" ynh_replace_string --match_string="__GATEWAY__" --replace_string="$gateway" --target_file="/etc/dnsmasq.d/02-pihole-dhcp.conf"
# Set a static ip for the server. # Set a static ip for the server.
echo "dhcp-host=$hw_adress,$localipv4" > "/etc/dnsmasq.d/04-pihole-static-dhcp.conf" echo "dhcp-host=$hw_adress,$localipv4" > "/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
fi fi
# Open the UDP port 67 for dhcp # Open the UDP port 67 for dhcp
ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp
#=================================================
# SET VERSIONS FOR THE FOOTER OF THE WEB INTERFACE
#=================================================
echo "master master master" > $pihole_storage/localbranches
echo "$pihole_core_version $dashboard_version $FTL_version" | tee $pihole_storage/{GitHubVersions,localversions} > /dev/null
#================================================= #=================================================
# INSTALL CRON JOB # INSTALL CRON JOB
#================================================= #=================================================
@ -457,12 +466,12 @@ admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)
if [ $enable_dhcp -eq 1 ] if [ $enable_dhcp -eq 1 ]
then then
dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole. dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole.
You should really read the __URL_TAG1__documentation about that__URL_TAG2__https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md__URL_TAG3__ You should really read the __URL_TAG1__documentation about that__URL_TAG2__https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md__URL_TAG3__
" "
else else
dhcp_alert="" dhcp_alert=""
fi fi
echo "${dhcp_alert}You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. echo "${dhcp_alert}You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.

View file

@ -113,14 +113,14 @@ ynh_script_progression --message="Closing port $port et 67..." --weight=13
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
ynh_print_info "Close port $port" ynh_print_info "Close port $port"
ynh_exec_quiet yunohost firewall disallow TCP $port ynh_exec_quiet yunohost firewall disallow TCP $port
fi fi
if yunohost firewall list | grep -q "\- 67$" if yunohost firewall list | grep -q "\- 67$"
then then
ynh_print_info "Close port 67" ynh_print_info "Close port 67"
ynh_exec_quiet yunohost firewall disallow UDP 67 ynh_exec_quiet yunohost firewall disallow UDP 67
fi fi
#================================================= #=================================================
@ -175,6 +175,12 @@ sed -i "/#Added by pihole#/d" /etc/hosts
#================================================= #=================================================
ynh_script_progression --message="Restarting Dnsmasq..." ynh_script_progression --message="Restarting Dnsmasq..."
if [ "$pihole_version" == "Last available" ]
then
# Quietly start dnsmasq a first time, because it usually doesn't start correctly the first time.
ynh_exec_fully_quiet systemctl start dnsmasq
sleep 1
fi
ynh_systemd_action --action=restart --service_name=dnsmasq ynh_systemd_action --action=restart --service_name=dnsmasq
#================================================= #=================================================

View file

@ -6,11 +6,12 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
# Load common variables for all scripts. # Load common variables for all scripts.
source ../settings/scripts/_variables source ../settings/scripts/_variables
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
@ -30,6 +31,13 @@ path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp) enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp)
admin=$(ynh_app_setting_get --app=$app --key=admin) admin=$(ynh_app_setting_get --app=$app --key=admin)
pihole_version="$(ynh_app_setting_get --app=$app --key=pihole_version)"
# Get variables from ynh_add_fpm_config
fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir)
fpm_service=$(ynh_app_setting_get --app=$app --key=fpm_service)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -37,9 +45,9 @@ admin=$(ynh_app_setting_get --app=$app --key=admin)
ynh_script_progression --message="Validating restoration parameters..." ynh_script_progression --message="Validating restoration parameters..."
ynh_webpath_available --domain=$domain --path_url=$path_url \ ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}" || ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path " || ynh_die --message="There is already a directory: $final_path "
#================================================= #=================================================
# ACTIVATE MAINTENANCE MODE # ACTIVATE MAINTENANCE MODE
@ -89,8 +97,14 @@ chown root: -R "/etc/pihole/logrotate"
#================================================= #=================================================
# RESTORE THE PHP-FPM CONFIGURATION # RESTORE THE PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Reconfiguring php-fpm..." --weight=7
ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" # Restore the file first, so it can have a backup if different
ynh_restore_file --origin_path="$fpm_config_dir/php-fpm-$app.conf"
ynh_restore_file --origin_path="$fpm_config_dir/pool.d/$app.conf"
# Recreate a dedicated php-fpm config
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --dedicated_service
#================================================= #=================================================
# SPECIFIC RESTORE # SPECIFIC RESTORE
@ -137,6 +151,42 @@ ynh_restore_file --origin_path="/usr/bin/pihole-FTL"
ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
#=================================================
# REPLACE THE DEFAULT DNSMASQ BY PIHOLE-FTL
#=================================================
if [ "$pihole_version" == "Last available" ]
then
# Last version available
# Stopped dnsmasq to replace it by pihole-FTL
ynh_systemd_action --action=stop --service_name=dnsmasq
# Disable the real dnsmasq service
ynh_exec_warn_less systemctl disable dnsmasq
# And move the files that make the service available in systemd to really disable it
mv /lib/systemd/system/dnsmasq.service /lib/systemd/system/.dnsmasq.service.backup_by_pihole
mv /etc/init.d/dnsmasq /etc/init.d/.dnsmasq.backup_by_pihole
# Move dnsmasq to preserve the current binary
mv /usr/sbin/dnsmasq /usr/sbin/dnsmasq.backup_by_pihole
# Replace dnsmasq by pihole-FTL
# NOTE: pihole-FTL is actually a modified version of dnsmasq
# https://github.com/pi-hole/FTL/tree/master/dnsmasq
ln -s /usr/bin/pihole-FTL /usr/sbin/dnsmasq
cp -a $pihole_local_repo/advanced/Templates/pihole-FTL.service /etc/init.d/pihole-FTL
chmod +x /etc/init.d/pihole-FTL
ynh_exec_warn_less systemctl enable pihole-FTL
# Replace the service dnsmasq by pihole-FTL
# That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
ln -s /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/multi-user.target.wants/dnsmasq.service
# Reload systemd config
systemctl daemon-reload
fi
#================================================= #=================================================
# RESTORE DNSMASQ CONFIG # RESTORE DNSMASQ CONFIG
#================================================= #=================================================
@ -146,11 +196,11 @@ ynh_systemd_action --action=stop --service_name=dnsmasq
ynh_restore_file --origin_path="/etc/dnsmasq.d/01-pihole.conf" ynh_restore_file --origin_path="/etc/dnsmasq.d/01-pihole.conf"
test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/02-pihole-dhcp.conf" && \ test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/02-pihole-dhcp.conf" && \
ynh_restore_file --origin_path="/etc/dnsmasq.d/02-pihole-dhcp.conf" ynh_restore_file --origin_path="/etc/dnsmasq.d/02-pihole-dhcp.conf"
test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/03-pihole-wildcard.conf" && \ test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/03-pihole-wildcard.conf" && \
ynh_restore_file --origin_path="/etc/dnsmasq.d/03-pihole-wildcard.conf" ynh_restore_file --origin_path="/etc/dnsmasq.d/03-pihole-wildcard.conf"
test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/04-pihole-static-dhcp.conf" && \ test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/04-pihole-static-dhcp.conf" && \
ynh_restore_file --origin_path="/etc/dnsmasq.d/04-pihole-static-dhcp.conf" ynh_restore_file --origin_path="/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
# To prevent any conflict with the original dnsmasq config, comment cache-size in the original config. # To prevent any conflict with the original dnsmasq config, comment cache-size in the original config.
ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file=/etc/dnsmasq.conf ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file=/etc/dnsmasq.conf
@ -168,20 +218,25 @@ localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f
# List all YunoHost domains # List all YunoHost domains
while read perdomain while read perdomain
do do
# Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution. # Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution.
ynh_replace_string --match_string="^127.0.0.1.*$perdomain" --replace_string="#Commented by pihole# &" --target_file=/etc/hosts ynh_replace_string --match_string="^127.0.0.1.*$perdomain" --replace_string="#Commented by pihole# &" --target_file=/etc/hosts
# And add a resolution on the local IP instead # And add a resolution on the local IP instead
grep -q "^$localipv4.*$perdomain" /etc/hosts || \ grep -q "^$localipv4.*$perdomain" /etc/hosts || \
echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts
done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
#================================================= #=================================================
# RESTART DNSMASQ # RESTART DNSMASQ
#================================================= #=================================================
ynh_script_progression --message="Restarting Dnsmasq..."
ynh_systemd_action --action=restart --service_name=dnsmasq # Restart dnsmasq only for the version 3.X, otherwise we're going to restart it twice.
if [ "$pihole_version" == "Last 3.X" ]
then
ynh_script_progression --message="Restarting Dnsmasq..."
ynh_systemd_action --action=restart --service_name=dnsmasq
fi
#================================================= #=================================================
# UPDATE VARIABLES FILE # UPDATE VARIABLES FILE
@ -211,8 +266,8 @@ ynh_systemd_action --action=restart --service_name=pihole-FTL
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server and php-fpm..." ynh_script_progression --message="Reloading nginx web server and php-fpm..."
ynh_systemd_action --action=reload --service_name=php7.0-fpm ynh_systemd_action --service_name=$fpm_service --action=reload
ynh_systemd_action --action=reload --service_name=nginx ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# DEACTIVE MAINTENANCE MODE # DEACTIVE MAINTENANCE MODE
@ -230,12 +285,12 @@ admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)
if [ $enable_dhcp -eq 1 ] if [ $enable_dhcp -eq 1 ]
then then
dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole. dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole.
You should really read the __URL_TAG1__documentation about that__URL_TAG2__https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md__URL_TAG3__ You should really read the __URL_TAG1__documentation about that__URL_TAG2__https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md__URL_TAG3__
" "
else else
dhcp_alert="" dhcp_alert=""
fi fi
echo "${dhcp_alert}You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. echo "${dhcp_alert}You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.

View file

@ -6,12 +6,12 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers
source _ynh_add_fpm_config
# Load common variables for all scripts. # Load common variables for all scripts.
source _variables source _variables
source _common.sh
source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
@ -26,6 +26,7 @@ query_logging=$(ynh_app_setting_get --app=$app --key=query_logging)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp) enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp)
port=$(ynh_app_setting_get --app=$app --key=port) port=$(ynh_app_setting_get --app=$app --key=port)
pihole_version="$(ynh_app_setting_get --app=$app --key=pihole_version)"
overwrite_setupvars=$(ynh_app_setting_get --app=$app --key=overwrite_setupvars) overwrite_setupvars=$(ynh_app_setting_get --app=$app --key=overwrite_setupvars)
overwrite_ftl=$(ynh_app_setting_get --app=$app --key=overwrite_ftl) overwrite_ftl=$(ynh_app_setting_get --app=$app --key=overwrite_ftl)
@ -48,38 +49,50 @@ ynh_script_progression --message="Ensuring downward compatibility..."
# If overwrite_setupvars doesn't exist, create it # If overwrite_setupvars doesn't exist, create it
if [ -z "$overwrite_setupvars" ]; then if [ -z "$overwrite_setupvars" ]; then
overwrite_setupvars=1 overwrite_setupvars=1
ynh_app_setting_set --app=$app --key=overwrite_setupvars --value=$overwrite_setupvars ynh_app_setting_set --app=$app --key=overwrite_setupvars --value=$overwrite_setupvars
fi fi
# If overwrite_ftl doesn't exist, create it # If overwrite_ftl doesn't exist, create it
if [ -z "$overwrite_ftl" ]; then if [ -z "$overwrite_ftl" ]; then
overwrite_ftl=1 overwrite_ftl=1
ynh_app_setting_set --app=$app --key=overwrite_ftl --value=$overwrite_ftl ynh_app_setting_set --app=$app --key=overwrite_ftl --value=$overwrite_ftl
fi fi
# If overwrite_nginx doesn't exist, create it # If overwrite_nginx doesn't exist, create it
if [ -z "$overwrite_nginx" ]; then if [ -z "$overwrite_nginx" ]; then
overwrite_nginx=1 overwrite_nginx=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
fi fi
# If overwrite_phpfpm doesn't exist, create it # If overwrite_phpfpm doesn't exist, create it
if [ -z "$overwrite_phpfpm" ]; then if [ -z "$overwrite_phpfpm" ]; then
overwrite_phpfpm=1 overwrite_phpfpm=1
ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value=$overwrite_phpfpm ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value=$overwrite_phpfpm
fi
# If admin_mail_html doesn't exist, create it
if [ -z "$admin_mail_html" ]; then
admin_mail_html=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html
fi fi
# If fpm_footprint doesn't exist, create it # If fpm_footprint doesn't exist, create it
if [ -z "$fpm_footprint" ]; then if [ -z "$fpm_footprint" ]; then
fpm_footprint=low fpm_footprint=low
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
fi fi
# If fpm_usage doesn't exist, create it # If fpm_usage doesn't exist, create it
if [ -z "$fpm_usage" ]; then if [ -z "$fpm_usage" ]; then
fpm_usage=low fpm_usage=low
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
fi
# If pihole_version doesn't exist, create it
if [ -z "$pihole_version" ]; then
pihole_version="Last 3.X"
ynh_app_setting_set --app=$app --key=pihole_version --value="$pihole_version"
fi fi
#================================================= #=================================================
@ -90,8 +103,8 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
# restore it if the upgrade fails # restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -126,11 +139,19 @@ ynh_install_app_dependencies $app_depencencies
pihole_local_repo="/etc/.pihole" pihole_local_repo="/etc/.pihole"
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading source files..." --weight=4 ynh_script_progression --message="Upgrading source files..." --weight=4
# Update the local copy pihole repository (for Gravity) if [ "$pihole_version" == "Last 3.X" ]
ynh_setup_source --dest_dir="$pihole_local_repo" then
# Update admin dashboard # Update the version 3.X
ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_3
# Update admin dashboard
ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard_3
else
# Update the last version available
ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_last
# Update admin dashboard
ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard_last
fi
fi fi
#================================================= #=================================================
@ -140,9 +161,9 @@ fi
# Overwrite the nginx configuration only if it's allowed # Overwrite the nginx configuration only if it's allowed
if [ $overwrite_nginx -eq 1 ] if [ $overwrite_nginx -eq 1 ]
then then
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=2 ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=2
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
fi fi
#================================================= #=================================================
@ -160,9 +181,9 @@ ynh_system_user_create --username=$app
# Overwrite the php-fpm configuration only if it's allowed # Overwrite the php-fpm configuration only if it's allowed
if [ $overwrite_phpfpm -eq 1 ] if [ $overwrite_phpfpm -eq 1 ]
then then
ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=3 ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=3
# Create a dedicated php-fpm config # Create a dedicated php-fpm config
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --dedicated_service
fi fi
#================================================= #=================================================
@ -191,7 +212,12 @@ cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.
#================================================= #=================================================
# This sudoers config allow pihole to execute /usr/local/bin/pihole as root without password. Nothing more. # This sudoers config allow pihole to execute /usr/local/bin/pihole as root without password. Nothing more.
cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole if [ "$pihole_version" == "Last 3.X" ]
then
cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole
else
cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
fi
echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
chmod 0440 /etc/sudoers.d/pihole chmod 0440 /etc/sudoers.d/pihole
@ -200,7 +226,12 @@ chmod 0440 /etc/sudoers.d/pihole
#================================================= #=================================================
pihole_storage="/etc/pihole" pihole_storage="/etc/pihole"
cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate" if [ "$pihole_version" == "Last 3.X" ]
then
cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate"
else
cp "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
fi
dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2) dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
sed -i "/# su #/d;" "$pihole_storage/logrotate" sed -i "/# su #/d;" "$pihole_storage/logrotate"
@ -213,30 +244,70 @@ ynh_systemd_action --action=stop --service_name=pihole-FTL
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
# Get the source of Pi-Hole-FTL # Get the source of Pi-Hole-FTL
FTL_temp_path=$(mktemp -d) FTL_temp_path=$(mktemp -d)
ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL if [ "$pihole_version" == "Last 3.X" ]
then
# Install the version 3.3.1
ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL_3
else
# Install the last version available
ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL_last
fi
# Instead of downloading a binary file, we're going to compile it # Instead of downloading a binary file, we're going to compile it
( cd "$FTL_temp_path" ( cd "$FTL_temp_path"
ynh_exec_warn_less make ynh_exec_warn_less make
ynh_exec_warn_less make install ) ynh_exec_warn_less make install )
ynh_secure_remove --file="$FTL_temp_path" ynh_secure_remove --file="$FTL_temp_path"
fi fi
# Overwrite pihole-FTL config file only if it's allowed # Overwrite pihole-FTL config file only if it's allowed
if [ $overwrite_ftl -eq 1 ] if [ $overwrite_ftl -eq 1 ]
then then
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. # Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different --file="$pihole_storage/pihole-FTL.conf" ynh_backup_if_checksum_is_different --file="$pihole_storage/pihole-FTL.conf"
cp "../conf/pihole-FTL.conf" "$pihole_storage" cp "../conf/pihole-FTL.conf" "$pihole_storage"
# Recalculate and store the checksum of the file for the next upgrade. # Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$pihole_storage/pihole-FTL.conf" ynh_store_file_checksum --file="$pihole_storage/pihole-FTL.conf"
fi fi
cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL if [ "$pihole_version" == "Last 3.X" ]
chmod +x /etc/init.d/pihole-FTL then
ynh_exec_warn_less systemctl enable pihole-FTL # Version 3.3.1
cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
chmod +x /etc/init.d/pihole-FTL
ynh_exec_warn_less systemctl enable pihole-FTL
else
# Last version available
# Stopped dnsmasq to replace it by pihole-FTL
ynh_systemd_action --action=stop --service_name=dnsmasq
# Disable the real dnsmasq service
ynh_exec_warn_less systemctl disable dnsmasq
# And move the files that make the service available in systemd to really disable it
mv /lib/systemd/system/dnsmasq.service /lib/systemd/system/.dnsmasq.service.backup_by_pihole
mv /etc/init.d/dnsmasq /etc/init.d/.dnsmasq.backup_by_pihole
# Move dnsmasq to preserve the current binary
mv /usr/sbin/dnsmasq /usr/sbin/dnsmasq.backup_by_pihole
# Replace dnsmasq by pihole-FTL
# NOTE: pihole-FTL is actually a modified version of dnsmasq
# https://github.com/pi-hole/FTL/tree/master/dnsmasq
ln -s /usr/bin/pihole-FTL /usr/sbin/dnsmasq
cp -a $pihole_local_repo/advanced/Templates/pihole-FTL.service /etc/init.d/pihole-FTL
chmod +x /etc/init.d/pihole-FTL
ynh_exec_warn_less systemctl enable pihole-FTL
# Replace the service dnsmasq by pihole-FTL
# That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
ln -s /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/multi-user.target.wants/dnsmasq.service
# Reload systemd config
systemctl daemon-reload
fi
#================================================= #=================================================
# BUILD VARIABLES FILE # BUILD VARIABLES FILE
@ -247,33 +318,38 @@ setupVars="$pihole_storage/setupVars.conf"
# Overwrite the setupVars config file only if it's allowed # Overwrite the setupVars config file only if it's allowed
if [ $overwrite_setupvars -eq 1 ] if [ $overwrite_setupvars -eq 1 ]
then then
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. # Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different --file="$setupVars" ynh_backup_if_checksum_is_different --file="$setupVars"
# Get the default network interface # Get the default network interface
main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}') main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
echo "PIHOLE_INTERFACE=$main_iface" > $setupVars echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars
echo "IPV6_ADDRESS=::1" >> $setupVars echo "IPV6_ADDRESS=::1" >> $setupVars
echo "PIHOLE_DNS_1=" >> $setupVars echo "PIHOLE_DNS_1=" >> $setupVars
echo "PIHOLE_DNS_2=" >> $setupVars echo "PIHOLE_DNS_2=" >> $setupVars
if [ $query_logging -eq 1 ]; then if [ $query_logging -eq 1 ]; then
query_logging=true query_logging=true
else else
query_logging=false query_logging=false
fi fi
echo "QUERY_LOGGING=$query_logging" >> $setupVars echo "QUERY_LOGGING=$query_logging" >> $setupVars
echo "INSTALL_WEB=true" >> $setupVars echo "INSTALL_WEB=true" >> $setupVars
# Recalculate and store the checksum of the file for the next upgrade. # Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$setupVars" ynh_store_file_checksum --file="$setupVars"
fi fi
#================================================= #=================================================
# UPDATE CRON JOB # UPDATE CRON JOB
#================================================= #=================================================
cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole if [ "$pihole_version" == "Last 3.X" ]
then
cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole
else
cp $pihole_local_repo/advanced/Templates/pihole.cron /etc/cron.d/pihole
fi
# Remove git usage for version. Which fails because we use here a release instead of master. # Remove git usage for version. Which fails because we use here a release instead of master.
ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --target_file=/etc/cron.d/pihole ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --target_file=/etc/cron.d/pihole
@ -311,10 +387,6 @@ ynh_maintenance_mode_OFF
# Get main domain and buid the url of the admin panel of the app. # Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
# Build the changelog
# Get the value of admin_mail_html
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
admin_mail_html="${admin_mail_html:-0}"
# If a html email is required. Apply html to the changelog. # If a html email is required. Apply html to the changelog.
if [ "$admin_mail_html" -eq 1 ]; then if [ "$admin_mail_html" -eq 1 ]; then
format=html format=html
@ -325,12 +397,12 @@ ynh_app_changelog --format=$format
if [ $enable_dhcp -eq 1 ] if [ $enable_dhcp -eq 1 ]
then then
dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole. dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole.
You should really read the documentation about that, https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md You should really read the documentation about that, https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md
" "
else else
dhcp_alert="" dhcp_alert=""
fi fi
echo "${dhcp_alert}You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. echo "${dhcp_alert}You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.

View file

@ -1,2 +0,0 @@
*.swp
*~

View file

@ -1,131 +0,0 @@
--- a/args.c 2019-05-25 21:37:26.000000000 +0200
+++ b/args.c 2020-04-24 00:32:27.000000000 +0200
@@ -17,20 +17,88 @@
int argc_dnsmasq = 0;
const char** argv_dnsmasq = NULL;
+static inline bool strEndsWith(const char *input, const char *end){
+ return strcmp(input + strlen(input) - strlen(end), end) == 0;
+}
+
void parse_args(int argc, char* argv[])
{
- int i;
-
// Regardless of any arguments, we always pass "-k" (nofork) to dnsmasq
argc_dnsmasq = 2;
argv_dnsmasq = calloc(argc_dnsmasq, sizeof(char*));
argv_dnsmasq[0] = "";
argv_dnsmasq[1] = "-k";
- // start from 1, as argv[0] is the executable name "pihole-FTL"
- for(i=1; i < argc; i++)
+ bool consume_for_dnsmasq = false;
+ // If the binary name is "dnsmasq" (e.g., symlink /usr/bin/dnsmasq -> /usr/bin/pihole-FTL),
+ // we operate in drop-in mode and consume all arguments for the embedded dnsmasq core
+ if(strEndsWith(argv[0], "dnsmasq"))
+ consume_for_dnsmasq = true;
+
+ // start from 1, as argv[0] is the executable name
+ for(int i = 1; i < argc; i++)
{
bool ok = false;
+
+ // Implement dnsmasq's test function, no need to prepare the entire FTL
+ // environment (initialize shared memory, lead queries from long-term
+ // database, ...) when the task is a simple (dnsmasq) syntax check
+ if(strcmp(argv[i], "dnsmasq-test") == 0 ||
+ strcmp(argv[i], "--test") == 0)
+ {
+ const char *arg[2];
+ arg[0] = "";
+ arg[1] = "--test";
+ main_dnsmasq(2, arg);
+ ok = true;
+ }
+
+ // If we find "--" we collect everything behind that for dnsmasq
+ if(strcmp(argv[i], "--") == 0)
+ {
+ // Remember that the rest is for dnsmasq ...
+ consume_for_dnsmasq = true;
+
+ // ... and skip the current argument ("--")
+ continue;
+ }
+
+ // If consume_for_dnsmasq is true, we collect all remaining options for
+ // dnsmasq
+ if(consume_for_dnsmasq)
+ {
+ argc_dnsmasq = argc - i + 2;
+ if(argv_dnsmasq != NULL)
+ free(argv_dnsmasq);
+
+ argv_dnsmasq = calloc(argc_dnsmasq, sizeof(const char*));
+ argv_dnsmasq[0] = "";
+
+ if(debug)
+ argv_dnsmasq[1] = "-d";
+ else
+ argv_dnsmasq[1] = "-k";
+
+ if(debug)
+ {
+ printf("dnsmasq options: [0]: %s\n", argv_dnsmasq[0]);
+ printf("dnsmasq options: [1]: %s\n", argv_dnsmasq[1]);
+ }
+
+ int j = 2;
+ while(i < argc)
+ {
+ argv_dnsmasq[j++] = strdup(argv[i++]);
+ if(debug)
+ printf("dnsmasq options: [%i]: %s\n", j-1, argv_dnsmasq[j-1]);
+ }
+
+ // Return early: We have consumes all available command line arguments
+ return;
+ }
+
+ // What follows beyond this point are FTL internal command line arguments
+
if(strcmp(argv[i], "d") == 0 ||
strcmp(argv[i], "debug") == 0)
{
@@ -97,35 +165,6 @@
ok = true;
}
- // Implement dnsmasq's test function
- if(strcmp(argv[i], "dnsmasq-test") == 0)
- {
- const char *arg[2];
- arg[0] = "";
- arg[1] = "--test";
- main_dnsmasq(2, arg);
- ok = true;
- }
-
- // If we find "--" we collect everything behind that for dnsmasq
- if(strcmp(argv[i], "--") == 0)
- {
- int j;
- argc_dnsmasq = argc - i + 1;
- if(argv_dnsmasq != NULL) free(argv_dnsmasq);
- argv_dnsmasq = calloc(argc_dnsmasq + 2,sizeof(const char*));
- argv_dnsmasq[0] = "";
- if(debug) argv_dnsmasq[1] = "-d";
- else argv_dnsmasq[1] = "-k";
-
- for(j=2; j < argc_dnsmasq; j++)
- {
- argv_dnsmasq[j] = strdup(argv[i+j-1]);
- if(debug) logg("dnsmasq options: [%i]: %s",j,argv_dnsmasq[j]);
- }
- return;
- }
-
// List of implemented arguments
if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "help") == 0 || strcmp(argv[i], "--help") == 0)
{