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) {
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");
req.params.addr = addr;
next();
req.params.addr = addr;
next();
}
router.use((req, res, next) => {
res.type('text/plain');
next();
next();
});
router.get("/", testIP, (req, res) => {
res.send(req.params.addr.toString());
res.send(req.params.addr.toString());
});
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) => {
if (e) return res.status(400).send("Error");
if (!d) return res.status(404).send("Unknown FQDN");
res.send([
d.ipv4 ? d.ipv4 : "0.0.0.0",
moment(d.ipv4LastPing).toISOString(),
d.ipv6 ? d.ipv6 : "::",
moment(d.ipv6LastPing).toISOString(),
].reduce((a, b) => a + "\n" + b));
});
if (e) return res.status(400).send("Error");
if (!d) return res.status(404).send("Unknown FQDN");
res.send([
d.ipv4 ? d.ipv4 : "0.0.0.0",
moment(d.ipv4LastPing).toISOString(),
d.ipv6 ? d.ipv6 : "::",
moment(d.ipv6LastPing).toISOString(),
].reduce((a, b) => a + "\n" + b));
});
});
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) => {
if (e) return res.status(400).send("Error");
if (d.affectedRows <= 0) return res.status(400).send("Invalid token");
res.send(addr.toString());
});
if (e) return res.status(400).send("Error");
if (d.affectedRows <= 0) return res.status(400).send("Invalid token");
res.send(addr.toString());
});
});
module.exports = router;

Loading…
Cancel
Save