-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (36 loc) · 1.54 KB
/
index.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
const fetch = require("node-fetch")
require("dotenv").config()
const zones = require("./config.json")
setInterval(async function () {
const { ip } = await fetch("https://api.ipify.org?format=json").then(res => res.json())
zones.forEach(async zone => {
const dns_records = await fetch(`https://api.cloudflare.com/client/v4/zones/${zone.id}/dns_records?type=A`, {
method: "GET",
headers: {
Authorization: `Bearer ${process.env.readAuthKey}`,
"Content-Type": "application/json"
}
}).then(res => res.json())
dns_records.result.forEach(async record => {
if (zone.exclude.includes(record.name)) return
const newRecord = await fetch(`https://api.cloudflare.com/client/v4/zones/${zone.id}/dns_records/${record.id}`, {
method: "PUT",
headers: {
Authorization: `Bearer ${process.env.editAuthKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
type: "A",
name: record.name,
content: ip,
ttl: 1,
proxied: true
})
}).then(res => res.json())
console.log(newRecord)
if (newRecord.success !== false) {
console.log(`Record ${newRecord.result.name} updated to ${ip} At ${new Date(newRecord.result.modified_on).toLocaleTimeString()}`)
}
})
})
}, 1000 * 60 * 5)