]>
Commit | Line | Data |
---|---|---|
aa665201 | 1 | #!/usr/bin/env -S python3 -u |
c0e0545b PD |
2 | import os |
3 | import sys | |
6c1e69e0 | 4 | import jinja2 |
c0e0545b PD |
5 | |
6 | program = sys.argv[0].split('-')[0] | |
7 | product = os.path.basename(program) | |
8 | ||
c0e0545b PD |
9 | apienvvar = None |
10 | apiconftemplate = None | |
6c1e69e0 PL |
11 | templateroot = '/etc/powerdns/templates.d' |
12 | templatedestination = '' | |
c0e0545b PD |
13 | args = [] |
14 | ||
15 | if product == 'pdns_recursor': | |
654b1265 | 16 | args = ['--disable-syslog'] |
654b1265 PL |
17 | apienvvar = 'PDNS_RECURSOR_API_KEY' |
18 | apiconftemplate = """webserver | |
6c1e69e0 | 19 | api-key={{ apikey }} |
c0e0545b PD |
20 | webserver-address=0.0.0.0 |
21 | webserver-allow-from=0.0.0.0/0 | |
6c1e69e0 | 22 | webserver-password={{ apikey }} |
654b1265 | 23 | """ |
6c1e69e0 | 24 | templatedestination = '/etc/powerdns/recursor.d' |
c0e0545b | 25 | elif product == 'pdns_server': |
654b1265 | 26 | args = ['--disable-syslog'] |
654b1265 PL |
27 | apienvvar = 'PDNS_AUTH_API_KEY' |
28 | apiconftemplate = """webserver | |
c0e0545b | 29 | api |
6c1e69e0 | 30 | api-key={{ apikey }} |
c0e0545b PD |
31 | webserver-address=0.0.0.0 |
32 | webserver-allow-from=0.0.0.0/0 | |
6c1e69e0 | 33 | webserver-password={{ apikey }} |
654b1265 | 34 | """ |
6c1e69e0 | 35 | templatedestination = '/etc/powerdns/pdns.d' |
c0e0545b | 36 | elif product == 'dnsdist': |
654b1265 | 37 | args = ['--supervised', '--disable-syslog'] |
654b1265 | 38 | apienvvar = 'DNSDIST_API_KEY' |
fa8766c5 | 39 | apiconftemplate = """webserver("0.0.0.0:8083") |
b9e82a46 | 40 | setWebserverConfig({password='{{ apikey }}', apiKey='{{ apikey }}', acl='0.0.0.0/0'}) |
c0e0545b | 41 | controlSocket('0.0.0.0:5199') |
6c1e69e0 | 42 | setKey('{{ apikey }}') |
c0e0545b | 43 | setConsoleACL('0.0.0.0/0') |
654b1265 | 44 | """ |
6c1e69e0 PL |
45 | templateroot = '/etc/dnsdist/templates.d' |
46 | templatedestination = '/etc/dnsdist/conf.d' | |
c0e0545b | 47 | |
d773b7bb CD |
48 | debug = os.getenv("DEBUG_CONFIG", 'no').lower() == 'yes' |
49 | ||
c0e0545b | 50 | apikey = os.getenv(apienvvar) |
c0e0545b | 51 | if apikey is not None: |
6c1e69e0 PL |
52 | webserver_conf = jinja2.Template(apiconftemplate).render(apikey=apikey) |
53 | conffile = os.path.join(templatedestination, '_api.conf') | |
54 | with open(conffile, 'w') as f: | |
55 | f.write(webserver_conf) | |
d773b7bb CD |
56 | if debug: |
57 | print("Created {} with content:\n{}\n".format(conffile, webserver_conf)) | |
6c1e69e0 PL |
58 | |
59 | templates = os.getenv('TEMPLATE_FILES') | |
60 | if templates is not None: | |
61 | for templateFile in templates.split(','): | |
62 | template = None | |
63 | with open(os.path.join(templateroot, templateFile + '.j2')) as f: | |
64 | template = jinja2.Template(f.read()) | |
65 | rendered = template.render(os.environ) | |
f51f65eb PL |
66 | target = os.path.join(templatedestination, templateFile + '.conf') |
67 | with open(target, 'w') as f: | |
6c1e69e0 | 68 | f.write(rendered) |
d773b7bb CD |
69 | if debug: |
70 | print("Created {} with content:\n{}\n".format(target, rendered)) | |
c0e0545b PD |
71 | |
72 | os.execv(program, [program]+args+sys.argv[1:]) |