From a80fe4ecbe6bf7bb7af3d3f4f46d7bb87834c154 Mon Sep 17 00:00:00 2001 From: ljf Date: Tue, 3 Nov 2020 21:28:45 +0100 Subject: [PATCH 1/6] [enh] New config panel --- config_panel.toml | 66 +++++++++++++++++++++++++++++++++++++++ scripts/config | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 config_panel.toml create mode 100644 scripts/config diff --git a/config_panel.toml b/config_panel.toml new file mode 100644 index 0000000..d1b143f --- /dev/null +++ b/config_panel.toml @@ -0,0 +1,66 @@ +version = "0.1" +name = "APP configuration panel" + +[main] +name = "Main configuration" + + [main.config_file] + name = "" + + [main.config_file.warning] + ask = "Here you can display a warning to user." + type = "warning" + + [main.config_file.outgoing_email] + ask = "Outgoing email From" + type = "string" + help = "Email from which comes email from this app" + + [main.config_file.expiration] + ask = "Default expiration" + type = "date" + + [main.config_file.logo] + ask = "Outgoing email From" + type = "file" + default = "" + optional = true + help = "You should upload a CA certificate to start" + source="__FINALPATH__/img/logo.png" + + [main.auth] + name = "Authentication" + + [main.auth.user] + ask = "Username" + type = "string" + default = "" + optional = true + pattern = "^[^/ ]+$" + + [main.auth.passphrase] + ask = "Password" + type = "password" + default = "" + optional = true + + +[advanced] +name = "Advanced configuration" + + [manual.dns] + name = "DNS" + + [manual.dns.dns0] + ask = "First resolver" + type = "string" + default = "" + optional = true + pattern = "^([0-9.]{8,16}|[0-9a-fA-F:]+)$" + + [manual.dns.dns1] + ask = "Second resolver" + type = "string" + default = "" + optional = true + pattern = "^([0-9.]{8,16}|[0-9a-fA-F:]+)$" diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..4f6f300 --- /dev/null +++ b/scripts/config @@ -0,0 +1,78 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +app=$YNH_APP_INSTANCE_NAME +final_path=$(ynh_app_setting_get $app final_path) + +#================================================= +# SPECIFIC GETTERS FOR TOML SHORT KEY +#================================================= +get__user() { + if [ -s $final_path/keys/credentials ] + then + sed -n 1p $final_path/keys/credentials + fi +} + +get__passphrase() { + if [ -s $final_path/keys/credentials ] + then + sed -n 2p $final_path/keys/credentials + fi +} + + +#================================================= +# SPECIFIC VALIDATORS FOR TOML SHORT KEYS +#================================================= +validate__user() { + [[ -n "$passphrase" && -z "$user" ]] && + echo 'A Username is needed when you suggest a Password' +} + +validate__passphrase() { + [[ -n "$user" && -z "$passphrase" ]] && + echo 'A Password is needed when you suggest a Username' +} + +#================================================= +# SPECIFIC SETTERS FOR TOML SHORT KEYS +#================================================= +set__user() { + if [ -z "$user" ] + then + echo "$user\n$passphrase" > $final_path/keys/credentials + else + echo "" > $final_path/keys/credentials + fi +} + +set__passphrase() { + : +} + + +#================================================= +# OVERWRITING APPLY STEP +#================================================= +ynh_panel_apply() { + + _ynh_panel_apply + + # Start vpn client + systemctl reload APP + +} + From 3051124936f3d74048746c60f130a7840f490844 Mon Sep 17 00:00:00 2001 From: ljf Date: Tue, 3 Nov 2020 21:38:15 +0100 Subject: [PATCH 2/6] [enh] New config panel --- config_panel.toml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index d1b143f..406b842 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -11,14 +11,18 @@ name = "Main configuration" ask = "Here you can display a warning to user." type = "warning" - [main.config_file.outgoing_email] + [main.config_file.from_email] ask = "Outgoing email From" type = "string" help = "Email from which comes email from this app" + pattern = "^[^@]+@[^@]+$" + source = "__FINALPATH__/conf/config.php" [main.config_file.expiration] ask = "Default expiration" type = "date" + pattern = "^\d\d\d\d-\d\d-\d\d$" + source = "__FINALPATH__/conf/config.php" [main.config_file.logo] ask = "Outgoing email From" @@ -48,7 +52,7 @@ name = "Main configuration" [advanced] name = "Advanced configuration" - [manual.dns] + [advanced.dns] name = "DNS" [manual.dns.dns0] From 6718f6403eed13e2321d2fc50ecf399c707df239 Mon Sep 17 00:00:00 2001 From: ljf Date: Tue, 3 Nov 2020 21:40:15 +0100 Subject: [PATCH 3/6] [enh] Remove uneeded title --- config_panel.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/config_panel.toml b/config_panel.toml index 406b842..03f9cf4 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -1,5 +1,4 @@ version = "0.1" -name = "APP configuration panel" [main] name = "Main configuration" From 0864c8b525c596f5beb104a2ac6581549739d28d Mon Sep 17 00:00:00 2001 From: ljf Date: Tue, 3 Nov 2020 21:42:27 +0100 Subject: [PATCH 4/6] [enh] Upgrade version config panel --- config_panel.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config_panel.toml b/config_panel.toml index 03f9cf4..b459c71 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -1,4 +1,4 @@ -version = "0.1" +version = "1.0" [main] name = "Main configuration" From 1dc8e862a6390c812556cfd65d43f277aee39706 Mon Sep 17 00:00:00 2001 From: ljf Date: Tue, 3 Nov 2020 21:48:58 +0100 Subject: [PATCH 5/6] [enh] Some doc about config panel --- scripts/config | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/scripts/config b/scripts/config index 4f6f300..bc1e6c6 100644 --- a/scripts/config +++ b/scripts/config @@ -1,20 +1,16 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= +# In most simple cases, you don't need a config script (or just to reload services). + +# With a simple config_panel.toml, you can write in the app settings, in the +# upstream config file or replace complete files (logo ...). + +# The config scripts allows you to go further, to handle specific cases +# (validation of several interdependent fields, specific getter/setter for a value, +# pre-loading of config type .cube ). -source _common.sh -source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= -app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY @@ -71,7 +67,7 @@ ynh_panel_apply() { _ynh_panel_apply - # Start vpn client + # Reload app service systemctl reload APP } From 6431e1eaff5bf4290b7ce47f14afe597d509884f Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Tue, 1 Jun 2021 01:26:50 +0200 Subject: [PATCH 6/6] [enh] Update config panel example --- config_panel.toml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index b459c71..1a0a23c 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -12,21 +12,21 @@ name = "Main configuration" [main.config_file.from_email] ask = "Outgoing email From" - type = "string" + type = "email" help = "Email from which comes email from this app" pattern = "^[^@]+@[^@]+$" - source = "__FINALPATH__/conf/config.php" + source = "email:__FINALPATH__/conf/config.php" [main.config_file.expiration] ask = "Default expiration" type = "date" pattern = "^\d\d\d\d-\d\d-\d\d$" - source = "__FINALPATH__/conf/config.php" + source = ":__FINALPATH__/conf/config.php" [main.config_file.logo] - ask = "Outgoing email From" + ask = "Logo" type = "file" - default = "" + accept = ".png" optional = true help = "You should upload a CA certificate to start" source="__FINALPATH__/img/logo.png" @@ -37,19 +37,20 @@ name = "Main configuration" [main.auth.user] ask = "Username" type = "string" - default = "" + example = "camille" optional = true pattern = "^[^/ ]+$" [main.auth.passphrase] ask = "Password" type = "password" - default = "" optional = true + visibleIf = "user" [advanced] name = "Advanced configuration" +collapsed = true [advanced.dns] name = "DNS" @@ -57,13 +58,11 @@ name = "Advanced configuration" [manual.dns.dns0] ask = "First resolver" type = "string" - default = "" optional = true pattern = "^([0-9.]{8,16}|[0-9a-fA-F:]+)$" [manual.dns.dns1] ask = "Second resolver" type = "string" - default = "" optional = true pattern = "^([0-9.]{8,16}|[0-9a-fA-F:]+)$"