Iptables generator funciton bugfix followup: allow host network ports

This commit is contained in:
2026-09-28 21:24:44 +01:00
parent 19486bbfa0
commit c42f0440ac
3 changed files with 84 additions and 83 deletions
@@ -5,7 +5,6 @@ import type {
} from "@/db/types/db";
import grabDirNames from "@/src/utils/grab-dir-names";
import { execSync } from "node:child_process";
import grabHostNetworkInterface from "./grab-host-network-interface";
import type { APIResponseObject } from "@moduletrace/bunext/types";
import BunSQLite from "@moduletrace/bun-sqlite";
import type { TableType, User } from "@/src/types";
@@ -92,8 +91,31 @@ export default async function setupWireguardHost({
rules_by_client_id.set(rule.client_id, existing_rules);
}
const TARGET_INTERFACE =
host?.interface || (await grabHostNetworkInterface());
const sibling_hosts_res = await BunSQLite.select<
BUN_SQLITE_WGUI_HOSTS,
TableType
>({
table: "hosts",
});
const sibling_subnets = [
...new Set(
(sibling_hosts_res.payload || [])
.filter(
(host_row) =>
host_row.id != HOST_ID &&
typeof host_row.wg_ip_address == "string" &&
host_row.wg_ip_address.trim() != "",
)
.map((host_row) => {
const parts = String(host_row.wg_ip_address)
.trim()
.split(".");
return `${parts.slice(0, 3).join(".")}.0/24`;
}),
),
];
const HOST_WG_IP = host?.wg_ip_address || wg_subnet_ip;
if (!HOST_WG_IP) {
@@ -178,8 +200,8 @@ export default async function setupWireguardHost({
const iptables_scripts = buildHostIptablesScripts({
host_id: Number(HOST_ID),
interface_name: INTERFACE_NAME,
target_interface: TARGET_INTERFACE || "eth0",
host_subnet: HOST_SUBNET,
sibling_subnets,
clients: clients.map((client) => ({
id: client.id,
wg_ip_address: client.wg_ip_address,