mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-04 01:36:39 +00:00
show IP of the server inside DNS records
This commit is contained in:
@@ -20,7 +20,7 @@ import { initTelemetryClient } from "./lib/telemetry.js";
|
|||||||
import { TraefikConfigManager } from "./lib/traefik/TraefikConfigManager.js";
|
import { TraefikConfigManager } from "./lib/traefik/TraefikConfigManager.js";
|
||||||
import { initCleanup } from "#dynamic/cleanup";
|
import { initCleanup } from "#dynamic/cleanup";
|
||||||
import license from "#dynamic/license/license";
|
import license from "#dynamic/license/license";
|
||||||
|
import { fetchServerIp } from "./lib/serverIpService.js";
|
||||||
async function startServers() {
|
async function startServers() {
|
||||||
await setHostMeta();
|
await setHostMeta();
|
||||||
|
|
||||||
@@ -31,6 +31,8 @@ async function startServers() {
|
|||||||
|
|
||||||
await runSetupFunctions();
|
await runSetupFunctions();
|
||||||
|
|
||||||
|
await fetchServerIp();
|
||||||
|
|
||||||
initTelemetryClient();
|
initTelemetryClient();
|
||||||
|
|
||||||
// Start all servers
|
// Start all servers
|
||||||
|
|||||||
28
server/lib/serverIpService.ts
Normal file
28
server/lib/serverIpService.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
let serverIp: string | null = null;
|
||||||
|
|
||||||
|
const services = [
|
||||||
|
"https://ifconfig.io/ip",
|
||||||
|
"https://api.ipify.org",
|
||||||
|
"https://checkip.amazonaws.com"
|
||||||
|
];
|
||||||
|
|
||||||
|
export async function fetchServerIp() {
|
||||||
|
for (const url of services) {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(url, { timeout: 5000 });
|
||||||
|
serverIp = response.data.trim();
|
||||||
|
console.log("Detected public IP:", serverIp);
|
||||||
|
return;
|
||||||
|
} catch (err: any) {
|
||||||
|
console.warn(`Failed to fetch server IP from ${url}: ${err.message || err.code}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error("All attempts to fetch server IP failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getServerIp() {
|
||||||
|
return serverIp;
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import createHttpError from "http-errors";
|
|||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
import { OpenAPITags, registry } from "@server/openApi";
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
|
import { getServerIp } from "@server/lib/serverIpService"; // your in-memory IP module
|
||||||
|
|
||||||
const getDNSRecordsSchema = z
|
const getDNSRecordsSchema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -70,8 +71,18 @@ export async function getDNSRecords(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const serverIp = getServerIp();
|
||||||
|
|
||||||
|
// Override value for type A or wildcard records
|
||||||
|
const updatedRecords = records.map(record => {
|
||||||
|
if ((record.recordType === "A" || record.baseDomain === "*") && serverIp) {
|
||||||
|
return { ...record, value: serverIp };
|
||||||
|
}
|
||||||
|
return record;
|
||||||
|
});
|
||||||
|
|
||||||
return response<GetDNSRecordsResponse>(res, {
|
return response<GetDNSRecordsResponse>(res, {
|
||||||
data: records,
|
data: updatedRecords,
|
||||||
success: true,
|
success: true,
|
||||||
error: false,
|
error: false,
|
||||||
message: "DNS records retrieved successfully",
|
message: "DNS records retrieved successfully",
|
||||||
|
|||||||
Reference in New Issue
Block a user