mirror of
https://github.com/YunoHost-Apps/pihole_ynh.git
synced 2024-09-03 20:05:58 +02:00
Panel-config + actions fully tested
This commit is contained in:
parent
2dab0cd059
commit
8aa9c84268
8 changed files with 316 additions and 24 deletions
22
actions.json
Normal file
22
actions.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
[{
|
||||
"id": "reset_default_setupvars",
|
||||
"name": "Reset the config file and restore a default one.",
|
||||
"command": "/bin/bash scripts/actions/reset_default_config \"setupVars.conf\"",
|
||||
"user": "root",
|
||||
"accepted_return_codes": [0],
|
||||
"description": {
|
||||
"en": "Reset the config file setupVars.conf.",
|
||||
"fr": "Réinitialise le fichier de configuration setupVars.conf."
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "reset_default_ftl",
|
||||
"name": "Reset the config file and restore a default one.",
|
||||
"command": "/bin/bash scripts/actions/reset_default_config \"pihole-FTL.conf\"",
|
||||
"user": "root",
|
||||
"accepted_return_codes": [0],
|
||||
"description": {
|
||||
"en": "Reset the config file pihole-FTL.conf.",
|
||||
"fr": "Réinitialise le fichier de configuration pihole-FTL.conf."
|
||||
}
|
||||
}]
|
|
@ -13,7 +13,7 @@
|
|||
setup_private=1
|
||||
setup_public=0
|
||||
upgrade=1
|
||||
upgrade=1 from_commit=32af3e208d36dd9601dd7a33efab656425822782
|
||||
upgrade=1 from_commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932
|
||||
backup_restore=1
|
||||
multi_instance=0
|
||||
incorrect_path=1
|
||||
|
@ -35,6 +35,6 @@
|
|||
Email=
|
||||
Notification=down
|
||||
;;; Upgrade options
|
||||
; commit=32af3e208d36dd9601dd7a33efab656425822782
|
||||
name= Première version du package
|
||||
; commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932
|
||||
name= Stretch fix
|
||||
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&query_logging=1&
|
||||
|
|
41
config_panel.json
Normal file
41
config_panel.json
Normal file
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"name": "PiHole configuration panel",
|
||||
"version": "0.1",
|
||||
"panel": [{
|
||||
"name": "PiHole configuration",
|
||||
"id": "main",
|
||||
"sections": [{
|
||||
"name": "Overwriting config files",
|
||||
"id": "overwrite_files",
|
||||
"options": [{
|
||||
"name": "Overwrite the config file setupVars.conf ?",
|
||||
"help": "If the file is overwritten, a backup will be created.",
|
||||
"id": "overwrite_setupvars",
|
||||
"type": "bool",
|
||||
"default": true
|
||||
},
|
||||
{
|
||||
"name": "Overwrite the config file pihole-FTL.conf ?",
|
||||
"help": "If the file is overwritten, a backup will be created.",
|
||||
"id": "overwrite_ftl",
|
||||
"type": "bool",
|
||||
"default": true
|
||||
},
|
||||
{
|
||||
"name": "Overwrite the nginx config file ?",
|
||||
"help": "If the file is overwritten, a backup will be created.",
|
||||
"id": "overwrite_nginx",
|
||||
"type": "bool",
|
||||
"default": true
|
||||
},
|
||||
{
|
||||
"name": "Overwrite the php-fpm config file ?",
|
||||
"help": "If the file is overwritten, a backup will be created.",
|
||||
"id": "overwrite_phpfpm",
|
||||
"type": "bool",
|
||||
"default": true
|
||||
}]
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -30,6 +30,24 @@ IS_PACKAGE_CHECK () {
|
|||
return $(env | grep -c container=lxc)
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# BOOLEAN CONVERTER
|
||||
#=================================================
|
||||
|
||||
bool_to_01 () {
|
||||
local var="$1"
|
||||
[ "$var" = "true" ] && var=1
|
||||
[ "$var" = "false" ] && var=0
|
||||
echo "$var"
|
||||
}
|
||||
|
||||
bool_to_true_false () {
|
||||
local var="$1"
|
||||
[ "$var" = "1" ] && var=true
|
||||
[ "$var" = "0" ] && var=false
|
||||
echo "$var"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
|
68
scripts/actions/reset_default_config
Executable file
68
scripts/actions/reset_default_config
Executable file
|
@ -0,0 +1,68 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS
|
||||
#=================================================
|
||||
|
||||
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
|
||||
query_logging=$(ynh_app_setting_get $app query_logging)
|
||||
|
||||
#=================================================
|
||||
# SORT OUT THE CONFIG FILE TO HANDLE
|
||||
#=================================================
|
||||
|
||||
file="$1"
|
||||
|
||||
if [ "$file" = "setupVars.conf" ]; then
|
||||
config_file="/etc/pihole/setupVars.conf"
|
||||
elif [ "$file" = "pihole-FTL.conf" ]; then
|
||||
config_file="/etc/pihole/pihole-FTL.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC ACTION
|
||||
#=================================================
|
||||
# RESET THE CONFIG FILE
|
||||
#=================================================
|
||||
|
||||
# Verify the checksum and backup the file if it's different
|
||||
ynh_backup_if_checksum_is_different "$config_file"
|
||||
|
||||
if [ "$file" = "setupVars.conf" ]
|
||||
then
|
||||
# Recreate the default config
|
||||
# Trouve l'interface réseau par défaut
|
||||
main_iface=$(ip route | grep default | awk '{print $5;}')
|
||||
echo "PIHOLE_INTERFACE=$main_iface" > "$config_file"
|
||||
echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file"
|
||||
echo "IPV6_ADDRESS=" >> "$config_file"
|
||||
echo "PIHOLE_DNS_1=" >> "$config_file"
|
||||
echo "PIHOLE_DNS_2=" >> "$config_file"
|
||||
if [ $query_logging -eq 1 ]; then
|
||||
query_logging=true
|
||||
else
|
||||
query_logging=false
|
||||
fi
|
||||
echo "QUERY_LOGGING=$query_logging" >> "$config_file"
|
||||
echo "INSTALL_WEB=true" >> "$config_file"
|
||||
|
||||
elif [ "$file" = "pihole-FTL.conf" ]
|
||||
then
|
||||
# Get the default file and overwrite the current config
|
||||
cp /etc/yunohost/apps/$app/conf/pihole-FTL.conf "$config_file"
|
||||
|
||||
# Restart pihole-FTL
|
||||
ynh_system_reload --service_name=pihole-FTL --action=restart
|
||||
fi
|
||||
|
||||
# Calculate and store the config file checksum into the app settings
|
||||
ynh_store_file_checksum "$config_file"
|
91
scripts/config
Normal file
91
scripts/config
Normal file
|
@ -0,0 +1,91 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS
|
||||
#=================================================
|
||||
|
||||
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC CODE
|
||||
#=================================================
|
||||
# LOAD VALUES
|
||||
#=================================================
|
||||
|
||||
# Load the real value from the app config or elsewhere.
|
||||
# Then get the value from the form.
|
||||
# If the form has a value for a variable, take the value from the form,
|
||||
# Otherwise, keep the value from the app config.
|
||||
|
||||
# Overwrite setupVars.conf file
|
||||
old_overwrite_setupvars="$(ynh_app_setting_get $app overwrite_setupvars)"
|
||||
old_overwrite_setupvars=$(bool_to_true_false $old_overwrite_setupvars)
|
||||
overwrite_setupvars="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS:-$old_overwrite_setupvars}"
|
||||
|
||||
# Overwrite pihole-FTL.conf file
|
||||
old_overwrite_ftl="$(ynh_app_setting_get $app overwrite_ftl)"
|
||||
old_overwrite_ftl=$(bool_to_true_false $old_overwrite_ftl)
|
||||
overwrite_ftl="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL:-$old_overwrite_ftl}"
|
||||
|
||||
# Overwrite nginx configuration
|
||||
old_overwrite_nginx="$(ynh_app_setting_get $app overwrite_nginx)"
|
||||
old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx)
|
||||
overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
|
||||
|
||||
# Overwrite php-fpm configuration
|
||||
old_overwrite_phpfpm="$(ynh_app_setting_get $app overwrite_phpfpm)"
|
||||
old_overwrite_phpfpm=$(bool_to_true_false $old_overwrite_phpfpm)
|
||||
overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
|
||||
|
||||
#=================================================
|
||||
# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
|
||||
#=================================================
|
||||
|
||||
show_config() {
|
||||
# here you are supposed to read some config file/database/other then print the values
|
||||
# echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
|
||||
|
||||
echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS=$overwrite_setupvars"
|
||||
echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL=$overwrite_ftl"
|
||||
echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
|
||||
echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# MODIFY THE CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
apply_config() {
|
||||
# Set overwrite_setupvars
|
||||
overwrite_setupvars=$(bool_to_01 $overwrite_setupvars)
|
||||
ynh_app_setting_set $app overwrite_setupvars "$overwrite_setupvars"
|
||||
# Set overwrite_ftl
|
||||
overwrite_ftl=$(bool_to_01 $overwrite_ftl)
|
||||
ynh_app_setting_set $app overwrite_ftl "$overwrite_ftl"
|
||||
# Set overwrite_nginx
|
||||
overwrite_nginx=$(bool_to_01 $overwrite_nginx)
|
||||
ynh_app_setting_set $app overwrite_nginx "$overwrite_nginx"
|
||||
# Set overwrite_phpfpm
|
||||
overwrite_phpfpm=$(bool_to_01 $overwrite_phpfpm)
|
||||
ynh_app_setting_set $app overwrite_phpfpm "$overwrite_phpfpm"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
|
||||
#=================================================
|
||||
|
||||
case $1 in
|
||||
show) show_config;;
|
||||
apply) apply_config;;
|
||||
esac
|
|
@ -53,6 +53,10 @@ ynh_app_setting_set $app path $path_url
|
|||
ynh_app_setting_set $app admin $admin
|
||||
ynh_app_setting_set $app query_logging $query_logging
|
||||
ynh_app_setting_set $app enable_dhcp $enable_dhcp
|
||||
ynh_app_setting_set $app overwrite_setupvars "1"
|
||||
ynh_app_setting_set $app overwrite_ftl "1"
|
||||
ynh_app_setting_set $app overwrite_nginx "1"
|
||||
ynh_app_setting_set $app overwrite_phpfpm "1"
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
|
|
|
@ -23,6 +23,10 @@ admin=$(ynh_app_setting_get $app admin)
|
|||
query_logging=$(ynh_app_setting_get $app query_logging)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
port=$(ynh_app_setting_get $app port)
|
||||
overwrite_setupvars=$(ynh_app_setting_get $app overwrite_setupvars)
|
||||
overwrite_ftl=$(ynh_app_setting_get $app overwrite_ftl)
|
||||
overwrite_nginx=$(ynh_app_setting_get $app overwrite_nginx)
|
||||
overwrite_phpfpm=$(ynh_app_setting_get $app overwrite_phpfpm)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
|
@ -30,6 +34,34 @@ port=$(ynh_app_setting_get $app port)
|
|||
|
||||
upgrade_type=$(ynh_check_app_version_changed)
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
|
||||
# If overwrite_setupvars doesn't exist, create it
|
||||
if [ -z "$overwrite_setupvars" ]; then
|
||||
overwrite_setupvars=1
|
||||
ynh_app_setting_set $app overwrite_setupvars $overwrite_setupvars
|
||||
fi
|
||||
|
||||
# If overwrite_ftl doesn't exist, create it
|
||||
if [ -z "$overwrite_ftl" ]; then
|
||||
overwrite_ftl=1
|
||||
ynh_app_setting_set $app overwrite_ftl $overwrite_ftl
|
||||
fi
|
||||
|
||||
# If overwrite_nginx doesn't exist, create it
|
||||
if [ -z "$overwrite_nginx" ]; then
|
||||
overwrite_nginx=1
|
||||
ynh_app_setting_set $app overwrite_nginx $overwrite_nginx
|
||||
fi
|
||||
|
||||
# If overwrite_phpfpm doesn't exist, create it
|
||||
if [ -z "$overwrite_phpfpm" ]; then
|
||||
overwrite_phpfpm=1
|
||||
ynh_app_setting_set $app overwrite_phpfpm $overwrite_phpfpm
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
|
@ -80,7 +112,11 @@ fi
|
|||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Overwrite the nginx configuration only if it's allowed
|
||||
if [ $overwrite_nginx -eq 1 ]
|
||||
then
|
||||
ynh_add_nginx_config
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
|
@ -92,7 +128,11 @@ ynh_system_user_create $app # Create the dedicated user, if not exist
|
|||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Overwrite the php-fpm configuration only if it's allowed
|
||||
if [ $overwrite_phpfpm -eq 1 ]
|
||||
then
|
||||
ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure.
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
|
@ -152,9 +192,13 @@ then
|
|||
ynh_secure_remove "$FTL_temp_path"
|
||||
fi
|
||||
|
||||
# Overwrite the pihole-FTL config file only if it's allowed
|
||||
if [ $overwrite_ftl -eq 1 ]
|
||||
then
|
||||
ynh_backup_if_checksum_is_different "$pihole_storage/pihole-FTL.conf" # Créé un backup du fichier de config si il a été modifié.
|
||||
cp "../conf/pihole-FTL.conf" "$pihole_storage"
|
||||
ynh_store_file_checksum "$pihole_storage/pihole-FTL.conf" # Enregistre la somme de contrôle du fichier de config
|
||||
fi
|
||||
|
||||
cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
|
||||
chmod +x /etc/init.d/pihole-FTL
|
||||
|
@ -166,6 +210,9 @@ ynh_exec_warn_less systemctl enable pihole-FTL
|
|||
|
||||
setupVars="$pihole_storage/setupVars.conf"
|
||||
|
||||
# Overwrite the setupVars config file only if it's allowed
|
||||
if [ $overwrite_setupvars -eq 1 ]
|
||||
then
|
||||
ynh_backup_if_checksum_is_different "$setupVars" # Créé un backup du fichier de config si il a été modifié.
|
||||
|
||||
# Trouve l'interface réseau par défaut
|
||||
|
@ -184,6 +231,7 @@ echo "QUERY_LOGGING=$query_logging" >> $setupVars
|
|||
echo "INSTALL_WEB=true" >> $setupVars
|
||||
|
||||
ynh_store_file_checksum "$setupVars" # Enregistre la somme de contrôle du fichier de config
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# UPDATE THE CRON JOB
|
||||
|
|
Loading…
Add table
Reference in a new issue