From dd41ade2baa6529ffd4a05d854898d2c5ed25c03 Mon Sep 17 00:00:00 2001 From: magikcypress Date: Sat, 20 May 2017 19:40:39 +0200 Subject: [PATCH] [fix] is_public boolean && add nginx configuration helper --- conf/nginx.conf | 8 ++++---- manifest.json | 4 ++-- scripts/_common | 37 ++++++++++++++++++++++++++++++++++++- scripts/install | 15 +++++---------- scripts/restore | 6 +++++- scripts/upgrade | 17 +++++++---------- 6 files changed, 59 insertions(+), 28 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 71a8b38..f33312c 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,5 +1,5 @@ -location YNH_WWW_PATH { - alias YNH_WWW_ALIAS ; +location __PATH__ { + alias __FINALPATH__; if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } @@ -7,7 +7,7 @@ location YNH_WWW_PATH { try_files $uri $uri/ index.php; location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param REMOTE_USER $remote_user; @@ -16,5 +16,5 @@ location YNH_WWW_PATH { } # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + # include conf.d/yunohost_panel.conf.inc; } diff --git a/manifest.json b/manifest.json index 173f588..4236550 100644 --- a/manifest.json +++ b/manifest.json @@ -43,12 +43,12 @@ }, { "name": "is_public", + "type": "boolean", "ask": { "en": "Is it a public Zerobin site ?", "fr": "Est-ce un site public ?" }, - "choices": ["Yes", "No"], - "default": "Yes" + "default": "true" } ] } diff --git a/scripts/_common b/scripts/_common index 5753486..00d8195 100644 --- a/scripts/_common +++ b/scripts/_common @@ -22,7 +22,7 @@ ynh_store_checksum_config () { ynh_app_setting_set $app $config_file_checksum $(sudo md5sum "$1" | cut -d' ' -f1) } -extract_source() { +extract_source () { local DESTDIR=$1 # retrieve and extract Roundcube tarball @@ -36,6 +36,41 @@ extract_source() { sudo rm "$rc_tarball" } + +# Add config nginx +ynh_nginx_config () { + finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_compare_checksum_config "$finalnginxconf" 1 + sudo cp ../conf/nginx.conf "$finalnginxconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${path:-}"; then + ynh_substitute_char "__PATH__" "$path" "$finalnginxconf" + fi + if test -n "${domain:-}"; then + ynh_substitute_char "__DOMAIN__" "$domain" "$finalnginxconf" + fi + if test -n "${port:-}"; then + ynh_substitute_char "__PORT__" "$port" "$finalnginxconf" + fi + if test -n "${app:-}"; then + ynh_substitute_char "__NAME__" "$app" "$finalnginxconf" + fi + if test -n "${final_path:-}"; then + ynh_substitute_char "__FINALPATH__" "$final_path" "$finalnginxconf" + fi + ynh_store_checksum_config "$finalnginxconf" + + sudo systemctl reload nginx +} + +# Remove config nginx +ynh_remove_nginx_config () { + ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf" + sudo systemctl reload nginx +} + ynh_fpm_config () { finalphpconf="/etc/php5/fpm/pool.d/$app.conf" ynh_compare_checksum_config "$finalphpconf" 1 diff --git a/scripts/install b/scripts/install index 86dd0ad..ced0633 100644 --- a/scripts/install +++ b/scripts/install @@ -42,20 +42,15 @@ sudo chown -R $app:root $final_path/{data,tmp} sudo chmod 700 $final_path/{data,tmp} # Modify Nginx configuration file and copy it to Nginx conf directory -sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf -sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf -nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf -sudo cp ../conf/nginx.conf $nginxconf -sudo chown root: $nginxconf -sudo chmod 600 $nginxconf +ynh_nginx_config # Create the php-fpm pool config ynh_fpm_config -# Set ssowat config -if [ "$is_public" = "No" ]; -then - ynh_app_setting_delete $app skipped_uris +# If app is public, add url to SSOWat conf as skipped_uris +if [[ $is_public -eq 1 ]]; then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set "$app" unprotected_uris "/" fi sudo systemctl reload nginx diff --git a/scripts/restore b/scripts/restore index 6a981a9..052c513 100644 --- a/scripts/restore +++ b/scripts/restore @@ -61,9 +61,13 @@ sudo chown -R root:root $final_path sudo chown -R www-data:root $final_path/{data,tmp} sudo chmod -R 700 $final_path/{data,tmp} -# Restore configuration files +# Restore nginx configuration files sudo cp -a ./conf/nginx.conf "${nginx_conf}" +# Restore php-fpm configuration files +sudo cp -a ./conf/php-fpm.conf "${phpfpm_conf}" +sudo cp -a ./conf/php-fpm.ini "${phpfpm_ini}" + # Set ssowat config if [ "$is_public" = "No" ]; then diff --git a/scripts/upgrade b/scripts/upgrade index 6d146b7..755853e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -57,21 +57,18 @@ sudo chown -R $app:root $final_path/{data,tmp} sudo chmod 700 $final_path/{data,tmp} # Modify Nginx configuration file and copy it to Nginx conf directory -sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf -sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf -nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf -sudo cp ../conf/nginx.conf $nginxconf -sudo chown root: $nginxconf -sudo chmod 600 $nginxconf +ynh_nginx_config # Create the php-fpm pool config ynh_fpm_config # Set ssowat config -ynh_app_setting_set "$app" is_public "$is_public" -if [ "$is_public" = "Yes" ]; -then - ynh_app_setting_set "$app" unprotected_uris "/" +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen + is_public=1 +else + ynh_app_setting_set $app is_public 0 + is_public=0 fi # Reload Nginx