mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-01 16:26:39 +00:00
Merge branch 'dev' into feat/update-popup
This commit is contained in:
2
.github/workflows/cicd.yml
vendored
2
.github/workflows/cicd.yml
vendored
@@ -31,7 +31,7 @@ jobs:
|
|||||||
timeout-minutes: 120
|
timeout-minutes: 120
|
||||||
env:
|
env:
|
||||||
# Target images
|
# Target images
|
||||||
DOCKERHUB_IMAGE: docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/${{ github.event.repository.name }}
|
DOCKERHUB_IMAGE: docker.io/fosrl/${{ github.event.repository.name }}
|
||||||
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -2089,5 +2089,19 @@
|
|||||||
"supportSend": "Send",
|
"supportSend": "Send",
|
||||||
"supportMessageSent": "Message Sent!",
|
"supportMessageSent": "Message Sent!",
|
||||||
"supportWillContact": "We'll be in touch shortly!",
|
"supportWillContact": "We'll be in touch shortly!",
|
||||||
"selectLogRetention": "Select log retention"
|
"selectLogRetention": "Select log retention",
|
||||||
|
"showColumns": "Show Columns",
|
||||||
|
"hideColumns": "Hide Columns",
|
||||||
|
"columnVisibility": "Column Visibility",
|
||||||
|
"toggleColumn": "Toggle {columnName} column",
|
||||||
|
"allColumns": "All Columns",
|
||||||
|
"defaultColumns": "Default Columns",
|
||||||
|
"customizeView": "Customize View",
|
||||||
|
"viewOptions": "View Options",
|
||||||
|
"selectAll": "Select All",
|
||||||
|
"selectNone": "Select None",
|
||||||
|
"selectedResources": "Selected Resources",
|
||||||
|
"enableSelected": "Enable Selected",
|
||||||
|
"disableSelected": "Disable Selected",
|
||||||
|
"checkSelectedStatus": "Check Status of Selected"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import path from "path";
|
|||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
// This is a placeholder value replaced by the build process
|
// This is a placeholder value replaced by the build process
|
||||||
export const APP_VERSION = "1.12.0-rc.0";
|
export const APP_VERSION = "1.12.1";
|
||||||
|
|
||||||
export const __FILENAME = fileURLToPath(import.meta.url);
|
export const __FILENAME = fileURLToPath(import.meta.url);
|
||||||
export const __DIRNAME = path.dirname(__FILENAME);
|
export const __DIRNAME = path.dirname(__FILENAME);
|
||||||
|
|||||||
@@ -352,20 +352,38 @@ export async function validateOidcCallback(
|
|||||||
|
|
||||||
if (!userOrgInfo.length) {
|
if (!userOrgInfo.length) {
|
||||||
if (existingUser) {
|
if (existingUser) {
|
||||||
// delete the user
|
// get existing user orgs
|
||||||
// cascade will also delete org users
|
const existingUserOrgs = await db
|
||||||
|
.select()
|
||||||
|
.from(userOrgs)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userOrgs.userId, existingUser.userId),
|
||||||
|
eq(userOrgs.autoProvisioned, false)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
await db
|
if (!existingUserOrgs.length) {
|
||||||
.delete(users)
|
// delete the user
|
||||||
.where(eq(users.userId, existingUser.userId));
|
await db
|
||||||
|
.delete(users)
|
||||||
|
.where(eq(users.userId, existingUser.userId));
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.UNAUTHORIZED,
|
||||||
|
`No policies matched for ${userIdentifier}. This user must be added to an organization before logging in.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// no orgs to provision and user doesn't exist
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.UNAUTHORIZED,
|
||||||
|
`No policies matched for ${userIdentifier}. This user must be added to an organization before logging in.`
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return next(
|
|
||||||
createHttpError(
|
|
||||||
HttpCode.UNAUTHORIZED,
|
|
||||||
`No policies matched for ${userIdentifier}. This user must be added to an organization before logging in.`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const orgUserCounts: { orgId: string; userCount: number }[] = [];
|
const orgUserCounts: { orgId: string; userCount: number }[] = [];
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export async function updateOrg(
|
|||||||
const { orgId } = parsedParams.data;
|
const { orgId } = parsedParams.data;
|
||||||
|
|
||||||
const isLicensed = await isLicensedOrSubscribed(orgId);
|
const isLicensed = await isLicensedOrSubscribed(orgId);
|
||||||
if (!isLicensed) {
|
if (build == "enterprise" && !isLicensed) {
|
||||||
parsedBody.data.requireTwoFactor = undefined;
|
parsedBody.data.requireTwoFactor = undefined;
|
||||||
parsedBody.data.maxSessionLengthHours = undefined;
|
parsedBody.data.maxSessionLengthHours = undefined;
|
||||||
parsedBody.data.passwordExpiryDays = undefined;
|
parsedBody.data.passwordExpiryDays = undefined;
|
||||||
@@ -100,6 +100,7 @@ export async function updateOrg(
|
|||||||
|
|
||||||
const { tier } = await getOrgTierData(orgId);
|
const { tier } = await getOrgTierData(orgId);
|
||||||
if (
|
if (
|
||||||
|
build == "saas" &&
|
||||||
tier != TierId.STANDARD &&
|
tier != TierId.STANDARD &&
|
||||||
parsedBody.data.settingsLogRetentionDaysRequest &&
|
parsedBody.data.settingsLogRetentionDaysRequest &&
|
||||||
parsedBody.data.settingsLogRetentionDaysRequest > 30
|
parsedBody.data.settingsLogRetentionDaysRequest > 30
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import {
|
|||||||
userResources,
|
userResources,
|
||||||
roleResources,
|
roleResources,
|
||||||
resourcePassword,
|
resourcePassword,
|
||||||
resourcePincode
|
resourcePincode,
|
||||||
|
targets,
|
||||||
|
targetHealthCheck,
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
@@ -40,6 +42,59 @@ const listResourcesSchema = z.object({
|
|||||||
.pipe(z.number().int().nonnegative())
|
.pipe(z.number().int().nonnegative())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// (resource fields + a single joined target)
|
||||||
|
type JoinedRow = {
|
||||||
|
resourceId: number;
|
||||||
|
niceId: string;
|
||||||
|
name: string;
|
||||||
|
ssl: boolean;
|
||||||
|
fullDomain: string | null;
|
||||||
|
passwordId: number | null;
|
||||||
|
sso: boolean;
|
||||||
|
pincodeId: number | null;
|
||||||
|
whitelist: boolean;
|
||||||
|
http: boolean;
|
||||||
|
protocol: string;
|
||||||
|
proxyPort: number | null;
|
||||||
|
enabled: boolean;
|
||||||
|
domainId: string | null;
|
||||||
|
headerAuthId: number | null;
|
||||||
|
|
||||||
|
targetId: number | null;
|
||||||
|
targetIp: string | null;
|
||||||
|
targetPort: number | null;
|
||||||
|
targetEnabled: boolean | null;
|
||||||
|
|
||||||
|
hcHealth: string | null;
|
||||||
|
hcEnabled: boolean | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// grouped by resource with targets[])
|
||||||
|
export type ResourceWithTargets = {
|
||||||
|
resourceId: number;
|
||||||
|
name: string;
|
||||||
|
ssl: boolean;
|
||||||
|
fullDomain: string | null;
|
||||||
|
passwordId: number | null;
|
||||||
|
sso: boolean;
|
||||||
|
pincodeId: number | null;
|
||||||
|
whitelist: boolean;
|
||||||
|
http: boolean;
|
||||||
|
protocol: string;
|
||||||
|
proxyPort: number | null;
|
||||||
|
enabled: boolean;
|
||||||
|
domainId: string | null;
|
||||||
|
niceId: string;
|
||||||
|
headerAuthId: number | null;
|
||||||
|
targets: Array<{
|
||||||
|
targetId: number;
|
||||||
|
ip: string;
|
||||||
|
port: number;
|
||||||
|
enabled: boolean;
|
||||||
|
healthStatus?: 'healthy' | 'unhealthy' | 'unknown';
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
function queryResources(accessibleResourceIds: number[], orgId: string) {
|
function queryResources(accessibleResourceIds: number[], orgId: string) {
|
||||||
return db
|
return db
|
||||||
.select({
|
.select({
|
||||||
@@ -57,7 +112,15 @@ function queryResources(accessibleResourceIds: number[], orgId: string) {
|
|||||||
enabled: resources.enabled,
|
enabled: resources.enabled,
|
||||||
domainId: resources.domainId,
|
domainId: resources.domainId,
|
||||||
niceId: resources.niceId,
|
niceId: resources.niceId,
|
||||||
headerAuthId: resourceHeaderAuth.headerAuthId
|
headerAuthId: resourceHeaderAuth.headerAuthId,
|
||||||
|
|
||||||
|
targetId: targets.targetId,
|
||||||
|
targetIp: targets.ip,
|
||||||
|
targetPort: targets.port,
|
||||||
|
targetEnabled: targets.enabled,
|
||||||
|
|
||||||
|
hcHealth: targetHealthCheck.hcHealth,
|
||||||
|
hcEnabled: targetHealthCheck.hcEnabled,
|
||||||
})
|
})
|
||||||
.from(resources)
|
.from(resources)
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
@@ -72,6 +135,11 @@ function queryResources(accessibleResourceIds: number[], orgId: string) {
|
|||||||
resourceHeaderAuth,
|
resourceHeaderAuth,
|
||||||
eq(resourceHeaderAuth.resourceId, resources.resourceId)
|
eq(resourceHeaderAuth.resourceId, resources.resourceId)
|
||||||
)
|
)
|
||||||
|
.leftJoin(targets, eq(targets.resourceId, resources.resourceId))
|
||||||
|
.leftJoin(
|
||||||
|
targetHealthCheck,
|
||||||
|
eq(targetHealthCheck.targetId, targets.targetId)
|
||||||
|
)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
inArray(resources.resourceId, accessibleResourceIds),
|
inArray(resources.resourceId, accessibleResourceIds),
|
||||||
@@ -81,7 +149,7 @@ function queryResources(accessibleResourceIds: number[], orgId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ListResourcesResponse = {
|
export type ListResourcesResponse = {
|
||||||
resources: NonNullable<Awaited<ReturnType<typeof queryResources>>>;
|
resources: ResourceWithTargets[];
|
||||||
pagination: { total: number; limit: number; offset: number };
|
pagination: { total: number; limit: number; offset: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -146,7 +214,7 @@ export async function listResources(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let accessibleResources;
|
let accessibleResources: Array<{ resourceId: number }>;
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
accessibleResources = await db
|
accessibleResources = await db
|
||||||
.select({
|
.select({
|
||||||
@@ -183,9 +251,56 @@ export async function listResources(
|
|||||||
|
|
||||||
const baseQuery = queryResources(accessibleResourceIds, orgId);
|
const baseQuery = queryResources(accessibleResourceIds, orgId);
|
||||||
|
|
||||||
const resourcesList = await baseQuery!.limit(limit).offset(offset);
|
const rows: JoinedRow[] = await baseQuery.limit(limit).offset(offset);
|
||||||
|
|
||||||
|
// avoids TS issues with reduce/never[]
|
||||||
|
const map = new Map<number, ResourceWithTargets>();
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
let entry = map.get(row.resourceId);
|
||||||
|
if (!entry) {
|
||||||
|
entry = {
|
||||||
|
resourceId: row.resourceId,
|
||||||
|
niceId: row.niceId,
|
||||||
|
name: row.name,
|
||||||
|
ssl: row.ssl,
|
||||||
|
fullDomain: row.fullDomain,
|
||||||
|
passwordId: row.passwordId,
|
||||||
|
sso: row.sso,
|
||||||
|
pincodeId: row.pincodeId,
|
||||||
|
whitelist: row.whitelist,
|
||||||
|
http: row.http,
|
||||||
|
protocol: row.protocol,
|
||||||
|
proxyPort: row.proxyPort,
|
||||||
|
enabled: row.enabled,
|
||||||
|
domainId: row.domainId,
|
||||||
|
headerAuthId: row.headerAuthId,
|
||||||
|
targets: [],
|
||||||
|
};
|
||||||
|
map.set(row.resourceId, entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.targetId != null && row.targetIp && row.targetPort != null && row.targetEnabled != null) {
|
||||||
|
let healthStatus: 'healthy' | 'unhealthy' | 'unknown' = 'unknown';
|
||||||
|
|
||||||
|
if (row.hcEnabled && row.hcHealth) {
|
||||||
|
healthStatus = row.hcHealth as 'healthy' | 'unhealthy' | 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.targets.push({
|
||||||
|
targetId: row.targetId,
|
||||||
|
ip: row.targetIp,
|
||||||
|
port: row.targetPort,
|
||||||
|
enabled: row.targetEnabled,
|
||||||
|
healthStatus: healthStatus,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const resourcesList: ResourceWithTargets[] = Array.from(map.values());
|
||||||
|
|
||||||
const totalCountResult = await countQuery;
|
const totalCountResult = await countQuery;
|
||||||
const totalCount = totalCountResult[0].count;
|
const totalCount = totalCountResult[0]?.count ?? 0;
|
||||||
|
|
||||||
return response<ListResourcesResponse>(res, {
|
return response<ListResourcesResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -48,10 +48,12 @@ export async function deleteTarget(
|
|||||||
|
|
||||||
const { targetId } = parsedParams.data;
|
const { targetId } = parsedParams.data;
|
||||||
|
|
||||||
const [deletedTarget] = await db
|
const [deletedTarget] = await db.transaction(async (tx) => {
|
||||||
.delete(targets)
|
return await tx
|
||||||
.where(eq(targets.targetId, targetId))
|
.delete(targets)
|
||||||
.returning();
|
.where(eq(targets.targetId, targetId))
|
||||||
|
.returning();
|
||||||
|
});
|
||||||
|
|
||||||
if (!deletedTarget) {
|
if (!deletedTarget) {
|
||||||
return next(
|
return next(
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { internal } from "@app/lib/api";
|
import { internal } from "@app/lib/api";
|
||||||
import { authCookieHeader } from "@app/lib/api/cookies";
|
import { authCookieHeader } from "@app/lib/api/cookies";
|
||||||
import ResourcesTable, {
|
import ResourcesTable, {
|
||||||
ResourceRow,
|
ResourceRow,
|
||||||
InternalResourceRow
|
InternalResourceRow
|
||||||
} from "../../../../components/ResourcesTable";
|
} from "../../../../components/ResourcesTable";
|
||||||
import { AxiosResponse } from "axios";
|
import { AxiosResponse } from "axios";
|
||||||
import { ListResourcesResponse } from "@server/routers/resource";
|
import { ListResourcesResponse } from "@server/routers/resource";
|
||||||
@@ -17,123 +17,130 @@ import { pullEnv } from "@app/lib/pullEnv";
|
|||||||
import { toUnicode } from "punycode";
|
import { toUnicode } from "punycode";
|
||||||
|
|
||||||
type ResourcesPageProps = {
|
type ResourcesPageProps = {
|
||||||
params: Promise<{ orgId: string }>;
|
params: Promise<{ orgId: string }>;
|
||||||
searchParams: Promise<{ view?: string }>;
|
searchParams: Promise<{ view?: string }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export default async function ResourcesPage(props: ResourcesPageProps) {
|
export default async function ResourcesPage(props: ResourcesPageProps) {
|
||||||
const params = await props.params;
|
const params = await props.params;
|
||||||
const searchParams = await props.searchParams;
|
const searchParams = await props.searchParams;
|
||||||
const t = await getTranslations();
|
const t = await getTranslations();
|
||||||
|
|
||||||
const env = pullEnv();
|
const env = pullEnv();
|
||||||
|
|
||||||
// Default to 'proxy' view, or use the query param if provided
|
// Default to 'proxy' view, or use the query param if provided
|
||||||
let defaultView: "proxy" | "internal" = "proxy";
|
let defaultView: "proxy" | "internal" = "proxy";
|
||||||
if (env.flags.enableClients) {
|
if (env.flags.enableClients) {
|
||||||
defaultView = searchParams.view === "internal" ? "internal" : "proxy";
|
defaultView = searchParams.view === "internal" ? "internal" : "proxy";
|
||||||
}
|
}
|
||||||
|
|
||||||
let resources: ListResourcesResponse["resources"] = [];
|
let resources: ListResourcesResponse["resources"] = [];
|
||||||
try {
|
try {
|
||||||
const res = await internal.get<AxiosResponse<ListResourcesResponse>>(
|
const res = await internal.get<AxiosResponse<ListResourcesResponse>>(
|
||||||
`/org/${params.orgId}/resources`,
|
`/org/${params.orgId}/resources`,
|
||||||
await authCookieHeader()
|
await authCookieHeader()
|
||||||
);
|
|
||||||
resources = res.data.data.resources;
|
|
||||||
} catch (e) { }
|
|
||||||
|
|
||||||
let siteResources: ListAllSiteResourcesByOrgResponse["siteResources"] = [];
|
|
||||||
try {
|
|
||||||
const res = await internal.get<
|
|
||||||
AxiosResponse<ListAllSiteResourcesByOrgResponse>
|
|
||||||
>(`/org/${params.orgId}/site-resources`, await authCookieHeader());
|
|
||||||
siteResources = res.data.data.siteResources;
|
|
||||||
} catch (e) { }
|
|
||||||
|
|
||||||
let org = null;
|
|
||||||
try {
|
|
||||||
const getOrg = cache(async () =>
|
|
||||||
internal.get<AxiosResponse<GetOrgResponse>>(
|
|
||||||
`/org/${params.orgId}`,
|
|
||||||
await authCookieHeader()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
const res = await getOrg();
|
|
||||||
org = res.data.data;
|
|
||||||
} catch {
|
|
||||||
redirect(`/${params.orgId}/settings/resources`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!org) {
|
|
||||||
redirect(`/${params.orgId}/settings/resources`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const resourceRows: ResourceRow[] = resources.map((resource) => {
|
|
||||||
return {
|
|
||||||
id: resource.resourceId,
|
|
||||||
name: resource.name,
|
|
||||||
orgId: params.orgId,
|
|
||||||
nice: resource.niceId,
|
|
||||||
domain: `${resource.ssl ? "https://" : "http://"}${toUnicode(resource.fullDomain || "")}`,
|
|
||||||
protocol: resource.protocol,
|
|
||||||
proxyPort: resource.proxyPort,
|
|
||||||
http: resource.http,
|
|
||||||
authState: !resource.http
|
|
||||||
? "none"
|
|
||||||
: resource.sso ||
|
|
||||||
resource.pincodeId !== null ||
|
|
||||||
resource.passwordId !== null ||
|
|
||||||
resource.whitelist ||
|
|
||||||
resource.headerAuthId
|
|
||||||
? "protected"
|
|
||||||
: "not_protected",
|
|
||||||
enabled: resource.enabled,
|
|
||||||
domainId: resource.domainId || undefined,
|
|
||||||
ssl: resource.ssl
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const internalResourceRows: InternalResourceRow[] = siteResources.map(
|
|
||||||
(siteResource) => {
|
|
||||||
return {
|
|
||||||
id: siteResource.siteResourceId,
|
|
||||||
name: siteResource.name,
|
|
||||||
orgId: params.orgId,
|
|
||||||
siteName: siteResource.siteName,
|
|
||||||
protocol: siteResource.protocol,
|
|
||||||
proxyPort: siteResource.proxyPort,
|
|
||||||
siteId: siteResource.siteId,
|
|
||||||
destinationIp: siteResource.destinationIp,
|
|
||||||
destinationPort: siteResource.destinationPort,
|
|
||||||
siteNiceId: siteResource.siteNiceId
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
resources = res.data.data.resources;
|
||||||
|
} catch (e) { }
|
||||||
|
|
||||||
return (
|
let siteResources: ListAllSiteResourcesByOrgResponse["siteResources"] = [];
|
||||||
<>
|
try {
|
||||||
<SettingsSectionTitle
|
const res = await internal.get<
|
||||||
title={t("resourceTitle")}
|
AxiosResponse<ListAllSiteResourcesByOrgResponse>
|
||||||
description={t("resourceDescription")}
|
>(`/org/${params.orgId}/site-resources`, await authCookieHeader());
|
||||||
/>
|
siteResources = res.data.data.siteResources;
|
||||||
|
} catch (e) { }
|
||||||
|
|
||||||
<OrgProvider org={org}>
|
let org = null;
|
||||||
<ResourcesTable
|
try {
|
||||||
resources={resourceRows}
|
const getOrg = cache(async () =>
|
||||||
internalResources={internalResourceRows}
|
internal.get<AxiosResponse<GetOrgResponse>>(
|
||||||
orgId={params.orgId}
|
`/org/${params.orgId}`,
|
||||||
defaultView={
|
await authCookieHeader()
|
||||||
env.flags.enableClients ? defaultView : "proxy"
|
)
|
||||||
}
|
|
||||||
defaultSort={{
|
|
||||||
id: "name",
|
|
||||||
desc: false
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</OrgProvider>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
const res = await getOrg();
|
||||||
|
org = res.data.data;
|
||||||
|
} catch {
|
||||||
|
redirect(`/${params.orgId}/settings/resources`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!org) {
|
||||||
|
redirect(`/${params.orgId}/settings/resources`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const resourceRows: ResourceRow[] = resources.map((resource) => {
|
||||||
|
return {
|
||||||
|
id: resource.resourceId,
|
||||||
|
name: resource.name,
|
||||||
|
orgId: params.orgId,
|
||||||
|
nice: resource.niceId,
|
||||||
|
domain: `${resource.ssl ? "https://" : "http://"}${toUnicode(resource.fullDomain || "")}`,
|
||||||
|
protocol: resource.protocol,
|
||||||
|
proxyPort: resource.proxyPort,
|
||||||
|
http: resource.http,
|
||||||
|
authState: !resource.http
|
||||||
|
? "none"
|
||||||
|
: resource.sso ||
|
||||||
|
resource.pincodeId !== null ||
|
||||||
|
resource.passwordId !== null ||
|
||||||
|
resource.whitelist ||
|
||||||
|
resource.headerAuthId
|
||||||
|
? "protected"
|
||||||
|
: "not_protected",
|
||||||
|
enabled: resource.enabled,
|
||||||
|
domainId: resource.domainId || undefined,
|
||||||
|
ssl: resource.ssl,
|
||||||
|
targets: resource.targets?.map(target => ({
|
||||||
|
targetId: target.targetId,
|
||||||
|
ip: target.ip,
|
||||||
|
port: target.port,
|
||||||
|
enabled: target.enabled,
|
||||||
|
healthStatus: target.healthStatus
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const internalResourceRows: InternalResourceRow[] = siteResources.map(
|
||||||
|
(siteResource) => {
|
||||||
|
return {
|
||||||
|
id: siteResource.siteResourceId,
|
||||||
|
name: siteResource.name,
|
||||||
|
orgId: params.orgId,
|
||||||
|
siteName: siteResource.siteName,
|
||||||
|
protocol: siteResource.protocol,
|
||||||
|
proxyPort: siteResource.proxyPort,
|
||||||
|
siteId: siteResource.siteId,
|
||||||
|
destinationIp: siteResource.destinationIp,
|
||||||
|
destinationPort: siteResource.destinationPort,
|
||||||
|
siteNiceId: siteResource.siteNiceId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<SettingsSectionTitle
|
||||||
|
title={t("resourceTitle")}
|
||||||
|
description={t("resourceDescription")}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<OrgProvider org={org}>
|
||||||
|
<ResourcesTable
|
||||||
|
resources={resourceRows}
|
||||||
|
internalResources={internalResourceRows}
|
||||||
|
orgId={params.orgId}
|
||||||
|
defaultView={
|
||||||
|
env.flags.enableClients ? defaultView : "proxy"
|
||||||
|
}
|
||||||
|
defaultSort={{
|
||||||
|
id: "name",
|
||||||
|
desc: false
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</OrgProvider>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -9,13 +9,15 @@ import {
|
|||||||
SortingState,
|
SortingState,
|
||||||
getSortedRowModel,
|
getSortedRowModel,
|
||||||
ColumnFiltersState,
|
ColumnFiltersState,
|
||||||
getFilteredRowModel
|
getFilteredRowModel,
|
||||||
|
VisibilityState
|
||||||
} from "@tanstack/react-table";
|
} from "@tanstack/react-table";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
} from "@app/components/ui/dropdown-menu";
|
} from "@app/components/ui/dropdown-menu";
|
||||||
import { Button } from "@app/components/ui/button";
|
import { Button } from "@app/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@@ -25,7 +27,16 @@ import {
|
|||||||
ArrowUpRight,
|
ArrowUpRight,
|
||||||
ShieldOff,
|
ShieldOff,
|
||||||
ShieldCheck,
|
ShieldCheck,
|
||||||
RefreshCw
|
RefreshCw,
|
||||||
|
Settings2,
|
||||||
|
Plus,
|
||||||
|
Search,
|
||||||
|
ChevronDown,
|
||||||
|
Clock,
|
||||||
|
Wifi,
|
||||||
|
WifiOff,
|
||||||
|
CheckCircle2,
|
||||||
|
XCircle,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
@@ -44,7 +55,6 @@ import { useTranslations } from "next-intl";
|
|||||||
import { InfoPopup } from "@app/components/ui/info-popup";
|
import { InfoPopup } from "@app/components/ui/info-popup";
|
||||||
import { Input } from "@app/components/ui/input";
|
import { Input } from "@app/components/ui/input";
|
||||||
import { DataTablePagination } from "@app/components/DataTablePagination";
|
import { DataTablePagination } from "@app/components/DataTablePagination";
|
||||||
import { Plus, Search } from "lucide-react";
|
|
||||||
import { Card, CardContent, CardHeader } from "@app/components/ui/card";
|
import { Card, CardContent, CardHeader } from "@app/components/ui/card";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
@@ -65,6 +75,15 @@ import EditInternalResourceDialog from "@app/components/EditInternalResourceDial
|
|||||||
import CreateInternalResourceDialog from "@app/components/CreateInternalResourceDialog";
|
import CreateInternalResourceDialog from "@app/components/CreateInternalResourceDialog";
|
||||||
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
||||||
|
|
||||||
|
|
||||||
|
export type TargetHealth = {
|
||||||
|
targetId: number;
|
||||||
|
ip: string;
|
||||||
|
port: number;
|
||||||
|
enabled: boolean;
|
||||||
|
healthStatus?: 'healthy' | 'unhealthy' | 'unknown';
|
||||||
|
};
|
||||||
|
|
||||||
export type ResourceRow = {
|
export type ResourceRow = {
|
||||||
id: number;
|
id: number;
|
||||||
nice: string | null;
|
nice: string | null;
|
||||||
@@ -78,8 +97,54 @@ export type ResourceRow = {
|
|||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
domainId?: string;
|
domainId?: string;
|
||||||
ssl: boolean;
|
ssl: boolean;
|
||||||
|
targetHost?: string;
|
||||||
|
targetPort?: number;
|
||||||
|
targets?: TargetHealth[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function getOverallHealthStatus(targets?: TargetHealth[]): 'online' | 'degraded' | 'offline' | 'unknown' {
|
||||||
|
if (!targets || targets.length === 0) {
|
||||||
|
return 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
const monitoredTargets = targets.filter(t => t.enabled && t.healthStatus && t.healthStatus !== 'unknown');
|
||||||
|
|
||||||
|
if (monitoredTargets.length === 0) {
|
||||||
|
return 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
const healthyCount = monitoredTargets.filter(t => t.healthStatus === 'healthy').length;
|
||||||
|
const unhealthyCount = monitoredTargets.filter(t => t.healthStatus === 'unhealthy').length;
|
||||||
|
|
||||||
|
if (healthyCount === monitoredTargets.length) {
|
||||||
|
return 'online';
|
||||||
|
} else if (unhealthyCount === monitoredTargets.length) {
|
||||||
|
return 'offline';
|
||||||
|
} else {
|
||||||
|
return 'degraded';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function StatusIcon({ status, className = "" }: {
|
||||||
|
status: 'online' | 'degraded' | 'offline' | 'unknown';
|
||||||
|
className?: string;
|
||||||
|
}) {
|
||||||
|
const iconClass = `h-4 w-4 ${className}`;
|
||||||
|
|
||||||
|
switch (status) {
|
||||||
|
case 'online':
|
||||||
|
return <CheckCircle2 className={`${iconClass} text-green-500`} />;
|
||||||
|
case 'degraded':
|
||||||
|
return <CheckCircle2 className={`${iconClass} text-yellow-500`} />;
|
||||||
|
case 'offline':
|
||||||
|
return <XCircle className={`${iconClass} text-destructive`} />;
|
||||||
|
case 'unknown':
|
||||||
|
return <Clock className={`${iconClass} text-gray-400`} />;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
export type InternalResourceRow = {
|
export type InternalResourceRow = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -143,6 +208,7 @@ const setStoredPageSize = (pageSize: number, tableId?: string): void => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function ResourcesTable({
|
export default function ResourcesTable({
|
||||||
resources,
|
resources,
|
||||||
internalResources,
|
internalResources,
|
||||||
@@ -158,6 +224,7 @@ export default function ResourcesTable({
|
|||||||
|
|
||||||
const api = createApiClient({ env });
|
const api = createApiClient({ env });
|
||||||
|
|
||||||
|
|
||||||
const [proxyPageSize, setProxyPageSize] = useState<number>(() =>
|
const [proxyPageSize, setProxyPageSize] = useState<number>(() =>
|
||||||
getStoredPageSize('proxy-resources', 20)
|
getStoredPageSize('proxy-resources', 20)
|
||||||
);
|
);
|
||||||
@@ -179,6 +246,10 @@ export default function ResourcesTable({
|
|||||||
const [proxySorting, setProxySorting] = useState<SortingState>(
|
const [proxySorting, setProxySorting] = useState<SortingState>(
|
||||||
defaultSort ? [defaultSort] : []
|
defaultSort ? [defaultSort] : []
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [proxyColumnVisibility, setProxyColumnVisibility] = useState<VisibilityState>({});
|
||||||
|
const [internalColumnVisibility, setInternalColumnVisibility] = useState<VisibilityState>({});
|
||||||
|
|
||||||
const [proxyColumnFilters, setProxyColumnFilters] =
|
const [proxyColumnFilters, setProxyColumnFilters] =
|
||||||
useState<ColumnFiltersState>([]);
|
useState<ColumnFiltersState>([]);
|
||||||
const [proxyGlobalFilter, setProxyGlobalFilter] = useState<any>([]);
|
const [proxyGlobalFilter, setProxyGlobalFilter] = useState<any>([]);
|
||||||
@@ -349,6 +420,76 @@ export default function ResourcesTable({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function TargetStatusCell({ targets }: { targets?: TargetHealth[] }) {
|
||||||
|
const overallStatus = getOverallHealthStatus(targets);
|
||||||
|
|
||||||
|
if (!targets || targets.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<StatusIcon status="unknown" />
|
||||||
|
<span className="text-sm text-muted-foreground">No targets</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const monitoredTargets = targets.filter(t => t.enabled && t.healthStatus && t.healthStatus !== 'unknown');
|
||||||
|
const unknownTargets = targets.filter(t => !t.enabled || !t.healthStatus || t.healthStatus === 'unknown');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" size="sm" className="flex items-center gap-2 h-8">
|
||||||
|
<StatusIcon status={overallStatus} />
|
||||||
|
<span className="text-sm">
|
||||||
|
{overallStatus === 'online' && 'Healthy'}
|
||||||
|
{overallStatus === 'degraded' && 'Degraded'}
|
||||||
|
{overallStatus === 'offline' && 'Offline'}
|
||||||
|
{overallStatus === 'unknown' && 'Unknown'}
|
||||||
|
</span>
|
||||||
|
<ChevronDown className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="start" className="min-w-[280px]">
|
||||||
|
{monitoredTargets.length > 0 && (
|
||||||
|
<>
|
||||||
|
{monitoredTargets.map((target) => (
|
||||||
|
<DropdownMenuItem key={target.targetId} className="flex items-center justify-between gap-4">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<StatusIcon
|
||||||
|
status={target.healthStatus === 'healthy' ? 'online' : 'offline'}
|
||||||
|
className="h-3 w-3"
|
||||||
|
/>
|
||||||
|
{`${target.ip}:${target.port}`}
|
||||||
|
</div>
|
||||||
|
<span className={`capitalize ${target.healthStatus === 'healthy' ? 'text-green-500' : 'text-destructive'
|
||||||
|
}`}>
|
||||||
|
{target.healthStatus}
|
||||||
|
</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{unknownTargets.length > 0 && (
|
||||||
|
<>
|
||||||
|
{unknownTargets.map((target) => (
|
||||||
|
<DropdownMenuItem key={target.targetId} className="flex items-center justify-between gap-4">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<StatusIcon status="unknown" className="h-3 w-3" />
|
||||||
|
{`${target.ip}:${target.port}`}
|
||||||
|
</div>
|
||||||
|
<span className="text-muted-foreground">
|
||||||
|
{!target.enabled ? 'Disabled' : 'Not monitored'}
|
||||||
|
</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const proxyColumns: ColumnDef<ResourceRow>[] = [
|
const proxyColumns: ColumnDef<ResourceRow>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: "name",
|
accessorKey: "name",
|
||||||
@@ -390,6 +531,33 @@ export default function ResourcesTable({
|
|||||||
return <span>{resourceRow.http ? (resourceRow.ssl ? "HTTPS" : "HTTP") : resourceRow.protocol.toUpperCase()}</span>;
|
return <span>{resourceRow.http ? (resourceRow.ssl ? "HTTPS" : "HTTP") : resourceRow.protocol.toUpperCase()}</span>;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "status",
|
||||||
|
accessorKey: "status",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() =>
|
||||||
|
column.toggleSorting(column.getIsSorted() === "asc")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t("status")}
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const resourceRow = row.original;
|
||||||
|
return <TargetStatusCell targets={resourceRow.targets} />;
|
||||||
|
},
|
||||||
|
sortingFn: (rowA, rowB) => {
|
||||||
|
const statusA = getOverallHealthStatus(rowA.original.targets);
|
||||||
|
const statusB = getOverallHealthStatus(rowB.original.targets);
|
||||||
|
const statusOrder = { online: 3, degraded: 2, offline: 1, unknown: 0 };
|
||||||
|
return statusOrder[statusA] - statusOrder[statusB];
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "domain",
|
accessorKey: "domain",
|
||||||
header: t("access"),
|
header: t("access"),
|
||||||
@@ -647,6 +815,7 @@ export default function ResourcesTable({
|
|||||||
onColumnFiltersChange: setProxyColumnFilters,
|
onColumnFiltersChange: setProxyColumnFilters,
|
||||||
getFilteredRowModel: getFilteredRowModel(),
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
onGlobalFilterChange: setProxyGlobalFilter,
|
onGlobalFilterChange: setProxyGlobalFilter,
|
||||||
|
onColumnVisibilityChange: setProxyColumnVisibility,
|
||||||
initialState: {
|
initialState: {
|
||||||
pagination: {
|
pagination: {
|
||||||
pageSize: proxyPageSize,
|
pageSize: proxyPageSize,
|
||||||
@@ -656,7 +825,8 @@ export default function ResourcesTable({
|
|||||||
state: {
|
state: {
|
||||||
sorting: proxySorting,
|
sorting: proxySorting,
|
||||||
columnFilters: proxyColumnFilters,
|
columnFilters: proxyColumnFilters,
|
||||||
globalFilter: proxyGlobalFilter
|
globalFilter: proxyGlobalFilter,
|
||||||
|
columnVisibility: proxyColumnVisibility
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -670,6 +840,7 @@ export default function ResourcesTable({
|
|||||||
onColumnFiltersChange: setInternalColumnFilters,
|
onColumnFiltersChange: setInternalColumnFilters,
|
||||||
getFilteredRowModel: getFilteredRowModel(),
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
onGlobalFilterChange: setInternalGlobalFilter,
|
onGlobalFilterChange: setInternalGlobalFilter,
|
||||||
|
onColumnVisibilityChange: setInternalColumnVisibility,
|
||||||
initialState: {
|
initialState: {
|
||||||
pagination: {
|
pagination: {
|
||||||
pageSize: internalPageSize,
|
pageSize: internalPageSize,
|
||||||
@@ -679,7 +850,8 @@ export default function ResourcesTable({
|
|||||||
state: {
|
state: {
|
||||||
sorting: internalSorting,
|
sorting: internalSorting,
|
||||||
columnFilters: internalColumnFilters,
|
columnFilters: internalColumnFilters,
|
||||||
globalFilter: internalGlobalFilter
|
globalFilter: internalGlobalFilter,
|
||||||
|
columnVisibility: internalColumnVisibility
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user