This commit is contained in:
Alexey Kovrizhkin
2017-08-26 17:50:41 +03:00
committed by Alexey Kovrizhkin
parent 5d33f20ade
commit b8320d89ef
4 changed files with 92 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.env
*.done

32
Makefile Normal file
View File

@@ -0,0 +1,32 @@
SHELL = /bin/bash
CFG=.env
SOURCES=$(wildcard *.sql)
OBJECTS=$(SOURCES:.sql=.done)
all: $(CFG) $(OBJECTS)
up: all
%.done: %.sql
@echo "*** $< ***"
@cat $< | docker exec -i $$PG_CONTAINER psql -U $$PG_USER > $@
clean:
rm -rf *.done
# шаблон файла .env
define CONFIG_DEF
# dockin-app-dns config file, generated by make $(CFG)
# Postgresql container name
PG_CONTAINER=dcape_db_1
# PowerDNS DB user (and database) name
PG_USER=dns
endef
export CONFIG_DEF
$(CFG):
@echo "*** $@ ***"
@[ -f $@ ] || { echo "$$CONFIG_DEF" > $@ ; echo >&2 "Warning: Created default $@" ; }

View File

@@ -1,2 +1,22 @@
# dcape-dns-config
Config for dcape based powerdns server
This project contains Makefile and sample sql zone definition for loading zones into PowerDNS server.
## Requirements
* [dcape](https://github.com/TenderPro/dcape) installed on remote host with pdns and gitea running
## Usage
* fork this project into your dcape gitea
* in gitea project settings setup hook for server where powerdns service running
* clone project locally from gitea
* add your zones .sql by example from domain.sql.sample
* make `git push` and change project env in dcape cis config frontend
* make `git push` again and see updated dns zones
## TODO
* [ ] Zone rectification SQL

38
domain.sql.sample Normal file
View File

@@ -0,0 +1,38 @@
DO $$
-- Reload PowerDNS zone data
DECLARE
v_domain text := 'dev.lan'; -- domain name
v_ip text := '127.0.0.1'; -- base ip
v_ns text := 'ns.dev.lan'; -- master DNS host
v_ns_admin text := 'admin.ns.dev.lan'; -- master DNS admin email
v_domain_id integer; -- internal domain id
v_stamp text; -- zone timestamp
v_key text := '1'; -- zone serial suffix
v_soa text; -- zone SOA
BEGIN
SELECT INTO v_domain_id id FROM domains WHERE name = v_domain;
IF NOT FOUND THEN
INSERT INTO domains (name, type) VALUES
(v_domain, 'MASTER')
RETURNING id INTO v_domain_id
;
END IF;
v_stamp := to_char(current_timestamp, 'YYYYMMDD') || v_key;
v_soa := concat_ws(' ', v_ns, v_ns_admin, v_stamp, '10800 3600 604800 1800');
DELETE FROM records WHERE domain_id = v_domain_id;
INSERT INTO records (domain_id, name, ttl, type, prio, content) VALUES
(v_domain_id, v_domain, 60, 'SOA', 0, v_soa)
, (v_domain_id, v_domain, 1800, 'NS', 0, 'ns.' || v_domain)
, (v_domain_id, v_domain, 1800, 'MX', 5, 'mail.' || v_domain)
, (v_domain_id, v_domain, 1800, 'A', 0, v_ip)
, (v_domain_id, v_domain, 1800,'TXT', 0, 'v=spf1 mx ~all')
, (v_domain_id, 'www.' || v_domain, 1800, 'A', 0, v_ip)
;
END;
$$;