Skip to content

Commit

Permalink
Update antipterovm.js
Browse files Browse the repository at this point in the history
  • Loading branch information
privt00 authored Apr 15, 2024
1 parent c2733f0 commit 5d6b4f5
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions misc/antipterovm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -222,7 +240,6 @@ module.exports.load = function (app, db) {

if (settings.anti_pteroVM.enabled == true) {
setInterval(scanServers, scanInterval);

scanServers();
} else {
console.log(" ");
Expand Down

0 comments on commit 5d6b4f5

Please sign in to comment.