diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..3c66214 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +* @SX-9 +/domains/ @partofmyid/maintainers \ No newline at end of file diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..a8026c3 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,14 @@ +name: Check + +on: pull_request + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: DNSControl check + uses: koenrh/dnscontrol-action@v3 + with: + args: check + config_file: 'dnsconfig.js' \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..9bcae7c --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,29 @@ +name: Publish + +on: + workflow_dispatch: + push: + branches: [main] + paths: + - "domains/**" + - ".github/workflows/publish.yml" + - "dnsconfig.js" + +concurrency: + group: ${{ github.ref }}-publish + cancel-in-progress: false + +jobs: + dns: + name: DNS + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: echo '{"cloudflare":{"TYPE":"CLOUDFLAREAPI","apitoken":"$CLOUDFLARE_API_TOKEN"}}' > ./creds.json + - name: Publish + uses: is-cool-me/dnscontrol-action@v4.11.0 + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} + with: + args: push + config_file: "dnsconfig.js" \ No newline at end of file diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml new file mode 100644 index 0000000..806a50a --- /dev/null +++ b/.github/workflows/validation.yml @@ -0,0 +1,38 @@ +name: Validation + +on: + workflow_dispatch: + pull_request: + push: + branches: [main] + paths: + - "domains/**" + - ".github/workflows/validation.yml" + - "dnsconfig.js" + +concurrency: + group: ${{ github.ref }}-validation + cancel-in-progress: true + +jobs: + dns: + name: DNS + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check + uses: koenrh/dnscontrol-action@v3 + with: + args: check + config_file: "dnsconfig.js" + json: + name: JSON + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: JSON Syntax Check + uses: limitusus/json-syntax-check@v2 + with: + pattern: "\\.json$" + env: + BASE: "domains/" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6d32cd8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +creds.json +types-dnscontrol.d.ts \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0783284 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "dnscontrol" + ] +} \ No newline at end of file diff --git a/dnsconfig.js b/dnsconfig.js new file mode 100644 index 0000000..2e7b0b3 --- /dev/null +++ b/dnsconfig.js @@ -0,0 +1,116 @@ +// @ts-check +/// +// ^^^^^^ https://docs.dnscontrol.org/getting-started/typescript +var regNone = NewRegistrar("none"); +var providerCf = DnsProvider(NewDnsProvider("cloudflare", "", { + // manage_redirects: true, +})); + +var rootDomain = 'part-of.my.id'; +var registerSite = 'register-site.pages.dev'; +var proxy = { + on: { "cloudflare_proxy": "on" }, + off: { "cloudflare_proxy": "off" } +} + +function getDomainsList(filesPath) { + // @ts-expect-error + var files = glob.apply(null, [filesPath, true, '.json']); + var result = []; + + for (var i = 0; i < files.length; i++) { + var basename = files[i].split('/').reverse()[0]; + var name = basename.split('.')[0]; + result.push({ name: name, data: require(files[i]) }); + } + return result; +} + +var domains = getDomainsList('./domains'); +var commits = []; + +for (var idx in domains) { + var domainData = domains[idx].data; + var subdomain = domains[idx].name; + var proxyState = proxy.on; + if (domainData.proxied === false) proxyState = proxy.off; + + if ('A' in domainData.record) { + for (var a in domainData.record.A) { + commits.push( + A(subdomain, IP(domainData.record.A[a]), proxyState) + ); + } + } + + if ('AAAA' in domainData.record) { + for (var aaaa in domainData.record.AAAA) { + commits.push( + AAAA(subdomain, domainData.record.AAAA[aaaa], proxyState) + ); + } + } + + if ('CNAME' in domainData.record) { + commits.push( + CNAME(subdomain, domainData.record.CNAME + ".", proxyState) + ); + } + + if ('MX' in domainData.record) { + for (var mx in domainData.record.MX) { + commits.push( + MX(subdomain, 10, domainData.record.MX[mx] + ".") + ); + } + } + + // if ('NS' in domainData.record) { + // for (var ns in domainData.record.NS) { + // commits.push( + // NS(subdomain, domainData.record.NS[ns] + ".") + // ); + // } + // } + + if ('TXT' in domainData.record) { + for (var txt in domainData.record.TXT) { + commits.push( + TXT(subdomain, domainData.record.TXT[txt]) + ); + } + } + + // if ('CAA' in domainData.record) { + // for (var caa in domainData.record.CAA) { + // var caaRecord = domainData.record.CAA[caa]; + // commits.push( + // CAA(subdomain, caaRecord.flags, caaRecord.tag, caaRecord.value) + // ); + // } + // } + + if ('SRV' in domainData.record) { + for (var srv in domainData.record.SRV) { + var srvRecord = domainData.record.SRV[srv]; + commits.push( + SRV(subdomain, srvRecord.priority, srvRecord.weight, srvRecord.port, srvRecord.target + ".") + ); + } + } + + // if ('PTR' in domainData.record) { + // for (var ptr in domainData.record.PTR) { + // commits.push( + // PTR(subdomain, domainData.record.PTR[ptr] + ".") + // ); + // } + // } +} + +commits.push( + // CF_REDIRECT("*", "https://" + rootDomain + '/unregistered'), + ALIAS("@", registerSite + ".", proxy.on) +); + +D(rootDomain, regNone, providerCf, commits); diff --git a/domains/satr14.json b/domains/satr14.json new file mode 100644 index 0000000..cf59e84 --- /dev/null +++ b/domains/satr14.json @@ -0,0 +1,8 @@ +{ + "owner": { + "username": "SX-9" + }, + "record": { + "CNAME": "4th-site.pages.dev" + } +} \ No newline at end of file