Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Added Rspamd installation #493

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
59b3b92
Added Rspamd installation
Spitfireap Apr 4, 2023
4ec6f55
Fixed dict, few fixes
Spitfireap Apr 4, 2023
7369278
Better configuration
Spitfireap Apr 4, 2023
bfbcdee
Removed installer.cfg
Spitfireap Apr 4, 2023
3a22ec1
fixed test
Spitfireap Apr 5, 2023
1b313cd
updated rspamd config
Spitfireap Jun 21, 2023
72be46c
fix
Spitfireap Sep 5, 2023
e628798
App incompatibility detection, updated for 2.2.0
Spitfireap Sep 6, 2023
5d0cd29
import fix
Spitfireap Sep 6, 2023
6f90016
Few fixes
tonioo Sep 12, 2023
c84e627
Fixed wrong settings initialization
tonioo Sep 14, 2023
8258657
Fixed issues in rspamd script
tonioo Sep 14, 2023
5db62a4
Fixed wrong setting names
tonioo Sep 14, 2023
aeee408
Consistency for variable names
tonioo Sep 14, 2023
0a6710e
Fixed wrong setting names!
tonioo Sep 14, 2023
0b8b6eb
Escape % character in config file
tonioo Sep 14, 2023
611cf13
Fixed wrong access to config option
tonioo Sep 14, 2023
b74b4da
Fixed tests
tonioo Sep 14, 2023
508cf42
Make rspamd installation work
tonioo Sep 21, 2023
e12cb5f
Convert codename to str
tonioo Sep 21, 2023
5d75afa
Fixed wrong call to mkdir_safe
tonioo Sep 21, 2023
526a7ac
Better custom repo installation
tonioo Sep 21, 2023
eb9ac91
Updated config and interactive mode
Spitfireap Sep 25, 2023
bd800a7
Fixed config
Spitfireap Sep 25, 2023
b046356
Added possibility of if directive in each entry
Spitfireap Sep 25, 2023
a4611ec
Fixed new source bug, removed bionic, added dynamic defaults
Spitfireap Oct 15, 2023
b66df5f
Fixed capped default choice, removed old py2 code
Spitfireap Oct 15, 2023
4f32252
small fix
Spitfireap Oct 15, 2023
027bea9
small fix part 2
Spitfireap Oct 15, 2023
d4b5cef
Bug fix
Spitfireap Oct 15, 2023
7d46095
small fix part 3
Spitfireap Oct 15, 2023
573eb36
small fix part 4
Spitfireap Oct 15, 2023
13bb288
added sieve rule to move spam to junk folder
Spitfireap Jan 12, 2024
54bbbac
Made 90-sieve a template
Spitfireap Jan 12, 2024
1eea9dc
Made junk sieve optional
Spitfireap Jan 12, 2024
0aea9d0
create sieve dir if needed
Spitfireap Jan 12, 2024
1d04ab3
Fixed file copy issue
tonioo Feb 23, 2024
ffe3bd5
Update after rebase
Spitfireap Oct 3, 2024
efd3fce
imported checks
Spitfireap Oct 31, 2024
462b8d3
fix import
Spitfireap Oct 31, 2024
ea085e4
imported arguments
Spitfireap Oct 31, 2024
bfce31a
Fixed indentation
Spitfireap Oct 31, 2024
6f044f4
Fixed dovecot
Spitfireap Oct 31, 2024
48ffb37
Fixed dovecot #2
Spitfireap Oct 31, 2024
ca55a46
Added rspamd dashboard info
Spitfireap Oct 31, 2024
7a9842b
Added Arc signing
Spitfireap Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ target/

# PyCharm
.idea/

#KDE
*.kdev4

installer.cfg
2 changes: 1 addition & 1 deletion checks.py → modoboa_installer/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def check_version():
"Check README file for instructions about how to update.\n"
"No support will be provided without an up-to-date installer!"
)
answer = utils.user_input("Continue anyway? (Y/n) ")
answer = utils.user_input("Continue anyway? (y/N) ")
if not answer.lower().startswith("y"):
sys.exit(0)
else:
Expand Down
7 changes: 7 additions & 0 deletions modoboa_installer/compatibility_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@
"modoboa-sievefilters": "2.3.0",
"modoboa-postfix-autoreply": "2.3.0"
}

APP_INCOMPATIBILITY = {
"opendkim": ["rspamd"],
"amavis": ["rspamd"],
"postwhite": ["rspamd"],
"spamassassin": ["rspamd"]
}
102 changes: 91 additions & 11 deletions modoboa_installer/config_dict_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ def is_email(user_input):
}
]
},
{
"name": "antispam",
"values": [
{
"option": "enabled",
"default": "true",
"customizable": True,
"values": ["true", "false"],
"question": "Do you want to setup an antispam utility?"
},
{
"option": "type",
"default": "rspamd",
"customizable": True,
"question": "Please select your antispam utility",
"values": ["rspamd", "amavis"],
"if": ["antispam.enabled=true"]
}
]
},
{
"name": "certificate",
"values": [
Expand All @@ -50,7 +70,7 @@ def is_email(user_input):
},
{
"name": "letsencrypt",
"if": "certificate.type=letsencrypt",
"if": ["certificate.type=letsencrypt"],
"values": [
{
"option": "email",
Expand Down Expand Up @@ -85,7 +105,7 @@ def is_email(user_input):
},
{
"name": "postgres",
"if": "database.engine=postgres",
"if": ["database.engine=postgres"],
"values": [
{
"option": "user",
Expand All @@ -101,7 +121,7 @@ def is_email(user_input):
},
{
"name": "mysql",
"if": "database.engine=mysql",
"if": ["database.engine=mysql"],
"values": [
{
"option": "user",
Expand Down Expand Up @@ -185,10 +205,18 @@ def is_email(user_input):
"customizable": True,
"question": "Please enter Modoboa db password",
},
{
"option": "cron_error_recipient",
"default": "root",
"customizable": True,
"question":
"Please enter a mail recipient for cron error reports"
},
{
"option": "extensions",
"default": (
"modoboa-amavis "
"modoboa-rspamd "
"modoboa-webmail modoboa-contacts "
"modoboa-radicale"
),
Expand Down Expand Up @@ -229,12 +257,60 @@ def is_email(user_input):
]
},
{
"name": "amavis",
"name": "rspamd",
"if": ["antispam.enabled=true", "antispam.type=rspamd"],
"values": [
{
"option": "enabled",
"default": ["antispam.enabled=true", "antispam.type=rspamd"],
},
{
"option": "user",
"default": "_rspamd",
},
{
"option": "password",
"default": make_password,
"customizable": True,
"question": "Please enter Rspamd interface password",
},
{
"option": "dnsbl",
"default": "true",
},
{
"option": "dkim_keys_storage_dir",
"default": "/var/lib/dkim"
},
{
"option": "key_map_path",
"default": "/var/lib/dkim/keys.path.map"
},
{
"option": "selector_map_path",
"default": "/var/lib/dkim/selectors.path.map"
},
{
"option": "greylisting",
"default": "true"
},
{
"option": "whitelist_auth",
"default": "true"
},
{
"option": "whitelist_auth_weigth",
"default": "-5"
}
],
},
{
"name": "amavis",
"values": [
{
"option": "enabled",
"default": ["antispam.enabled=true", "antispam.type=amavis"],
},
{
"option": "user",
"default": "amavis",
Expand All @@ -254,8 +330,6 @@ def is_email(user_input):
{
"option": "dbpassword",
"default": make_password,
"customizable": True,
"question": "Please enter amavis db password"
},
],
},
Expand Down Expand Up @@ -305,7 +379,11 @@ def is_email(user_input):
},
{
"option": "radicale_auth_socket_path",
"default": "/var/run/dovecot/auth-radicale"
"default": "/var/run/dovecot/auth-radicale",
},
{
"option": "move_spam_to_junk",
"default": "true",
},
]
},
Expand All @@ -327,7 +405,7 @@ def is_email(user_input):
"values": [
{
"option": "enabled",
"default": "true",
"default": "false",
},
{
"option": "config_dir",
Expand Down Expand Up @@ -361,7 +439,7 @@ def is_email(user_input):
"values": [
{
"option": "enabled",
"default": "true",
"default": ["antispam.enabled=true", "antispam.type=amavis"],
},
{
"option": "config_dir",
Expand All @@ -371,10 +449,11 @@ def is_email(user_input):
},
{
"name": "spamassassin",
"if": ["antispam.enabled=true", "antispam.type=amavis"],
"values": [
{
"option": "enabled",
"default": "true",
"default": ["antispam.enabled=true", "antispam.type=amavis"],
},
{
"option": "config_dir",
Expand Down Expand Up @@ -440,10 +519,11 @@ def is_email(user_input):
},
{
"name": "opendkim",
"if": ["antispam.enabled=true", "antispam.type=amavis"],
"values": [
{
"option": "enabled",
"default": "true",
"default": ["antispam.enabled=true", "antispam.type=amavis"],
},
{
"option": "user",
Expand Down
51 changes: 51 additions & 0 deletions modoboa_installer/disclaimers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from . import utils


def installation_disclaimer(args, config):
"""Display installation disclaimer."""
hostname = config.get("general", "hostname")
utils.printcolor(
"Notice:\n"
"It is recommanded to run this installer on a FRESHLY installed server.\n"
"(ie. with nothing special already installed on it)\n",
utils.CYAN
)
utils.printcolor(
"Warning:\n"
"Before you start the installation, please make sure the following "
"DNS records exist for domain '{}':\n"
" {} IN A <IP ADDRESS OF YOUR SERVER>\n"
" @ IN MX {}.\n".format(
args.domain,
hostname.replace(".{}".format(args.domain), ""),
hostname
),
utils.YELLOW
)
utils.printcolor(
"Your mail server will be installed with the following components:",
utils.BLUE)


def upgrade_disclaimer(config):
"""Display upgrade disclaimer."""
utils.printcolor(
"Your mail server is about to be upgraded and the following components"
" will be impacted:", utils.BLUE
)


def backup_disclaimer():
"""Display backup disclamer. """
utils.printcolor(
"Your mail server will be backed up locally.\n"
" !! You should really transfer the backup somewhere else...\n"
" !! Custom configuration (like for postfix) won't be saved.", utils.BLUE)


def restore_disclaimer():
"""Display restore disclamer. """
utils.printcolor(
"You are about to restore a previous installation of Modoboa.\n"
"If a new version has been released in between, please update your database!",
utils.BLUE)
29 changes: 27 additions & 2 deletions modoboa_installer/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import re

from os.path import isfile as file_exists

from . import utils


Expand Down Expand Up @@ -29,7 +31,7 @@ class DEBPackage(Package):
FORMAT = "deb"

def __init__(self, dist_name):
super(DEBPackage, self).__init__(dist_name)
super().__init__(dist_name)
self.index_updated = False
self.policy_file = "/usr/sbin/policy-rc.d"

Expand All @@ -42,6 +44,29 @@ def prepare_system(self):
def restore_system(self):
utils.exec_cmd("rm -f {}".format(self.policy_file))

def add_custom_repository(self,
name: str,
url: str,
key_url: str,
codename: str,
with_source: bool = True):
key_file = f"/etc/apt/keyrings/{name}.gpg"
utils.exec_cmd(
f"wget -O - {key_url} | gpg --dearmor | tee {key_file} > /dev/null"
)
line_types = ["deb"]
if with_source:
line_types.append("deb-src")
for line_type in line_types:
line = (
f"{line_type} [arch=amd64 signed-by={key_file}] "
f"{url} {codename} main"
)
target_file = f"/etc/apt/sources.list.d/{name}.list"
tee_option = "-a" if file_exists(target_file) else ""
utils.exec_cmd(f'echo "{line}" | tee {tee_option} {target_file}')
self.index_updated = False

def update(self):
"""Update local cache."""
if self.index_updated:
Expand Down Expand Up @@ -82,7 +107,7 @@ class RPMPackage(Package):

def __init__(self, dist_name):
"""Initialize backend."""
super(RPMPackage, self).__init__(dist_name)
super().__init__(dist_name)
if "centos" in dist_name:
self.install("epel-release")

Expand Down
7 changes: 4 additions & 3 deletions modoboa_installer/scripts/clamav.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ def post_run(self):
"""Additional tasks."""
if package.backend.FORMAT == "deb":
user = self.config.get(self.appname, "user")
system.add_user_to_group(
user, self.config.get("amavis", "user")
)
if self.config.get("amavis", "enabled").lower() == "true":
system.add_user_to_group(
user, self.config.get("amavis", "user")
)
pattern = (
"s/^AllowSupplementaryGroups false/"
"AllowSupplementaryGroups true/")
Expand Down
Loading