1
0
Fork 0
mirror of https://github.com/Luzifer/dns.git synced 2024-12-22 19:01:20 +00:00

Remove code duplication by using mailserver sets

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-02-18 13:49:51 +01:00
parent 3cbf555584
commit 2fd806a998
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 39 additions and 57 deletions

View file

@ -106,6 +106,18 @@ def check_soa(soa, nameservers):
warn('SOA minimum ttl out of recommended bounds 300 - 86400') warn('SOA minimum ttl out of recommended bounds 300 - 86400')
def check_mailserver_sets(mailserver_sets):
for name, set in mailserver_sets.items():
for mx, weight in set.items():
if not str(weight).isdigit():
error('Mailserver Set {} - entry {} has non-digit weight {}'.format(
name, mx, weight))
if not re.match(MATCH_FQDN, mx):
warn('Mailserver Set {} - MX {} does not match fqdn regexp'.format(
name, mx))
def check_nameserver(nameservers): def check_nameserver(nameservers):
if len(nameservers) < 2: if len(nameservers) < 2:
error('Number of nameservers below required 2 servers') error('Number of nameservers below required 2 servers')
@ -124,15 +136,18 @@ def check_nameserver(nameservers):
def check_zone(name, config): def check_zone(name, config):
expected_zone = ['mailserver', 'entries', 'default_ttl'] expected_zone = ['mailserver', 'mailserver_set', 'entries', 'default_ttl']
for k in config.keys(): for k in config.keys():
if k not in expected_zone: if k not in expected_zone:
warn('Unexpected entry in zone {} found: {}'.format(name, k)) warn('Unexpected entry in zone {} found: {}'.format(name, k))
if 'mailserver' not in config and ('entries' not in config or len(config['entries']) == 0): if 'mailserver' not in config and 'mailserver_set' not in config and ('entries' not in config or len(config['entries']) == 0):
warn('Zone {} has no mailservers and no entries'.format(name)) warn('Zone {} has no mailservers and no entries'.format(name))
if 'mailserver' in config and 'mailserver_set' in config:
error('Zone {} contains mailserver and mailserver_set'.format(name))
if 'mailserver' in config: if 'mailserver' in config:
for mx, weight in config['mailserver'].items(): for mx, weight in config['mailserver'].items():
if not str(weight).isdigit(): if not str(weight).isdigit():

View file

@ -138,8 +138,12 @@ def main():
for entry in default(config, 'entries', []): for entry in default(config, 'entries', []):
entries.extend(sanitize(entry)) entries.extend(sanitize(entry))
mailserver = default(config, 'mailserver', {})
if 'mailserver_set' in config and config['mailserver_set'] in zone_data['mailserver_sets']:
mailserver = zone_data['mailserver_sets'][config['mailserver_set']]
write_zone(zone, ttl, zone_data['soa'], write_zone(zone, ttl, zone_data['soa'],
zone_data['nameserver'], default(config, 'mailserver', {}), entries) zone_data['nameserver'], mailserver, entries)
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -8,6 +8,14 @@ soa:
expire: 1209600 expire: 1209600
ttl: 86400 ttl: 86400
mailserver_sets:
google:
aspmx.l.google.com.: 1
alt1.aspmx.l.google.com.: 5
alt2.aspmx.l.google.com.: 5
alt3.aspmx.l.google.com.: 10
alt4.aspmx.l.google.com.: 10
nameserver: nameserver:
- ns1.kserver.biz. - ns1.kserver.biz.
- ns2.kserver.biz. - ns2.kserver.biz.
@ -15,12 +23,7 @@ nameserver:
zones: zones:
2k0.de: 2k0.de:
mailserver: mailserver_set: google
aspmx.l.google.com.: 1
alt1.aspmx.l.google.com.: 5
alt2.aspmx.l.google.com.: 5
alt3.aspmx.l.google.com.: 10
alt4.aspmx.l.google.com.: 10
entries: entries:
- name: googleffffffffffc3b235 - name: googleffffffffffc3b235
type: CNAME type: CNAME
@ -28,12 +31,7 @@ zones:
- google.com. - google.com.
ahlers.me: ahlers.me:
mailserver: mailserver_set: google
aspmx.l.google.com.: 1
alt1.aspmx.l.google.com.: 5
alt2.aspmx.l.google.com.: 5
alt3.aspmx.l.google.com.: 10
alt4.aspmx.l.google.com.: 10
entries: entries:
- name: "" - name: ""
ttl: 600 ttl: 600
@ -87,12 +85,7 @@ zones:
- docker01.cloud.kserver.biz. - docker01.cloud.kserver.biz.
cloudkeys.de: cloudkeys.de:
mailserver: mailserver_set: google
aspmx.l.google.com.: 1
alt1.aspmx.l.google.com.: 5
alt2.aspmx.l.google.com.: 5
alt3.aspmx.l.google.com.: 10
alt4.aspmx.l.google.com.: 10
entries: entries:
- name: "" - name: ""
alias: docker01.cloud.kserver.biz alias: docker01.cloud.kserver.biz
@ -102,12 +95,7 @@ zones:
- docker01.cloud.kserver.biz. - docker01.cloud.kserver.biz.
gobuilder.me: gobuilder.me:
mailserver: mailserver_set: google
aspmx.l.google.com.: 1
alt1.aspmx.l.google.com.: 5
alt2.aspmx.l.google.com.: 5
alt3.aspmx.l.google.com.: 10
alt4.aspmx.l.google.com.: 10
entries: entries:
- name: "" - name: ""
ttl: 600 ttl: 600
@ -137,12 +125,7 @@ zones:
alias: docker01.cloud.kserver.biz alias: docker01.cloud.kserver.biz
itpad.de: itpad.de:
mailserver: mailserver_set: google
aspmx.l.google.com.: 1
alt1.aspmx.l.google.com.: 5
alt2.aspmx.l.google.com.: 5
alt3.aspmx.l.google.com.: 10
alt4.aspmx.l.google.com.: 10
entries: entries:
- name: "" - name: ""
alias: docker01.cloud.kserver.biz alias: docker01.cloud.kserver.biz
@ -185,12 +168,7 @@ zones:
- google.com. - google.com.
knut-ahlers.de: knut-ahlers.de:
mailserver: mailserver_set: google
aspmx.l.google.com.: 1
alt1.aspmx.l.google.com.: 5
alt2.aspmx.l.google.com.: 5
alt3.aspmx.l.google.com.: 10
alt4.aspmx.l.google.com.: 10
entries: entries:
- name: "" - name: ""
alias: docker01.cloud.kserver.biz alias: docker01.cloud.kserver.biz
@ -215,12 +193,7 @@ zones:
alias: docker01.cloud.kserver.biz. alias: docker01.cloud.kserver.biz.
knut.me: knut.me:
mailserver: mailserver_set: google
aspmx.l.google.com.: 1
alt1.aspmx.l.google.com.: 5
alt2.aspmx.l.google.com.: 5
alt3.aspmx.l.google.com.: 10
alt4.aspmx.l.google.com.: 10
entries: entries:
- name: 28d72ef8af97.blog - name: 28d72ef8af97.blog
type: CNAME type: CNAME
@ -274,12 +247,7 @@ zones:
- docker01.cloud.kserver.biz. - docker01.cloud.kserver.biz.
knutshome.de: knutshome.de:
mailserver: mailserver_set: google
aspmx.l.google.com.: 1
alt1.aspmx.l.google.com.: 5
alt2.aspmx.l.google.com.: 5
alt3.aspmx.l.google.com.: 10
alt4.aspmx.l.google.com.: 10
entries: entries:
- name: "" - name: ""
type: TXT type: TXT
@ -304,12 +272,7 @@ zones:
- cdn.luzifer.cc.s3.amazonaws.com. - cdn.luzifer.cc.s3.amazonaws.com.
luzifer.io: luzifer.io:
mailserver: mailserver_set: google
aspmx.l.google.com.: 1
alt1.aspmx.l.google.com.: 5
alt2.aspmx.l.google.com.: 5
alt3.aspmx.l.google.com.: 10
alt4.aspmx.l.google.com.: 10
entries: entries:
- name: "" - name: ""
alias: docker01.cloud.kserver.biz. alias: docker01.cloud.kserver.biz.