940: Fix host variables r=mergify[bot] a=ionutfilip

## What type of PR?
bug-fix

## What does this PR do?

### Related issue(s)
- Fix #884

## Prerequistes
Before we can consider review and merge, please make sure the following list is done and checked.
If an entry in not applicable, you can check it or remove it from the list.

- [x] In case of feature or enhancement: documentation updated accordingly
- [x] Unless it's docs or a minor change: place entry in the [changelog](CHANGELOG.md), under the latest un-released version.


Co-authored-by: Ionut Filip <ionut.philip@gmail.com>
Co-authored-by: Tim Möhlmann <muhlemmer@gmail.com>
master
bors[bot] 5 years ago committed by GitHub
commit 3e626b8500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -52,13 +52,19 @@ DEFAULT_CONFIG = {
'RECAPTCHA_PRIVATE_KEY': '', 'RECAPTCHA_PRIVATE_KEY': '',
# Advanced settings # Advanced settings
'PASSWORD_SCHEME': 'BLF-CRYPT', 'PASSWORD_SCHEME': 'BLF-CRYPT',
'LOG_LEVEL': 'WARNING',
# Host settings # Host settings
'HOST_IMAP': 'imap', 'HOST_IMAP': 'imap',
'HOST_LMTP': 'imap:2525',
'HOST_POP3': 'imap', 'HOST_POP3': 'imap',
'HOST_SMTP': 'smtp', 'HOST_SMTP': 'smtp',
'HOST_AUTHSMTP': 'smtp',
'HOST_ADMIN': 'admin',
'HOST_ANTISPAM': 'antispam:11334',
'HOST_WEBMAIL': 'webmail', 'HOST_WEBMAIL': 'webmail',
'HOST_WEBDAV': 'webdav:5232',
'HOST_REDIS': 'redis',
'HOST_FRONT': 'front', 'HOST_FRONT': 'front',
'HOST_AUTHSMTP': os.environ.get('HOST_SMTP', 'smtp'),
'SUBNET': '192.168.203.0/24', 'SUBNET': '192.168.203.0/24',
'POD_ADDRESS_RANGE': None 'POD_ADDRESS_RANGE': None
} }
@ -73,7 +79,7 @@ class ConfigManager(dict):
'mysql': 'mysql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}' 'mysql': 'mysql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}'
} }
HOSTS = ('IMAP', 'POP3', 'AUTHSMTP', 'SMTP') HOSTS = ('IMAP', 'POP3', 'AUTHSMTP', 'SMTP', 'REDIS')
OPTIONAL_HOSTS = ('WEBMAIL', 'ANTISPAM') OPTIONAL_HOSTS = ('WEBMAIL', 'ANTISPAM')
def __init__(self): def __init__(self):
@ -83,7 +89,8 @@ class ConfigManager(dict):
optional = [item for item in self.OPTIONAL_HOSTS if item in self.config and self.config[item] != "none"] optional = [item for item in self.OPTIONAL_HOSTS if item in self.config and self.config[item] != "none"]
for item in list(self.HOSTS) + optional: for item in list(self.HOSTS) + optional:
host = 'HOST_' + item host = 'HOST_' + item
self.config[host] = system.resolve_address(self.config[host]) address = item + '_ADDRESS'
self.config[address] = system.resolve_address(self.config[host])
def __coerce_value(self, value): def __coerce_value(self, value):
if isinstance(value, str) and value.lower() in ('true','yes'): if isinstance(value, str) and value.lower() in ('true','yes'):
@ -105,6 +112,9 @@ class ConfigManager(dict):
if self.config['DB_FLAVOR']: if self.config['DB_FLAVOR']:
template = self.DB_TEMPLATES[self.config['DB_FLAVOR']] template = self.DB_TEMPLATES[self.config['DB_FLAVOR']]
self.config['SQLALCHEMY_DATABASE_URI'] = template.format(**self.config) self.config['SQLALCHEMY_DATABASE_URI'] = template.format(**self.config)
self.config['RATELIMIT_STORAGE_URL'] = 'redis://{0}/2'.format(self.config['REDIS_ADDRESS'])
self.config['QUOTA_STORAGE_URL'] = 'redis://{0}/1'.format(self.config['REDIS_ADDRESS'])
# update the app config itself # update the app config itself
app.config = self app.config = self

@ -80,12 +80,12 @@ def extract_host_port(host_and_port, default_port):
def get_server(protocol, authenticated=False): def get_server(protocol, authenticated=False):
if protocol == "imap": if protocol == "imap":
hostname, port = extract_host_port(app.config['HOST_IMAP'], 143) hostname, port = extract_host_port(app.config['IMAP_ADDRESS'], 143)
elif protocol == "pop3": elif protocol == "pop3":
hostname, port = extract_host_port(app.config['HOST_POP3'], 110) hostname, port = extract_host_port(app.config['POP3_ADDRESS'], 110)
elif protocol == "smtp": elif protocol == "smtp":
if authenticated: if authenticated:
hostname, port = extract_host_port(app.config['HOST_AUTHSMTP'], 10025) hostname, port = extract_host_port(app.config['AUTHSMTP_ADDRESS'], 10025)
else: else:
hostname, port = extract_host_port(app.config['HOST_SMTP'], 25) hostname, port = extract_host_port(app.config['SMTP_ADDRESS'], 25)
return hostname, port return hostname, port

@ -21,11 +21,11 @@ def start_podop():
]) ])
# Actual startup script # Actual startup script
os.environ["FRONT_ADDRESS"] = system.resolve_address(os.environ.get("FRONT_ADDRESS", "front")) os.environ["FRONT_ADDRESS"] = system.resolve_address(os.environ.get("HOST_FRONT", "front"))
os.environ["REDIS_ADDRESS"] = system.resolve_address(os.environ.get("REDIS_ADDRESS", "redis")) os.environ["REDIS_ADDRESS"] = system.resolve_address(os.environ.get("HOST_REDIS", "redis"))
os.environ["ADMIN_ADDRESS"] = system.resolve_address(os.environ.get("ADMIN_ADDRESS", "admin")) os.environ["ADMIN_ADDRESS"] = system.resolve_address(os.environ.get("HOST_ADMIN", "admin"))
if os.environ["WEBMAIL"] != "none": if os.environ["WEBMAIL"] != "none":
os.environ["WEBMAIL_ADDRESS"] = system.resolve_address(os.environ.get("WEBMAIL_ADDRESS", "webmail")) os.environ["WEBMAIL_ADDRESS"] = system.resolve_address(os.environ.get("HOST_WEBMAIL", "webmail"))
for dovecot_file in glob.glob("/conf/*.conf"): for dovecot_file in glob.glob("/conf/*.conf"):
conf.jinja(dovecot_file, os.environ, os.path.join("/etc/dovecot", os.path.basename(dovecot_file))) conf.jinja(dovecot_file, os.environ, os.path.join("/etc/dovecot", os.path.basename(dovecot_file)))

@ -41,10 +41,14 @@ http {
# Favicon stuff # Favicon stuff
root /static; root /static;
# Variables for proxifying # Variables for proxifying
set $admin {{ HOST_ADMIN }}; set $admin {{ ADMIN_ADDRESS }};
set $antispam {{ HOST_ANTISPAM }}; set $antispam {{ ANTISPAM_ADDRESS }};
set $webmail {{ HOST_WEBMAIL }}; {% if WEBMAIL_ADDRESS %}
set $webdav {{ HOST_WEBDAV }}; set $webmail {{ WEBMAIL_ADDRESS }};
{% endif %}
{% if WEBDAV_ADDRESS %}
set $webdav {{ WEBDAV_ADDRESS }};
{% endif %}
# Always listen over HTTP # Always listen over HTTP
listen 80; listen 80;
@ -168,7 +172,7 @@ http {
# Forwarding authentication server # Forwarding authentication server
server { server {
# Variables for proxifying # Variables for proxifying
set $admin {{ HOST_ADMIN }}; set $admin {{ ADMIN_ADDRESS }};
listen 127.0.0.1:8000; listen 127.0.0.1:8000;

@ -14,14 +14,14 @@ with open("/etc/resolv.conf") as handle:
content = handle.read().split() content = handle.read().split()
args["RESOLVER"] = content[content.index("nameserver") + 1] args["RESOLVER"] = content[content.index("nameserver") + 1]
args["HOST_ADMIN"] = system.resolve_address(args.get("HOST_ADMIN", "admin")) args["ADMIN_ADDRESS"] = system.resolve_address(args.get("HOST_ADMIN", "admin"))
args["HOST_ANTISPAM"] = system.resolve_address(args.get("HOST_ANTISPAM", "antispam:11334")) args["ANTISPAM_ADDRESS"] = system.resolve_address(args.get("HOST_ANTISPAM", "antispam:11334"))
args["HOST_WEBMAIL"] = args.get("HOST_WEBMAIL", "webmail") args["HOST_WEBMAIL"] = args.get("HOST_WEBMAIL", "webmail")
if args["WEBMAIL"] != "none": if args["WEBMAIL"] != "none":
args["HOST_WEBMAIL"] = system.resolve_address(args.get("HOST_WEBMAIL")) args["WEBMAIL_ADDRESS"] = system.resolve_address(args.get("HOST_WEBMAIL"))
args["HOST_WEBDAV"] = args.get("HOST_WEBDAV", "webdav:5232") args["HOST_WEBDAV"] = args.get("HOST_WEBDAV", "webdav:5232")
if args["WEBDAV"] != "none": if args["WEBDAV"] != "none":
args["HOST_WEBDAV"] = system.resolve_address(args.get("HOST_WEBDAV")) args["WEBDAV_ADDRESS"] = system.resolve_address(args.get("HOST_WEBDAV"))
# TLS configuration # TLS configuration
cert_name = os.getenv("TLS_CERT_FILENAME", default="cert.pem") cert_name = os.getenv("TLS_CERT_FILENAME", default="cert.pem")

@ -73,7 +73,7 @@ virtual_mailbox_maps = ${podop}mailbox
# Mails are transported if required, then forwarded to Dovecot for delivery # Mails are transported if required, then forwarded to Dovecot for delivery
relay_domains = ${podop}transport relay_domains = ${podop}transport
transport_maps = ${podop}transport transport_maps = ${podop}transport
virtual_transport = lmtp:inet:{{ HOST_LMTP }} virtual_transport = lmtp:inet:{{ LMTP_ADDRESS }}
# In order to prevent Postfix from running DNS query, enforce the use of the # In order to prevent Postfix from running DNS query, enforce the use of the
# native DNS stack, that will check /etc/hosts properly. # native DNS stack, that will check /etc/hosts properly.
@ -112,7 +112,7 @@ unverified_recipient_reject_reason = Address lookup failure
# Milter # Milter
############### ###############
smtpd_milters = inet:{{ HOST_ANTISPAM }} smtpd_milters = inet:{{ ANTISPAM_ADDRESS }}
milter_protocol = 6 milter_protocol = 6
milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen} milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}
milter_default_action = tempfail milter_default_action = tempfail

@ -26,10 +26,10 @@ def start_podop():
]) ])
# Actual startup script # Actual startup script
os.environ["FRONT_ADDRESS"] = system.resolve_address(os.environ.get("FRONT_ADDRESS", "front")) os.environ["FRONT_ADDRESS"] = system.resolve_address(os.environ.get("HOST_FRONT", "front"))
os.environ["ADMIN_ADDRESS"] = system.resolve_address(os.environ.get("ADMIN_ADDRESS", "admin")) os.environ["ADMIN_ADDRESS"] = system.resolve_address(os.environ.get("HOST_ADMIN", "admin"))
os.environ["HOST_ANTISPAM"] = system.resolve_address(os.environ.get("HOST_ANTISPAM", "antispam:11332")) os.environ["ANTISPAM_ADDRESS"] = system.resolve_address(os.environ.get("HOST_ANTISPAM", "antispam:11332"))
os.environ["HOST_LMTP"] = system.resolve_address(os.environ.get("HOST_LMTP", "imap:2525")) os.environ["LMTP_ADDRESS"] = system.resolve_address(os.environ.get("HOST_LMTP", "imap:2525"))
for postfix_file in glob.glob("/conf/*.cf"): for postfix_file in glob.glob("/conf/*.cf"):
conf.jinja(postfix_file, os.environ, os.path.join("/etc/postfix", os.path.basename(postfix_file))) conf.jinja(postfix_file, os.environ, os.path.join("/etc/postfix", os.path.basename(postfix_file)))

@ -1 +1 @@
servers = "{{ HOST_REDIS }}"; servers = "{{ REDIS_ADDRESS }}";

@ -1 +1 @@
servers = "{{ HOST_REDIS }}"; servers = "{{ REDIS_ADDRESS }}";

@ -9,9 +9,11 @@ from socrate import system, conf
log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING")) log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING"))
# Actual startup script # Actual startup script
os.environ["FRONT_ADDRESS"] = system.resolve_address(os.environ.get("FRONT_ADDRESS", "front")) os.environ["FRONT_ADDRESS"] = system.resolve_address(os.environ.get("HOST_FRONT", "front"))
if "HOST_REDIS" not in os.environ:
os.environ["REDIS_ADDRESS"] = system.resolve_address(os.environ.get("HOST_REDIS", "redis"))
if "HOST_REDIS" not in os.environ: os.environ["HOST_REDIS"] = "redis"
for rspamd_file in glob.glob("/conf/*"): for rspamd_file in glob.glob("/conf/*"):
conf.jinja(rspamd_file, os.environ, os.path.join("/etc/rspamd/local.d", os.path.basename(rspamd_file))) conf.jinja(rspamd_file, os.environ, os.path.join("/etc/rspamd/local.d", os.path.basename(rspamd_file)))

@ -0,0 +1 @@
Fix HOST_* variable usage

@ -9,8 +9,8 @@ from socrate import system, conf
log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING")) log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING"))
# Actual startup script # Actual startup script
os.environ["FRONT_ADDRESS"] = system.resolve_address(os.environ.get("FRONT_ADDRESS", "front")) os.environ["FRONT_ADDRESS"] = system.resolve_address(os.environ.get("HOST_FRONT", "front"))
os.environ["IMAP_ADDRESS"] = system.resolve_address(os.environ.get("IMAP_ADDRESS", "imap")) os.environ["IMAP_ADDRESS"] = system.resolve_address(os.environ.get("HOST_IMAP", "imap"))
os.environ["MAX_FILESIZE"] = str(int(int(os.environ.get("MESSAGE_SIZE_LIMIT"))*0.66/1048576)) os.environ["MAX_FILESIZE"] = str(int(int(os.environ.get("MESSAGE_SIZE_LIMIT"))*0.66/1048576))

Loading…
Cancel
Save