Updated config and interactive mode
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -59,4 +59,7 @@ target/
|
|||||||
# PyCharm
|
# PyCharm
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
#KDE
|
||||||
|
*.kdev4
|
||||||
|
|
||||||
installer.cfg
|
installer.cfg
|
||||||
@@ -27,6 +27,22 @@ ConfigDictTemplate = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "antispam",
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"option": "enabled",
|
||||||
|
"default": "true",
|
||||||
|
"question": "Do you want to setup an antispam utility?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"option": "type",
|
||||||
|
"default": "rspamd",
|
||||||
|
"question": "Please select your antispam utility",
|
||||||
|
"values": ["rspamd", "amavis"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "certificate",
|
"name": "certificate",
|
||||||
"values": [
|
"values": [
|
||||||
@@ -50,7 +66,7 @@ ConfigDictTemplate = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "letsencrypt",
|
"name": "letsencrypt",
|
||||||
"if": "certificate.type=letsencrypt",
|
"if": ["certificate.type=letsencrypt"],
|
||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"option": "email",
|
"option": "email",
|
||||||
@@ -85,7 +101,7 @@ ConfigDictTemplate = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "postgres",
|
"name": "postgres",
|
||||||
"if": "database.engine=postgres",
|
"if": ["database.engine=postgres"],
|
||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"option": "user",
|
"option": "user",
|
||||||
@@ -101,7 +117,7 @@ ConfigDictTemplate = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "mysql",
|
"name": "mysql",
|
||||||
"if": "database.engine=mysql",
|
"if": ["database.engine=mysql"],
|
||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"option": "user",
|
"option": "user",
|
||||||
@@ -271,9 +287,11 @@ ConfigDictTemplate = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "amavis",
|
"name": "amavis",
|
||||||
|
"if": ["antispam.enabled=true", "antispam.type=amavis"],
|
||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"option": "enabled",
|
"option": "enabled",
|
||||||
|
"default-if": "true",
|
||||||
"default": "false",
|
"default": "false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -362,7 +380,7 @@ ConfigDictTemplate = [
|
|||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"option": "enabled",
|
"option": "enabled",
|
||||||
"default": "true",
|
"default": "false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"option": "config_dir",
|
"option": "config_dir",
|
||||||
@@ -393,9 +411,11 @@ ConfigDictTemplate = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "postwhite",
|
"name": "postwhite",
|
||||||
|
"if": ["antispam.enabled=true", "antispam.type=amavis"],
|
||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"option": "enabled",
|
"option": "enabled",
|
||||||
|
"default-if": "true",
|
||||||
"default": "false",
|
"default": "false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -406,9 +426,11 @@ ConfigDictTemplate = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "spamassassin",
|
"name": "spamassassin",
|
||||||
|
"if": ["antispam.enabled=true", "antispam.type=amavis"],
|
||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"option": "enabled",
|
"option": "enabled",
|
||||||
|
"default-if": "true",
|
||||||
"default": "false",
|
"default": "false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -475,9 +497,11 @@ ConfigDictTemplate = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "opendkim",
|
"name": "opendkim",
|
||||||
|
"if": ["antispam.enabled=true", "antispam.type=amavis"],
|
||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"option": "enabled",
|
"option": "enabled",
|
||||||
|
"default-if": "true",
|
||||||
"default": "false",
|
"default": "false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""Amavis related functions."""
|
"""Rspamd related functions."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
|
|||||||
@@ -185,25 +185,29 @@ def copy_from_template(template, dest, context):
|
|||||||
fp.write(ConfigFileTemplate(buf).substitute(context))
|
fp.write(ConfigFileTemplate(buf).substitute(context))
|
||||||
|
|
||||||
|
|
||||||
def check_config_file(dest, interactive=False, upgrade=False, backup=False, restore=False):
|
def check_config_file(dest,
|
||||||
|
interactive=False,
|
||||||
|
upgrade=False,
|
||||||
|
backup=False,
|
||||||
|
restore=False):
|
||||||
"""Create a new installer config file if needed."""
|
"""Create a new installer config file if needed."""
|
||||||
is_present = True
|
is_present = True
|
||||||
if os.path.exists(dest):
|
if os.path.exists(dest):
|
||||||
return is_present, update_config(dest, False)
|
return is_present, update_config(dest, False)
|
||||||
if upgrade:
|
if upgrade:
|
||||||
printcolor(
|
error(
|
||||||
"You cannot upgrade an existing installation without a "
|
"You cannot upgrade an existing installation without a "
|
||||||
"configuration file.", RED)
|
"configuration file.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif backup:
|
elif backup:
|
||||||
is_present = False
|
is_present = False
|
||||||
printcolor(
|
error(
|
||||||
"Your configuration file hasn't been found. A new one will be generated. "
|
"Your configuration file hasn't been found. A new one will be generated. "
|
||||||
"Please edit it with correct password for the databases !", RED)
|
"Please edit it with correct password for the databases !")
|
||||||
elif restore:
|
elif restore:
|
||||||
printcolor(
|
error(
|
||||||
"You cannot restore an existing installation without a "
|
"You cannot restore an existing installation without a "
|
||||||
f"configuration file. (file : {dest} has not been found...", RED)
|
f"configuration file. (file : {dest} has not been found...")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
printcolor(
|
printcolor(
|
||||||
@@ -310,10 +314,17 @@ def validate(value, config_entry):
|
|||||||
|
|
||||||
|
|
||||||
def get_entry_value(entry, interactive):
|
def get_entry_value(entry, interactive):
|
||||||
if callable(entry["default"]):
|
if entry.get("default-if") is not None and interactive:
|
||||||
default_value = entry["default"]()
|
# In case in interactive we try to look for a default-if
|
||||||
|
default_entry = entry["default-if"]
|
||||||
else:
|
else:
|
||||||
default_value = entry["default"]
|
default_entry = entry["default"]
|
||||||
|
|
||||||
|
if callable(default_entry):
|
||||||
|
default_value = default_entry()
|
||||||
|
else:
|
||||||
|
default_value = default_entry
|
||||||
|
|
||||||
user_value = None
|
user_value = None
|
||||||
if entry.get("customizable") and interactive:
|
if entry.get("customizable") and interactive:
|
||||||
while (user_value != '' and not validate(user_value, entry)):
|
while (user_value != '' and not validate(user_value, entry)):
|
||||||
@@ -349,13 +360,14 @@ def load_config_template(interactive):
|
|||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
# only ask about options we need, else still generate default
|
# only ask about options we need, else still generate default
|
||||||
for section in tpl_dict:
|
for section in tpl_dict:
|
||||||
|
interactive_section = interactive
|
||||||
if "if" in section:
|
if "if" in section:
|
||||||
config_key, value = section.get("if").split("=")
|
for condition in section.get("if"):
|
||||||
section_name, option = config_key.split(".")
|
config_key, value = condition.split("=")
|
||||||
interactive_section = (
|
section_name, option = config_key.split(".")
|
||||||
config.get(section_name, option) == value and interactive)
|
interactive_section = interactive_section and (
|
||||||
else:
|
config.get(section_name, option) == value)
|
||||||
interactive_section = interactive
|
|
||||||
config.add_section(section["name"])
|
config.add_section(section["name"])
|
||||||
for config_entry in section["values"]:
|
for config_entry in section["values"]:
|
||||||
value = get_entry_value(config_entry, interactive_section)
|
value = get_entry_value(config_entry, interactive_section)
|
||||||
|
|||||||
Reference in New Issue
Block a user