Added postwhite support. (#171)
* Added postwhite support. see #109 * Fixed unit test.
This commit is contained in:
@@ -315,6 +315,19 @@ ConfigDictTemplate = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "postwhite",
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"option": "enabled",
|
||||||
|
"default": "true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"option": "config_dir",
|
||||||
|
"default": "/etc",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "spamassassin",
|
"name": "spamassassin",
|
||||||
"values": [
|
"values": [
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Installer(object):
|
|||||||
appname = None
|
appname = None
|
||||||
no_daemon = False
|
no_daemon = False
|
||||||
daemon_name = None
|
daemon_name = None
|
||||||
packages = []
|
packages = {}
|
||||||
with_user = False
|
with_user = False
|
||||||
with_db = False
|
with_db = False
|
||||||
config_files = []
|
config_files = []
|
||||||
@@ -97,7 +97,7 @@ class Installer(object):
|
|||||||
|
|
||||||
def get_packages(self):
|
def get_packages(self):
|
||||||
"""Return the list of packages to install."""
|
"""Return the list of packages to install."""
|
||||||
return self.packages[package.backend.FORMAT]
|
return self.packages.get(package.backend.FORMAT, {})
|
||||||
|
|
||||||
def install_packages(self):
|
def install_packages(self):
|
||||||
"""Install required packages."""
|
"""Install required packages."""
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ smtpd_recipient_restrictions =
|
|||||||
#
|
#
|
||||||
postscreen_access_list =
|
postscreen_access_list =
|
||||||
permit_mynetworks
|
permit_mynetworks
|
||||||
|
cidr:/etc/postfix/postscreen_spf_whitelist.cidr
|
||||||
postscreen_blacklist_action = enforce
|
postscreen_blacklist_action = enforce
|
||||||
|
|
||||||
# Use some DNSBL
|
# Use some DNSBL
|
||||||
|
|||||||
9
modoboa_installer/scripts/files/postwhite/crontab.tpl
Normal file
9
modoboa_installer/scripts/files/postwhite/crontab.tpl
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#
|
||||||
|
# Postwhite specific cron jobs
|
||||||
|
#
|
||||||
|
|
||||||
|
# Update Postscreen Whitelists
|
||||||
|
@daily root /usr/local/bin/postwhite/postwhite > /dev/null 2>&1
|
||||||
|
|
||||||
|
# Update Yahoo! IPs for Postscreen Whitelists
|
||||||
|
@weekly root /usr/local/bin/postwhite/scrape_yahoo > /dev/null 2>&1
|
||||||
@@ -10,6 +10,7 @@ from .. import package
|
|||||||
from .. import utils
|
from .. import utils
|
||||||
|
|
||||||
from . import base
|
from . import base
|
||||||
|
from . import install
|
||||||
|
|
||||||
|
|
||||||
class Postfix(base.Installer):
|
class Postfix(base.Installer):
|
||||||
@@ -92,3 +93,6 @@ class Postfix(base.Installer):
|
|||||||
aliases_file = "/etc/aliases"
|
aliases_file = "/etc/aliases"
|
||||||
if os.path.exists(aliases_file):
|
if os.path.exists(aliases_file):
|
||||||
utils.exec_cmd("postalias {}".format(aliases_file))
|
utils.exec_cmd("postalias {}".format(aliases_file))
|
||||||
|
|
||||||
|
# Postwhite
|
||||||
|
install("postwhite", self.config)
|
||||||
|
|||||||
51
modoboa_installer/scripts/postwhite.py
Normal file
51
modoboa_installer/scripts/postwhite.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
"""postwhite related functions."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from .. import utils
|
||||||
|
|
||||||
|
from . import base
|
||||||
|
|
||||||
|
POSTWHITE_REPOSITORY = "https://github.com/stevejenkins/postwhite"
|
||||||
|
SPF_TOOLS_REPOSITORY = "https://github.com/jsarenik/spf-tools"
|
||||||
|
|
||||||
|
|
||||||
|
class Postwhite(base.Installer):
|
||||||
|
"""Postwhite installer."""
|
||||||
|
|
||||||
|
appname = "postwhite"
|
||||||
|
config_files = [
|
||||||
|
"crontab=/etc/cron.d/postwhite",
|
||||||
|
]
|
||||||
|
no_daemon = True
|
||||||
|
packages = {
|
||||||
|
"rpm": ["bind-utils"]
|
||||||
|
}
|
||||||
|
|
||||||
|
def install_from_archive(self, repository, target_dir):
|
||||||
|
"""Install from an archive."""
|
||||||
|
url = "{}/archive/master.zip".format(repository)
|
||||||
|
target = os.path.join(target_dir, os.path.basename(url))
|
||||||
|
if os.path.exists(target):
|
||||||
|
os.unlink(target)
|
||||||
|
utils.exec_cmd("wget {}".format(url), cwd=target_dir)
|
||||||
|
app_name = os.path.basename(repository)
|
||||||
|
archive_dir = os.path.join(target_dir, app_name)
|
||||||
|
if os.path.exists(archive_dir):
|
||||||
|
shutil.rmtree(archive_dir)
|
||||||
|
utils.exec_cmd("unzip master.zip", cwd=target_dir)
|
||||||
|
utils.exec_cmd(
|
||||||
|
"mv {name}-master {name}".format(name=app_name), cwd=target_dir)
|
||||||
|
os.unlink(target)
|
||||||
|
return archive_dir
|
||||||
|
|
||||||
|
def post_run(self):
|
||||||
|
"""Additionnal tasks."""
|
||||||
|
install_dir = "/usr/local/bin"
|
||||||
|
self.install_from_archive(SPF_TOOLS_REPOSITORY, install_dir)
|
||||||
|
postw_dir = self.install_from_archive(
|
||||||
|
POSTWHITE_REPOSITORY, install_dir)
|
||||||
|
utils.copy_file(os.path.join(postw_dir, "postwhite.conf"), "/etc")
|
||||||
|
postw_bin = os.path.join(postw_dir, "postwhite")
|
||||||
|
utils.exec_cmd("{} /etc/postwhite.conf".format(postw_bin))
|
||||||
2
tests.py
2
tests.py
@@ -87,7 +87,7 @@ class ConfigFileTestCase(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.exists(self.cfgfile))
|
self.assertTrue(os.path.exists(self.cfgfile))
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"modoboa automx amavis clamav dovecot nginx razor postfix"
|
"modoboa automx amavis clamav dovecot nginx razor postfix"
|
||||||
" spamassassin uwsgi",
|
" postwhite spamassassin uwsgi",
|
||||||
out.getvalue()
|
out.getvalue()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user