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,9 +1,21 @@
;; 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
enable_dhcp=0
pihole_version="Last available"
; Config_panel
main.overwrite_files.overwrite_setupvars=0|1
main.overwrite_files.overwrite_ftl=0|1
main.overwrite_files.overwrite_nginx=0|1
main.overwrite_files.overwrite_phpfpm=0|1
main.global_config.email_type=0|1
main.php_fpm_config.footprint=low|medium|high
main.php_fpm_config.free_footprint=20
main.php_fpm_config.usage=low|medium|high
main.php_fpm_config.force_max_children=20|0
; Checks ; Checks
pkg_linter=1 pkg_linter=1
setup_sub_dir=1 setup_sub_dir=1
@ -12,11 +24,27 @@
setup_private=1 setup_private=1
setup_public=0 setup_public=0
upgrade=1 upgrade=1
upgrade=1 from_commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932
backup_restore=1 backup_restore=1
multi_instance=0 multi_instance=0
port_already_use=1 (4711) port_already_use=1 (4711)
change_url=1 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

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

@ -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

@ -6,7 +6,7 @@
"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": {
@ -14,7 +14,7 @@
"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": [

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)
@ -27,6 +34,8 @@ 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,11 +48,12 @@ 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"
@ -66,6 +76,27 @@ then
# 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

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,6 +70,14 @@ 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
#================================================= #=================================================
@ -87,6 +96,7 @@ show_config() {
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"
} }
#================================================= #=================================================
@ -119,7 +129,10 @@ apply_config() {
# 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

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
#================================================= #=================================================
@ -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"
@ -373,6 +375,13 @@ 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
#================================================= #=================================================

View file

@ -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
@ -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
#================================================= #=================================================
@ -179,9 +229,14 @@ done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
#================================================= #=================================================
# RESTART DNSMASQ # RESTART 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_script_progression --message="Restarting Dnsmasq..."
ynh_systemd_action --action=restart --service_name=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

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)
@ -70,6 +71,12 @@ if [ -z "$overwrite_phpfpm" ]; then
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 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
# 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
@ -82,6 +89,12 @@ if [ -z "$fpm_usage" ]; then
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 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
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
@ -127,10 +140,18 @@ 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 the version 3.X
ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_3
# Update admin dashboard # Update admin dashboard
ynh_setup_source --dest_dir="$final_path" --source_id=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
#================================================= #=================================================
@ -162,7 +183,7 @@ 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.
if [ "$pihole_version" == "Last 3.X" ]
then
cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole 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"
if [ "$pihole_version" == "Last 3.X" ]
then
cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate" 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"
@ -215,7 +246,14 @@ 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"
@ -234,9 +272,42 @@ then
ynh_store_file_checksum --file="$pihole_storage/pihole-FTL.conf" ynh_store_file_checksum --file="$pihole_storage/pihole-FTL.conf"
fi fi
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 cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
chmod +x /etc/init.d/pihole-FTL chmod +x /etc/init.d/pihole-FTL
ynh_exec_warn_less systemctl enable 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
@ -273,7 +344,12 @@ fi
# UPDATE CRON JOB # UPDATE CRON JOB
#================================================= #=================================================
if [ "$pihole_version" == "Last 3.X" ]
then
cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole 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

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)
{