2018-07-26 21:57:21 +02:00
|
|
|
#!/usr/bin/python3
|
2017-09-24 14:34:46 +02:00
|
|
|
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
import shutil
|
2018-07-26 21:57:21 +02:00
|
|
|
import multiprocessing
|
2019-01-07 23:49:10 +02:00
|
|
|
import logging as log
|
|
|
|
import sys
|
2019-01-24 14:28:21 +02:00
|
|
|
from mailustart import resolve, convert
|
2018-07-26 21:57:21 +02:00
|
|
|
|
|
|
|
from podop import run_server
|
|
|
|
|
2019-01-08 05:16:05 +02:00
|
|
|
log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING"))
|
2018-07-26 21:57:21 +02:00
|
|
|
|
|
|
|
def start_podop():
|
|
|
|
os.setuid(100)
|
2019-01-17 16:32:47 +02:00
|
|
|
url = "http://" + os.environ["ADMIN_ADDRESS"] + "/internal/postfix/"
|
2019-01-07 23:49:10 +02:00
|
|
|
# TODO: Remove verbosity setting from Podop?
|
|
|
|
run_server(0, "postfix", "/tmp/podop.socket", [
|
2019-01-17 16:32:47 +02:00
|
|
|
("transport", "url", url + "transport/§"),
|
|
|
|
("alias", "url", url + "alias/§"),
|
|
|
|
("domain", "url", url + "domain/§"),
|
|
|
|
("mailbox", "url", url + "mailbox/§"),
|
|
|
|
("senderaccess", "url", url + "sender/access/§"),
|
|
|
|
("senderlogin", "url", url + "sender/login/§")
|
2018-07-26 21:57:21 +02:00
|
|
|
])
|
|
|
|
|
2019-01-07 23:49:10 +02:00
|
|
|
# Actual startup script
|
2018-10-22 16:02:43 +02:00
|
|
|
os.environ["FRONT_ADDRESS"] = resolve(os.environ.get("FRONT_ADDRESS", "front"))
|
2019-01-17 16:32:47 +02:00
|
|
|
os.environ["ADMIN_ADDRESS"] = resolve(os.environ.get("ADMIN_ADDRESS", "admin"))
|
2019-01-24 16:14:33 +02:00
|
|
|
os.environ["HOST_ANTISPAM"] = resolve(os.environ.get("HOST_ANTISPAM", "antispam:11332"))
|
|
|
|
os.environ["HOST_LMTP"] = resolve(os.environ.get("HOST_LMTP", "imap:2525"))
|
2017-09-24 14:34:46 +02:00
|
|
|
|
|
|
|
for postfix_file in glob.glob("/conf/*.cf"):
|
|
|
|
convert(postfix_file, os.path.join("/etc/postfix", os.path.basename(postfix_file)))
|
|
|
|
|
|
|
|
if os.path.exists("/overrides/postfix.cf"):
|
|
|
|
for line in open("/overrides/postfix.cf").read().strip().split("\n"):
|
|
|
|
os.system('postconf -e "{}"'.format(line))
|
|
|
|
|
|
|
|
if os.path.exists("/overrides/postfix.master"):
|
|
|
|
for line in open("/overrides/postfix.master").read().strip().split("\n"):
|
|
|
|
os.system('postconf -Me "{}"'.format(line))
|
|
|
|
|
|
|
|
for map_file in glob.glob("/overrides/*.map"):
|
|
|
|
destination = os.path.join("/etc/postfix", os.path.basename(map_file))
|
|
|
|
shutil.copyfile(map_file, destination)
|
|
|
|
os.system("postmap {}".format(destination))
|
|
|
|
os.remove(destination)
|
|
|
|
|
2019-03-04 19:52:04 +02:00
|
|
|
if "RELAYUSER" in os.environ:
|
|
|
|
path = "/etc/postfix/sasl_passwd"
|
2019-06-26 20:22:02 +02:00
|
|
|
convert("/conf/sasl_passwd", path)
|
2019-03-04 19:52:04 +02:00
|
|
|
os.system("postmap {}".format(path))
|
|
|
|
|
2018-07-26 21:57:21 +02:00
|
|
|
# Run Podop and Postfix
|
|
|
|
multiprocessing.Process(target=start_podop).start()
|
2019-06-23 21:00:01 +02:00
|
|
|
os.system("/usr/libexec/postfix/post-install meta_directory=/etc/postfix create-missing")
|
2019-06-23 21:18:39 +02:00
|
|
|
os.system("postfix start-fg")
|