mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-11 08:22:05 +02:00
Filter out disabled
This commit is contained in:
@@ -496,6 +496,7 @@ export function generateRemoteSubnets(
|
|||||||
): string[] {
|
): string[] {
|
||||||
const remoteSubnets = allSiteResources
|
const remoteSubnets = allSiteResources
|
||||||
.filter((sr) => {
|
.filter((sr) => {
|
||||||
|
if (!sr.enabled) return false;
|
||||||
if (!sr.destination) return false;
|
if (!sr.destination) return false;
|
||||||
|
|
||||||
if (sr.mode === "cidr") {
|
if (sr.mode === "cidr") {
|
||||||
@@ -530,6 +531,7 @@ export function generateAliasConfig(allSiteResources: SiteResource[]): Alias[] {
|
|||||||
return allSiteResources
|
return allSiteResources
|
||||||
.filter(
|
.filter(
|
||||||
(sr) =>
|
(sr) =>
|
||||||
|
sr.enabled &&
|
||||||
sr.aliasAddress &&
|
sr.aliasAddress &&
|
||||||
((sr.alias && (sr.mode == "host" || sr.mode == "ssh")) ||
|
((sr.alias && (sr.mode == "host" || sr.mode == "ssh")) ||
|
||||||
(sr.fullDomain && sr.mode == "http"))
|
(sr.fullDomain && sr.mode == "http"))
|
||||||
@@ -662,6 +664,13 @@ export async function generateSubnetProxyTargetV2(
|
|||||||
subnet: string | null;
|
subnet: string | null;
|
||||||
}[]
|
}[]
|
||||||
): Promise<SubnetProxyTargetV2[] | undefined> {
|
): Promise<SubnetProxyTargetV2[] | undefined> {
|
||||||
|
if (!siteResource.enabled) {
|
||||||
|
logger.debug(
|
||||||
|
`Site resource ${siteResource.siteResourceId} is disabled, skipping target generation.`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (clients.length === 0) {
|
if (clients.length === 0) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`No clients have access to site resource ${siteResource.siteResourceId}, skipping target generation.`
|
`No clients have access to site resource ${siteResource.siteResourceId}, skipping target generation.`
|
||||||
|
|||||||
@@ -1561,9 +1561,19 @@ export async function handleMessagingForUpdatedSiteResource(
|
|||||||
updatedSiteResource.udpPortRangeString ||
|
updatedSiteResource.udpPortRangeString ||
|
||||||
existingSiteResource.disableIcmp !==
|
existingSiteResource.disableIcmp !==
|
||||||
updatedSiteResource.disableIcmp);
|
updatedSiteResource.disableIcmp);
|
||||||
|
// Toggling enabled on/off doesn't change any of the fields above, but it
|
||||||
|
// does change whether targets/peer data should exist at all, so it needs
|
||||||
|
// to drive the same old->new diff machinery: going enabled->disabled
|
||||||
|
// diffs "real data" against "nothing" (a remove), and disabled->enabled
|
||||||
|
// diffs "nothing" against "real data" (an add). generateSubnetProxyTargetV2/
|
||||||
|
// generateRemoteSubnets/generateAliasConfig already return nothing for a
|
||||||
|
// disabled resource, so no other changes are needed here.
|
||||||
|
const enabledChanged =
|
||||||
|
existingSiteResource &&
|
||||||
|
existingSiteResource.enabled !== updatedSiteResource.enabled;
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`handleMessagingForUpdatedSiteResource: change flags destinationChanged=${Boolean(destinationChanged)} destinationPortChanged=${Boolean(destinationPortChanged)} aliasChanged=${Boolean(aliasChanged)} fullDomainChanged=${Boolean(fullDomainChanged)} sslChanged=${Boolean(sslChanged)} portRangesChanged=${Boolean(portRangesChanged)}`
|
`handleMessagingForUpdatedSiteResource: change flags destinationChanged=${Boolean(destinationChanged)} destinationPortChanged=${Boolean(destinationPortChanged)} aliasChanged=${Boolean(aliasChanged)} fullDomainChanged=${Boolean(fullDomainChanged)} sslChanged=${Boolean(sslChanged)} portRangesChanged=${Boolean(portRangesChanged)} enabledChanged=${Boolean(enabledChanged)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// if the existingSiteResource is undefined (new resource) we don't need to do anything here, the rebuild above handled it all
|
// if the existingSiteResource is undefined (new resource) we don't need to do anything here, the rebuild above handled it all
|
||||||
@@ -1574,14 +1584,16 @@ export async function handleMessagingForUpdatedSiteResource(
|
|||||||
fullDomainChanged ||
|
fullDomainChanged ||
|
||||||
sslChanged ||
|
sslChanged ||
|
||||||
portRangesChanged ||
|
portRangesChanged ||
|
||||||
destinationPortChanged
|
destinationPortChanged ||
|
||||||
|
enabledChanged
|
||||||
) {
|
) {
|
||||||
const shouldUpdateTargets =
|
const shouldUpdateTargets =
|
||||||
destinationChanged ||
|
destinationChanged ||
|
||||||
sslChanged ||
|
sslChanged ||
|
||||||
portRangesChanged ||
|
portRangesChanged ||
|
||||||
fullDomainChanged ||
|
fullDomainChanged ||
|
||||||
destinationPortChanged;
|
destinationPortChanged ||
|
||||||
|
enabledChanged;
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`handleMessagingForUpdatedSiteResource: entering unchanged-site update path shouldUpdateTargets=${shouldUpdateTargets}`
|
`handleMessagingForUpdatedSiteResource: entering unchanged-site update path shouldUpdateTargets=${shouldUpdateTargets}`
|
||||||
@@ -1657,9 +1669,11 @@ export async function handleMessagingForUpdatedSiteResource(
|
|||||||
peerDataUpdateBatch.push({
|
peerDataUpdateBatch.push({
|
||||||
clientId: client.clientId,
|
clientId: client.clientId,
|
||||||
siteId,
|
siteId,
|
||||||
remoteSubnets: destinationChanged
|
remoteSubnets:
|
||||||
|
destinationChanged || enabledChanged
|
||||||
? {
|
? {
|
||||||
oldRemoteSubnets: !oldDestinationStillInUseBySite
|
oldRemoteSubnets:
|
||||||
|
!oldDestinationStillInUseBySite
|
||||||
? generateRemoteSubnets([
|
? generateRemoteSubnets([
|
||||||
existingSiteResource
|
existingSiteResource
|
||||||
])
|
])
|
||||||
@@ -1670,7 +1684,7 @@ export async function handleMessagingForUpdatedSiteResource(
|
|||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
aliases:
|
aliases:
|
||||||
aliasChanged || fullDomainChanged // the full domain is sent down as an alias
|
aliasChanged || fullDomainChanged || enabledChanged // the full domain is sent down as an alias
|
||||||
? {
|
? {
|
||||||
oldAliases: generateAliasConfig([
|
oldAliases: generateAliasConfig([
|
||||||
existingSiteResource
|
existingSiteResource
|
||||||
|
|||||||
@@ -148,7 +148,12 @@ export async function buildClientConfigurationForNewtClient(
|
|||||||
.from(siteResources)
|
.from(siteResources)
|
||||||
.innerJoin(networks, eq(siteResources.networkId, networks.networkId))
|
.innerJoin(networks, eq(siteResources.networkId, networks.networkId))
|
||||||
.innerJoin(siteNetworks, eq(networks.networkId, siteNetworks.networkId))
|
.innerJoin(siteNetworks, eq(networks.networkId, siteNetworks.networkId))
|
||||||
.where(eq(siteNetworks.siteId, siteId))
|
.where(
|
||||||
|
and(
|
||||||
|
eq(siteNetworks.siteId, siteId),
|
||||||
|
eq(siteResources.enabled, true)
|
||||||
|
)
|
||||||
|
)
|
||||||
.then((rows) => rows.map((r) => r.siteResources));
|
.then((rows) => rows.map((r) => r.siteResources));
|
||||||
|
|
||||||
const targetsToSend: SubnetProxyTargetV2[] = [];
|
const targetsToSend: SubnetProxyTargetV2[] = [];
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
generateRemoteSubnets
|
generateRemoteSubnets
|
||||||
} from "@server/lib/ip";
|
} from "@server/lib/ip";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { eq, inArray } from "drizzle-orm";
|
import { and, eq, inArray } from "drizzle-orm";
|
||||||
import { addPeer, deletePeer } from "../newt/peers";
|
import { addPeer, deletePeer } from "../newt/peers";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
|
|
||||||
@@ -70,7 +70,13 @@ export async function buildSiteConfigurationForOlmClient(
|
|||||||
.innerJoin(networks, eq(siteResources.networkId, networks.networkId))
|
.innerJoin(networks, eq(siteResources.networkId, networks.networkId))
|
||||||
.innerJoin(siteNetworks, eq(networks.networkId, siteNetworks.networkId))
|
.innerJoin(siteNetworks, eq(networks.networkId, siteNetworks.networkId))
|
||||||
.where(
|
.where(
|
||||||
eq(clientSiteResourcesAssociationsCache.clientId, client.clientId)
|
and(
|
||||||
|
eq(
|
||||||
|
clientSiteResourcesAssociationsCache.clientId,
|
||||||
|
client.clientId
|
||||||
|
),
|
||||||
|
eq(siteResources.enabled, true)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const siteResourcesBySiteId = new Map<number, SiteResource[]>();
|
const siteResourcesBySiteId = new Map<number, SiteResource[]>();
|
||||||
|
|||||||
Reference in New Issue
Block a user