This repository was archived by the owner on Oct 23, 2024. It is now read-only.
forked from is-a-dev/register
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnsconfig.js
114 lines (97 loc) · 3.7 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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 domains = getDomainsList("./domains");
var commit = [];
for (var subdomain in domains) {
var subdomainName = domains[subdomain].name;
var fullSubdomain = subdomainName + ".is-a.dev";
var domainData = domains[subdomain].data;
var proxyState = domainData.proxied ? { cloudflare_proxy: "on" } : { cloudflare_proxy: "off" };
// Handle A records
if (domainData.record.A) {
for (var a in domainData.record.A) {
commit.push(A(subdomainName, IP(domainData.record.A[a]), proxyState));
}
}
// Handle AAAA records
if (domainData.record.AAAA) {
for (var aaaa in domainData.record.AAAA) {
commit.push(AAAA(subdomainName, domainData.record.AAAA[aaaa], proxyState));
}
}
// Handle CAA records
if (domainData.record.CAA) {
for (var caa in domainData.record.CAA) {
var caaRecord = domainData.record.CAA[caa];
commit.push(CAA(subdomainName, caaRecord.flags, caaRecord.tag, caaRecord.value));
}
}
// Handle CNAME records
if (domainData.record.CNAME) {
// Allow CNAME record on root
if (subdomainName === "@") {
commit.push(ALIAS(subdomainName, domainData.record.CNAME + ".", proxyState));
} else {
commit.push(CNAME(subdomainName, domainData.record.CNAME + ".", proxyState));
}
}
// Handle DS records
if (domainData.record.DS) {
commit.push(DS(subdomainName, domainData.record.DS.key_tag, domainData.record.DS.algorithm, domainData.record.DS.digest_type, domainData.record.DS.digest));
}
// Handle MX records
if (domainData.record.MX) {
for (var mx in domainData.record.MX) {
commit.push(MX(subdomainName, 10, domainData.record.MX[mx] + "."));
}
}
// Handle NS records
if (domainData.record.NS) {
for (var ns in domainData.record.NS) {
commit.push(NS(subdomainName, domainData.record.NS[ns] + "."));
}
}
// Handle SRV records
if (domainData.record.SRV) {
for (var srv in domainData.record.SRV) {
var srvRecord = domainData.record.SRV[srv];
commit.push(SRV(subdomainName, srvRecord.priority, srvRecord.weight, srvRecord.port, srvRecord.target + "."));
}
}
// Handle TXT records
if (domainData.record.TXT) {
if (Array.isArray(domainData.record.TXT)) {
for (var txt in domainData.record.TXT) {
commit.push(TXT(subdomainName, domainData.record.TXT[txt]));
}
} else {
commit.push(TXT(subdomainName, domainData.record.TXT));
}
}
// Handle URL records
if (domainData.record.URL) {
commit.push(A(subdomainName, "192.0.2.1", { cloudflare_proxy: "on" }));
}
}
// Exceptions
commit.push(IGNORE("@", "MX,TXT"));
commit.push(IGNORE("\\*"));
commit.push(IGNORE("*._domainkey", "TXT"));
commit.push(IGNORE("_acme-challenge", "TXT"));
commit.push(IGNORE("_autodiscover._tcp", "SRV"));
commit.push(IGNORE("_dmarc", "TXT"));
commit.push(IGNORE("_psl", "TXT"));
commit.push(IGNORE("autoconfig", "CNAME"));
commit.push(IGNORE("autodiscover", "CNAME"));
commit.push(IGNORE("ns[1-5]", "A,AAAA"));
commit.push(IGNORE("test"));
commit.push(IGNORE("**.test"));
// Commit all DNS records
D("is-a.dev", NewRegistrar("none"), DnsProvider(NewDnsProvider("cloudflare", { "manage_single_redirects": true })), commit);