node-red-contrib-dnspod
Advanced tools
Comparing version 1.0.6 to 1.0.7
104
dnspod.js
@@ -31,21 +31,14 @@ module.exports = function (RED) { | ||
let token = this.server.token | ||
node.on('input', function (msg) { | ||
var real_ip = '' | ||
var domain = config.domain | ||
var tempList = domain.split("."); | ||
var payload = {} | ||
if (tempList.length <= 1) { | ||
payload['status'] = -1 | ||
payload["message"] = `未知域名错误, 传入的域名为: ${domain}` | ||
msg.payload = payload | ||
node.send(msg) | ||
return | ||
} | ||
let mainDomain = tempList[tempList.length - 2] + "." + tempList[tempList.length - 1], | ||
var domain = config.domain | ||
var tempList = domain.split("."); | ||
var payload = {} | ||
if (tempList.length <= 1) { | ||
this.status({fill:"red", shape:"ring", text: `未知域名错误, 传入的域名为: ${domain}`}); | ||
return null | ||
} | ||
this.status({fill:"blue", shape:"ring", text: `域名为: ${domain}`}); | ||
let mainDomain = tempList[tempList.length - 2] + "." + tempList[tempList.length - 1], | ||
subDomain = tempList.concat().slice(0, tempList.length - 2).join("."); | ||
let login_token = `${id},${token}` | ||
var Record = { | ||
let login_token = `${id},${token}` | ||
var Record = { | ||
"login_token": login_token, | ||
@@ -55,3 +48,49 @@ 'format': 'json', | ||
'domain': mainDomain | ||
} | ||
var real_ip = '' | ||
node.on('input', function (msg) { | ||
real_ip = msg.data | ||
console.log(`msg: ${JSON.stringify(msg)}`) | ||
if (real_ip) { | ||
console.log(`ip5: ${real_ip}`) | ||
node.status({fill:"blue", shape:"ring", text: `ip: ${real_ip}`}) | ||
updateIp(msg) | ||
}else { | ||
if(config.myip) { | ||
myIp(function(ip, err){ | ||
if(err) { | ||
payload['status'] = -2 | ||
payload["message"] = `ip修改发生错误` | ||
msg['all'] = error | ||
msg.payload = payload | ||
node.send(msg) | ||
return | ||
} | ||
console.log(`ip: ${ip}`) | ||
real_ip = ip | ||
node.status({fill:"blue", shape:"ring", text: `ip: ${real_ip}`}) | ||
updateIp(msg) | ||
}) | ||
}else { | ||
ipcn(function(ip, err){ | ||
if(err) { | ||
payload['status'] = -2 | ||
payload["message"] = `ip修改发生错误` | ||
msg['all'] = error | ||
msg.payload = payload | ||
node.send(msg) | ||
return | ||
} | ||
console.log(`ip2: ${ip}`) | ||
real_ip = ip | ||
node.status({fill:"blue", shape:"ring", text: `ip: ${real_ip}`}) | ||
updateIp(msg) | ||
}) | ||
} | ||
} | ||
}); | ||
function myIp(callback) { | ||
axios({ | ||
@@ -66,7 +105,28 @@ method: 'get', | ||
var ip_cn = /((\d{1,3}\.){3}\d{1,3})/.exec(response.data)[1] | ||
real_ip = msg.real_ip || ip_cn | ||
console.log(real_ip) | ||
return axios.post('https://dnsapi.cn/Record.List', Record, projectConfig) | ||
callback(ip_cn, null) | ||
}).catch(function (error) { | ||
callback(null, error) | ||
}) | ||
} | ||
function ipcn(callback){ | ||
axios({ | ||
method: 'get', | ||
url: 'https://api.myip.com/', | ||
headers: { | ||
'Content-type': 'application/x-www-form-urlencoded' | ||
} | ||
}).then(function (response) { | ||
callback(response.data.ip, null) | ||
}).catch(function (error) { | ||
callback(null, error) | ||
}) | ||
} | ||
function updateIp(msg) { | ||
axios.post('https://dnsapi.cn/Record.List', Record, projectConfig) | ||
.then(function (response) { | ||
var json = response.data | ||
@@ -123,3 +183,3 @@ if (1 != json['status']['code']) { | ||
}) | ||
}); | ||
} | ||
@@ -126,0 +186,0 @@ } |
{ | ||
"name": "node-red-contrib-dnspod", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "node red node for dnspod", | ||
@@ -5,0 +5,0 @@ "main": "test.js", |
Sorry, the diff of this file is not supported yet
11594
173
5