From 0617fcaab782b7d5c6fff6a005561266df56f1b8 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Mon, 31 Jan 2022 12:27:39 +0000 Subject: [PATCH 01/16] configpanel update for php --- config_panel.toml | 9 +-- scripts/config | 159 ++++++++++++++++++++-------------------------- 2 files changed, 74 insertions(+), 94 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index b54f7cd..8bd0fc3 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -1,4 +1,4 @@ -version = "0.1" +version = "1.0" name = "My webapp configuration panel" [main] @@ -21,7 +21,7 @@ name = "My webapp configuration" [main.php_fpm_config] name = "PHP-FPM configuration" - [main.php_fpm_config.footprint] + [main.php_fpm_config.fpm_footprint] ask = "Memory footprint of the service?" choices = ["low", "medium", "high", "specific"] default = "low" @@ -31,10 +31,11 @@ name = "My webapp configuration" ask = "Memory footprint of the service?" type = "number" default = "0" + visible = "match(fpm_footprint, 'specific')" help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values." - [main.php_fpm_config.usage] + [main.php_fpm_config.fpm_usage] ask = "Expected usage of the service?" choices = ["low", "medium", "high"] 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.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
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.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding." diff --git a/scripts/config b/scripts/config index e30a1c3..5ccd0d7 100644 --- a/scripts/config +++ b/scripts/config @@ -9,115 +9,94 @@ source _common.sh source /usr/share/yunohost/helpers +ynh_abort_if_errors + #================================================= # RETRIEVE ARGUMENTS #================================================= -app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} +final_path=$(ynh_app_setting_get $app final_path) + +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) #================================================= -# SPECIFIC CODE -#================================================= -# LOAD VALUES +# SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= -# 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. - -# with_sftp -old_with_sftp="$(ynh_app_setting_get --app=$app --key=with_sftp)" -with_sftp="${YNH_CONFIG_MAIN_SFTP_SFTP:-$old_with_sftp}" - -# sftp password -is_password_exist=0 -password=$(ynh_app_setting_get --app=$app --key=password) -if [ -n "$password" ] -then - ynh_print_warn --message="A password already exist, it will not be replaced." - # If a password already exist, unset the variable password and to not change it. - unset password - is_password_exist=1 -else - # Otherwise, get the new password - password="$YNH_CONFIG_MAIN_SFTP_PASSWORD" -fi - - -# Footprint for PHP-FPM -old_fpm_footprint="$(ynh_app_setting_get --app=$app --key=fpm_footprint)" -fpm_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT:-$old_fpm_footprint}" - -# Free footprint value for PHP-FPM -# Check if fpm_footprint is an integer -if [ "$fpm_footprint" -eq "$fpm_footprint" ] 2> /dev/null -then - # If fpm_footprint is an integer, that's a numeric value for the footprint - old_free_footprint=$fpm_footprint -else - old_free_footprint=0 -fi -free_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT:-$old_free_footprint}" - -# Usage for PHP-FPM -old_fpm_usage="$(ynh_app_setting_get --app=$app --key=fpm_usage)" -fpm_usage="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE:-$old_fpm_usage}" - -#================================================= -# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND -#================================================= - -show_config() { - # here you are supposed to read some config file/database/other then print the values - # ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value" - ynh_return "YNH_CONFIG_MAIN_SFTP_SFTP=$with_sftp" -# ynh_return "YNH_CONFIG_MAIN_SFTP_PASSWORD=$password" - - 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_USAGE=$fpm_usage" +get__fpm_footprint() { + # Free footprint value for php-fpm + # Check if current_fpm_footprint is an integer + if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null + then + echo "specific" + else + echo "$current_fpm_footprint" + fi } -#================================================= -# MODIFY THE CONFIGURATION -#================================================= - -apply_config() { - #================================================= - # REMOVE OR ADD SFTP ACCESS - #================================================= - - if [ "$with_sftp" != "$old_with_sftp" ] +get__free_footprint() { + # Free footprint value for php-fpm + # Check if current_fpm_footprint is an integer + if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null then - yunohost app action run $app sftp --args with_sftp=$with_sftp - - # Change the password only if none was already set for the user - if [ $is_password_exist -eq 0 ] && [ $with_sftp -eq 1 ] - then - # Add the password to the user - chpasswd <<< "${app}:${password}" - ynh_app_setting_set --app=$app --key=password --value="$password" - fi + # If current_fpm_footprint is an integer, that's a numeric value for the footprint + echo "$current_fpm_footprint" + else + echo "0" fi +} - #================================================= - # RECONFIGURE PHP-FPM - #================================================= - if [ "$fpm_usage" != "$old_fpm_usage" ] || [ "$fpm_footprint" != "$old_fpm_footprint" ] +#================================================= +# SPECIFIC VALIDATORS FOR TOML SHORT KEYS +#================================================= + +#================================================= +# SPECIFIC SETTERS FOR TOML SHORT KEYS +#================================================= + +set__fpm_footprint() { + if [ "$fpm_footprint" != "specific" ] then - ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint" + fi +} + +set__free_footprint() { + if [ "$fpm_footprint" == "specific" ] + then + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$free_footprint" fi } #================================================= # GENERIC FINALIZATION #================================================= -# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT -#================================================= -case $1 in - show) show_config;; - apply) apply_config;; -esac +ynh_app_config_validate() { + _ynh_app_config_validate + + if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[free_footprint]}" == "true" ]; then + # If fpm_footprint is set to 'specific', use $free_footprint value. + if [ "$fpm_footprint" = "specific" ] + then + fpm_footprint=$free_footprint + fi + + if [ "$fpm_footprint" == "0" ] + then + ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below." + + exit 0 + fi + fi +} + +ynh_app_config_apply() { + _ynh_app_config_apply + + ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint +} + +ynh_app_config_run $1 From 3c2b4bc2a7e9456d986cc00710784eccf8a70e04 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Mon, 31 Jan 2022 12:48:53 +0000 Subject: [PATCH 02/16] configpanel update with_sftp --- config_panel.toml | 5 +++-- scripts/_common.sh | 35 +++++++++++++++++++++++++++++++++++ scripts/config | 30 +++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index 8bd0fc3..56d9cb1 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -7,7 +7,7 @@ name = "My webapp configuration" [main.sftp] name = "SFTP access" - [main.sftp.sftp] + [main.sftp.with_sftp] ask = "Do you need a SFTP access?" type = "boolean" default = true @@ -16,7 +16,8 @@ name = "My webapp configuration" ask = "Set a password for the SFTP access" type = "password" optional = true - help = "If a password already exist, it will not be replaced." + visible = "stfp" + help = "If a password already exist, leave blank and it will not be replaced." [main.php_fpm_config] name = "PHP-FPM configuration" diff --git a/scripts/_common.sh b/scripts/_common.sh index ed3594e..31498b2 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -365,3 +365,38 @@ ynh_app_changelog () { echo "No significative changes from the changelog..." > "${final_changelog}_lite" fi } + +ynh_system_user_add_group() { + # Declare an array to define the options of this helper. + local legacy_args=uhs + local -A args_array=([u]=username= [g]=groups=) + local username + local groups + + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + groups="${groups:-}" + + local group + for group in $groups; do + usermod -a -G "$group" "$username" + done +} + + +ynh_system_user_del_group() { + # Declare an array to define the options of this helper. + local legacy_args=uhs + local -A args_array=([u]=username= [g]=groups=) + local username + local groups + + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + groups="${groups:-}" + + local group + for group in $groups; do + gpasswd -d "$username" "$group" + done +} diff --git a/scripts/config b/scripts/config index 5ccd0d7..d6b5e66 100644 --- a/scripts/config +++ b/scripts/config @@ -20,6 +20,13 @@ final_path=$(ynh_app_setting_get $app final_path) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) +is_password_exist=0 +current_password=$(ynh_app_setting_get --app=$app --key=password) +if [ -n "$current_password" ] +then + is_password_exist=1 +fi + #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= @@ -47,7 +54,6 @@ get__free_footprint() { fi } - #================================================= # SPECIFIC VALIDATORS FOR TOML SHORT KEYS #================================================= @@ -70,6 +76,13 @@ set__free_footprint() { fi } +set__password() { + if [ ! $is_password_exist -eq 1 ] + then + ynh_app_setting_set --app=$app --key=password --value="$password" + fi +} + #================================================= # GENERIC FINALIZATION #================================================= @@ -97,6 +110,21 @@ ynh_app_config_apply() { _ynh_app_config_apply ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint + + if [ $with_sftp -eq 1 ] + then + ynh_system_user_add_group --username=$app --groups="sftp.app" + + if [ $is_password_exist -eq 1 ] + then + ynh_print_warn --message="A password already exist, it will not be replaced." + else + # Add the password to the user + chpasswd <<< "${app}:${password}" + fi + else + ynh_system_user_del_group --username=$app --groups="sftp.app" + fi } ynh_app_config_run $1 From 9c22d79bcbfbf64b27beaa976173b92c44f78f6a Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Mon, 31 Jan 2022 13:24:52 +0000 Subject: [PATCH 03/16] oopsy --- config_panel.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index 56d9cb1..eeeb340 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -1,5 +1,4 @@ version = "1.0" -name = "My webapp configuration panel" [main] name = "My webapp configuration" @@ -16,7 +15,7 @@ name = "My webapp configuration" ask = "Set a password for the SFTP access" type = "password" optional = true - visible = "stfp" + visible = "with_sftp" help = "If a password already exist, leave blank and it will not be replaced." [main.php_fpm_config] From 071d38bfb1531e6e01dea1a67d9912299537d710 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Mon, 31 Jan 2022 13:25:33 +0000 Subject: [PATCH 04/16] configpanel update password test --- scripts/config | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/config b/scripts/config index d6b5e66..656d5fe 100644 --- a/scripts/config +++ b/scripts/config @@ -77,7 +77,7 @@ set__free_footprint() { } set__password() { - if [ ! $is_password_exist -eq 1 ] + if [ $password -eq "" ] then ynh_app_setting_set --app=$app --key=password --value="$password" fi @@ -115,11 +115,8 @@ ynh_app_config_apply() { then ynh_system_user_add_group --username=$app --groups="sftp.app" - if [ $is_password_exist -eq 1 ] + if [ ! $password -eq "" ] then - ynh_print_warn --message="A password already exist, it will not be replaced." - else - # Add the password to the user chpasswd <<< "${app}:${password}" fi else From 17534e2819fa17a781247956f6ca7bee5780daa5 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Mon, 31 Jan 2022 15:24:14 +0000 Subject: [PATCH 05/16] configpanel phpversion --- config_panel.toml | 17 ++++++++++++++++- scripts/config | 26 ++++++++++++++------------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index eeeb340..b3955c3 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -21,21 +21,36 @@ name = "My webapp configuration" [main.php_fpm_config] name = "PHP-FPM configuration" + [main.php_fpm_config.phpversion] + ask = "PHP version" + choices = ["none", "7.3", "7.4", "8.0"] + default = "none" + [main.php_fpm_config.fpm_footprint] ask = "Memory footprint of the service?" choices = ["low", "medium", "high", "specific"] default = "low" + visible = "! match(phpversion, 'none')" help = "low <= 20Mb per pool. medium between 20Mb and 40Mb per pool. high > 40Mb per pool.
Use specific to set a value with the following option." [main.php_fpm_config.free_footprint] ask = "Memory footprint of the service?" type = "number" default = "0" - visible = "match(fpm_footprint, 'specific')" + visible = "match(fpm_footprint, 'specific') && ! match(phpversion, 'none')" help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values." [main.php_fpm_config.fpm_usage] ask = "Expected usage of the service?" choices = ["low", "medium", "high"] default = "low" + visible = "! match(phpversion, 'none')" 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.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding." + +# TODO: Add protected_path as tags, which are created as permission "label (path)", so admin can protect a specific path +# [main.permissions] +# [main.permissions.proteced_path] +# ask = "Protected path" +# help = "A permission will be created so you can restrict the access to a subpath of the web app." +# type = "tags" + \ No newline at end of file diff --git a/scripts/config b/scripts/config index 656d5fe..34a6a47 100644 --- a/scripts/config +++ b/scripts/config @@ -17,16 +17,6 @@ ynh_abort_if_errors final_path=$(ynh_app_setting_get $app final_path) -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) -current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) - -is_password_exist=0 -current_password=$(ynh_app_setting_get --app=$app --key=password) -if [ -n "$current_password" ] -then - is_password_exist=1 -fi - #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= @@ -109,13 +99,25 @@ ynh_app_config_validate() { ynh_app_config_apply() { _ynh_app_config_apply - ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint + # If there's any change to the php config, remove the old one and add a new one if applicable + if [ "${changed[phpversion]}" == "true" ] || "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[free_footprint]}" == "true" ]; then + ynh_remove_fpm_config + + if [[ ! "$phpversion" == "none" ]]; then + ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint + fi + fi + + if [[ ! $phpversion == "none" ]] + then + ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint + fi if [ $with_sftp -eq 1 ] then ynh_system_user_add_group --username=$app --groups="sftp.app" - if [ ! $password -eq "" ] + if [[ ! $password == "" ]] then chpasswd <<< "${app}:${password}" fi From 93532de252e60ecf31a8ab795e4123a8e054ab0a Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Mon, 31 Jan 2022 15:33:59 +0000 Subject: [PATCH 06/16] oops --- scripts/config | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/config b/scripts/config index 34a6a47..9077007 100644 --- a/scripts/config +++ b/scripts/config @@ -16,6 +16,7 @@ ynh_abort_if_errors #================================================= final_path=$(ynh_app_setting_get $app final_path) +current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY From 8c2943a6b002d487bb8f7fc8ceb8e900a9e82267 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Mon, 31 Jan 2022 15:50:16 +0000 Subject: [PATCH 07/16] oopsies /o\ --- scripts/config | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/config b/scripts/config index 9077007..680c4a5 100644 --- a/scripts/config +++ b/scripts/config @@ -68,7 +68,7 @@ set__free_footprint() { } set__password() { - if [ $password -eq "" ] + if [ "$password" == "" ] then ynh_app_setting_set --app=$app --key=password --value="$password" fi @@ -104,12 +104,12 @@ ynh_app_config_apply() { if [ "${changed[phpversion]}" == "true" ] || "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[free_footprint]}" == "true" ]; then ynh_remove_fpm_config - if [[ ! "$phpversion" == "none" ]]; then + if [ ! "$phpversion" == "none" ]; then ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint fi fi - if [[ ! $phpversion == "none" ]] + if [ ! "$phpversion" == "none" ] then ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint fi @@ -118,7 +118,7 @@ ynh_app_config_apply() { then ynh_system_user_add_group --username=$app --groups="sftp.app" - if [[ ! $password == "" ]] + if [ ! "$password" == "" ] then chpasswd <<< "${app}:${password}" fi From 36c982d8359d5826600379a2a0437acb122ace57 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Tue, 1 Feb 2022 16:42:06 +0000 Subject: [PATCH 08/16] fix match --- config_panel.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index b3955c3..40ae334 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -30,21 +30,21 @@ name = "My webapp configuration" ask = "Memory footprint of the service?" choices = ["low", "medium", "high", "specific"] default = "low" - visible = "! match(phpversion, 'none')" + visible = '! match(phpversion, "none")' help = "low <= 20Mb per pool. medium between 20Mb and 40Mb per pool. high > 40Mb per pool.
Use specific to set a value with the following option." [main.php_fpm_config.free_footprint] ask = "Memory footprint of the service?" type = "number" default = "0" - visible = "match(fpm_footprint, 'specific') && ! match(phpversion, 'none')" + visible = 'match(fpm_footprint, "specific") && ! match(phpversion, "none")' help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values." [main.php_fpm_config.fpm_usage] ask = "Expected usage of the service?" choices = ["low", "medium", "high"] default = "low" - visible = "! match(phpversion, 'none')" + visible = '! match(phpversion, "none")' 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.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding." # TODO: Add protected_path as tags, which are created as permission "label (path)", so admin can protect a specific path From 2231f5bb4ff8a67f5890c632a9fc30f8b2da9ce3 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Tue, 1 Feb 2022 18:36:10 +0000 Subject: [PATCH 09/16] config: password should be defined even if empty --- scripts/install | 2 +- scripts/upgrade | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 1cddee6..6644e77 100644 --- a/scripts/install +++ b/scripts/install @@ -52,6 +52,7 @@ ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=with_mysql --value=$with_mysql ynh_app_setting_set --app=$app --key=with_sftp --value=$with_sftp +ynh_app_setting_set --app=$app --key=password --value="$password" ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=phpversion --value=$phpversion @@ -117,7 +118,6 @@ if [ $with_sftp -eq 1 ] then # Add the password to this user chpasswd <<< "${app}:${password}" - ynh_app_setting_set --app=$app --key=password --value="$password" fi #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 5f98d6d..fc9a33e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -112,6 +112,9 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi +# Ensure password is a setting even if empty, for the config panel +ynh_app_setting_set --app=$app --key=password --value="$password" + #================================================= # ACTIVATE MAINTENANCE MODE #================================================= From 325d0ac03a8ddf3f48c06f718d1bd976cbb83fef Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Tue, 1 Feb 2022 18:36:24 +0000 Subject: [PATCH 10/16] config: missing type --- config_panel.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config_panel.toml b/config_panel.toml index 40ae334..858ca17 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -23,11 +23,13 @@ name = "My webapp configuration" [main.php_fpm_config.phpversion] ask = "PHP version" + type = "select" choices = ["none", "7.3", "7.4", "8.0"] default = "none" [main.php_fpm_config.fpm_footprint] ask = "Memory footprint of the service?" + type = "select" choices = ["low", "medium", "high", "specific"] default = "low" visible = '! match(phpversion, "none")' @@ -41,6 +43,7 @@ name = "My webapp configuration" help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values." [main.php_fpm_config.fpm_usage] + type = "select" ask = "Expected usage of the service?" choices = ["low", "medium", "high"] default = "low" From a7f4f0badfb200ff950f0fc67050f2903fdaf46d Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Tue, 1 Feb 2022 23:41:35 +0000 Subject: [PATCH 11/16] fix --- config_panel.toml | 23 --------------- scripts/config | 73 +++++++---------------------------------------- scripts/install | 2 ++ 3 files changed, 13 insertions(+), 85 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index 858ca17..ee9f4ed 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -27,29 +27,6 @@ name = "My webapp configuration" choices = ["none", "7.3", "7.4", "8.0"] default = "none" - [main.php_fpm_config.fpm_footprint] - ask = "Memory footprint of the service?" - type = "select" - choices = ["low", "medium", "high", "specific"] - default = "low" - visible = '! match(phpversion, "none")' - help = "low <= 20Mb per pool. medium between 20Mb and 40Mb per pool. high > 40Mb per pool.
Use specific to set a value with the following option." - - [main.php_fpm_config.free_footprint] - ask = "Memory footprint of the service?" - type = "number" - default = "0" - visible = 'match(fpm_footprint, "specific") && ! match(phpversion, "none")' - help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values." - - [main.php_fpm_config.fpm_usage] - type = "select" - ask = "Expected usage of the service?" - choices = ["low", "medium", "high"] - default = "low" - visible = '! match(phpversion, "none")' - 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.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding." - # TODO: Add protected_path as tags, which are created as permission "label (path)", so admin can protect a specific path # [main.permissions] # [main.permissions.proteced_path] diff --git a/scripts/config b/scripts/config index 680c4a5..e1d0d2f 100644 --- a/scripts/config +++ b/scripts/config @@ -22,29 +22,6 @@ current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) # SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= -get__fpm_footprint() { - # Free footprint value for php-fpm - # Check if current_fpm_footprint is an integer - if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null - then - echo "specific" - else - echo "$current_fpm_footprint" - fi -} - -get__free_footprint() { - # Free footprint value for php-fpm - # Check if current_fpm_footprint is an integer - if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null - then - # If current_fpm_footprint is an integer, that's a numeric value for the footprint - echo "$current_fpm_footprint" - else - echo "0" - fi -} - #================================================= # SPECIFIC VALIDATORS FOR TOML SHORT KEYS #================================================= @@ -53,20 +30,6 @@ get__free_footprint() { # SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= -set__fpm_footprint() { - if [ "$fpm_footprint" != "specific" ] - then - ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint" - fi -} - -set__free_footprint() { - if [ "$fpm_footprint" == "specific" ] - then - ynh_app_setting_set --app=$app --key=fpm_footprint --value="$free_footprint" - fi -} - set__password() { if [ "$password" == "" ] then @@ -81,40 +44,25 @@ set__password() { ynh_app_config_validate() { _ynh_app_config_validate - if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[free_footprint]}" == "true" ]; then - # If fpm_footprint is set to 'specific', use $free_footprint value. - if [ "$fpm_footprint" = "specific" ] - then - fpm_footprint=$free_footprint - fi - - if [ "$fpm_footprint" == "0" ] - then - ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below." - - exit 0 - fi + if [ "${changed[with_sftp]}" == "true" ] && [ $with_sftp -eq 1 ] && [ "$password" == "" ] + then + ynh_die --message="You need to set a password to enable SFTP" fi } ynh_app_config_apply() { _ynh_app_config_apply - # If there's any change to the php config, remove the old one and add a new one if applicable - if [ "${changed[phpversion]}" == "true" ] || "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[free_footprint]}" == "true" ]; then - ynh_remove_fpm_config - if [ ! "$phpversion" == "none" ]; then - ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint - fi - fi - - if [ ! "$phpversion" == "none" ] + if [ "${changed[phpversion]}" == "true" ] && [ "$phpversion" == "none" ] then - ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint + ynh_remove_fpm_config + elif [ "${changed[phpversion]}" == "true" ] + then + ynh_add_fpm_config --usage=low --footprint=low --phpversion=$phpversion fi - if [ $with_sftp -eq 1 ] + if [ "${changed[with_sftp]}" == "true" ] && [ $with_sftp -eq 1 ] then ynh_system_user_add_group --username=$app --groups="sftp.app" @@ -122,7 +70,8 @@ ynh_app_config_apply() { then chpasswd <<< "${app}:${password}" fi - else + elif [ "${changed[with_sftp]}" == "true" ] && [ $with_sftp -eq 0 ] + then ynh_system_user_del_group --username=$app --groups="sftp.app" fi } diff --git a/scripts/install b/scripts/install index 6644e77..5fb75d5 100644 --- a/scripts/install +++ b/scripts/install @@ -40,6 +40,8 @@ ynh_script_progression --message="Validating installation parameters..." --weigh final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" +[ $with_sftp -eq 0 ] || [ "$password" != "" ] || ynh_die --message="You need to set a password to enable SFTP" + # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url From 612a87a4a8d0f849fb08ef6516d770b294f2ce31 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Sun, 27 Feb 2022 19:31:15 +0000 Subject: [PATCH 12/16] comment --- scripts/config | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/config b/scripts/config index e1d0d2f..1087de0 100644 --- a/scripts/config +++ b/scripts/config @@ -56,6 +56,9 @@ ynh_app_config_apply() { if [ "${changed[phpversion]}" == "true" ] && [ "$phpversion" == "none" ] then + # FIXME: This miserably fails because the setting phpversion get his + # new value before ynh_app_config_apply gets called, so + # ynh_remove_fpm_config try to remove the new not-yet-existent version. ynh_remove_fpm_config elif [ "${changed[phpversion]}" == "true" ] then From 1d8afa6ad6add185338c2f38fc1ada8ffbf6200d Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Thu, 19 May 2022 11:15:38 +0200 Subject: [PATCH 13/16] Update config_panel.toml --- config_panel.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config_panel.toml b/config_panel.toml index ee9f4ed..e05e66c 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -1,7 +1,7 @@ version = "1.0" [main] -name = "My webapp configuration" +name = "My Webapp configuration" [main.sftp] name = "SFTP access" From ee6a4cf5f8ef627a65115c7d26bc7bd3c6d295c9 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 7 Aug 2022 16:55:40 +0200 Subject: [PATCH 14/16] [fix] handling phpversion in config panel Co-authored-by: Alexandre Aubin Co-authored-by: ljf (zamentur) --- scripts/config | 32 +++++++++++++++++++++++--------- scripts/install | 1 + scripts/upgrade | 5 +++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/scripts/config b/scripts/config index 1087de0..b853d6b 100644 --- a/scripts/config +++ b/scripts/config @@ -16,7 +16,11 @@ ynh_abort_if_errors #================================================= final_path=$(ynh_app_setting_get $app final_path) -current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) + +fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) +fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY @@ -53,16 +57,26 @@ ynh_app_config_validate() { ynh_app_config_apply() { _ynh_app_config_apply - - if [ "${changed[phpversion]}" == "true" ] && [ "$phpversion" == "none" ] + if [ "${changed[phpversion]}" == "true" ] then - # FIXME: This miserably fails because the setting phpversion get his - # new value before ynh_app_config_apply gets called, so - # ynh_remove_fpm_config try to remove the new not-yet-existent version. + ynh_app_setting_set --app=$app --key=phpversion --value="${old[phpversion]}" ynh_remove_fpm_config - elif [ "${changed[phpversion]}" == "true" ] - then - ynh_add_fpm_config --usage=low --footprint=low --phpversion=$phpversion + # ^ the helper includes ynh_remove_app_dependencies + YNH_PHP_VERSION=$phpversion + # ^ ynh_add_config replaces __PHPVERSION__ by __PHP_YNH_VERSION__... + ynh_app_setting_set --app=$app --key=phpversion --value="$phpversion" + + if [ "$phpversion" == "none" ] + then + cp ../conf/nginx{_no_php,}.conf + else + cp ../conf/nginx{_with_php,}.conf + ynh_install_app_dependencies "php${phpversion}-fpm" + ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --phpversion=$phpversion + # ^ the helper takes care of ynh_app_setting_set the phpversion + fi + + ynh_add_nginx_config fi if [ "${changed[with_sftp]}" == "true" ] && [ $with_sftp -eq 1 ] diff --git a/scripts/install b/scripts/install index 5fb75d5..e2f7713 100644 --- a/scripts/install +++ b/scripts/install @@ -95,6 +95,7 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=2 if [ $phpversion != "none" ] then cp ../conf/nginx{_with_php,}.conf + YNH_PHP_VERSION="$phpversion" else cp ../conf/nginx{_no_php,}.conf fi diff --git a/scripts/upgrade b/scripts/upgrade index fc9a33e..9a38aa2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -91,9 +91,9 @@ if [ -z "$with_sftp" ]; then ynh_app_setting_set --app=$app --key=with_sftp --value=$with_sftp fi -# If phpversion doesn't exist, create it +# If phpversion doesn't exist, create it. We assume it is the default system one. if [ -z "$phpversion" ]; then - phpversion=$YNH_PHP_VERSION + phpversion=$YNH_DEFAULT_PHP_VERSION ynh_app_setting_set --app=$app --key=phpversion --value=$phpversion fi @@ -145,6 +145,7 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - if [ $phpversion != "none" ] then cp ../conf/nginx{_with_php,}.conf + YNH_PHP_VERSION="$phpversion" else cp ../conf/nginx{_no_php,}.conf fi From 38e6e12553e16488e0f5148ef50f9b913c8836af Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 7 Aug 2022 17:34:22 +0200 Subject: [PATCH 15/16] Implement FPM usage and footprint in config panel --- config_panel.toml | 25 ++++++++++++++++++++- scripts/config | 55 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/upgrade | 7 ++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/config_panel.toml b/config_panel.toml index e05e66c..d2ba140 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -27,10 +27,33 @@ name = "My Webapp configuration" choices = ["none", "7.3", "7.4", "8.0"] default = "none" + [main.php_fpm_config.fpm_footprint] + ask = "Memory footprint of the service?" + type = "select" + choices.low = "Low, <= 20Mb per pool" + choices.medium = "Medium, between 20Mb and 40Mb per pool" + choices.high = "High, > 40Mb per pool" + choices.specific = "Use specific value" + default = "low" + + [main.php_fpm_config.fpm_free_footprint] + visible = "fpm_footprint == 'specific'" + ask = "Memory footprint of the service?" + type = "number" + default = "0" + help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values." + + [main.php_fpm_config.fpm_usage] + ask = "Expected usage of the service?" + type = "select" + choices = ["low", "medium", "high"] + 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.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding." + # TODO: Add protected_path as tags, which are created as permission "label (path)", so admin can protect a specific path # [main.permissions] # [main.permissions.proteced_path] # ask = "Protected path" # help = "A permission will be created so you can restrict the access to a subpath of the web app." # type = "tags" - \ No newline at end of file + diff --git a/scripts/config b/scripts/config index b853d6b..188b1b6 100644 --- a/scripts/config +++ b/scripts/config @@ -19,6 +19,7 @@ final_path=$(ynh_app_setting_get $app final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) +current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) @@ -26,6 +27,29 @@ fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) # SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= +get__fpm_footprint() { + # Free footprint value for php-fpm + # Check if current_fpm_footprint is an integer + if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null + then + echo "specific" + else + echo "$current_fpm_footprint" + fi +} + +get__free_footprint() { + # Free footprint value for php-fpm + # Check if current_fpm_footprint is an integer + if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null + then + # If current_fpm_footprint is an integer, that's a numeric value for the footprint + echo "$current_fpm_footprint" + else + echo "0" + fi +} + #================================================= # SPECIFIC VALIDATORS FOR TOML SHORT KEYS #================================================= @@ -41,6 +65,20 @@ set__password() { fi } +set__fpm_footprint() { + if [ "$fpm_footprint" != "specific" ] + then + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint" + fi +} + +set__fpm_free_footprint() { + if [ "$fpm_footprint" = "specific" ] + then + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_free_footprint" + fi +} + #================================================= # GENERIC FINALIZATION #================================================= @@ -52,6 +90,21 @@ ynh_app_config_validate() { then ynh_die --message="You need to set a password to enable SFTP" fi + + if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[fpm_free_footprint]}" == "true" ]; then + # If fpm_footprint is set to 'specific', use $fpm_free_footprint value. + if [ "$fpm_footprint" = "specific" ] + then + fpm_footprint=$fpm_free_footprint + fi + + if [ "$fpm_footprint" == "0" ] + then + ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below." + + exit 0 + fi + fi } ynh_app_config_apply() { @@ -91,6 +144,8 @@ ynh_app_config_apply() { then ynh_system_user_del_group --username=$app --groups="sftp.app" fi + + ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint } ynh_app_config_run $1 diff --git a/scripts/upgrade b/scripts/upgrade index 9a38aa2..71dd841 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -28,6 +28,7 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) admin_mail_html=$(ynh_app_setting_get --app=$app --key=admin_mail_html) fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) +fpm_free_footprint=$(ynh_app_setting_get --app=$app --key=fpm_free_footprint) fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) #================================================= @@ -79,6 +80,12 @@ if [ -z "$fpm_footprint" ]; then ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint fi +# If fpm_free_footprint doesn't exist, create it +if [ -z "$fpm_free_footprint" ]; then + fpm_free_footprint=0 + ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint +fi + # If fpm_usage doesn't exist, create it if [ -z "$fpm_usage" ]; then fpm_usage=low From 233829c50cda4acd299a93fec249df9232eca159 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 7 Aug 2022 17:57:06 +0200 Subject: [PATCH 16/16] Make FPM usage and footprint visible only if PHP is enabled --- config_panel.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config_panel.toml b/config_panel.toml index d2ba140..1d5407d 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -28,6 +28,7 @@ name = "My Webapp configuration" default = "none" [main.php_fpm_config.fpm_footprint] + visible = "phpversion != 'none'" ask = "Memory footprint of the service?" type = "select" choices.low = "Low, <= 20Mb per pool" @@ -37,13 +38,14 @@ name = "My Webapp configuration" default = "low" [main.php_fpm_config.fpm_free_footprint] - visible = "fpm_footprint == 'specific'" + visible = "fpm_footprint == 'specific' && phpversion != 'none'" ask = "Memory footprint of the service?" type = "number" default = "0" help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values." [main.php_fpm_config.fpm_usage] + visible = "phpversion != 'none'" ask = "Expected usage of the service?" type = "select" choices = ["low", "medium", "high"]