node-red-contrib-dnspod
Advanced tools
Comparing version 1.0.7 to 1.0.8
222
dnspod.js
@@ -1,194 +0,48 @@ | ||
module.exports = function (RED) { | ||
var axios = require('axios'); | ||
var qs = require('qs') | ||
const DnsPods = require('./lib/DnsPods') | ||
const projectConfig = { | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
}, | ||
transformRequest: [ | ||
data => qsString(data) | ||
], | ||
paramsSerializer: params => qsString(params), | ||
module.exports = RED => { | ||
// config | ||
RED.nodes.registerType('dnspod-server', class { | ||
constructor (config) { | ||
RED.nodes.createNode(this, config) | ||
Object.assign(this, config) | ||
} | ||
const qsString = obj => qs.stringify(obj) | ||
}) | ||
function pushbearNode(config) { | ||
RED.nodes.createNode(this, config); | ||
// 更新 dns | ||
RED.nodes.registerType('dnspod', class { | ||
constructor (config) { | ||
const node = this | ||
RED.nodes.createNode(node, config) | ||
const server = RED.nodes.getNode(config.server) | ||
const dns = new DnsPods(node, server) | ||
node.on('input', async data => { | ||
try { | ||
// Retrieve the config node | ||
this.server = RED.nodes.getNode(config.server); | ||
var node = this; | ||
if (this.server) { | ||
// 合并值,未细想 | ||
for (const key in config) { if (config[key] != '' && config[key] != null) { data[key] = config[key] } } | ||
} else { | ||
node.error("没有配置正确的dnspod server", msg); | ||
return | ||
const res = await dns.update(data) | ||
node.status({ text: '更新成功', fill: ' gree', shape: 'ring' }) | ||
data.payload = res | ||
data.stauts = 0 | ||
node.send(data) | ||
} catch (err) { | ||
node.status({ text: err.message, fill: 'red', shape: 'ring' }) | ||
node.warn(err) | ||
data.payload = err.message | ||
data.stauts = -1 | ||
node.send(data) | ||
} | ||
let id = this.server.dnspod_id | ||
let token = this.server.token | ||
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 = { | ||
"login_token": login_token, | ||
'format': 'json', | ||
'sub_domain': subDomain, | ||
'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({ | ||
method: 'get', | ||
url: 'http://ip.cn', | ||
headers: { | ||
'Content-type': 'application/x-www-form-urlencoded' | ||
} | ||
}).then(function (response) { | ||
var ip_cn = /((\d{1,3}\.){3}\d{1,3})/.exec(response.data)[1] | ||
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 | ||
if (1 != json['status']['code']) { | ||
node.log("信息添加有误,清查 msg.all") | ||
payload['status'] = -3 | ||
payload["message"] = `信息添加有误,清查 msg.all` | ||
payload.all = json | ||
msg.payload = payload | ||
return | ||
} | ||
let ip = json['records'][0]['value'] | ||
let recordId = json['records'][0]['id'] | ||
if (real_ip === ip) { | ||
node.log("ip相同不需要修改") | ||
payload['status'] = 1 | ||
payload["message"] = `ip相同不需要修改` | ||
msg.payload = payload | ||
return | ||
} else { | ||
node.log("ip变化了,需要修改") | ||
} | ||
return axios.post('https://dnsapi.cn/Record.Modify', | ||
{ | ||
record_id: recordId, | ||
sub_domain: subDomain, | ||
domain: mainDomain, | ||
"login_token": login_token, | ||
'format': 'json', | ||
record_type: 'A', | ||
record_line: '默认', | ||
mx: 1, | ||
value: real_ip | ||
}, projectConfig) | ||
}).then(function (response) { | ||
if (payload['status'] === 1 || payload['status'] === -3) { | ||
}else { | ||
payload['status'] = 0 | ||
payload["message"] = `ip修改成功` | ||
msg['all'] = response.data | ||
msg.payload = payload | ||
} | ||
node.send(msg) | ||
}).catch(function (error) { | ||
console.log(error) | ||
payload['status'] = -2 | ||
payload["message"] = `ip修改发生错误` | ||
msg['all'] = error | ||
msg.payload = payload | ||
node.send(msg) | ||
}) | ||
} | ||
}) | ||
} | ||
RED.nodes.registerType("dnspod", pushbearNode); | ||
}) | ||
function RemoteServerNode(n) { | ||
RED.nodes.createNode(this, n); | ||
this.name = n.name; | ||
this.dnspod_id = n.dnspod_id; | ||
this.token = n.token; | ||
} | ||
RED.nodes.registerType("dnspod-server", RemoteServerNode); | ||
} | ||
} |
{ | ||
"name": "node-red-contrib-dnspod", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "node red node for dnspod", | ||
@@ -18,8 +18,18 @@ "main": "test.js", | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/smarthomefans/smarthomefans-nodes/issues" | ||
}, | ||
"author": "yaming116", | ||
"license": "MIT", | ||
"dependencies": { | ||
"axios": "^0.18.0", | ||
"qs": "^6.5.2" | ||
"axios": "^0.21.0", | ||
"qs": "^6.9.4" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^10.0.1", | ||
"eslint": "^5.16.0", | ||
"eslint-utils": "^1.4.2", | ||
"eslint-config-vue": "^2.0.2", | ||
"eslint-plugin-vue": "^5.2.2" | ||
} | ||
} |
@@ -1,30 +0,10 @@ | ||
# node-red-contrib-dnspod | ||
# dnspod | ||
> Simple, persistent, dnspod for Node-RED | ||
This provides a simple NR node to push message with pushbear | ||
## Install | ||
* 流程 | ||
**Requires Node.js v6.0 or newer** | ||
``` json | ||
Either install from the Node-RED palette manager, or: | ||
``` | ||
$ npm i node-red-contrib-dnspod | ||
``` | ||
## Usage | ||
Nodes are found within the **dnspod** category in NR's palette. | ||
See node documentation ("info" panel) for specific usage. | ||
## Maintainers | ||
[@yaming116](https://github.com/yaming116) | ||
## License | ||
MIT © 2018 yaming116 | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
2
8
210
0
11026
5
10
1
+ Addedaxios@0.21.4(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedgopd@1.0.1(transitive)
- Removedaxios@0.18.1(transitive)
- Removedfollow-redirects@1.5.10(transitive)
- Removedgopd@1.1.0(transitive)
- Removedis-buffer@2.0.5(transitive)
Updatedaxios@^0.21.0
Updatedqs@^6.9.4