From 471d9abf2b054fcf73e299988c28a65d56f34c88 Mon Sep 17 00:00:00 2001 From: ljf Date: Tue, 3 Nov 2020 21:28:45 +0100 Subject: [PATCH] [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 + +} +