Merge branch 'main' of github.com:lyz05/danmaku

This commit is contained in:
lyz05
2022-12-09 19:24:59 +08:00
3 changed files with 49 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ const router = express.Router();
const libqqwry = require("lib-qqwry");
const dns = require("dns");
const qqwry = libqqwry(); //初始化IP库解析器
const dnspod = require("../utils/dnspod");
/* GET home page. */
router.get("/", function (req, res) {
@@ -10,17 +11,57 @@ router.get("/", function (req, res) {
dns.lookup(ip, (err, address) => {
let ipL;
if (err) {
ipL = { "ip": ip, "msg": "域名解析IP失败" };
ipL = {
"ip": ip,
"msg": "域名解析IP失败"
};
} else {
ip = address;
try {
ipL = qqwry.searchIP(ip); //查询IP信息
} catch (e) {
ipL = { "ip": ip, "msg": e };
ipL = {
"ip": ip,
"msg": e
};
}
}
res.json(ipL);
});
});
router.get("/ddns", async function (req, res) {
let ip = req.ip,
subdomain = req.query.subdomain;
if (ip.substr(0, 7) === "::ffff:") {
ip = ip.substr(7);
}
if (!subdomain || subdomain === "") {
res.json({ msg: "请提供subdomain参数" });
return;
}
const record_type = (ip.indexOf(":") !== -1)? "AAAA": "A";
const records = await dnspod.get_record("home999.cc", subdomain, record_type);
if (!records || records.length !== 1) {
res.json({ msg: "获取不到相关记录或者记录条数不是1。" });
return;
}
const record = records[0];
if (record.value === ip) {
res.json({ msg: "不需要更新IP" });
} else {
record.value = ip;
const status = await dnspod.update_record("home999.cc",record);
if (status.code==="1") {
res.json({msg: "更新成功" ,ip});
} else {
res.json({
msg: "更新失败",
status
});
}
}
});
module.exports = router;

View File

@@ -1,5 +1,5 @@
const axios = require("axios");
const dnspod = require("./dnspod");
const dnspod = require("../utils/dnspod");
const KEY = "o1zrmHAF";
const DOMAINS = {

View File

@@ -6,12 +6,13 @@ const instance = axios.create({
baseURL: "https://dnsapi.cn"
});
async function get_record(domain, subdomain) {
async function get_record(domain, subdomain, recordtype) {
const api = "/Record.List";
const data = querystring.stringify({
"domain": domain,
"sub_domain": subdomain,
"login_token": token,
"record_type": recordtype,
"format": "json"
});
const res = await instance.post(api, data);
@@ -32,7 +33,7 @@ async function update_record(domain, record) {
"format": "json",
});
const res = await instance.post(api, data);
return res.data;
return res.data.status;
}
async function add_record(domain, record) {
@@ -67,14 +68,8 @@ async function del_record(domain, record) {
module.exports = {get_record, update_record, add_record, del_record};
if (!module.parent) {
get_record("home999.cc", "gd").then(res => {
get_record("home999.cc", "n1","AAAA").then(res => {
console.log(res);
for (const record of res) {
if (record.line !== "默认") {
del_record("home999.cc", record).then(res => {
console.log(res);
});
}
}
});
}