mirror of
https://github.com/Luzifer/dns.git
synced 2024-11-09 14:40:05 +00:00
Remove code duplication by using mailserver sets
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
3cbf555584
commit
2fd806a998
3 changed files with 39 additions and 57 deletions
|
@ -106,6 +106,18 @@ def check_soa(soa, nameservers):
|
|||
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):
|
||||
if len(nameservers) < 2:
|
||||
error('Number of nameservers below required 2 servers')
|
||||
|
@ -124,15 +136,18 @@ def check_nameserver(nameservers):
|
|||
|
||||
|
||||
def check_zone(name, config):
|
||||
expected_zone = ['mailserver', 'entries', 'default_ttl']
|
||||
expected_zone = ['mailserver', 'mailserver_set', 'entries', 'default_ttl']
|
||||
|
||||
for k in config.keys():
|
||||
if k not in expected_zone:
|
||||
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))
|
||||
|
||||
if 'mailserver' in config and 'mailserver_set' in config:
|
||||
error('Zone {} contains mailserver and mailserver_set'.format(name))
|
||||
|
||||
if 'mailserver' in config:
|
||||
for mx, weight in config['mailserver'].items():
|
||||
if not str(weight).isdigit():
|
||||
|
|
|
@ -138,8 +138,12 @@ def main():
|
|||
for entry in default(config, 'entries', []):
|
||||
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'],
|
||||
zone_data['nameserver'], default(config, 'mailserver', {}), entries)
|
||||
zone_data['nameserver'], mailserver, entries)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
71
zones.yml
71
zones.yml
|
@ -8,6 +8,14 @@ soa:
|
|||
expire: 1209600
|
||||
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:
|
||||
- ns1.kserver.biz.
|
||||
- ns2.kserver.biz.
|
||||
|
@ -15,12 +23,7 @@ nameserver:
|
|||
|
||||
zones:
|
||||
2k0.de:
|
||||
mailserver:
|
||||
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
|
||||
mailserver_set: google
|
||||
entries:
|
||||
- name: googleffffffffffc3b235
|
||||
type: CNAME
|
||||
|
@ -28,12 +31,7 @@ zones:
|
|||
- google.com.
|
||||
|
||||
ahlers.me:
|
||||
mailserver:
|
||||
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
|
||||
mailserver_set: google
|
||||
entries:
|
||||
- name: ""
|
||||
ttl: 600
|
||||
|
@ -87,12 +85,7 @@ zones:
|
|||
- docker01.cloud.kserver.biz.
|
||||
|
||||
cloudkeys.de:
|
||||
mailserver:
|
||||
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
|
||||
mailserver_set: google
|
||||
entries:
|
||||
- name: ""
|
||||
alias: docker01.cloud.kserver.biz
|
||||
|
@ -102,12 +95,7 @@ zones:
|
|||
- docker01.cloud.kserver.biz.
|
||||
|
||||
gobuilder.me:
|
||||
mailserver:
|
||||
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
|
||||
mailserver_set: google
|
||||
entries:
|
||||
- name: ""
|
||||
ttl: 600
|
||||
|
@ -137,12 +125,7 @@ zones:
|
|||
alias: docker01.cloud.kserver.biz
|
||||
|
||||
itpad.de:
|
||||
mailserver:
|
||||
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
|
||||
mailserver_set: google
|
||||
entries:
|
||||
- name: ""
|
||||
alias: docker01.cloud.kserver.biz
|
||||
|
@ -185,12 +168,7 @@ zones:
|
|||
- google.com.
|
||||
|
||||
knut-ahlers.de:
|
||||
mailserver:
|
||||
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
|
||||
mailserver_set: google
|
||||
entries:
|
||||
- name: ""
|
||||
alias: docker01.cloud.kserver.biz
|
||||
|
@ -215,12 +193,7 @@ zones:
|
|||
alias: docker01.cloud.kserver.biz.
|
||||
|
||||
knut.me:
|
||||
mailserver:
|
||||
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
|
||||
mailserver_set: google
|
||||
entries:
|
||||
- name: 28d72ef8af97.blog
|
||||
type: CNAME
|
||||
|
@ -274,12 +247,7 @@ zones:
|
|||
- docker01.cloud.kserver.biz.
|
||||
|
||||
knutshome.de:
|
||||
mailserver:
|
||||
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
|
||||
mailserver_set: google
|
||||
entries:
|
||||
- name: ""
|
||||
type: TXT
|
||||
|
@ -304,12 +272,7 @@ zones:
|
|||
- cdn.luzifer.cc.s3.amazonaws.com.
|
||||
|
||||
luzifer.io:
|
||||
mailserver:
|
||||
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
|
||||
mailserver_set: google
|
||||
entries:
|
||||
- name: ""
|
||||
alias: docker01.cloud.kserver.biz.
|
||||
|
|
Loading…
Reference in a new issue