Improve wg-ui host setup: IP availability checks and current-user install script
- setup-main-host-button: live availability status, grab-next-subnet helper, error/success feedback - setup-wireguard-host: harden generated shell scripts with set -e - check-private-ip-address-availability: add user access check, drop manual body validation - setup-main-host: pass host object with wg_ip_address - install-wg-ui.sh: run service as the invoking user (root or sudo) instead of a dedicated wgui user, and skip systemd/OpenRC daemon setup when NODE_ENV=development
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import checkUserAccess from "@/src/functions/backend/auth/check-user-access";
|
||||
import userAuth from "@/src/functions/backend/auth/user-auth";
|
||||
import checkPrivateIPAvailability from "@/src/functions/backend/setup/check-private-ip-availability";
|
||||
import type { ApiReqParams } from "@/src/types";
|
||||
@@ -11,7 +12,7 @@ export const handler: BunextAPIRouteHandler<APIResponseObject> = async (
|
||||
params,
|
||||
) => {
|
||||
const req = params.req;
|
||||
const body = params.body as ApiReqParams | undefined;
|
||||
const body = params.body as ApiReqParams;
|
||||
|
||||
if (req.method !== "POST") {
|
||||
return {
|
||||
@@ -30,17 +31,13 @@ export const handler: BunextAPIRouteHandler<APIResponseObject> = async (
|
||||
}
|
||||
|
||||
try {
|
||||
const ip_address = body?.ip_address;
|
||||
|
||||
if (!ip_address) {
|
||||
throw new Error(`No IP address passed!`);
|
||||
}
|
||||
|
||||
return await checkPrivateIPAvailability({ ip_address });
|
||||
return await checkPrivateIPAvailability({
|
||||
ip_address: body?.ip_address || "",
|
||||
});
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
msg: error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -41,7 +41,9 @@ export const handler: BunextAPIRouteHandler<APIResponseObject> = async (
|
||||
}
|
||||
|
||||
return await setupWireguardHost({
|
||||
wg_subnet_ip: body.ip_address,
|
||||
host: {
|
||||
wg_ip_address: body.ip_address,
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user