App incompatibility detection, updated for 2.2.0

This commit is contained in:
Spitap
2023-09-06 12:46:20 +02:00
committed by Antoine Nguyen
parent df23f4e181
commit 70e9cffd87
7 changed files with 40 additions and 8 deletions

View File

@@ -37,3 +37,10 @@ REMOVED_EXTENSIONS = {
"modoboa-radicale": "2.4.0",
"modoboa-webmail": "2.4.0",
}
APP_INCOMPATIBILITY = {
"opendkim": ["rspamd"],
"amavis": ["rspamd"],
"postwhite": ["rspamd"],
"spamassassin": ["rspamd"]
}

View File

@@ -244,11 +244,11 @@ ConfigDictTemplate = [
"default": "/var/lib/dkim"
},
{
"option": "keys_path_map",
"option": "key_map_path",
"default": "/var/lib/dkim/keys.path.map"
},
{
"option": "selectors_path_map",
"option": "selector_map_path",
"default": "/var/lib/dkim/selectors.path.map"
},
{
@@ -392,7 +392,7 @@ ConfigDictTemplate = [
"values": [
{
"option": "enabled",
"default": "true",
"default": "false",
},
{
"option": "config_dir",

View File

@@ -3,7 +3,7 @@ autostart=true
autorestart=true
command=%{venv_path}/bin/python %{home_dir}/instance/manage.py rqworker dkim
directory=%{home_dir}
user=%{opendkim_user}
user=%{dkim_user}
redirect_stderr=true
numprocs=1
stopsignal=TERM

View File

@@ -248,6 +248,7 @@ class Modoboa(base.Installer):
"dovecot_mailboxes_owner": (
self.config.get("dovecot", "mailboxes_owner")),
"opendkim_user": self.config.get("opendkim", "user"),
"dkim_user": "_rspamd" if self.config.getboolean("rspamd", "enabled") else self.config.get("opendkim", "user")
"minutes": random.randint(1, 59),
"hours": f"{random_hour},{random_hour+12}",
"modoboa_2_2_or_greater": "" if self.modoboa_2_2_or_greater else "#",
@@ -291,6 +292,15 @@ class Modoboa(base.Installer):
if self.config.getboolean("opendkim", "enabled"):
settings["admin"]["dkim_keys_storage_dir"] = (
self.config.get("opendkim", "keys_storage_dir"))
if self.config.getboolean("rspamd", "enabled"):
settings["admin"]["dkim_keys_storage_dir"] = (
self.config.get("rspamd", "dkim_keys_storage_dir"))
settings["modoboa_rspamd"]["key_map_path"] = (
self.config.get("rspamd", "key_map_path"))
settings["modoboa_rspamd"]["selector_map_path"] = (
self.config.get("rspamd", "selector_map_path"))
settings = json.dumps(settings)
query = (
"UPDATE core_localconfig SET _parameters='{}'"

View File

@@ -60,8 +60,7 @@ class Rspamd(base.Installer):
def install_config_files(self):
"""Make sure config directory exists."""
user = self.config.get("modoboa", "user")
pw = pwd.getpwnam(user)
pw = pwd.getpwnam("_rspamd")
targets = [
[self.app_config["dkim_keys_storage_dir"], pw[2], pw[3]]
]

View File

@@ -19,6 +19,7 @@ except ImportError:
import ConfigParser as configparser
from . import config_dict_template
from . import compatibility_matrix.APP_INCOMPATIBILITY
ENV = {}
@@ -504,3 +505,15 @@ def create_oauth2_app(app_name: str, client_id: str, config) -> tuple[str, str]:
)
exec_cmd(cmd)
return client_id, client_secret
def check_app_compatibility(section, config):
"""Check that the app can be installed in regards to other enabled apps."""
incompatible_app = []
if section in APP_INCOMPATIBILITY.keys():
for app in APP_INCOMPATIBILITY[section]:
if config.getboolean(app, "enabled"):
error(f"{section} cannont be installed if {app} is enabled. "
"Please disable one of them.")
incompatible_app.append(app)
return len(incompatible_app) == 0