// @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:** at ()\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] }) }); } });