ping.js: Changed tabs to spaces

master
Felix Stupp 5 years ago
parent b0d3fcc672
commit 9af27ac110
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -15,41 +15,41 @@ function toList(array) {
} }
function testIP(req, res, next) { function testIP(req, res, next) {
let addr = ipaddr.parse(req.ip); let addr = ipaddr.parse(req.ip);
if (!IP_TYPES.includes(addr.kind())) return res.status(400).send("Invalid ip address"); if (!IP_TYPES.includes(addr.kind())) return res.status(400).send("Invalid ip address");
req.params.addr = addr; req.params.addr = addr;
next(); next();
} }
router.use((req, res, next) => { router.use((req, res, next) => {
res.type('text/plain'); res.type('text/plain');
next(); next();
}); });
router.get("/", testIP, (req, res) => { router.get("/", testIP, (req, res) => {
res.send(req.params.addr.toString()); res.send(req.params.addr.toString());
}); });
router.get("/:fqdn", (req, res) => { router.get("/:fqdn", (req, res) => {
db.q.select(IP_TYPES.concat(IP_TYPES.map(e => e + "LastPing"))).from("addresses").filter("fqdn", req.params.fqdn).first((e, d) => { db.q.select(IP_TYPES.concat(IP_TYPES.map(e => e + "LastPing"))).from("addresses").filter("fqdn", req.params.fqdn).first((e, d) => {
if (e) return res.status(400).send("Error"); if (e) return res.status(400).send("Error");
if (!d) return res.status(404).send("Unknown FQDN"); if (!d) return res.status(404).send("Unknown FQDN");
res.send([ res.send([
d.ipv4 ? d.ipv4 : "0.0.0.0", d.ipv4 ? d.ipv4 : "0.0.0.0",
moment(d.ipv4LastPing).toISOString(), moment(d.ipv4LastPing).toISOString(),
d.ipv6 ? d.ipv6 : "::", d.ipv6 ? d.ipv6 : "::",
moment(d.ipv6LastPing).toISOString(), moment(d.ipv6LastPing).toISOString(),
].reduce((a, b) => a + "\n" + b)); ].reduce((a, b) => a + "\n" + b));
}); });
}); });
router.get("/:fqdn/:code", testIP, (req, res) => { router.get("/:fqdn/:code", testIP, (req, res) => {
let addr = req.params.addr; let addr = req.params.addr;
db.query("UPDATE addresses SET " + addr.kind() + " = ?, " + addr.kind() + "LastPing = CURRENT_TIMESTAMP WHERE fqdn = ? AND code = ?", [addr.toString(), req.params.fqdn, req.params.code], (e, d) => { db.query("UPDATE addresses SET " + addr.kind() + " = ?, " + addr.kind() + "LastPing = CURRENT_TIMESTAMP WHERE fqdn = ? AND code = ?", [addr.toString(), req.params.fqdn, req.params.code], (e, d) => {
if (e) return res.status(400).send("Error"); if (e) return res.status(400).send("Error");
if (d.affectedRows <= 0) return res.status(400).send("Invalid token"); if (d.affectedRows <= 0) return res.status(400).send("Invalid token");
res.send(addr.toString()); res.send(addr.toString());
}); });
}); });
module.exports = router; module.exports = router;

Loading…
Cancel
Save