mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-28 13:48:13 +02:00
Merge branch 'main' into dev
This commit is contained in:
commit
55b4a9eddb
43 changed files with 898 additions and 346 deletions
|
@ -271,7 +271,7 @@ export async function getNextAvailableClientSubnet(
|
|||
)
|
||||
].filter((address) => address !== null) as string[];
|
||||
|
||||
let subnet = findNextAvailableCidr(addresses, 32, org.subnet); // pick the sites address in the org
|
||||
const subnet = findNextAvailableCidr(addresses, 32, org.subnet); // pick the sites address in the org
|
||||
if (!subnet) {
|
||||
throw new Error("No available subnets remaining in space");
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ export async function getNextAvailableOrgSubnet(): Promise<string> {
|
|||
|
||||
const addresses = existingAddresses.map((org) => org.subnet!);
|
||||
|
||||
let subnet = findNextAvailableCidr(
|
||||
const subnet = findNextAvailableCidr(
|
||||
addresses,
|
||||
config.getRawConfig().orgs.block_size,
|
||||
config.getRawConfig().orgs.subnet_group
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { MemoryStore, Store } from "express-rate-limit";
|
||||
|
||||
export function createStore(): Store {
|
||||
let rateLimitStore: Store = new MemoryStore();
|
||||
const rateLimitStore: Store = new MemoryStore();
|
||||
return rateLimitStore;
|
||||
}
|
||||
|
|
|
@ -222,7 +222,7 @@ export async function listAccessTokens(
|
|||
(resource) => resource.resourceId
|
||||
);
|
||||
|
||||
let countQuery: any = db
|
||||
const countQuery: any = db
|
||||
.select({ count: count() })
|
||||
.from(resources)
|
||||
.where(inArray(resources.resourceId, accessibleResourceIds));
|
||||
|
|
|
@ -48,7 +48,7 @@ export async function getAllRelays(
|
|||
}
|
||||
|
||||
// Fetch exit node
|
||||
let [exitNode] = await db.select().from(exitNodes).where(eq(exitNodes.publicKey, publicKey));
|
||||
const [exitNode] = await db.select().from(exitNodes).where(eq(exitNodes.publicKey, publicKey));
|
||||
if (!exitNode) {
|
||||
return next(createHttpError(HttpCode.NOT_FOUND, "Exit node not found"));
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ export async function getAllRelays(
|
|||
}
|
||||
|
||||
// Initialize mappings object for multi-peer support
|
||||
let mappings: { [key: string]: ProxyMapping } = {};
|
||||
const mappings: { [key: string]: ProxyMapping } = {};
|
||||
|
||||
// Process each site
|
||||
for (const site of sitesRes) {
|
||||
|
|
|
@ -112,7 +112,7 @@ export async function getConfig(
|
|||
)
|
||||
);
|
||||
|
||||
let peers = await Promise.all(
|
||||
const peers = await Promise.all(
|
||||
sitesRes.map(async (site) => {
|
||||
if (site.type === "wireguard") {
|
||||
return {
|
||||
|
|
|
@ -68,7 +68,7 @@ export async function createOidcIdp(
|
|||
);
|
||||
}
|
||||
|
||||
let {
|
||||
const {
|
||||
clientId,
|
||||
clientSecret,
|
||||
authUrl,
|
||||
|
|
|
@ -85,7 +85,7 @@ export async function updateOidcIdp(
|
|||
}
|
||||
|
||||
const { idpId } = parsedParams.data;
|
||||
let {
|
||||
const {
|
||||
clientId,
|
||||
clientSecret,
|
||||
authUrl,
|
||||
|
|
|
@ -238,7 +238,7 @@ export async function validateOidcCallback(
|
|||
const defaultRoleMapping = existingIdp.idp.defaultRoleMapping;
|
||||
const defaultOrgMapping = existingIdp.idp.defaultOrgMapping;
|
||||
|
||||
let userOrgInfo: { orgId: string; roleId: number }[] = [];
|
||||
const userOrgInfo: { orgId: string; roleId: number }[] = [];
|
||||
for (const org of allOrgs) {
|
||||
const [idpOrgRes] = await db
|
||||
.select()
|
||||
|
@ -314,7 +314,7 @@ export async function validateOidcCallback(
|
|||
|
||||
let existingUserId = existingUser?.userId;
|
||||
|
||||
let orgUserCounts: { orgId: string; userCount: number }[] = [];
|
||||
const orgUserCounts: { orgId: string; userCount: number }[] = [];
|
||||
|
||||
// sync the user with the orgs and roles
|
||||
await db.transaction(async (trx) => {
|
||||
|
|
|
@ -55,7 +55,7 @@ export const handleNewtPingRequestMessage: MessageHandler = async (context) => {
|
|||
);
|
||||
|
||||
if (currentConnections.count >= maxConnections) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
|
||||
weight =
|
||||
|
|
|
@ -37,7 +37,7 @@ export const startOfflineChecker = (): void => {
|
|||
}, OFFLINE_CHECK_INTERVAL);
|
||||
|
||||
logger.info("Started offline checker interval");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops the background interval that checks for offline clients
|
||||
|
@ -48,7 +48,7 @@ export const stopOfflineChecker = (): void => {
|
|||
offlineCheckerInterval = null;
|
||||
logger.info("Stopped offline checker interval");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles ping messages from clients and responds with pong
|
||||
|
|
|
@ -102,7 +102,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||
.where(eq(clientSites.clientId, client.clientId));
|
||||
|
||||
// Prepare an array to store site configurations
|
||||
let siteConfigurations = [];
|
||||
const siteConfigurations = [];
|
||||
logger.debug(`Found ${sitesData.length} sites for client ${client.clientId}`);
|
||||
|
||||
if (sitesData.length === 0) {
|
||||
|
|
|
@ -35,7 +35,7 @@ const listResourceRulesSchema = z.object({
|
|||
});
|
||||
|
||||
function queryResourceRules(resourceId: number) {
|
||||
let baseQuery = db
|
||||
const baseQuery = db
|
||||
.select({
|
||||
ruleId: resourceRules.ruleId,
|
||||
resourceId: resourceRules.resourceId,
|
||||
|
@ -117,7 +117,7 @@ export async function listResourceRules(
|
|||
|
||||
const baseQuery = queryResourceRules(resourceId);
|
||||
|
||||
let countQuery = db
|
||||
const countQuery = db
|
||||
.select({ count: sql<number>`cast(count(*) as integer)` })
|
||||
.from(resourceRules)
|
||||
.where(eq(resourceRules.resourceId, resourceId));
|
||||
|
|
|
@ -231,7 +231,7 @@ export async function listResources(
|
|||
(resource) => resource.resourceId
|
||||
);
|
||||
|
||||
let countQuery: any = db
|
||||
const countQuery: any = db
|
||||
.select({ count: count() })
|
||||
.from(resources)
|
||||
.where(inArray(resources.resourceId, accessibleResourceIds));
|
||||
|
|
|
@ -100,7 +100,7 @@ export async function listRoles(
|
|||
|
||||
const { orgId } = parsedParams.data;
|
||||
|
||||
let countQuery: any = db
|
||||
const countQuery: any = db
|
||||
.select({ count: sql<number>`cast(count(*) as integer)` })
|
||||
.from(roles)
|
||||
.where(eq(roles.orgId, orgId));
|
||||
|
|
|
@ -176,7 +176,7 @@ export async function listSites(
|
|||
const accessibleSiteIds = accessibleSites.map((site) => site.siteId);
|
||||
const baseQuery = querySites(orgId, accessibleSiteIds);
|
||||
|
||||
let countQuery = db
|
||||
const countQuery = db
|
||||
.select({ count: count() })
|
||||
.from(sites)
|
||||
.where(
|
||||
|
|
|
@ -86,7 +86,7 @@ export async function pickSiteDefaults(
|
|||
.where(eq(sites.exitNodeId, exitNode.exitNodeId));
|
||||
|
||||
// TODO: we need to lock this subnet for some time so someone else does not take it
|
||||
let subnets = sitesQuery.map((site) => site.subnet).filter((subnet) => subnet !== null);
|
||||
const subnets = sitesQuery.map((site) => site.subnet).filter((subnet) => subnet !== null);
|
||||
// exclude the exit node address by replacing after the / with a site block size
|
||||
subnets.push(
|
||||
exitNode.address.replace(
|
||||
|
|
|
@ -2,7 +2,7 @@ import { db } from "@server/db";
|
|||
import { resources, targets } from "@server/db";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
let currentBannedPorts: number[] = [];
|
||||
const currentBannedPorts: number[] = [];
|
||||
|
||||
export async function pickPort(siteId: number): Promise<{
|
||||
internalPort: number;
|
||||
|
@ -15,8 +15,8 @@ export async function pickPort(siteId: number): Promise<{
|
|||
|
||||
// TODO: is this all inefficient?
|
||||
// Fetch targets for all resources of this site
|
||||
let targetIps: string[] = [];
|
||||
let targetInternalPorts: number[] = [];
|
||||
const targetIps: string[] = [];
|
||||
const targetInternalPorts: number[] = [];
|
||||
await Promise.all(
|
||||
resourcesRes.map(async (resource) => {
|
||||
const targetsRes = await db
|
||||
|
|
|
@ -35,7 +35,7 @@ const listTargetsSchema = z.object({
|
|||
});
|
||||
|
||||
function queryTargets(resourceId: number) {
|
||||
let baseQuery = db
|
||||
const baseQuery = db
|
||||
.select({
|
||||
targetId: targets.targetId,
|
||||
ip: targets.ip,
|
||||
|
@ -99,7 +99,7 @@ export async function listTargets(
|
|||
|
||||
const baseQuery = queryTargets(resourceId);
|
||||
|
||||
let countQuery = db
|
||||
const countQuery = db
|
||||
.select({ count: sql<number>`cast(count(*) as integer)` })
|
||||
.from(targets)
|
||||
.where(eq(targets.resourceId, resourceId));
|
||||
|
|
|
@ -62,7 +62,7 @@ const wss: WebSocketServer = new WebSocketServer({ noServer: true });
|
|||
const NODE_ID = uuidv4();
|
||||
|
||||
// Client tracking map (local to this node)
|
||||
let connectedClients: Map<string, AuthenticatedWebSocket[]> = new Map();
|
||||
const connectedClients: Map<string, AuthenticatedWebSocket[]> = new Map();
|
||||
// Helper to get map key
|
||||
const getClientMapKey = (clientId: string) => clientId;
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
if (rawConfig.server?.trust_proxy) {
|
||||
|
|
|
@ -23,8 +23,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
delete rawConfig.server.secure_cookies;
|
||||
|
|
|
@ -25,8 +25,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
if (!rawConfig.flags) {
|
||||
|
|
|
@ -30,8 +30,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
const baseDomain = rawConfig.app.base_domain;
|
||||
|
|
|
@ -22,8 +22,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
// Validate the structure
|
||||
|
|
|
@ -22,8 +22,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
// Validate the structure
|
||||
|
|
|
@ -25,8 +25,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
// Validate the structure
|
||||
|
|
|
@ -23,8 +23,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
// Validate the structure
|
||||
|
|
|
@ -58,8 +58,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
rawConfig.server.resource_session_request_param =
|
||||
|
@ -122,7 +122,7 @@ export default async function migration() {
|
|||
const traefikFileContents = fs.readFileSync(traefikPath, "utf8");
|
||||
const traefikConfig = yaml.load(traefikFileContents) as any;
|
||||
|
||||
let parsedConfig: any = schema.safeParse(traefikConfig);
|
||||
const parsedConfig: any = schema.safeParse(traefikConfig);
|
||||
|
||||
if (parsedConfig.success) {
|
||||
// Ensure websecure entrypoint exists
|
||||
|
@ -179,7 +179,7 @@ export default async function migration() {
|
|||
const traefikFileContents = fs.readFileSync(traefikPath, "utf8");
|
||||
const traefikConfig = yaml.load(traefikFileContents) as any;
|
||||
|
||||
let parsedConfig: any = schema.safeParse(traefikConfig);
|
||||
const parsedConfig: any = schema.safeParse(traefikConfig);
|
||||
|
||||
if (parsedConfig.success) {
|
||||
// delete permanent from redirect-to-https middleware
|
||||
|
|
|
@ -43,8 +43,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
if (!rawConfig.flags) {
|
||||
|
|
|
@ -177,7 +177,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any = yaml.load(fileContents);
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
if (!rawConfig.server.secret) {
|
||||
rawConfig.server.secret = generateIdFromEntropySize(32);
|
||||
|
|
|
@ -44,8 +44,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
if (rawConfig.cors?.headers) {
|
||||
|
|
|
@ -45,8 +45,8 @@ export default async function migration() {
|
|||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
let rawConfig: any;
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
if (rawConfig.server?.trust_proxy) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue