From dcc52cea2d2636333c3831a5127605bc90952555 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Fri, 22 Jan 2021 23:47:08 +0100 Subject: [PATCH] Add config-panel feature --- conf/message | 1 + config_panel.toml | 14 ++++++++++ scripts/change_url | 2 ++ scripts/config | 67 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/install | 6 +++++ scripts/upgrade | 2 ++ 6 files changed, 92 insertions(+) create mode 100644 config_panel.toml create mode 100755 scripts/config diff --git a/conf/message b/conf/message index d8a5625..09b8a8a 100644 --- a/conf/message +++ b/conf/message @@ -1,4 +1,5 @@ Standard Notes - Syncing Server was successfully __TYPE__. Please configure the Standard Notes web app or mobile app to use this syninc server: https://__DOMAIN____PATH_URL__/ __ACTION__ +__CONFIG_PANEL__ __EXTENSIONS__ diff --git a/config_panel.toml b/config_panel.toml new file mode 100644 index 0000000..0fb6cdb --- /dev/null +++ b/config_panel.toml @@ -0,0 +1,14 @@ +version = "1.0" +name = "SNServer configuration panel" + +[main] +name = "SNserver configuration" + + [main.access_domain] + name = "Access Domain" + + [main.access_domain.access_domain] + ask = "Which web app can access the Standart Notes Extensions?" + type = "string" + default = "" + help = "Please enter the domain without the path of a Standart Notes Web App, which should have access to the Standard Notes Extensions.
Example: domain.tld, notes.domain.tld" diff --git a/scripts/change_url b/scripts/change_url index 1b88348..82d2976 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -180,6 +180,7 @@ admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4) message_extensions="To install extensions open this page: https://$domain$path_url/extensions/\n\ You changed the url of the syncing server. All extensions installed from here must be reinstalled by the users." action="You can find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__" +config_panel="You can find some specific configurations for this app by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__" ynh_replace_string --match_string="__TYPE__" --replace_string="changed the url" --target_file="../conf/message" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" @@ -192,6 +193,7 @@ else ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="" --target_file="../conf/message" fi ynh_replace_string --match_string="__ACTION__" --replace_string="$action" --target_file="../conf/message" +ynh_replace_string --match_string="__CONFIG_PANEL__" --replace_string="$config_panel" --target_file="../conf/message" ynh_send_readme_to_admin --app_message="../conf/message" --type='upgrade' diff --git a/scripts/config b/scripts/config new file mode 100755 index 0000000..c696738 --- /dev/null +++ b/scripts/config @@ -0,0 +1,67 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source ./_common.sh +source /usr/share/yunohost/helpers + +# Stop script if errors +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +app=$YNH_APP_INSTANCE_NAME +access_domain=$(ynh_app_setting_get --app=$app --key=access_domain) +domain=$(ynh_app_setting_get --app=$app --key=domain) + +#================================================= +# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND +#================================================= + +show_config() { + if [ ! -z $access_domain ] + then + ynh_return "YNH_CONFIG_MAIN_ACCESS_DOMAIN_ACCESS_DOMAIN=$access_domain" + else + ynh_return "YNH_CONFIG_MAIN_ACCESS_DOMAIN_ACCESS_DOMAIN=$domain" + fi +} + +#================================================= +# MODIFY THE CONFIGURATION +#================================================= + +apply_config() { + access_domain=${YNH_CONFIG_MAIN_ACCESS_DOMAIN_ACCESS_DOMAIN:-$access_domain} + ynh_print_info "1: $access_domain" + ynh_app_setting_set --app=$app --key=access_domain --value=$access_domain + + access_domain=$(ynh_app_setting_get --app=$app --key=access_domain) + ynh_print_info "2: $access_domain" + + nginx_conf_path=/etc/nginx/conf.d/$domain.d/$app.conf + ynh_delete_file_checksum --file=$nginx_conf_path + ynh_replace_string \ + --match_string='more_set_headers "X-Frame-Options: allow-from .*";' \ + --replace_string='more_set_headers "X-Frame-Options: allow-from '$access_domain'";' \ + --target_file=$nginx_conf_path + ynh_store_file_checksum --file=$nginx_conf_path + + systemctl reload nginx +} + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT +#================================================= +case $1 in + show) show_config;; + apply) apply_config;; +esac diff --git a/scripts/install b/scripts/install index e4baa18..a73f02e 100755 --- a/scripts/install +++ b/scripts/install @@ -34,6 +34,10 @@ then access_domain=$domain else access_domain=$YNH_APP_ARG_ACCESS_DOMAIN + if [ -z $access_domain ] + then + access_domain=$domain + fi fi #================================================= @@ -294,6 +298,7 @@ You can configure this app by using the config-panel" admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" action="You can find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__" +config_panel="You can find some specific configurations for this app by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__" ynh_replace_string --match_string="__TYPE__" --replace_string="installed" --target_file="../conf/message" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" @@ -306,6 +311,7 @@ else ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_no_extensions" --target_file="../conf/message" fi ynh_replace_string --match_string="__ACTION__" --replace_string="$action" --target_file="../conf/message" +ynh_replace_string --match_string="__CONFIG_PANEL__" --replace_string="$config_panel" --target_file="../conf/message" ynh_send_readme_to_admin --app_message="../conf/message" --type='install' diff --git a/scripts/upgrade b/scripts/upgrade index bbe0b40..c051379 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -341,6 +341,7 @@ You can configure this app by using the config-panel" admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" action="You can find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__" +config_panel="You can find some specific configurations for this app by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__" ynh_replace_string --match_string="__TYPE__" --replace_string="installed" --target_file="../conf/message" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" @@ -353,6 +354,7 @@ else ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_no_extensions" --target_file="../conf/message" fi ynh_replace_string --match_string="__ACTION__" --replace_string="$action" --target_file="../conf/message" +ynh_replace_string --match_string="__CONFIG_PANEL__" --replace_string="$config_panel" --target_file="../conf/message" ynh_send_readme_to_admin --app_message="../conf/message" --type='upgrade'