From 1c3c28427e75c855bb19f7f9b13301c1248459d6 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Tue, 1 Aug 2017 18:27:23 +0200 Subject: [PATCH] Do not override secret key... --- modoboa_installer/scripts/modoboa.py | 8 ++++++++ modoboa_installer/utils.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/modoboa_installer/scripts/modoboa.py b/modoboa_installer/scripts/modoboa.py index 6c8361e..e264d24 100644 --- a/modoboa_installer/scripts/modoboa.py +++ b/modoboa_installer/scripts/modoboa.py @@ -188,6 +188,14 @@ class Modoboa(base.Installer): "handle_mailboxes": True, "account_auto_removal": True }, + # FIXME: since we rewrite all parameters, the secret key + # previously created will disappear. As a quick fix, we + # recreate a new one here but it will mess up opened + # sessions if the installer is used to upgrade an existing + # database... + "core": { + "secret_key": utils.random_key() + }, "modoboa_amavis": { "am_pdp_mode": "inet", }, diff --git a/modoboa_installer/utils.py b/modoboa_installer/utils.py index e4baee8..8402a80 100644 --- a/modoboa_installer/utils.py +++ b/modoboa_installer/utils.py @@ -208,3 +208,17 @@ def convert_version_to_int(version): number += num << total_bits total_bits += bits return number + + +def random_key(l=16): + """Generate a random key. + + :param integer l: the key's length + :return: a string + """ + punctuation = """!#$%&()*+,-./:;<=>?@[]^_`{|}~""" + population = string.digits + string.ascii_letters + punctuation + while True: + key = "".join(random.sample(population * l, l)) + if len(key) == l: + return key