mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-17 11:06:30 +02:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f1999c5089 | |||
| 5d20956a0e | |||
| e5398d441e | |||
| d4138e2141 | |||
| 09d5d9082e | |||
| 5cb316f4e9 | |||
| 6b6c9cf4d8 | |||
| 05617c63c0 | |||
| d4c52bbf2f | |||
| 87f50bf0cc | |||
| 2c66da1b19 | |||
| ab19955502 | |||
| 1db9dcec81 | |||
| 49c2d3163e | |||
| 45b9e13a13 |
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM node:24-alpine
|
FROM node:26-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ services:
|
|||||||
- 80:80 # Port for traefik because of the network_mode
|
- 80:80 # Port for traefik because of the network_mode
|
||||||
|
|
||||||
traefik:
|
traefik:
|
||||||
image: traefik:v3.6
|
image: traefik:v3.7
|
||||||
container_name: traefik
|
container_name: traefik
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
network_mode: service:gerbil # Ports appear on the gerbil service
|
network_mode: service:gerbil # Ports appear on the gerbil service
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ services:
|
|||||||
- 80:80{{end}}
|
- 80:80{{end}}
|
||||||
|
|
||||||
traefik:
|
traefik:
|
||||||
image: docker.io/traefik:v3.6
|
image: docker.io/traefik:v3.7
|
||||||
container_name: traefik
|
container_name: traefik
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
{{if .InstallGerbil}}network_mode: service:gerbil # Ports appear on the gerbil service{{end}}{{if not .InstallGerbil}}
|
{{if .InstallGerbil}}network_mode: service:gerbil # Ports appear on the gerbil service{{end}}{{if not .InstallGerbil}}
|
||||||
|
|||||||
+1
-2
@@ -3811,6 +3811,5 @@
|
|||||||
"rdpUploadFailed": "Upload failed",
|
"rdpUploadFailed": "Upload failed",
|
||||||
"rdpUnicodeKeyboardMode": "Unicode keyboard mode",
|
"rdpUnicodeKeyboardMode": "Unicode keyboard mode",
|
||||||
"sessionToolbarShow": "Show toolbar",
|
"sessionToolbarShow": "Show toolbar",
|
||||||
"sessionToolbarHide": "Hide toolbar",
|
"sessionToolbarHide": "Hide toolbar"
|
||||||
"actionUpdateSiteApprovals": "Update Site Approvals"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,6 @@ export const sites = pgTable(
|
|||||||
lastPing: integer("lastPing"),
|
lastPing: integer("lastPing"),
|
||||||
address: varchar("address"),
|
address: varchar("address"),
|
||||||
endpoint: varchar("endpoint"),
|
endpoint: varchar("endpoint"),
|
||||||
localEndpoints: varchar("localEndpoints"), // JSON encoded list of string ips on the local machine to try to connect to
|
|
||||||
publicKey: varchar("publicKey"),
|
publicKey: varchar("publicKey"),
|
||||||
lastHolePunch: bigint("lastHolePunch", { mode: "number" }),
|
lastHolePunch: bigint("lastHolePunch", { mode: "number" }),
|
||||||
listenPort: integer("listenPort"),
|
listenPort: integer("listenPort"),
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ export const sites = sqliteTable("sites", {
|
|||||||
// exit node stuff that is how to connect to the site when it has a wg server
|
// exit node stuff that is how to connect to the site when it has a wg server
|
||||||
address: text("address"), // this is the address of the wireguard interface in newt
|
address: text("address"), // this is the address of the wireguard interface in newt
|
||||||
endpoint: text("endpoint"), // this is how to reach gerbil externally - gets put into the wireguard config
|
endpoint: text("endpoint"), // this is how to reach gerbil externally - gets put into the wireguard config
|
||||||
localEndpoints: text("localEndpoints"), // JSON encoded list of string ips on the local machine to try to connect to
|
|
||||||
publicKey: text("publicKey"), // TODO: Fix typo in publicKey
|
publicKey: text("publicKey"), // TODO: Fix typo in publicKey
|
||||||
lastHolePunch: integer("lastHolePunch"),
|
lastHolePunch: integer("lastHolePunch"),
|
||||||
listenPort: integer("listenPort"),
|
listenPort: integer("listenPort"),
|
||||||
|
|||||||
@@ -239,31 +239,6 @@ export async function updatePrivateResources(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resourceData.alias) {
|
|
||||||
const [aliasConflict] = await trx
|
|
||||||
.select({
|
|
||||||
siteResourceId: siteResources.siteResourceId
|
|
||||||
})
|
|
||||||
.from(siteResources)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(siteResources.orgId, orgId),
|
|
||||||
eq(siteResources.alias, resourceData.alias),
|
|
||||||
ne(
|
|
||||||
siteResources.siteResourceId,
|
|
||||||
existingResource.siteResourceId
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (aliasConflict) {
|
|
||||||
throw new Error(
|
|
||||||
`Alias ${resourceData.alias} already in use by another site resource in org ${orgId}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update existing resource
|
// Update existing resource
|
||||||
const [updatedResource] = await trx
|
const [updatedResource] = await trx
|
||||||
.update(siteResources)
|
.update(siteResources)
|
||||||
@@ -505,27 +480,6 @@ export async function updatePrivateResources(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resourceData.alias) {
|
|
||||||
const [aliasConflict] = await trx
|
|
||||||
.select({
|
|
||||||
siteResourceId: siteResources.siteResourceId
|
|
||||||
})
|
|
||||||
.from(siteResources)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(siteResources.orgId, orgId),
|
|
||||||
eq(siteResources.alias, resourceData.alias)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (aliasConflict) {
|
|
||||||
throw new Error(
|
|
||||||
`Alias ${resourceData.alias} already in use by another site resource in org ${orgId}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const [network] = await trx
|
const [network] = await trx
|
||||||
.insert(networks)
|
.insert(networks)
|
||||||
.values({
|
.values({
|
||||||
|
|||||||
+18
-49
@@ -8,42 +8,26 @@ const STATUS_HISTORY_CACHE_TTL = 60; // seconds
|
|||||||
function statusHistoryCacheKey(
|
function statusHistoryCacheKey(
|
||||||
entityType: string,
|
entityType: string,
|
||||||
entityId: number,
|
entityId: number,
|
||||||
days: number,
|
days: number
|
||||||
tzOffsetMinutes: number
|
|
||||||
): string {
|
): string {
|
||||||
return `statusHistory:${entityType}:${entityId}:${days}:${tzOffsetMinutes}`;
|
return `statusHistory:${entityType}:${entityId}:${days}`;
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the epoch seconds of the most recent local-calendar-day midnight,
|
|
||||||
// where "local" is defined by tzOffsetMinutes (minutes to ADD to UTC to get
|
|
||||||
// local time, e.g. Australia/Sydney standard time is 600). Defaults to 0
|
|
||||||
// (UTC) so callers that don't pass a timezone keep the original behavior.
|
|
||||||
function localMidnightSec(tzOffsetMinutes: number): number {
|
|
||||||
const localNow = new Date(Date.now() + tzOffsetMinutes * 60_000);
|
|
||||||
localNow.setUTCHours(0, 0, 0, 0);
|
|
||||||
return Math.floor(localNow.getTime() / 1000) - tzOffsetMinutes * 60;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCachedStatusHistory(
|
export async function getCachedStatusHistory(
|
||||||
entityType: string,
|
entityType: string,
|
||||||
entityId: number,
|
entityId: number,
|
||||||
days: number,
|
days: number
|
||||||
tzOffsetMinutes: number = 0
|
|
||||||
): Promise<StatusHistoryResponse> {
|
): Promise<StatusHistoryResponse> {
|
||||||
const cacheKey = statusHistoryCacheKey(
|
const cacheKey = statusHistoryCacheKey(entityType, entityId, days);
|
||||||
entityType,
|
|
||||||
entityId,
|
|
||||||
days,
|
|
||||||
tzOffsetMinutes
|
|
||||||
);
|
|
||||||
const cached = await cache.get<StatusHistoryResponse>(cacheKey);
|
const cached = await cache.get<StatusHistoryResponse>(cacheKey);
|
||||||
if (cached !== undefined) {
|
if (cached !== undefined) {
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Anchor to local midnight (UTC when tzOffsetMinutes is 0) so the query
|
// Anchor to UTC midnight so the query window aligns with stable calendar days
|
||||||
// window aligns with stable calendar days for the requesting client
|
const utcToday = new Date();
|
||||||
const todayMidnightSec = localMidnightSec(tzOffsetMinutes);
|
utcToday.setUTCHours(0, 0, 0, 0);
|
||||||
|
const todayMidnightSec = Math.floor(utcToday.getTime() / 1000);
|
||||||
const startSec = todayMidnightSec - days * 86400;
|
const startSec = todayMidnightSec - days * 86400;
|
||||||
|
|
||||||
const events = await logsDb
|
const events = await logsDb
|
||||||
@@ -79,8 +63,7 @@ export async function getCachedStatusHistory(
|
|||||||
const { buckets, totalDowntime } = computeBuckets(
|
const { buckets, totalDowntime } = computeBuckets(
|
||||||
events,
|
events,
|
||||||
days,
|
days,
|
||||||
priorStatus,
|
priorStatus
|
||||||
tzOffsetMinutes
|
|
||||||
);
|
);
|
||||||
const totalWindow = days * 86400;
|
const totalWindow = days * 86400;
|
||||||
const overallUptime =
|
const overallUptime =
|
||||||
@@ -116,19 +99,11 @@ export const statusHistoryQuerySchema = z
|
|||||||
days: z
|
days: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.transform((v) => (v ? parseInt(v, 10) : 90)),
|
.transform((v) => (v ? parseInt(v, 10) : 90))
|
||||||
// Minutes to add to UTC to get the requesting client's local time
|
|
||||||
// (e.g. Australia/Sydney standard time is 600). Optional and
|
|
||||||
// defaults to 0 (UTC) so older clients keep the prior behavior.
|
|
||||||
tzOffsetMinutes: z
|
|
||||||
.string()
|
|
||||||
.optional()
|
|
||||||
.transform((v) => (v ? parseInt(v, 10) : 0))
|
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
z.object({
|
z.object({
|
||||||
days: z.number().int().min(1).max(365),
|
days: z.number().int().min(1).max(365)
|
||||||
tzOffsetMinutes: z.number().int().min(-720).max(840)
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -158,15 +133,15 @@ export function computeBuckets(
|
|||||||
id: number;
|
id: number;
|
||||||
}[],
|
}[],
|
||||||
days: number,
|
days: number,
|
||||||
priorStatus: string | null = null,
|
priorStatus: string | null = null
|
||||||
tzOffsetMinutes: number = 0
|
|
||||||
): { buckets: StatusHistoryDayBucket[]; totalDowntime: number } {
|
): { buckets: StatusHistoryDayBucket[]; totalDowntime: number } {
|
||||||
const nowSec = Math.floor(Date.now() / 1000);
|
const nowSec = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
// Anchor bucket boundaries to local midnight (UTC when tzOffsetMinutes is
|
// Anchor bucket boundaries to UTC midnight so dates are stable calendar days
|
||||||
// 0) so dates are stable calendar days for the requesting client and
|
// and don't drift as the cache expires and is recomputed
|
||||||
// don't drift as the cache expires and is recomputed
|
const utcToday = new Date();
|
||||||
const todayMidnightSec = localMidnightSec(tzOffsetMinutes);
|
utcToday.setUTCHours(0, 0, 0, 0);
|
||||||
|
const todayMidnightSec = Math.floor(utcToday.getTime() / 1000);
|
||||||
|
|
||||||
const buckets: StatusHistoryDayBucket[] = [];
|
const buckets: StatusHistoryDayBucket[] = [];
|
||||||
let totalDowntime = 0;
|
let totalDowntime = 0;
|
||||||
@@ -262,13 +237,7 @@ export function computeBuckets(
|
|||||||
)
|
)
|
||||||
: 100;
|
: 100;
|
||||||
|
|
||||||
// Shift by the client's offset before formatting so the label reflects
|
const dateStr = new Date(dayStartSec * 1000).toISOString().slice(0, 10);
|
||||||
// their local calendar date rather than the UTC date of dayStartSec
|
|
||||||
const dateStr = new Date(
|
|
||||||
(dayStartSec + tzOffsetMinutes * 60) * 1000
|
|
||||||
)
|
|
||||||
.toISOString()
|
|
||||||
.slice(0, 10);
|
|
||||||
|
|
||||||
const hasAnyData = currentStatus !== null || dayEvents.length > 0;
|
const hasAnyData = currentStatus !== null || dayEvents.length > 0;
|
||||||
|
|
||||||
|
|||||||
@@ -55,14 +55,9 @@ export async function getHealthCheckStatusHistory(
|
|||||||
|
|
||||||
const entityType = "health_check";
|
const entityType = "health_check";
|
||||||
const entityId = parsedParams.data.healthCheckId;
|
const entityId = parsedParams.data.healthCheckId;
|
||||||
const { days, tzOffsetMinutes } = parsedQuery.data;
|
const { days } = parsedQuery.data;
|
||||||
|
|
||||||
const data = await getCachedStatusHistory(
|
const data = await getCachedStatusHistory(entityType, entityId, days);
|
||||||
entityType,
|
|
||||||
entityId,
|
|
||||||
days,
|
|
||||||
tzOffsetMinutes
|
|
||||||
);
|
|
||||||
|
|
||||||
return response<StatusHistoryResponse>(res, {
|
return response<StatusHistoryResponse>(res, {
|
||||||
data,
|
data,
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export const handleNewtGetConfigMessage: MessageHandler = async (context) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { publicKey, port, localEndpoints, chainId } = message.data;
|
const { publicKey, port, chainId } = message.data;
|
||||||
const siteId = newt.siteId;
|
const siteId = newt.siteId;
|
||||||
|
|
||||||
// Get the current site data
|
// Get the current site data
|
||||||
@@ -69,10 +69,7 @@ export const handleNewtGetConfigMessage: MessageHandler = async (context) => {
|
|||||||
.update(sites)
|
.update(sites)
|
||||||
.set({
|
.set({
|
||||||
publicKey,
|
publicKey,
|
||||||
listenPort: port,
|
listenPort: port
|
||||||
localEndpoints: localEndpoints
|
|
||||||
? JSON.stringify(localEndpoints)
|
|
||||||
: null
|
|
||||||
})
|
})
|
||||||
.where(eq(sites.siteId, siteId))
|
.where(eq(sites.siteId, siteId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ export async function buildSiteConfigurationForOlmClient(
|
|||||||
siteId: number;
|
siteId: number;
|
||||||
name?: string;
|
name?: string;
|
||||||
endpoint?: string;
|
endpoint?: string;
|
||||||
localEndpoints?: string[];
|
|
||||||
publicKey?: string;
|
publicKey?: string;
|
||||||
serverIP?: string | null;
|
serverIP?: string | null;
|
||||||
serverPort?: number | null;
|
serverPort?: number | null;
|
||||||
@@ -207,9 +206,6 @@ export async function buildSiteConfigurationForOlmClient(
|
|||||||
name: site.name,
|
name: site.name,
|
||||||
// relayEndpoint: relayEndpoint, // this can be undefined now if not relayed // lets not do this for now because it would conflict with the hole punch testing
|
// relayEndpoint: relayEndpoint, // this can be undefined now if not relayed // lets not do this for now because it would conflict with the hole punch testing
|
||||||
endpoint: site.endpoint,
|
endpoint: site.endpoint,
|
||||||
localEndpoints: site.localEndpoints
|
|
||||||
? JSON.parse(site.localEndpoints)
|
|
||||||
: undefined,
|
|
||||||
publicKey: site.publicKey,
|
publicKey: site.publicKey,
|
||||||
serverIP: site.address,
|
serverIP: site.address,
|
||||||
serverPort: site.listenPort,
|
serverPort: site.listenPort,
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
import { db, sites } from "@server/db";
|
|
||||||
import { MessageHandler } from "@server/routers/ws";
|
|
||||||
import { clients, Olm } from "@server/db";
|
|
||||||
import { and, eq } from "drizzle-orm";
|
|
||||||
import { updatePeer as newtUpdatePeer } from "../newt/peers";
|
|
||||||
import logger from "@server/logger";
|
|
||||||
|
|
||||||
export const handleOlmLocalMessage: MessageHandler = async (context) => {
|
|
||||||
const { message, client: c, sendToClient } = context;
|
|
||||||
const olm = c as Olm;
|
|
||||||
|
|
||||||
logger.info("Handling local olm message!");
|
|
||||||
|
|
||||||
if (!olm) {
|
|
||||||
logger.warn("Olm not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!olm.clientId) {
|
|
||||||
logger.warn("Olm has no client!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const clientId = olm.clientId;
|
|
||||||
|
|
||||||
const [client] = await db
|
|
||||||
.select()
|
|
||||||
.from(clients)
|
|
||||||
.where(eq(clients.clientId, clientId))
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (!client) {
|
|
||||||
logger.warn("Client not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure we hand endpoints for both the site and the client and the lastHolePunch is not too old
|
|
||||||
if (!client.pubKey) {
|
|
||||||
logger.warn("Client has no endpoint or listen port");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { siteId, chainId } = message.data;
|
|
||||||
|
|
||||||
// Get the site
|
|
||||||
const [site] = await db
|
|
||||||
.select()
|
|
||||||
.from(sites)
|
|
||||||
.where(eq(sites.siteId, siteId))
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (!site || !site.exitNodeId) {
|
|
||||||
logger.warn("Site not found or has no exit node");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the peer on the newt
|
|
||||||
await newtUpdatePeer(siteId, client.pubKey, {
|
|
||||||
endpoint: "" // this removes the endpoint so the newt knows to accept local
|
|
||||||
});
|
|
||||||
|
|
||||||
// Just ack the message, we don't keep sending it
|
|
||||||
return {
|
|
||||||
message: {
|
|
||||||
type: "olm/wg/peer/local",
|
|
||||||
data: {
|
|
||||||
siteId: siteId,
|
|
||||||
chainId
|
|
||||||
}
|
|
||||||
},
|
|
||||||
broadcast: false,
|
|
||||||
excludeSender: false
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -79,9 +79,9 @@ export const handleOlmRelayMessage: MessageHandler = async (context) => {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// update the peer on the newt
|
// update the peer on the exit node
|
||||||
await newtUpdatePeer(siteId, client.pubKey, {
|
await newtUpdatePeer(siteId, client.pubKey, {
|
||||||
endpoint: "" // this removes the endpoint so the newt knows to relay
|
endpoint: "" // this removes the endpoint so the exit node knows to relay
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -3,15 +3,24 @@ import {
|
|||||||
db,
|
db,
|
||||||
networks,
|
networks,
|
||||||
siteNetworks,
|
siteNetworks,
|
||||||
siteResources
|
siteResources,
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import { MessageHandler } from "@server/routers/ws";
|
import { MessageHandler } from "@server/routers/ws";
|
||||||
import { clients, clientSitesAssociationsCache, Olm, sites } from "@server/db";
|
import {
|
||||||
|
clients,
|
||||||
|
clientSitesAssociationsCache,
|
||||||
|
Olm,
|
||||||
|
sites
|
||||||
|
} from "@server/db";
|
||||||
import { and, eq, inArray, isNotNull, isNull } from "drizzle-orm";
|
import { and, eq, inArray, isNotNull, isNull } from "drizzle-orm";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { generateAliasConfig } from "@server/lib/ip";
|
import {
|
||||||
|
generateAliasConfig,
|
||||||
|
} from "@server/lib/ip";
|
||||||
import { generateRemoteSubnets } from "@server/lib/ip";
|
import { generateRemoteSubnets } from "@server/lib/ip";
|
||||||
import { addPeer as newtAddPeer } from "@server/routers/newt/peers";
|
import {
|
||||||
|
addPeer as newtAddPeer,
|
||||||
|
} from "@server/routers/newt/peers";
|
||||||
|
|
||||||
export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
||||||
context
|
context
|
||||||
@@ -126,7 +135,10 @@ export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
|||||||
clientSiteResourcesAssociationsCache.siteResourceId
|
clientSiteResourcesAssociationsCache.siteResourceId
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.innerJoin(networks, eq(siteResources.networkId, networks.networkId))
|
.innerJoin(
|
||||||
|
networks,
|
||||||
|
eq(siteResources.networkId, networks.networkId)
|
||||||
|
)
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
siteNetworks,
|
siteNetworks,
|
||||||
and(
|
and(
|
||||||
@@ -135,7 +147,10 @@ export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.where(
|
.where(
|
||||||
eq(clientSiteResourcesAssociationsCache.clientId, client.clientId)
|
eq(
|
||||||
|
clientSiteResourcesAssociationsCache.clientId,
|
||||||
|
client.clientId
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Return connect message with all site configurations
|
// Return connect message with all site configurations
|
||||||
@@ -146,9 +161,6 @@ export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
|||||||
siteId: site.siteId,
|
siteId: site.siteId,
|
||||||
name: site.name,
|
name: site.name,
|
||||||
endpoint: site.endpoint,
|
endpoint: site.endpoint,
|
||||||
localEndpoints: site.localEndpoints
|
|
||||||
? JSON.parse(site.localEndpoints)
|
|
||||||
: undefined,
|
|
||||||
publicKey: site.publicKey,
|
publicKey: site.publicKey,
|
||||||
serverIP: site.address,
|
serverIP: site.address,
|
||||||
serverPort: site.listenPort,
|
serverPort: site.listenPort,
|
||||||
@@ -158,7 +170,7 @@ export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
|||||||
aliases: generateAliasConfig(
|
aliases: generateAliasConfig(
|
||||||
allSiteResources.map(({ siteResources }) => siteResources)
|
allSiteResources.map(({ siteResources }) => siteResources)
|
||||||
),
|
),
|
||||||
chainId: chainId
|
chainId: chainId,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
broadcast: false,
|
broadcast: false,
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
import { db, exitNodes, sites } from "@server/db";
|
|
||||||
import { MessageHandler } from "@server/routers/ws";
|
|
||||||
import { clients, clientSitesAssociationsCache, Olm } from "@server/db";
|
|
||||||
import { and, eq } from "drizzle-orm";
|
|
||||||
import { updatePeer as newtUpdatePeer } from "../newt/peers";
|
|
||||||
import logger from "@server/logger";
|
|
||||||
|
|
||||||
export const handleOlmUnLocalMessage: MessageHandler = async (context) => {
|
|
||||||
const { message, client: c, sendToClient } = context;
|
|
||||||
const olm = c as Olm;
|
|
||||||
|
|
||||||
logger.info("Handling unlocal olm message!");
|
|
||||||
|
|
||||||
if (!olm) {
|
|
||||||
logger.warn("Olm not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!olm.clientId) {
|
|
||||||
logger.warn("Olm has no client!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const clientId = olm.clientId;
|
|
||||||
|
|
||||||
const [client] = await db
|
|
||||||
.select()
|
|
||||||
.from(clients)
|
|
||||||
.where(eq(clients.clientId, clientId))
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (!client) {
|
|
||||||
logger.warn("Client not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure we hand endpoints for both the site and the client and the lastHolePunch is not too old
|
|
||||||
if (!client.pubKey) {
|
|
||||||
logger.warn("Client has no endpoint or listen port");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { siteId, chainId } = message.data;
|
|
||||||
|
|
||||||
// Get the site
|
|
||||||
const [site] = await db
|
|
||||||
.select()
|
|
||||||
.from(sites)
|
|
||||||
.where(eq(sites.siteId, siteId))
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (!site) {
|
|
||||||
logger.warn("Site not found or has no exit node");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [clientSiteAssociation] = await db
|
|
||||||
.select()
|
|
||||||
.from(clientSitesAssociationsCache)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(clientSitesAssociationsCache.clientId, olm.clientId),
|
|
||||||
eq(clientSitesAssociationsCache.siteId, siteId)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!clientSiteAssociation) {
|
|
||||||
logger.warn("Client-Site association not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientSiteAssociation.endpoint) {
|
|
||||||
logger.warn("Client-Site association has no endpoint, cannot unrelay");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the peer on the newt
|
|
||||||
await newtUpdatePeer(siteId, client.pubKey, {
|
|
||||||
endpoint: clientSiteAssociation.isRelayed
|
|
||||||
? ""
|
|
||||||
: clientSiteAssociation.endpoint // this is the endpoint of the client to connect directly to the newt
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
message: {
|
|
||||||
type: "olm/wg/peer/unlocal",
|
|
||||||
data: {
|
|
||||||
siteId: siteId,
|
|
||||||
chainId
|
|
||||||
}
|
|
||||||
},
|
|
||||||
broadcast: false,
|
|
||||||
excludeSender: false
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -77,9 +77,9 @@ export const handleOlmUnRelayMessage: MessageHandler = async (context) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the peer on the newt
|
// update the peer on the exit node
|
||||||
await newtUpdatePeer(siteId, client.pubKey, {
|
await newtUpdatePeer(siteId, client.pubKey, {
|
||||||
endpoint: clientSiteAssociation.endpoint // this is the endpoint of the client to connect directly to the newt
|
endpoint: clientSiteAssociation.endpoint // this is the endpoint of the client to connect directly to the exit node
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -13,5 +13,3 @@ export * from "./recoverOlmWithFingerprint";
|
|||||||
export * from "./handleOlmDisconnectingMessage";
|
export * from "./handleOlmDisconnectingMessage";
|
||||||
export * from "./handleOlmServerInitAddPeerHandshake";
|
export * from "./handleOlmServerInitAddPeerHandshake";
|
||||||
export * from "./offlineChecker";
|
export * from "./offlineChecker";
|
||||||
export * from "./handleOlmUnLocalMessage";
|
|
||||||
export * from "./handleOlmLocalMessage";
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ export async function addPeer(
|
|||||||
serverPort: number | null;
|
serverPort: number | null;
|
||||||
remoteSubnets: string[] | null; // optional, comma-separated list of subnets that this site can access
|
remoteSubnets: string[] | null; // optional, comma-separated list of subnets that this site can access
|
||||||
aliases: Alias[];
|
aliases: Alias[];
|
||||||
localEndpoints?: string[]; // optional, list of local endpoints for the peer
|
|
||||||
},
|
},
|
||||||
olmId?: string,
|
olmId?: string,
|
||||||
version?: string | null
|
version?: string | null
|
||||||
@@ -45,7 +44,6 @@ export async function addPeer(
|
|||||||
name: peer.name,
|
name: peer.name,
|
||||||
publicKey: peer.publicKey,
|
publicKey: peer.publicKey,
|
||||||
endpoint: peer.endpoint,
|
endpoint: peer.endpoint,
|
||||||
localEndpoints: peer.localEndpoints,
|
|
||||||
relayEndpoint: peer.relayEndpoint,
|
relayEndpoint: peer.relayEndpoint,
|
||||||
serverIP: peer.serverIP,
|
serverIP: peer.serverIP,
|
||||||
serverPort: peer.serverPort,
|
serverPort: peer.serverPort,
|
||||||
|
|||||||
@@ -42,14 +42,9 @@ export async function getResourceStatusHistory(
|
|||||||
|
|
||||||
const entityType = "resource";
|
const entityType = "resource";
|
||||||
const entityId = parsedParams.data.resourceId;
|
const entityId = parsedParams.data.resourceId;
|
||||||
const { days, tzOffsetMinutes } = parsedQuery.data;
|
const { days } = parsedQuery.data;
|
||||||
|
|
||||||
const data = await getCachedStatusHistory(
|
const data = await getCachedStatusHistory(entityType, entityId, days);
|
||||||
entityType,
|
|
||||||
entityId,
|
|
||||||
days,
|
|
||||||
tzOffsetMinutes
|
|
||||||
);
|
|
||||||
|
|
||||||
return response<StatusHistoryResponse>(res, {
|
return response<StatusHistoryResponse>(res, {
|
||||||
data,
|
data,
|
||||||
|
|||||||
@@ -42,14 +42,9 @@ export async function getSiteStatusHistory(
|
|||||||
|
|
||||||
const entityType = "site";
|
const entityType = "site";
|
||||||
const entityId = parsedParams.data.siteId;
|
const entityId = parsedParams.data.siteId;
|
||||||
const { days, tzOffsetMinutes } = parsedQuery.data;
|
const { days } = parsedQuery.data;
|
||||||
|
|
||||||
const data = await getCachedStatusHistory(
|
const data = await getCachedStatusHistory(entityType, entityId, days);
|
||||||
entityType,
|
|
||||||
entityId,
|
|
||||||
days,
|
|
||||||
tzOffsetMinutes
|
|
||||||
);
|
|
||||||
|
|
||||||
return response<StatusHistoryResponse>(res, {
|
return response<StatusHistoryResponse>(res, {
|
||||||
data,
|
data,
|
||||||
|
|||||||
@@ -20,9 +20,7 @@ import {
|
|||||||
handleOlmServerPeerAddMessage,
|
handleOlmServerPeerAddMessage,
|
||||||
handleOlmUnRelayMessage,
|
handleOlmUnRelayMessage,
|
||||||
handleOlmDisconnectingMessage,
|
handleOlmDisconnectingMessage,
|
||||||
handleOlmServerInitAddPeerHandshake,
|
handleOlmServerInitAddPeerHandshake
|
||||||
handleOlmLocalMessage,
|
|
||||||
handleOlmUnLocalMessage
|
|
||||||
} from "../olm";
|
} from "../olm";
|
||||||
import { handleHealthcheckStatusMessage } from "../target";
|
import { handleHealthcheckStatusMessage } from "../target";
|
||||||
import { handleRoundTripMessage } from "./handleRoundTripMessage";
|
import { handleRoundTripMessage } from "./handleRoundTripMessage";
|
||||||
@@ -34,8 +32,6 @@ export const messageHandlers: Record<string, MessageHandler> = {
|
|||||||
"olm/wg/register": handleOlmRegisterMessage,
|
"olm/wg/register": handleOlmRegisterMessage,
|
||||||
"olm/wg/relay": handleOlmRelayMessage,
|
"olm/wg/relay": handleOlmRelayMessage,
|
||||||
"olm/wg/unrelay": handleOlmUnRelayMessage,
|
"olm/wg/unrelay": handleOlmUnRelayMessage,
|
||||||
"olm/wg/local": handleOlmLocalMessage,
|
|
||||||
"olm/wg/unlocal": handleOlmUnLocalMessage,
|
|
||||||
"olm/ping": handleOlmPingMessage,
|
"olm/ping": handleOlmPingMessage,
|
||||||
"olm/disconnecting": handleOlmDisconnectingMessage,
|
"olm/disconnecting": handleOlmDisconnectingMessage,
|
||||||
"newt/disconnecting": handleNewtDisconnectingMessage,
|
"newt/disconnecting": handleNewtDisconnectingMessage,
|
||||||
|
|||||||
+5
-12
@@ -650,13 +650,9 @@ export const orgQueries = {
|
|||||||
queryOptions({
|
queryOptions({
|
||||||
queryKey: ["SITE_STATUS_HISTORY", siteId, days] as const,
|
queryKey: ["SITE_STATUS_HISTORY", siteId, days] as const,
|
||||||
queryFn: async ({ signal, meta }) => {
|
queryFn: async ({ signal, meta }) => {
|
||||||
const tzOffsetMinutes = -new Date().getTimezoneOffset();
|
|
||||||
const res = await meta!.api.get<
|
const res = await meta!.api.get<
|
||||||
AxiosResponse<StatusHistoryResponse>
|
AxiosResponse<StatusHistoryResponse>
|
||||||
>(
|
>(`/site/${siteId}/status-history?days=${days}`, { signal });
|
||||||
`/site/${siteId}/status-history?days=${days}&tzOffsetMinutes=${tzOffsetMinutes}`,
|
|
||||||
{ signal }
|
|
||||||
);
|
|
||||||
return res.data.data;
|
return res.data.data;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -671,13 +667,11 @@ export const orgQueries = {
|
|||||||
queryOptions({
|
queryOptions({
|
||||||
queryKey: ["RESOURCE_STATUS_HISTORY", resourceId, days] as const,
|
queryKey: ["RESOURCE_STATUS_HISTORY", resourceId, days] as const,
|
||||||
queryFn: async ({ signal, meta }) => {
|
queryFn: async ({ signal, meta }) => {
|
||||||
const tzOffsetMinutes = -new Date().getTimezoneOffset();
|
|
||||||
const res = await meta!.api.get<
|
const res = await meta!.api.get<
|
||||||
AxiosResponse<StatusHistoryResponse>
|
AxiosResponse<StatusHistoryResponse>
|
||||||
>(
|
>(`/resource/${resourceId}/status-history?days=${days}`, {
|
||||||
`/resource/${resourceId}/status-history?days=${days}&tzOffsetMinutes=${tzOffsetMinutes}`,
|
signal
|
||||||
{ signal }
|
});
|
||||||
);
|
|
||||||
return res.data.data;
|
return res.data.data;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -699,11 +693,10 @@ export const orgQueries = {
|
|||||||
days
|
days
|
||||||
] as const,
|
] as const,
|
||||||
queryFn: async ({ signal, meta }) => {
|
queryFn: async ({ signal, meta }) => {
|
||||||
const tzOffsetMinutes = -new Date().getTimezoneOffset();
|
|
||||||
const res = await meta!.api.get<
|
const res = await meta!.api.get<
|
||||||
AxiosResponse<StatusHistoryResponse>
|
AxiosResponse<StatusHistoryResponse>
|
||||||
>(
|
>(
|
||||||
`/org/${orgId}/health-check/${healthCheckId}/status-history?days=${days}&tzOffsetMinutes=${tzOffsetMinutes}`,
|
`/org/${orgId}/health-check/${healthCheckId}/status-history?days=${days}`,
|
||||||
{ signal }
|
{ signal }
|
||||||
);
|
);
|
||||||
return res.data.data;
|
return res.data.data;
|
||||||
|
|||||||
Reference in New Issue
Block a user