From 83b4be5345fcb604f8f497ef3b185f99f649292c Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Fri, 6 Sep 2019 03:30:52 +0200 Subject: [PATCH 1/7] Add setting to configure pop3 for dovecot --- data/hooks/conf_regen/25-dovecot | 11 ++++++----- data/templates/dovecot/dovecot.conf | 3 +-- locales/en.json | 1 + src/yunohost/settings.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/data/hooks/conf_regen/25-dovecot b/data/hooks/conf_regen/25-dovecot index 4c5ae24c1..d7136df4d 100755 --- a/data/hooks/conf_regen/25-dovecot +++ b/data/hooks/conf_regen/25-dovecot @@ -2,6 +2,8 @@ set -e +. /usr/share/yunohost/helpers + do_pre_regen() { pending_dir=$1 @@ -14,11 +16,10 @@ do_pre_regen() { cp dovecot-ldap.conf "${dovecot_dir}/dovecot-ldap.conf" cp dovecot.sieve "${dovecot_dir}/global_script/dovecot.sieve" - # prepare dovecot.conf conf file - main_domain=$(cat /etc/yunohost/current_host) - cat dovecot.conf \ - | sed "s/{{ main_domain }}/${main_domain}/g" \ - > "${dovecot_dir}/dovecot.conf" + export pop3_enabled="$(yunohost settings get 'pop3.enabled')" + export main_domain=$(cat /etc/yunohost/current_host) + + ynh_render_template "dovecot.conf" "${dovecot_dir}/dovecot.conf" # adapt it for IPv4-only hosts if [ ! -f /proc/net/if_inet6 ]; then diff --git a/data/templates/dovecot/dovecot.conf b/data/templates/dovecot/dovecot.conf index 116bb2db7..477ccbfb1 100644 --- a/data/templates/dovecot/dovecot.conf +++ b/data/templates/dovecot/dovecot.conf @@ -8,11 +8,10 @@ mail_home = /var/mail/%n mail_location = maildir:/var/mail/%n mail_uid = 500 -protocols = imap sieve +protocols = imap sieve {% if pop3_enabled == "True" %}pop3{% endif %} mail_plugins = $mail_plugins quota - ssl = yes ssl_cert = Date: Wed, 11 Sep 2019 01:46:50 +0100 Subject: [PATCH 2/7] Fix typos --- src/yunohost/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yunohost/settings.py b/src/yunohost/settings.py index df7221db5..59135814c 100644 --- a/src/yunohost/settings.py +++ b/src/yunohost/settings.py @@ -28,7 +28,7 @@ SETTINGS_PATH_OTHER_LOCATION = "/etc/yunohost/settings-%s.json" # * bool # * int # * string -# * enum (in form a python list) +# * enum (in the form of a python list) DEFAULTS = OrderedDict([ ("example.bool", {"type": "bool", "default": True}), From b470c9192c00a6f03456110594c621fc41ea7bb5 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 11 Sep 2019 01:47:16 +0100 Subject: [PATCH 3/7] Add "on" to valid boolean and refactor is_true --- src/yunohost/app.py | 4 ++-- src/yunohost/tests/test_settings.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index d17ea8424..8c7b441b4 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -2903,9 +2903,9 @@ def is_true(arg): if isinstance(arg, bool): return arg elif isinstance(arg, basestring): - true_list = ['yes', 'Yes', 'true', 'True'] + true_list = ['yes', 'true', 'on'] for string in true_list: - if arg == string: + if arg.lower() == string: return True return False else: diff --git a/src/yunohost/tests/test_settings.py b/src/yunohost/tests/test_settings.py index 0da12597f..ea6c6922c 100644 --- a/src/yunohost/tests/test_settings.py +++ b/src/yunohost/tests/test_settings.py @@ -62,6 +62,8 @@ def test_settings_set(): settings_set("example.bool", False) assert settings_get("example.bool") == False + settings_set("example.bool", "on") + assert settings_get("example.bool") == True def test_settings_set_int(): settings_set("example.int", 21) From 25f270298f51a93068d868af070284f23ab3daa6 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 11 Sep 2019 01:48:08 +0100 Subject: [PATCH 4/7] Add is_boolean and use when calling settings_set The CLI always passes the value as a string so we need to manage this type casting step by hand. --- src/yunohost/settings.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/yunohost/settings.py b/src/yunohost/settings.py index 59135814c..c52752fcc 100644 --- a/src/yunohost/settings.py +++ b/src/yunohost/settings.py @@ -15,6 +15,25 @@ logger = getActionLogger('yunohost.settings') SETTINGS_PATH = "/etc/yunohost/settings.json" SETTINGS_PATH_OTHER_LOCATION = "/etc/yunohost/settings-%s.json" +def is_boolean(value): + """ + Ensure a string value is intended as a boolean + + Keyword arguments: + arg -- The string to check + + Returns: + Boolean + + """ + if isinstance(value, bool): + return True + elif isinstance(value, basestring): + return str(value).lower() in ['true', 'on', 'yes', 'false', 'off', 'no'] + else: + return False + + # a settings entry is in the form of: # namespace.subnamespace.name: {type, value, default, description, [choices]} # choices is only for enum @@ -95,7 +114,7 @@ def settings_set(key, value): key_type = settings[key]["type"] if key_type == "bool": - if not isinstance(value, bool): + if not is_boolean(value): raise YunohostError('global_settings_bad_type_for_setting', setting=key, received_type=type(value).__name__, expected_type=key_type) elif key_type == "int": From 4f583aadc20405077dfe0fc31ba2bef419c2d5cc Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 11 Sep 2019 01:49:18 +0100 Subject: [PATCH 5/7] Remove comment This isn't an issue AFAICT, since the hooks manage this themselves already. Hence, I assume this is an old comment and out of date. --- src/yunohost/settings.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/yunohost/settings.py b/src/yunohost/settings.py index c52752fcc..2fc6915f3 100644 --- a/src/yunohost/settings.py +++ b/src/yunohost/settings.py @@ -147,8 +147,6 @@ def settings_set(key, value): settings[key]["value"] = value _save_settings(settings) - # TODO : whatdo if the old value is the same as - # the new value... try: trigger_post_change_hook(key, old_value, value) except Exception as e: From 74a5979e9128ea14a1a6436a5ca50df3b8dfa54e Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Tue, 17 Sep 2019 17:14:42 +0200 Subject: [PATCH 6/7] Fix typo in copy/pasta'd function --- src/yunohost/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yunohost/settings.py b/src/yunohost/settings.py index 2fc6915f3..2427f8677 100644 --- a/src/yunohost/settings.py +++ b/src/yunohost/settings.py @@ -315,7 +315,7 @@ def reconfigure_ssh(setting_name, old_value, new_value): service_regen_conf(names=['ssh']) @post_change_hook("security.postfix.compatibility") -def reconfigure_ssh(setting_name, old_value, new_value): +def reconfigure_postfix(setting_name, old_value, new_value): if old_value != new_value: service_regen_conf(names=['postfix']) From c15311f7e725218d31783e3d9e319fada96968ff Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Mon, 23 Sep 2019 13:36:50 +0200 Subject: [PATCH 7/7] Carry over fixes from @alexAubin Lost during the rebasing but revived! --- src/yunohost/app.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 8c7b441b4..fb233fde5 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -2903,11 +2903,7 @@ def is_true(arg): if isinstance(arg, bool): return arg elif isinstance(arg, basestring): - true_list = ['yes', 'true', 'on'] - for string in true_list: - if arg.lower() == string: - return True - return False + return arg.lower() in ['yes', 'true', 'on'] else: logger.debug('arg should be a boolean or a string, got %r', arg) return True if arg else False