mirror of
https://github.com/YunoHost-Apps/domoticz_ynh.git
synced 2024-09-03 18:26:17 +02:00
Merge pull request #14 from YunoHost-Apps/switch-nginx-conf
Split nginx conf
This commit is contained in:
commit
27311ad7b8
12 changed files with 29 additions and 13 deletions
|
@ -129,7 +129,7 @@ allow ::/1;
|
|||
This will authorized only IPv4 within local network to access your domoticz API.
|
||||
You may add individual IPv6 address in the same way.
|
||||
|
||||
**Shipped version:** 2020.2~ynh6
|
||||
**Shipped version:** 2020.2~ynh7
|
||||
## Disclaimers / important information
|
||||
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ Ceci autorisera seulement les adresses IPv4 local a accéder aux API de domoticz
|
|||
Vous pouvez ajouter des adresses IPv6 de la même façon.
|
||||
|
||||
|
||||
**Version incluse :** 2020.2~ynh6
|
||||
**Version incluse :** 2020.2~ynh7
|
||||
## Avertissements / informations importantes
|
||||
|
||||
|
||||
|
|
6
conf/api_nginx.conf
Normal file
6
conf/api_nginx.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
#set the list of authorized json command here in regex format
|
||||
#you may retrieve the command from https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's
|
||||
#By default, sensors updates and toggle switch are authorized
|
||||
if ( $args ~* type=command¶m=udevice&idx=[0-9]*&nvalue=[0-9]*&svalue=.*$|type=command¶m=switchlight&idx=[0-9]*&switchcmd=Toggle$) {
|
||||
set $api "1";
|
||||
}
|
|
@ -20,7 +20,7 @@ location __PATH__/ {
|
|||
include conf.d/yunohost_panel.conf.inc;
|
||||
}
|
||||
|
||||
#This part should be split in a second file to not be overwritten
|
||||
|
||||
#sub_path_only rewrite ^api___PATH__$ api___PATH__/ permanent;
|
||||
location __API_PATH__/ {
|
||||
#Alternative path for api, only authorized json command will be accepted
|
||||
|
@ -45,15 +45,11 @@ location __API_PATH__/ {
|
|||
|
||||
set $api "0";
|
||||
|
||||
#set the list of authorized json command here in regex format
|
||||
#you may retrieve the command from https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's
|
||||
#By default, sensors updates and toggle switch are authorized
|
||||
if ( $args ~* type=command¶m=udevice&idx=[0-9]*&nvalue=[0-9]*&svalue=.*$|type=command¶m=switchlight&idx=[0-9]*&switchcmd=Toggle$) {
|
||||
set $api "1";
|
||||
}
|
||||
|
||||
include /etc/nginx/conf.d/__DOMAIN__.d/api___APP__.conf;
|
||||
|
||||
if ($api = 0) {
|
||||
return 403;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
"en": "Very light weight open sources home automation system that lets you monitor and configure miscellaneous devices",
|
||||
"fr": "Logiciel open sources et gratuit de domotique qui vous permet de configurer un grand nombre d'appareils"
|
||||
},
|
||||
"version": "2020.2~ynh6",
|
||||
"version": "2020.2~ynh7",
|
||||
"url": "https://www.domoticz.com",
|
||||
"upstream": {
|
||||
"license": "GPL-3.0-or-later",
|
||||
|
@ -22,7 +22,7 @@
|
|||
"email": "misterl56@hotmail.com"
|
||||
},
|
||||
"requirements": {
|
||||
"yunohost": ">= 4.1.3"
|
||||
"yunohost": ">= 11.0.0"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"services": [
|
||||
|
|
|
@ -47,6 +47,7 @@ ynh_backup --src_path="$final_path"
|
|||
#=================================================
|
||||
|
||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/api_"$app".conf"
|
||||
[[ ! -z "$mqtt_domain" ]] && ynh_backup --src_path="/etc/nginx/conf.d/$mqtt_domain.d/mqtt_$app.conf" --not_mandatory
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -87,6 +87,7 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app
|
|||
ynh_script_progression --message="Updating NGINX web server configuration..."
|
||||
|
||||
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
nginx_api_conf_path=/etc/nginx/conf.d/$old_domain.d/api_$app.conf
|
||||
|
||||
# Change the path in the NGINX config file
|
||||
if [ $change_path -eq 1 ]
|
||||
|
@ -107,8 +108,11 @@ then
|
|||
# Delete file checksum for the old conf file location
|
||||
ynh_delete_file_checksum --file="$nginx_conf_path"
|
||||
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||
ynh_replace_string --match_string="/etc/nginx/conf.d/$old_domain.d/" --replace_string="/etc/nginx/conf.d/$new_domain.d/" --target_file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
mv $nginx_api_conf_path /etc/nginx/conf.d/$new_domain.d/api_$app.conf
|
||||
# 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/api_$app.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -182,6 +182,7 @@ cp -R ../sources/hooks/conf_regen/95-nginx_domoticz /usr/share/yunohost/hooks/co
|
|||
yunohost tools regen-conf nginx
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_config --template="api_nginx.conf" --destination="/etc/nginx/conf.d/"$domain".d/api_"$app".conf"
|
||||
ynh_add_nginx_config
|
||||
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ yunohost tools regen-conf postfix
|
|||
# Remove the dedicated NGINX config
|
||||
[[ ! -z "$mqtt_domain" ]] && ynh_secure_remove --file="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf"
|
||||
|
||||
ynh_secure_remove --file="/etc/nginx/conf.d/"$domain".d/api_"$app".conf"
|
||||
ynh_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -56,6 +56,7 @@ test "$backup_mach" = "$mach" \
|
|||
ynh_script_progression --message="Restoring the NGINX web server configuration..."
|
||||
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/"$domain".d/api_"$app".conf"
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$mqtt_domain.d/mqtt_$app.conf" --not_mandatory
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -234,6 +234,12 @@ cp -R ../sources/hooks/conf_regen/95-nginx_domoticz /usr/share/yunohost/hooks/co
|
|||
yunohost tools regen-conf nginx
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
if [[ ! -f "/etc/nginx/conf.d/"$domain".d/api_"$app".conf" ]]
|
||||
then
|
||||
ynh_print_warn --message="The nginx conf file will now be splitted between standard and api related path"
|
||||
ynh_print_warn --message="Report any manual changes on the new /etc/nginx/conf.d/$domain.d/api_$app.conf file for json command to keep working"
|
||||
ynh_add_config --template="api_nginx.conf" --destination="/etc/nginx/conf.d/"$domain".d/api_"$app".conf"
|
||||
fi
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -16,7 +16,7 @@ nginx_mqtt="$nginx_conf"/conf.d/"$mqtt_domain".conf
|
|||
[[ -e $nginx_mqtt ]] || exit 0
|
||||
|
||||
|
||||
if [[ "$mqtt_domain" != "domain" ]]; then
|
||||
if [[ "$mqtt_domain" != "$domain" ]]; then
|
||||
#single quote pour ne pas étendre les variables du fichier de config nginx et doubles quote pour les variables à étendre
|
||||
sed -i '/map $http_upgrade $connection_upgrade {/i upstream '"${mqtt_domain}"' {\n server localhost:'"${mqtt_port}"';\n}\n' $nginx_mqtt
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue