-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (33 loc) Β· 1.2 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
39
40
41
42
const schedule = require('node-schedule')
const api = require('./api')
const config = require("./config");
async function updateDNS() {
const { security_token } = await api.login(config.CPANEL_USER, config.CPANEL_PWD)
const payload = await api.fetchZone(security_token, config.DOMAIN)
if(payload && payload.cpanelresult && payload.cpanelresult.data && payload.cpanelresult.data.length >0 ) {
const zones = payload.cpanelresult.data[0]
const zone = zones.record.filter(z => z.name === config.SUBDOMAIN.toLocaleLowerCase() + '.')
if(Array.isArray(zone) && zone.length > 0) {
let data = {
domain: config.DOMAIN,
...zone[0]
}
data.address = await api.getMyIP()
const res = await api.patchDNS(security_token, data)
if(res.cpanelresult.event.result) {
console.log('Patching DNS successfull :-)')
} else {
console.log('Patching Failed :-(\nReason unknown.')
}
} else {
console.log('Patching DNS failed, Subdomain not found!')
}
} else {
console.log('Patching DNS failed, Domain not found!')
}
}
api.init(config.CPANEL_BASEURL)
updateDNS()
schedule.scheduleJob(config.UPDATE_SCHEDULE, () => {
updateDNS()
})