Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list of used network ip`s #394

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/pages/admin/controller/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const Controller = () => {
api.admin.getControllerStats.useQuery();
const { data: unlinkedNetworks } = api.admin.unlinkedNetwork.useQuery();

const { networkCount, totalMembers, controllerStatus } = controllerData || {};
const { networkCount, totalMembers, controllerStatus, assignedIPs } =
controllerData || {};

const { allowManagementFrom, allowTcpFallbackRelay, listeningOn } =
controllerStatus?.config?.settings || {};
Expand Down Expand Up @@ -59,6 +60,22 @@ const Controller = () => {
<p>{t("controller.networkMembers.totalUnlinkedNetworks")}</p>
<p>{unlinkedNetworks?.length}</p>
</div>
<div className="grid grid-cols-3">
<div>
<p>Assigned Network IP's</p>
</div>
<div className="col-span-3 xl:col-span-2 ml-auto">
<div className="grid grid-cols-2 gap-1">
{assignedIPs?.map((ip, index) => (
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
<p key={index} className="badge badge-primary">
{ip}
</p>
))}
</div>
</div>
</div>

{unlinkedNetworks && unlinkedNetworks?.length > 0 ? (
<div className="py-4">
<p>{t("controller.networkMembers.unlinkedNetworks.title")}</p>
Expand Down Expand Up @@ -86,10 +103,14 @@ const Controller = () => {
</div>
<div className="grid grid-cols-3">
<p>{t("controller.management.listeningOn")}</p>
<div className="col-span-2 gap-1 flex flex-col items-end">
{listeningOn?.map((address) => (
<span key={address}>{address}</span>
))}
<div className="col-span-3 xl:col-span-2 ml-auto">
<div className="grid grid-cols-2 gap-1">
{listeningOn?.map((address) => (
<span key={address} className="w-full badge badge-primary text-left">
{address}
</span>
))}
</div>
</div>
</div>
</div>
Expand Down
16 changes: 13 additions & 3 deletions src/server/api/routers/adminRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { decrypt, encrypt, generateInstanceSecret } from "~/utils/encryption";
import { SMTP_SECRET } from "~/utils/encryption";
import { ZT_FOLDER } from "~/utils/ztApi";
import { isRunningInDocker } from "~/utils/docker";
import { getNetworkClassCIDR } from "~/utils/IPv4gen";

type WithError<T> = T & { error?: boolean; message?: string };

Expand Down Expand Up @@ -220,12 +221,20 @@ export const adminRouter = createTRPCRouter({
try {
const isCentral = false;
const networks = await ztController.get_controller_networks(ctx, isCentral);

const networkCount = networks.length;
let totalMembers = 0;
const assignedIPs = new Set<string>();
for (const network of networks) {
const members = await ztController.network_members(ctx, network as string);
totalMembers += Object.keys(members).length;
const networkDetails = await ztController.local_network_detail(
ctx,
network as string,
isCentral,
);
totalMembers += networkDetails?.members.length;

// @ts-expect-error
const usedIp = getNetworkClassCIDR(networkDetails?.network?.ipAssignmentPools);
if (usedIp[0]?.target) assignedIPs.add(usedIp[0]?.target);
}

const controllerStatus = (await ztController.get_controller_status(
Expand All @@ -236,6 +245,7 @@ export const adminRouter = createTRPCRouter({
networkCount,
totalMembers,
controllerStatus,
assignedIPs: Array.from(assignedIPs),
};
} catch (error) {
return throwError(error);
Expand Down
Loading