Do not override secret key...

This commit is contained in:
Antoine Nguyen
2017-08-01 18:27:23 +02:00
parent ea8b4e8afa
commit 1c3c28427e
2 changed files with 22 additions and 0 deletions

View File

@@ -188,6 +188,14 @@ class Modoboa(base.Installer):
"handle_mailboxes": True, "handle_mailboxes": True,
"account_auto_removal": 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": { "modoboa_amavis": {
"am_pdp_mode": "inet", "am_pdp_mode": "inet",
}, },

View File

@@ -208,3 +208,17 @@ def convert_version_to_int(version):
number += num << total_bits number += num << total_bits
total_bits += bits total_bits += bits
return number 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