mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-23 10:48:28 +02:00
Include get hostname, filter sites fix gerbil conf
This commit is contained in:
parent
8355d3664e
commit
3b8d1f40a7
8 changed files with 68 additions and 16 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -34,6 +34,10 @@ bin
|
||||||
.secrets
|
.secrets
|
||||||
test_event.json
|
test_event.json
|
||||||
.idea/
|
.idea/
|
||||||
|
public/branding
|
||||||
server/db/index.ts
|
server/db/index.ts
|
||||||
|
config/openapi.yaml
|
||||||
|
server/build.ts
|
||||||
|
postgres/
|
||||||
dynamic/
|
dynamic/
|
||||||
certificates/
|
certificates/
|
||||||
|
|
|
@ -22,8 +22,7 @@ services:
|
||||||
command:
|
command:
|
||||||
- --reachableAt=http://gerbil:3003
|
- --reachableAt=http://gerbil:3003
|
||||||
- --generateAndSaveKeyTo=/var/config/key
|
- --generateAndSaveKeyTo=/var/config/key
|
||||||
- --remoteConfig=http://pangolin:3001/api/v1/gerbil/get-config
|
- --remoteConfig=http://pangolin:3001/api/v1/
|
||||||
- --reportBandwidthTo=http://pangolin:3001/api/v1/gerbil/receive-bandwidth
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./config/:/var/config
|
- ./config/:/var/config
|
||||||
cap_add:
|
cap_add:
|
||||||
|
|
|
@ -22,8 +22,7 @@ services:
|
||||||
command:
|
command:
|
||||||
- --reachableAt=http://gerbil:3003
|
- --reachableAt=http://gerbil:3003
|
||||||
- --generateAndSaveKeyTo=/var/config/key
|
- --generateAndSaveKeyTo=/var/config/key
|
||||||
- --remoteConfig=http://pangolin:3001/api/v1/gerbil/get-config
|
- --remoteConfig=http://pangolin:3001/api/v1/
|
||||||
- --reportBandwidthTo=http://pangolin:3001/api/v1/gerbil/receive-bandwidth
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./config/:/var/config
|
- ./config/:/var/config
|
||||||
cap_add:
|
cap_add:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { db, exitNodes } from "@server/db";
|
import { db, exitNodes } from "@server/db";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { ExitNodePingResult } from "@server/routers/newt";
|
import { ExitNodePingResult } from "@server/routers/newt";
|
||||||
import { eq, and, or } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
|
||||||
export async function verifyExitNodeOrgAccess(
|
export async function verifyExitNodeOrgAccess(
|
||||||
exitNodeId: number,
|
exitNodeId: number,
|
||||||
|
@ -30,7 +30,7 @@ export async function listExitNodes(orgId: string, filterOnline = false) {
|
||||||
maxConnections: exitNodes.maxConnections,
|
maxConnections: exitNodes.maxConnections,
|
||||||
online: exitNodes.online,
|
online: exitNodes.online,
|
||||||
lastPing: exitNodes.lastPing,
|
lastPing: exitNodes.lastPing,
|
||||||
type: exitNodes.type,
|
type: exitNodes.type
|
||||||
})
|
})
|
||||||
.from(exitNodes);
|
.from(exitNodes);
|
||||||
|
|
||||||
|
@ -54,9 +54,6 @@ export function selectBestExitNode(
|
||||||
return pingResults[0];
|
return pingResults[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkExitNodeOrg(
|
export async function checkExitNodeOrg(exitNodeId: number, orgId: string) {
|
||||||
exitNodeId: number,
|
|
||||||
orgId: string
|
|
||||||
) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
46
server/routers/gerbil/getResolvedHostname.ts
Normal file
46
server/routers/gerbil/getResolvedHostname.ts
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { z } from "zod";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
|
||||||
|
// Define Zod schema for request validation
|
||||||
|
const getResolvedHostnameSchema = z.object({
|
||||||
|
hostname: z.string(),
|
||||||
|
publicKey: z.string()
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function getResolvedHostname(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
// Validate request parameters
|
||||||
|
const parsedParams = getResolvedHostnameSchema.safeParse(
|
||||||
|
req.body
|
||||||
|
);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the endpoints
|
||||||
|
return res.status(HttpCode.OK).send({
|
||||||
|
endpoints: [] // ALWAYS ROUTE LOCALLY
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"An error occurred..."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,3 +2,4 @@ export * from "./getConfig";
|
||||||
export * from "./receiveBandwidth";
|
export * from "./receiveBandwidth";
|
||||||
export * from "./updateHolePunch";
|
export * from "./updateHolePunch";
|
||||||
export * from "./getAllRelays";
|
export * from "./getAllRelays";
|
||||||
|
export * from "./getResolvedHostname";
|
|
@ -66,6 +66,10 @@ if (config.isHybridMode()) {
|
||||||
proxyToRemote(req, res, next, "hybrid/gerbil/get-all-relays")
|
proxyToRemote(req, res, next, "hybrid/gerbil/get-all-relays")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
gerbilRouter.post("/get-resolved-hostname", (req, res, next) =>
|
||||||
|
proxyToRemote(req, res, next, `hybrid/gerbil/get-resolved-hostname`)
|
||||||
|
);
|
||||||
|
|
||||||
// GET CONFIG IS HANDLED IN THE ORIGINAL HANDLER
|
// GET CONFIG IS HANDLED IN THE ORIGINAL HANDLER
|
||||||
// SO IT CAN REGISTER THE LOCAL EXIT NODE
|
// SO IT CAN REGISTER THE LOCAL EXIT NODE
|
||||||
} else {
|
} else {
|
||||||
|
@ -73,6 +77,7 @@ if (config.isHybridMode()) {
|
||||||
gerbilRouter.post("/receive-bandwidth", gerbil.receiveBandwidth);
|
gerbilRouter.post("/receive-bandwidth", gerbil.receiveBandwidth);
|
||||||
gerbilRouter.post("/update-hole-punch", gerbil.updateHolePunch);
|
gerbilRouter.post("/update-hole-punch", gerbil.updateHolePunch);
|
||||||
gerbilRouter.post("/get-all-relays", gerbil.getAllRelays);
|
gerbilRouter.post("/get-all-relays", gerbil.getAllRelays);
|
||||||
|
gerbilRouter.post("/get-resolved-hostname", gerbil.getResolvedHostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
// WE HANDLE THE PROXY INSIDE OF THIS FUNCTION
|
// WE HANDLE THE PROXY INSIDE OF THIS FUNCTION
|
||||||
|
|
|
@ -45,7 +45,7 @@ export async function traefikConfigProvider(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let traefikConfig = await getTraefikConfig(currentExitNodeId);
|
let traefikConfig = await getTraefikConfig(currentExitNodeId, ["newt", "local", "wireguard"]);
|
||||||
|
|
||||||
traefikConfig.http.middlewares[badgerMiddlewareName] = {
|
traefikConfig.http.middlewares[badgerMiddlewareName] = {
|
||||||
plugin: {
|
plugin: {
|
||||||
|
@ -80,7 +80,7 @@ export async function traefikConfigProvider(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getTraefikConfig(exitNodeId: number): Promise<any> {
|
export async function getTraefikConfig(exitNodeId: number, siteTypes: string[]): Promise<any> {
|
||||||
// Define extended target type with site information
|
// Define extended target type with site information
|
||||||
type TargetWithSite = Target & {
|
type TargetWithSite = Target & {
|
||||||
site: {
|
site: {
|
||||||
|
@ -135,6 +135,7 @@ export async function getTraefikConfig(exitNodeId: number): Promise<any> {
|
||||||
eq(sites.exitNodeId, exitNodeId),
|
eq(sites.exitNodeId, exitNodeId),
|
||||||
isNull(sites.exitNodeId)
|
isNull(sites.exitNodeId)
|
||||||
),
|
),
|
||||||
|
inArray(sites.type, siteTypes),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue