From db45c9af5600b1a9acdd82a47598218ab298c969 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 17 Sep 2023 13:10:33 +0530 Subject: [PATCH 1/8] feat(script): adds support for multiple txt records --- tests/register.test.js | 50 ++++++++++++++++++++++++++++++++------- tests/validations.test.js | 2 +- utils/validations.js | 2 +- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/tests/register.test.js b/tests/register.test.js index 88eb4694e..e472588e7 100644 --- a/tests/register.test.js +++ b/tests/register.test.js @@ -3,7 +3,16 @@ const { toHostList, registerDomains } = require('../scripts/register-domains'); const { TTL, DOMAIN_DOMAIN } = require('../utils/constants'); const { getDomainService } = require('../utils/domain-service'); -const getCpanel = ({ zone, addZone, removeZone, redir, addRedir, removeRedir } = {}) => ({ +const getCpanel = ({ + zone, + addZone, + removeZone, + redir, + addRedir, + removeRedir, + addEmail, + removeEmail +} = {}) => ({ zone: { fetch: (_) => zone(), add: (rec) => addZone(rec), @@ -95,13 +104,16 @@ describe('registerDomains', () => { it('should add the new set hosts', async () => { const localHosts = [ - { name: 'a', record: { CNAME: 'boo', URL: 'z' } }, - { name: 'b', record: { CNAME: 'xaa', URL: 'x' } }, - { name: 'c', record: { CNAME: 'yello', URL: 'https://google.com' } }, + { name: 'a', record: { CNAME: 'boo' } }, + { name: 'b', record: { A: [ '1.1.1.1', '1.1.1.2' ], MX: 'somemx', TXT: 'some txt' } }, + { name: 'c', record: { URL: 'https://google.com' } }, + { name: 'd', record: { CNAME: 'foobar' } }, + { name: 'e', record: { A: [ '2.2.2.2' ], TXT: ['some', 'extra', 'txt'] } } ]; const remoteHosts = [ { line: 1, name: 'a', type: 'CNAME', address: 'boo' }, - { line: 2, name: 'b', type: 'CNAME', address: 'xaa' }, + { line: 2, name: 'b', type: 'MX', address: 'othermx' }, + { line: 3, name: 'd', type: 'CNAME', address: 'foobaz' }, ]; const remoteRedirections = [ { domain: `b.${DOMAIN_DOMAIN}`, destination: 'x' }, @@ -111,10 +123,30 @@ describe('registerDomains', () => { const domainService = mockDS({ zones: remoteHosts, redirections: remoteRedirections }); await registerDomains({ getDomains: async () => localHosts, domainService }); - expect(addZone).toBeCalledTimes(1); - expect(removeZone).toBeCalledTimes(0); - expect(addRedir).toBeCalledTimes(2); - expect(removeRedir).toBeCalledTimes(1); + expect(addZone).toBeCalledTimes(8); + expect(addZone).toHaveBeenCalledWith({ name: 'b', type: 'A', address: '1.1.1.2', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'd', type: 'CNAME', cname: 'foobar', address: 'foobar', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'b', type: 'A', address: '1.1.1.2', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'b', type: 'TXT', address: 'some txt', txtdata: 'some txt', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'A', address: '2.2.2.2', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'TXT', address: 'some', txtdata: 'some', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'TXT', address: 'extra', txtdata: 'extra', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'TXT', address: 'txt', txtdata: 'txt', line: undefined }); + + expect(removeZone).toBeCalledTimes(1); + expect(removeZone).toHaveBeenCalledWith({ line: 3 }); + + expect(addRedir).toBeCalledTimes(1); + expect(addRedir).toHaveBeenCalledWith({ + domain: 'c.booboo.xyz', + redirect: 'https://google.com', + redirect_wildcard: 1, + redirect_www: 1, + type: 'permanent', + }); + + expect(addEmail).toBeCalledTimes(1); + expect(addEmail).toHaveBeenCalledWith({ domain: 'b.is-a.dev', exchanger: 'somemx', priority: 20 }); }); }); diff --git a/tests/validations.test.js b/tests/validations.test.js index e97ddbb08..219546bad 100644 --- a/tests/validations.test.js +++ b/tests/validations.test.js @@ -54,7 +54,6 @@ describe('validateDomainData', () => { { ...defaultDomain, record: { CNAME: 'foobar.com', A: ['11.22.22.33'] } }, { ...defaultDomain, record: { CNAME: 'foobar.com', MX: ['ALT4.ASPMX.L.GOOGLE.COM'] } }, ...INVALID_NAMES.map(name => ({ ...defaultDomain, name })).slice(0, 1), - { ...defaultDomain, record: { TXT: ['foobar wow nice!!!'] } }, { ...defaultDomain, name: 'a.b' }, { ...defaultDomain, name: 'ww2.baa' }, { ...defaultDomain, name: 'help.baa' }, @@ -86,6 +85,7 @@ describe('validateDomainData', () => { { ...defaultDomain, name: '_github-challenge-phenax.akshay' }, { ...defaultDomain, name: '_github-challenge-hello01-ga' }, { ...defaultDomain, name: '_github-challenge-hello01_ga' }, + { ...defaultDomain, record: { TXT: ['foobar wow nice!!!', 'more text'] } }, ]; it('should return false for invalid data', () => { diff --git a/utils/validations.js b/utils/validations.js index 963e8ed3d..9a99343fa 100644 --- a/utils/validations.js +++ b/utils/validations.js @@ -74,7 +74,7 @@ const validateDomainData = validate({ [R.has('A'), validateARecord('A')], [R.has('URL'), R.propSatisfies(isValidURL, 'URL')], [R.has('MX'), validateMXRecord('MX')], - [R.has('TXT'), R.propSatisfies(R.is(String), 'TXT')], + [R.has('TXT'), R.propSatisfies(or([ R.is(String), R.is(Array) ]), 'TXT')], [R.T, R.T], ]), ]), From d24c7220b0f94236f0da0fe3cf5fb39598fda22f Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 17 Sep 2023 14:51:19 +0530 Subject: [PATCH 2/8] chore(domains): adds multiple txt example for akshay.json --- domains/akshay.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/domains/akshay.json b/domains/akshay.json index 130700660..095fe26f3 100644 --- a/domains/akshay.json +++ b/domains/akshay.json @@ -6,6 +6,7 @@ "email": "phenax5@gmail.com" }, "record": { - "URL": "https://phenax.github.io" + "URL": "https://phenax.github.io", + "TXT": [ "Hello there!", "It's me, Akshay" ] } } From 4617b5c174c31009cb64891b81f9ef55c39d808f Mon Sep 17 00:00:00 2001 From: saumonarcenciel Date: Sun, 17 Sep 2023 12:28:09 +0200 Subject: [PATCH 3/8] feat(domain): saumon.is-a.dev --- domains/saumon.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/domains/saumon.json b/domains/saumon.json index ef3e4714b..2040d27f0 100644 --- a/domains/saumon.json +++ b/domains/saumon.json @@ -3,8 +3,9 @@ "username": "saumonarcenciel", "email": "viala38000@gmail.com" }, - "record": { - "A": ["185.143.241.106"] + "A": ["217.174.245.249"], + "MX": ["hosts.is-a.dev"], + "TXT": "v=spf1 a mx ip4:217.174.245.249 ~all" } -} +} \ No newline at end of file From ed1c83abf307c308ab58693e94ed4792f3510884 Mon Sep 17 00:00:00 2001 From: DenDanskeMine Date: Sun, 17 Sep 2023 12:54:20 +0200 Subject: [PATCH 4/8] feat(domain): christian.is-a.dev --- domains/christian.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 domains/christian.json diff --git a/domains/christian.json b/domains/christian.json new file mode 100644 index 000000000..5a1ce84c4 --- /dev/null +++ b/domains/christian.json @@ -0,0 +1,11 @@ +{ + "owner": { + "username": "DenDanskeMine", + "email": "christianhrose@outlook.dk" + }, + "record": { + "A": ["217.174.245.249"], + "MX": ["hosts.is-a.dev"], + "TXT": "v=spf1 a mx ip4:217.174.245.249 ~all" + } +} \ No newline at end of file From d6cefedace98a680164406b1aea583797e330340 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 17 Sep 2023 16:55:15 +0530 Subject: [PATCH 5/8] chore: cert script changes --- .gitignore | 1 + scripts/certbot-auth.sh | 6 ++++-- scripts/certbot.sh | 7 +++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b4bfa3d64..3794cfc91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ *.env.* *.log +is-a-dev-cert/ diff --git a/scripts/certbot-auth.sh b/scripts/certbot-auth.sh index fd0245777..6b4ee8bc7 100755 --- a/scripts/certbot-auth.sh +++ b/scripts/certbot-auth.sh @@ -6,10 +6,12 @@ echo "AUTH ::[$CERTBOT_VALIDATION]::[$CERTBOT_TOKEN]::[$CERTBOT_REMAINING_CHALLE echo "[$CERTBOT_DOMAIN]"; sleep 1; - ./scripts/certbot.sh acme_txt "$CERTBOT_VALIDATION"; -sleep $((5*60)); +echo "Going to sleep for a few minutes..."; + +# TODO: Check if $CERTBOT_VALIDATION == $(./scripts/certbot.sh get-acme)? +sleep $((3*60)); ./scripts/certbot.sh check; diff --git a/scripts/certbot.sh b/scripts/certbot.sh index 451df74b6..2ab0447ae 100755 --- a/scripts/certbot.sh +++ b/scripts/certbot.sh @@ -18,7 +18,6 @@ generate_certificate() { -m 'phenax5@gmail.com' \ -d '*.is-a.dev,is-a.dev' \ --agree-tos \ - --dry-run \ $(if_dry_run "--dry-run" ""); echo "+-----------------------------------------------+"; @@ -68,10 +67,14 @@ update_acme_txt_record() { reset_acme() { sleep 1; update_record remove TXT '_acme-challenge' ''; + update_record remove TXT '_acme-challenge' ''; } +get_acme() { dig +noall +answer _acme-challenge.is-a.dev TXT | awk '{print $5}'; } + case "$1" in - check) echo "TXT record:: $(dig +noall +answer _acme-challenge.is-a.dev TXT | awk '{print $5}')" ;; + check) echo "TXT record:: $(get_acme)" ;; + get-acme) get_acme ;; cert) generate_certificate ;; acme_txt) update_acme_txt_record "$2" ;; reset) reset_acme ;; From e5bb66c8709d65657da2b2a7ac41aae1d6927ca0 Mon Sep 17 00:00:00 2001 From: Noah <108767214+NoahPrm@users.noreply.github.com> Date: Sun, 17 Sep 2023 15:30:56 +0200 Subject: [PATCH 6/8] feat(domain): add `noah.is-a.dev` --- domains/noah.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 domains/noah.json diff --git a/domains/noah.json b/domains/noah.json new file mode 100644 index 000000000..211aab7f6 --- /dev/null +++ b/domains/noah.json @@ -0,0 +1,10 @@ +{ + "owner": { + "username": "NoahPrm", + "email": "noah.parmentier@icloud.com" + }, + + "record": { + "A": ["185.143.241.106"] + } +} From 62a66dc923676fbb7288b6ac5727484ca409b117 Mon Sep 17 00:00:00 2001 From: MrBogdanYT Date: Sun, 17 Sep 2023 17:21:13 +0300 Subject: [PATCH 7/8] feat(domain): bogdan.is-a.dev --- domains/bogdan.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 domains/bogdan.json diff --git a/domains/bogdan.json b/domains/bogdan.json new file mode 100644 index 000000000..052d58fbe --- /dev/null +++ b/domains/bogdan.json @@ -0,0 +1,11 @@ +{ + "owner": { + "username": "MrBogdanYT", + "email": "hysbskyblockgod@gmail.com" + }, + "record": { + "A": ["217.174.245.249"], + "MX": ["hosts.is-a.dev"], + "TXT": "v=spf1 a mx ip4:217.174.245.249 ~all" + } +} \ No newline at end of file From ccdb5a988bcaa91f7f8450d21f6a88a04f4a6a38 Mon Sep 17 00:00:00 2001 From: npc-123 Date: Sun, 17 Sep 2023 22:33:59 +0700 Subject: [PATCH 8/8] feat(domain): npc.is-a.dev --- domains/npc.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 domains/npc.json diff --git a/domains/npc.json b/domains/npc.json new file mode 100644 index 000000000..5eb5e5abe --- /dev/null +++ b/domains/npc.json @@ -0,0 +1,11 @@ +{ + "owner": { + "username": "npc-123", + "email": "aziznasrul85@gmail.com" + }, + "record": { + "A": ["217.174.245.249"], + "MX": ["hosts.is-a.dev"], + "TXT": "v=spf1 a mx ip4:217.174.245.249 ~all" + } +} \ No newline at end of file