1
0
Fork 0
endlessh-logger/index.mjs

42 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2025-02-02 14:45:25 -05:00
// @ts-check
import { readFileSync, watch } from "fs";
import { readFile } from "fs/promises";
let lastFlaggedLength = 0;
watch("/opt/endlessh/endlessh.INFO", async (eventType, filename) => {
const fileContent = (await readFile("/opt/endlessh/endlessh.INFO", "utf8"))
.split("\n")
.filter(line => line.includes("ACCEPT"));
if (lastFlaggedLength !== fileContent.length) {
lastFlaggedLength = fileContent.length;
const entry = fileContent[fileContent.length - 1];
// @ts-ignore
const ip = entry.match(/host=(\S+) /)[1];
console.log(ip);
const response = await (
await fetch(`http://ip-api.com/json/${ip}`)
).json();
const t = Math.floor(Date.now() / 1000);
const embed = {
title: "New login",
description: `> **Time:** <t:${t}:D> at <t:${t}:T> (<t:${t}:R>)\n> **IP:** \`${response.query}\``
};
if (response.status === "success") {
embed.description += `\n**Country:** ${response.country}\n**Region:** ${response.regionName}\n**City:** ${response.city}\n**Provider:** ${response.as}`;
}
// @ts-ignore
fetch(process.env.WEBHOOK, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
embeds: [embed]
})
});
}
});