From 5d6b4f5e693bf4c02ccbf67953790e3d64251010 Mon Sep 17 00:00:00 2001 From: tfcprivt <141457761+privt00@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:26:59 +0200 Subject: [PATCH] Update antipterovm.js --- misc/antipterovm.js | 51 ++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/misc/antipterovm.js b/misc/antipterovm.js index 350b47f..a2e80b2 100644 --- a/misc/antipterovm.js +++ b/misc/antipterovm.js @@ -180,24 +180,42 @@ module.exports.load = function (app, db) { chalk.cyan("]") + chalk.whiteBright(" Scanning servers for Ptero-VM...") ); - const serversResponse = await fetch( - `${panelUrl}/api/application/servers`, - { - headers: { - Authorization: `Bearer ${panelApiKey}`, - Accept: "application/vnd.pterodactyl.v1+json", - }, - } - ); + + const servers = []; + + async function getServersOnPage(page) { + return new Promise(async (resolve) => { + const response = await fetch( + settings.pterodactyl.domain + "/api/application/servers/?page=" + page, + { + headers: { + "Authorization": `Bearer ${settings.pterodactyl.key}` + } + } + ); - if (!serversResponse.ok) { - throw new Error( - `Failed to retrieve server list: ${serversResponse.status} ${serversResponse.statusText}` - ); - } + if (!response.ok) { + throw new Error(`Failed to fetch server list: ${response.status} ${response.statusText}`); + } - const serversData = await serversResponse.json(); - const servers = serversData.data; + resolve(response.json()); + }); + }; + + let currentPage = 1; + try { + while (true) { + const serversResponse = await getServersOnPage(currentPage); + servers.push(...serversResponse.data); + if (serversResponse.meta.pagination.total_pages > currentPage) { + currentPage++; + } else { + break; + } + } + } catch (error) { + console.error("Failed to fetch server list:", error); + } for (const server of servers) { const serverId = server.attributes.identifier; @@ -222,7 +240,6 @@ module.exports.load = function (app, db) { if (settings.anti_pteroVM.enabled == true) { setInterval(scanServers, scanInterval); - scanServers(); } else { console.log(" ");