Add firewall rules logic for all hosts
This commit is contained in:
@@ -9,6 +9,8 @@ import type { TableType, User } from "@/src/types";
|
||||
import manageWireguardHost from "./manage-wireguard-host";
|
||||
import grabHostDirnames from "./grab-host-dir-names";
|
||||
import grabClientDirnames from "./grab-client-dir-names";
|
||||
import removeSubnetFirewallRules from "../firewall/remove-subnet-firewall-rules";
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import { execSync } from "node:child_process";
|
||||
|
||||
type Params = {
|
||||
@@ -74,6 +76,41 @@ export default async function deleteWireguardHost({
|
||||
});
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
const host_res = await BunSQLite.select<
|
||||
BUN_SQLITE_WGUI_HOSTS,
|
||||
TableType
|
||||
>({
|
||||
table: "hosts",
|
||||
targetId: host_id,
|
||||
});
|
||||
|
||||
const host = host_res.singleRes;
|
||||
|
||||
if (host?.wg_ip_address) {
|
||||
const host_subnet = `${host.wg_ip_address
|
||||
.split(".")
|
||||
.slice(0, 3)
|
||||
.join(".")}.0/24`;
|
||||
|
||||
const firewall_res = await removeSubnetFirewallRules({
|
||||
subnet: host_subnet,
|
||||
listen_port:
|
||||
host.listen_port || AppData["DefaultWGListenPort"],
|
||||
});
|
||||
|
||||
if (!firewall_res.success) {
|
||||
console.log(
|
||||
`Warning removing firewall rules for host ${host_id} => ${firewall_res.msg}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.log(
|
||||
`Warning removing firewall rules for host ${host_id} => ${error.message}`,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
execSync(`rm -rf ${HOST_CONFIG_DIR}`, { encoding: "utf-8" });
|
||||
} catch {}
|
||||
|
||||
Reference in New Issue
Block a user