From 021f9aa93568bd51ba086c577c6a0ef4144e7dcd Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Thu, 10 Jun 2021 11:44:27 +0200 Subject: [PATCH] Fix --- conf/nginx.conf | 40 +++++++++++++++++++------------------- scripts/install | 18 ++++++----------- scripts/restore | 19 +++++++----------- scripts/upgrade | 51 +++++++++++++------------------------------------ 4 files changed, 46 insertions(+), 82 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 1bace38..eaf9881 100755 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,3 +1,23 @@ +location ~ /ws/ { + proxy_pass http://127.0.0.1:__PORT__; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + client_max_body_size 50M; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Frame-Options SAMEORIGIN; + proxy_buffers 256 16k; + proxy_buffer_size 16k; + client_body_timeout 60; + send_timeout 300; + lingering_timeout 5; + proxy_connect_timeout 1d; + proxy_send_timeout 1d; + proxy_read_timeout 1d; +} + location / { # Force usage of https @@ -28,26 +48,6 @@ location / { more_clear_input_headers 'Accept-Encoding'; } -location ~ /ws/ { - proxy_pass http://127.0.0.1:__PORT__; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - client_max_body_size 50M; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header X-Frame-Options SAMEORIGIN; - proxy_buffers 256 16k; - proxy_buffer_size 16k; - client_body_timeout 60; - send_timeout 300; - lingering_timeout 5; - proxy_connect_timeout 1d; - proxy_send_timeout 1d; - proxy_read_timeout 1d; -} - location /uploads/ { alias __FILES_PATH__/uploads/ ; } diff --git a/scripts/install b/scripts/install index 4c0efc9..416b1a9 100755 --- a/scripts/install +++ b/scripts/install @@ -94,6 +94,10 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # CREATE DIRECTORIES #================================================= @@ -102,6 +106,8 @@ files_path=/home/yunohost.app/$app ynh_app_setting_set --app=$app --key=files_path --value=$files_path mkdir -p $files_path/files +chown -R $app:$app $files_path +chmod -R 755 $files_path #================================================= # NGINX CONFIGURATION @@ -124,18 +130,6 @@ ynh_add_systemd_config #================================================= ynh_add_config --template="../conf/config.json" --destination="$final_path/config.json" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions to app files -chown -R $app:$app $final_path -chown -R $app:$app $files_path -#chmod -R o-rwx $final_path -chmod -R 755 $files_path chmod 600 $final_path/config.json #================================================= diff --git a/scripts/restore b/scripts/restore index 46f856b..fedd8b4 100755 --- a/scripts/restore +++ b/scripts/restore @@ -53,13 +53,6 @@ test ! -d $final_path \ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# RESTORE THE APP MAIN DIR -#================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=1 - -ynh_restore_file --origin_path="$final_path" - #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -69,13 +62,15 @@ ynh_script_progression --message="Recreating the dedicated system user..." --wei ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= -# RESTORE USER RIGHTS +# RESTORE THE APP MAIN DIR #================================================= +ynh_script_progression --message="Restoring the app main directory..." --weight=1 -# Restore permissions on app files -chown -R $app:$app $final_path -#chmod -R o-rwx $final_path -chmod 600 $final_path/config.json +ynh_restore_file --origin_path="$final_path" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SPECIFIC RESTORATION diff --git a/scripts/upgrade b/scripts/upgrade index 2101585..ee57837 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,7 +20,6 @@ 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) db_name=$(ynh_app_setting_get --app=$app --key=db_name) -files_path=$(ynh_app_setting_get --app=$app --key=files_path) port=$(ynh_app_setting_get --app=$app --key=port) #================================================= @@ -64,6 +63,14 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=3 + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -71,26 +78,15 @@ ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$ if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=1 - - # Create a temporary directory - tmpdir="$(mktemp -d)" - - # Backup the config file in the temp dir - cp -a "$final_path/config.json" "$tmpdir/config.json" - - # Remove the app directory securely - ynh_secure_remove --file="$final_path" # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" #--keep="foo bar" to integrate when https://github.com/YunoHost/yunohost/pull/1200 is upstream - - # Copy the admin saved settings from tmp directory to final path - cp -a "$tmpdir/config.json" "$final_path/config.json" - - # Remove the tmp directory securely - ynh_secure_remove --file="$tmpdir" + ynh_setup_source --dest_dir="$final_path" --keep="$final_path/config.json" fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -106,14 +102,6 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=2 ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=3 - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" - #================================================= # SETUP SYSTEMD #================================================= @@ -122,19 +110,6 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions on app files -chown -R $app:$app $final_path -chown -R $app:$app $files_path -#chmod -R o-rwx "$final_path" -chmod -R 755 $files_path -chmod 600 $final_path/config.json - #================================================= # INTEGRATE SERVICE IN YUNOHOST #=================================================