-
-
Notifications
You must be signed in to change notification settings - Fork 391
/
dnsconfig.js
71 lines (58 loc) · 2.34 KB
/
dnsconfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function getDomainsList(filesPath) {
var result = [];
var files = glob.apply(null, [filesPath, true, ".json"]);
for (var i = 0; i < files.length; i++) {
var name = files[i].split("/").pop().replace(/\.json$/, "");
result.push({ name: name, data: require(files[i]) });
}
return result;
}
var allDomains = getDomainsList("./domains");
var commit = [];
for (var subdomain in allDomains) {
var subdomainName = allDomains[subdomain].name;
var domainData = allDomains[subdomain].data;
var proxyState = domainData.proxied ? { cloudflare_proxy: "on" } : { cloudflare_proxy: "off" };
// Handle A records
if (domainData.target.A) {
for (var a in domainData.target.A.value) {
commit.push(A(domainData.target.A.name, IP(domainData.target.A.value[a]), proxyState));
}
}
// Handle AAAA records
if (domainData.target.AAAA) {
for (var aaaa in domainData.target.AAAA.value) {
commit.push(AAAA(domainData.target.AAAA.name, domainData.target.AAAA.value[aaaa], proxyState));
}
}
// Handle CNAME records
if (domainData.target.CNAME) {
// Allow CNAME target on root
if (subdomainName === "@") {
commit.push(ALIAS(domainData.target.CNAME.name, domainData.target.CNAME.value + ".", proxyState));
} else {
commit.push(CNAME(domainData.target.CNAME.name, domainData.target.CNAME.value + ".", proxyState));
}
}
// Handle NS records
if (domainData.target.NS) {
for (var ns in domainData.target.NS.value) {
commit.push(NS(domainData.target.NS.name, domainData.target.NS.value[ns] + "."));
}
}
// Handle TXT records
if (domainData.target.TXT) {
if (Array.isArray(domainData.target.TXT)) {
for (var txt in domainData.target.TXT) {
var txtRecord = domainData.target.TXT[txt];
commit.push(TXT(txtRecord.name, txtRecord.value));
}
} else {
commit.push(TXT(domainData.target.TXT.name === "@" ? subdomainName : domainData.target.TXT.name + "." + subdomainName, domainData.target.TXT.value));
}
}
}
// *.mx.is-a-good.dev
commit.push(IGNORE("*", "MX", "*"));
// Commit all DNS records
D("is-a-good.dev", NewRegistrar("none"), DnsProvider(NewDnsProvider("cloudflare")), commit);