This commit is contained in:
Owen
2025-10-04 18:36:44 -07:00
parent 3123f858bb
commit c2c907852d
320 changed files with 35785 additions and 2984 deletions

View File

@@ -42,15 +42,15 @@ const createSiteSchema = z
address: z.string().optional(),
type: z.enum(["newt", "wireguard", "local"])
})
.strict()
.refine((data) => {
if (data.type === "local") {
return !config.getRawConfig().flags?.disable_local_sites;
} else if (data.type === "wireguard") {
return !config.getRawConfig().flags?.disable_basic_wireguard_sites;
}
return true;
});
.strict();
// .refine((data) => {
// if (data.type === "local") {
// return !config.getRawConfig().flags?.disable_local_sites;
// } else if (data.type === "wireguard") {
// return !config.getRawConfig().flags?.disable_basic_wireguard_sites;
// }
// return true;
// });
export type CreateSiteBody = z.infer<typeof createSiteSchema>;

View File

@@ -1,4 +1,4 @@
import { db, newts } from "@server/db";
import { db, exitNodes, newts } from "@server/db";
import { orgs, roleSites, sites, userSites } from "@server/db";
import logger from "@server/logger";
import HttpCode from "@server/types/HttpCode";
@@ -105,11 +105,15 @@ function querySites(orgId: string, accessibleSiteIds: number[]) {
type: sites.type,
online: sites.online,
address: sites.address,
newtVersion: newts.version
newtVersion: newts.version,
exitNodeId: sites.exitNodeId,
exitNodeName: exitNodes.name,
exitNodeEndpoint: exitNodes.endpoint
})
.from(sites)
.leftJoin(orgs, eq(sites.orgId, orgs.orgId))
.leftJoin(newts, eq(newts.siteId, sites.siteId))
.leftJoin(exitNodes, eq(exitNodes.exitNodeId, sites.exitNodeId))
.where(
and(
inArray(sites.siteId, accessibleSiteIds),

View File

@@ -74,6 +74,12 @@ export async function pickSiteDefaults(
const randomExitNode =
exitNodesList[Math.floor(Math.random() * exitNodesList.length)];
if (!randomExitNode) {
return next(
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "No available exit node")
);
}
// TODO: this probably can be optimized...
// list all of the sites on that exit node
const sitesQuery = await db
@@ -86,6 +92,7 @@ export async function pickSiteDefaults(
// TODO: we need to lock this subnet for some time so someone else does not take it
const subnets = sitesQuery
.map((site) => site.subnet)
.filter((subnet) => subnet && /^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/.test(subnet))
.filter((subnet) => subnet !== null);
// exclude the exit node address by replacing after the / with a site block size
subnets.push(