commit5c22600d98Merge:bc12ca7bcdbb4aAuthor: Antoine Nguyen <tonio@ngyn.org> Date: Tue Nov 29 16:54:28 2022 +0100 Merge pull request #462 from Spitfireap/randomize-api-call-time randomize api call time commitbcdbb4a2ceAuthor: Spitap <dev@asdrip.fr> Date: Tue Nov 29 14:53:05 2022 +0100 fix typo commitbd1ddcef21Author: Spitap <dev@asdrip.fr> Date: Tue Nov 29 13:45:31 2022 +0100 randomize api call time commitbc12ca7327Merge:d364239bd0ecd0Author: Antoine Nguyen <tonio@ngyn.org> Date: Mon Nov 14 15:49:41 2022 +0100 Merge pull request #458 from Spitfireap/fix-include_try fix typo in dovecot configuration file commitbd0ecd0949Author: Spitap <dev@asdrip.fr> Date: Thu Nov 10 14:57:43 2022 +0100 fix typo in dovecot configuration file commitd364239348Merge:61838db3763300Author: Antoine Nguyen <tonio@ngyn.org> Date: Wed Nov 9 10:51:30 2022 +0100 Merge pull request #456 from modoboa/feature/improved_backup_restore WIP: Improved backup/restore system. commit37633008cbAuthor: Antoine Nguyen <tonio@ngyn.org> Date: Wed Nov 9 10:30:44 2022 +0100 Fixed restore mode commitd6f9a5b913Author: Antoine Nguyen <tonio@ngyn.org> Date: Tue Nov 8 17:20:25 2022 +0100 Few fixes. commit8b1d60ee59Author: Antoine Nguyen <tonio@ngyn.org> Date: Tue Nov 8 17:19:23 2022 +0100 Few fixes commit2b5edae5d5Author: Antoine Nguyen <tonio@ngyn.org> Date: Sun Nov 6 10:30:24 2022 +0100 WIP: Improved backup/restore system. commit61838dbe4dAuthor: Antoine Nguyen <tonio@ngyn.org> Date: Sat Nov 5 09:30:50 2022 +0100 Check if restore is defined before doing anything else. fix #453 commit962cac3ad9Merge:1b192c5ef2359aAuthor: Antoine Nguyen <tonio@ngyn.org> Date: Fri Nov 4 09:41:20 2022 +0100 Merge pull request #450 from Spitfireap/fixed-super-call fixed super call in modoboa's script commitef2359a2a8Author: Spitap <dev@asdrip.fr> Date: Thu Nov 3 23:10:21 2022 +0100 fixed super call commit1b192c5fd5Merge:754d652b0b0146Author: Antoine Nguyen <tonio@ngyn.org> Date: Thu Nov 3 15:34:48 2022 +0100 Merge pull request #449 from Spitfireap/fixed-import-typo fixed constants import commitb0b01465d9Author: Spitap <dev@asdrip.fr> Date: Thu Nov 3 15:00:07 2022 +0100 fixed constants import commit754d652fc2Author: Antoine Nguyen <tonio@ngyn.org> Date: Thu Nov 3 12:27:04 2022 +0100 Few fixes commitcb5fa75693Merge:1afb8e6e01265aAuthor: Antoine Nguyen <tonio@ngyn.org> Date: Thu Nov 3 12:20:25 2022 +0100 Merge pull request #444 from Spitfireap/tighter-config-file-perm tighter config file permission commit1afb8e61fcMerge:15c17798dd0b7dAuthor: Antoine Nguyen <tonio@ngyn.org> Date: Thu Nov 3 12:17:16 2022 +0100 Merge pull request #424 from Spitfireap/restore Backup & restore system commit8dd0b7d497Author: Spitap <dev@asdrip.fr> Date: Thu Nov 3 10:57:03 2022 +0100 Last camelCase commit554611b366Author: Spitap <dev@asdrip.fr> Date: Thu Nov 3 10:54:06 2022 +0100 review fix commit15c17796f2Merge:ce8e7e684d1363Author: Antoine Nguyen <tonio@ngyn.org> Date: Fri Oct 28 09:43:30 2022 +0200 Merge pull request #446 from Spitfireap/fix-ssl-min-protocol fixed ssl_min_protocol setting commit84d13633a1Author: Spitap <dev@asdrip.fr> Date: Thu Oct 27 22:37:47 2022 +0200 fixed ssl_min_protocol setting commitce8e7e6027Merge:8e8ae5ffe7df27Author: Antoine Nguyen <tonio@ngyn.org> Date: Thu Oct 27 17:56:37 2022 +0200 Merge pull request #445 from Spitfireap/dovecot-fixes Fixes ssl permission error, updated ssl_protocol parameter commite01265a4eeMerge:a5fba03235ef3bAuthor: Spitap <dev@asdrip.fr> Date: Thu Oct 27 17:44:37 2022 +0200 Merge branch 'tighter-config-file-perm' of https://github.com/Spitfireap/modoboa-installer into tighter-config-file-perm commita5fba03264Author: Spitap <dev@asdrip.fr> Date: Thu Oct 27 11:13:47 2022 +0200 tighter config file permission commitfe7df276fcAuthor: Spitap <dev@asdrip.fr> Date: Thu Oct 27 17:25:39 2022 +0200 Check dovecot version greater commit8f34f0af6fAuthor: Spitap <dev@asdrip.fr> Date: Thu Oct 27 17:00:58 2022 +0200 Fixes ssl permission error, updated ssl_protocol parameter commit8e8ae5fb9cMerge:67f6ceefefbf54Author: Antoine Nguyen <tonio@ngyn.org> Date: Thu Oct 27 16:49:20 2022 +0200 Merge pull request #439 from stefaweb/master Update config_dict_template.py for default max_servers value commit235ef3befbAuthor: Spitap <dev@asdrip.fr> Date: Thu Oct 27 11:13:47 2022 +0200 thighter config file permission commit67f6cee8eaMerge:b84abbb53f7f8eAuthor: Antoine Nguyen <tonio@ngyn.org> Date: Tue Oct 25 19:32:37 2022 +0200 Merge pull request #442 from Spitfireap/patch-1 Set $max_server to 2 to avoid amavis crash commit5c9d5c9a03Author: Spitap <dev@asdrip.fr> Date: Tue Oct 25 16:58:57 2022 +0200 DKIM keys restore, Radicale backup/restore, fixes commit4c1f8710b5Author: Spitap <dev@asdrip.fr> Date: Tue Oct 25 16:04:55 2022 +0200 Added dkim key backup commite34eb4b337Author: Spitap <dev@asdrip.fr> Date: Tue Oct 25 13:59:28 2022 +0200 fix database path commit53f7f8ef9dAuthor: Spitfireap <45575529+Spitfireap@users.noreply.github.com> Date: Wed Oct 19 08:19:40 2022 +0000 Update config_dict_template.py commit35778cd614Merge:6726f5bb84abbbAuthor: Spitfireap <45575529+Spitfireap@users.noreply.github.com> Date: Tue Oct 18 17:17:48 2022 +0200 Merge branch 'modoboa:master' into restore commitfefbf549a4Author: Stephane Leclerc <sleclerc@actionweb.fr> Date: Thu Oct 6 13:36:13 2022 +0200 Update config_dict_template.py for default max_server value commit6726f5b1a2Author: Spitap <dev@asdrip.fr> Date: Mon Sep 26 13:39:28 2022 +0200 Improved path generation, path mistake proofing commita192cbcbd0Author: Spitap <dev@asdrip.fr> Date: Mon Sep 19 16:40:25 2022 +0200 Updated doc, default path on conf file commit5bed9655eaAuthor: Spitap <dev@asdrip.fr> Date: Mon Sep 19 15:53:19 2022 +0200 fixed typo commit6b096a7470Author: Spitap <dev@asdrip.fr> Date: Mon Sep 19 15:50:03 2022 +0200 Simplified db dumps restore commite30add03fdMerge:d75d83f1f8dd1bAuthor: Spitap <dev@asdrip.fr> Date: Mon Sep 19 15:39:05 2022 +0200 Update from master commitd75d83f202Author: Spitap <dev@asdrip.fr> Date: Mon Sep 19 15:13:44 2022 +0200 more refactoring commitf3811b4b39Author: Spitap <dev@asdrip.fr> Date: Mon Sep 19 14:59:43 2022 +0200 refactoring commitb0d56b3989Author: Spitap <dev@asdrip.fr> Date: Thu Sep 15 11:32:57 2022 +0200 PEP formating commit53e3e3ec58Author: Spitap <dev@asdrip.fr> Date: Fri Aug 5 15:20:11 2022 +0200 Better UX, use of os to concatenate path commite546d2cb23Author: Spitap <dev@asdrip.fr> Date: Wed Jul 27 16:32:59 2022 +0200 Better UX commit70faa1c5cbAuthor: Spitap <dev@asdrip.fr> Date: Wed Jul 27 15:58:41 2022 +0200 Fixed backupdir index commit563979a7ddAuthor: Spitap <dev@asdrip.fr> Date: Wed Jul 27 15:51:22 2022 +0200 fixed mail backup/restore commitee2ccf0647Author: Spitap <dev@asdrip.fr> Date: Wed Jul 27 14:35:48 2022 +0200 Fixed postfix install, added restore to readme commit2077c94b52Author: Spitap <dev@asdrip.fr> Date: Tue Jul 26 17:05:00 2022 +0200 Fix amavis config file not copied to right location commit4a7222bd24Author: Spitap <dev@asdrip.fr> Date: Tue Jul 26 16:53:24 2022 +0200 Fixed nginx call to uwsgi commite7b6104195Author: Spitap <dev@asdrip.fr> Date: Tue Jul 26 16:39:41 2022 +0200 fixed install within class commit4a00590354Author: Spitap <dev@asdrip.fr> Date: Tue Jul 26 16:20:03 2022 +0200 fixed restore disclamer commit15768c429eAuthor: Spitap <dev@asdrip.fr> Date: Tue Jul 26 12:07:42 2022 +0200 Restore workflow done commit439ffb94c4Author: Spitap <dev@asdrip.fr> Date: Mon Jul 25 18:54:47 2022 +0200 initial commit commit37bc21dfd3Author: Spitap <dev@asdrip.fr> Date: Tue Jul 26 10:36:08 2022 +0200 Backup postewhite.conf instead of custom whitelist Postwhite.conf contains a custom host list commit26204143afMerge:2097055d495afdAuthor: Spitap <dev@asdrip.fr> Date: Mon Jul 25 22:10:26 2022 +0200 Merge branch 'master' into backup commit20970557deAuthor: Spitap <dev@asdrip.fr> Date: Mon Jul 25 22:05:35 2022 +0200 Allow to disable mail backup commit632c26596eAuthor: Spitap <dev@asdrip.fr> Date: Mon Jul 25 21:52:15 2022 +0200 Update backup readme commit9e1c18cd6bAuthor: Spitap <dev@asdrip.fr> Date: Thu Jul 21 19:09:53 2022 +0200 Fix argument passed as list instead of string commitdb6457c5f5Author: Spitap <dev@asdrip.fr> Date: Thu Jul 21 19:07:18 2022 +0200 better path handling commit579faccfa5Author: Spitap <dev@asdrip.fr> Date: Thu Jul 21 19:00:32 2022 +0200 added an automatic bash option (no path provided) or a path provided bash (for cron job) commit5318fa279bAuthor: Spitap <dev@asdrip.fr> Date: Thu Jul 21 18:00:50 2022 +0200 bash option commit74de6a9bb1Author: Spitap <dev@asdrip.fr> Date: Thu Jul 21 17:31:56 2022 +0200 Reset pgpass before trying to backup secondary dbs commit54185a7c5aAuthor: Spitap <dev@asdrip.fr> Date: Thu Jul 21 17:26:40 2022 +0200 Fix database backup logic issue commit1f9d69c37cAuthor: Spitap <dev@asdrip.fr> Date: Thu Jul 21 17:21:59 2022 +0200 Fix copy issue commit8d02d2a9fbAuthor: Spitap <dev@asdrip.fr> Date: Thu Jul 21 17:09:23 2022 +0200 added safe mkdir in utils, use utils.mkdir_safe() in backup commit6f604a5fecAuthor: Spitap <dev@asdrip.fr> Date: Thu Jul 21 16:53:56 2022 +0200 Fix loop logic commit568c4a65a0Author: Spitap <dev@asdrip.fr> Date: Thu Jul 21 16:51:32 2022 +0200 fix none-type passed to os.path commitdc84a79528Author: Spitap <dev@asdrip.fr> Date: Thu Jul 21 14:12:35 2022 +0200 Note : capitalize affects only first letter commit304e25fa3cAuthor: Spitap <dev@asdrip.fr> Date: Thu Jul 21 14:10:57 2022 +0200 Fix getattr commit070efd61c4Author: Spitap <dev@asdrip.fr> Date: Thu Jul 21 14:08:39 2022 +0200 Fix import commit9917d8023eAuthor: Spitap <dev@asdrip.fr> Date: Thu Jul 21 14:02:41 2022 +0200 Edited README, fix backup run process commit27b9de6755Author: Spitap <dev@asdrip.fr> Date: Thu Jul 21 13:48:44 2022 +0200 database backup commit56ed214fb5Author: Spitap <dev@asdrip.fr> Date: Tue Jul 19 19:06:53 2022 +0200 Starting work on backup system
173 lines
6.7 KiB
Python
173 lines
6.7 KiB
Python
"""Dovecot related tools."""
|
|
|
|
import glob
|
|
import os
|
|
import pwd
|
|
import shutil
|
|
|
|
from .. import database
|
|
from .. import package
|
|
from .. import system
|
|
from .. import utils
|
|
|
|
from . import base
|
|
|
|
|
|
class Dovecot(base.Installer):
|
|
|
|
"""Dovecot installer."""
|
|
|
|
appname = "dovecot"
|
|
packages = {
|
|
"deb": [
|
|
"dovecot-imapd", "dovecot-lmtpd", "dovecot-managesieved",
|
|
"dovecot-sieve"],
|
|
"rpm": [
|
|
"dovecot", "dovecot-pigeonhole"]
|
|
}
|
|
config_files = [
|
|
"dovecot.conf", "dovecot-dict-sql.conf.ext", "conf.d/10-ssl.conf",
|
|
"conf.d/10-master.conf", "conf.d/20-lmtp.conf", "conf.d/10-ssl-keys.try"]
|
|
with_user = True
|
|
|
|
def get_config_files(self):
|
|
"""Additional config files."""
|
|
return self.config_files + [
|
|
"dovecot-sql-{}.conf.ext=dovecot-sql.conf.ext"
|
|
.format(self.dbengine),
|
|
"dovecot-sql-master-{}.conf.ext=dovecot-sql-master.conf.ext"
|
|
.format(self.dbengine),
|
|
"postlogin-{}.sh=/usr/local/bin/postlogin.sh"
|
|
.format(self.dbengine),
|
|
]
|
|
|
|
def get_packages(self):
|
|
"""Additional packages."""
|
|
packages = ["dovecot-{}".format(self.db_driver)]
|
|
if package.backend.FORMAT == "deb":
|
|
if "pop3" in self.config.get("dovecot", "extra_protocols"):
|
|
packages += ["dovecot-pop3d"]
|
|
return super(Dovecot, self).get_packages() + packages
|
|
|
|
def install_packages(self):
|
|
"""Preconfigure Dovecot if needed."""
|
|
package.backend.preconfigure(
|
|
"dovecot-core", "create-ssl-cert", "boolean", "false")
|
|
super(Dovecot, self).install_packages()
|
|
|
|
def get_template_context(self):
|
|
"""Additional variables."""
|
|
context = super(Dovecot, self).get_template_context()
|
|
pw = pwd.getpwnam(self.user)
|
|
dovecot_package = {"deb": "dovecot-core", "rpm": "dovecot"}
|
|
ssl_protocol_parameter = "ssl_protocols"
|
|
if package.backend.get_installed_version(dovecot_package[package.backend.FORMAT]) > "2.3":
|
|
ssl_protocol_parameter = "ssl_min_protocol"
|
|
ssl_protocols = "!SSLv2 !SSLv3"
|
|
if package.backend.get_installed_version("openssl").startswith("1.1") \
|
|
or package.backend.get_installed_version("openssl").startswith("3"):
|
|
ssl_protocols = "!SSLv3"
|
|
if ssl_protocol_parameter == "ssl_min_protocol":
|
|
ssl_protocols = "TLSv1"
|
|
if "centos" in utils.dist_name():
|
|
protocols = "protocols = imap lmtp sieve"
|
|
extra_protocols = self.config.get("dovecot", "extra_protocols")
|
|
if extra_protocols:
|
|
protocols += " {}".format(extra_protocols)
|
|
else:
|
|
# Protocols are automatically guessed on debian/ubuntu
|
|
protocols = ""
|
|
context.update({
|
|
"db_driver": self.db_driver,
|
|
"mailboxes_owner_uid": pw[2],
|
|
"mailboxes_owner_gid": pw[3],
|
|
"modoboa_user": self.config.get("modoboa", "user"),
|
|
"modoboa_dbname": self.config.get("modoboa", "dbname"),
|
|
"modoboa_dbuser": self.config.get("modoboa", "dbuser"),
|
|
"modoboa_dbpassword": self.config.get("modoboa", "dbpassword"),
|
|
"protocols": protocols,
|
|
"ssl_protocols": ssl_protocols,
|
|
"ssl_protocol_parameter": ssl_protocol_parameter,
|
|
"radicale_user": self.config.get("radicale", "user"),
|
|
"radicale_auth_socket_path": os.path.basename(
|
|
self.config.get("dovecot", "radicale_auth_socket_path"))
|
|
})
|
|
return context
|
|
|
|
def post_run(self):
|
|
"""Additional tasks."""
|
|
if self.dbengine == "postgres":
|
|
dbname = self.config.get("modoboa", "dbname")
|
|
dbuser = self.config.get("modoboa", "dbuser")
|
|
dbpassword = self.config.get("modoboa", "dbpassword")
|
|
backend = database.get_backend(self.config)
|
|
backend.load_sql_file(
|
|
dbname, dbuser, dbpassword,
|
|
self.get_file_path("install_modoboa_postgres_trigger.sql")
|
|
)
|
|
backend.load_sql_file(
|
|
dbname, dbuser, dbpassword,
|
|
self.get_file_path("fix_modoboa_postgres_schema.sql")
|
|
)
|
|
for f in glob.glob("{}/*".format(self.get_file_path("conf.d"))):
|
|
utils.copy_file(f, "{}/conf.d".format(self.config_dir))
|
|
# Make postlogin script executable
|
|
utils.exec_cmd("chmod +x /usr/local/bin/postlogin.sh")
|
|
# Add mailboxes user to dovecot group for modoboa mailbox commands.
|
|
# See https://github.com/modoboa/modoboa/issues/2157.
|
|
system.add_user_to_group(
|
|
self.config.get("dovecot", "mailboxes_owner"),
|
|
'dovecot'
|
|
)
|
|
|
|
def restart_daemon(self):
|
|
"""Restart daemon process.
|
|
|
|
Note: we don't capture output and manually redirect stdout to
|
|
/dev/null since this command may hang depending on the process
|
|
being restarted (dovecot for example)...
|
|
|
|
"""
|
|
code, output = utils.exec_cmd("service dovecot status")
|
|
action = "start" if code else "restart"
|
|
utils.exec_cmd(
|
|
"service {} {} > /dev/null 2>&1".format(self.appname, action),
|
|
capture_output=False)
|
|
system.enable_service(self.get_daemon_name())
|
|
|
|
def backup(self, path):
|
|
"""Backup emails."""
|
|
home_dir = self.config.get("dovecot", "home_dir")
|
|
utils.printcolor("Backing up mails", utils.MAGENTA)
|
|
if not os.path.exists(home_dir) or os.path.isfile(home_dir):
|
|
utils.error("Error backing up emails, provided path "
|
|
f" ({home_dir}) seems not right...")
|
|
return
|
|
|
|
dst = os.path.join(path, "mails/")
|
|
if os.path.exists(dst):
|
|
shutil.rmtree(dst)
|
|
shutil.copytree(home_dir, dst)
|
|
utils.success("Mail backup complete!")
|
|
|
|
def restore(self):
|
|
"""Restore emails."""
|
|
home_dir = self.config.get("dovecot", "home_dir")
|
|
mail_dir = os.path.join(self.archive_path, "mails/")
|
|
if len(os.listdir(mail_dir)) > 0:
|
|
utils.success("Copying mail backup over dovecot directory.")
|
|
if os.path.exists(home_dir):
|
|
shutil.rmtree(home_dir)
|
|
shutil.copytree(mail_dir, home_dir)
|
|
# Resetting permission for vmail
|
|
for dirpath, dirnames, filenames in os.walk(home_dir):
|
|
shutil.chown(dirpath, self.user, self.user)
|
|
for filename in filenames:
|
|
shutil.chown(os.path.join(dirpath, filename),
|
|
self.user, self.user)
|
|
else:
|
|
utils.printcolor(
|
|
"It seems that emails were not backed up, skipping restoration.",
|
|
utils.MAGENTA
|
|
)
|