2020-05-11 10:51:30 +02:00
|
|
|
let express = require("express");
|
2020-05-25 12:02:04 +02:00
|
|
|
let app = express();
|
|
|
|
let server = require("http").Server(app);
|
2020-05-11 10:51:30 +02:00
|
|
|
let morgan = require("morgan");
|
2020-05-25 12:02:04 +02:00
|
|
|
let io = require("socket.io")(server);
|
|
|
|
let https = require("https");
|
|
|
|
let fs = require("fs");
|
|
|
|
|
|
|
|
server.listen(process.env.PORT || 8080);
|
2020-05-11 10:51:30 +02:00
|
|
|
|
|
|
|
let indexRoute = require("./routes/index");
|
|
|
|
let notFoundRoute = require("./routes/notFound");
|
|
|
|
let errorRoute = require("./routes/error");
|
|
|
|
|
|
|
|
|
|
|
|
app.use(morgan("dev"))
|
|
|
|
.use(express.static("public"))
|
|
|
|
.set("view engine", "pug")
|
|
|
|
.use("/", indexRoute)
|
|
|
|
.use(notFoundRoute)
|
2020-05-25 12:02:04 +02:00
|
|
|
.use(errorRoute);
|
|
|
|
|
|
|
|
io.on("connection", (socket) => {
|
|
|
|
socket.emit("connected");
|
|
|
|
console.log("New connection !");
|
|
|
|
socket.on("checkMail", (data) => {
|
|
|
|
let key = fs.readFileSync("key", "utf-8");
|
|
|
|
let request = https.request({
|
|
|
|
hostname: "haveibeenpwned.com",
|
|
|
|
port: 443,
|
|
|
|
path: "/api/v3/breachedaccount/" + data.email,
|
|
|
|
method: "GET",
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
"user-agent": "InternetSecurity",
|
|
|
|
"hibp-api-key": key
|
|
|
|
}
|
|
|
|
}, res => {
|
|
|
|
let sendData = false;
|
|
|
|
res.setEncoding("utf-8");
|
|
|
|
res.on("data", d => {
|
|
|
|
socket.emit("resultMail", d);
|
|
|
|
sendData = true;
|
|
|
|
});
|
|
|
|
res.on("close", () => {
|
|
|
|
if (!sendData)
|
|
|
|
socket.emit("resultMail", []);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
request.on("error", err => {
|
|
|
|
console.error(err);
|
|
|
|
socket.emit("resultMail", null);
|
|
|
|
});
|
|
|
|
request.end();
|
|
|
|
})
|
|
|
|
});
|