|
|
|
@ -3,11 +3,25 @@ let ipaddr = require("ipaddr.js");
|
|
|
|
|
let db = require("../libs/Database").instance();
|
|
|
|
|
let router = express.Router();
|
|
|
|
|
|
|
|
|
|
function combineToList(a, b) {
|
|
|
|
|
return a + "\n" + b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toList(array) {
|
|
|
|
|
return array.reduce(combineToList, "").trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
router.use((req, res, next) => {
|
|
|
|
|
res.type('text/plain');
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get("/", (req, res) => {
|
|
|
|
|
db.q.select("fqdn").from("addresses").list((e, d) => {
|
|
|
|
|
res.send(toList(d))
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get("/:fqdn", (req, res) => {
|
|
|
|
|
db.q.select(["ipv4", "ipv6"]).from("addresses").filter("fqdn", req.params.fqdn).first((e, d) => {
|
|
|
|
|
if (e) return res.status(400).send("Error");
|
|
|
|
|