4 Commits

Author SHA1 Message Date
mxmlndml
325bc905f0 1.0.2 2023-08-28 20:17:49 +02:00
mxmlndml
4995a08260 detect dns records to patch properly 2023-08-28 20:17:42 +02:00
mxmlndml
6695db9d31 1.0.1 2023-08-28 19:39:24 +02:00
mxmlndml
64de314ea5 fix node script 2023-08-28 19:37:47 +02:00
2 changed files with 11 additions and 9 deletions

View File

@@ -1,11 +1,12 @@
{ {
"name": "cloudflare-dynamic-dns", "name": "cloudflare-dynamic-dns",
"version": "1.0.0-alpha", "version": "1.0.2",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"build": "rimraf ./dist && tsc", "start": "node .",
"start": "pnpm build && node ." "dev": "tsc -w",
"build": "rimraf ./dist && tsc"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
@@ -15,4 +16,4 @@
"rimraf": "^5.0.1", "rimraf": "^5.0.1",
"typescript": "^5.0.4" "typescript": "^5.0.4"
} }
} }

View File

@@ -2,7 +2,8 @@ import { getDnsRecords, patchDnsRecords } from "./cloudflare";
import getPublicIp from "./getPublicIp"; import getPublicIp from "./getPublicIp";
import * as log from "./log"; import * as log from "./log";
const { ZONE_ID, DOMAIN_NAMES, API_KEY, INTERVAL } = process.env; const { ZONE_ID, DOMAIN_NAMES, API_KEY } = process.env;
const INTERVAL = process.env.INTERVAL ?? "5";
if (ZONE_ID === undefined) { if (ZONE_ID === undefined) {
log.error("could not access environment variable 'ZONE_ID'"); log.error("could not access environment variable 'ZONE_ID'");
@@ -27,9 +28,9 @@ const dynamicDns = async () => {
getDnsRecords(ZONE_ID, domainNames, "A", API_KEY), getDnsRecords(ZONE_ID, domainNames, "A", API_KEY),
]); ]);
const dnsRecordsToPatch = dnsRecords.filter((dnsRecord) => { const dnsRecordsToPatch = dnsRecords.filter((dnsRecord) =>
dnsRecord.content !== publicIp; dnsRecord.content !== publicIp
}); );
if (dnsRecordsToPatch.length === 0) { if (dnsRecordsToPatch.length === 0) {
log.info(`public ip address remained at '${publicIp}', no patch needed`); log.info(`public ip address remained at '${publicIp}', no patch needed`);
@@ -60,5 +61,5 @@ const dynamicDns = async () => {
dynamicDns(); dynamicDns();
setInterval( setInterval(
dynamicDns, dynamicDns,
Number.parseInt(INTERVAL === undefined ? "5" : INTERVAL) * 60 * 1000, Number.parseInt(INTERVAL) * 60 * 1000,
); );