Skip to content

Commit

Permalink
Fix gen config
Browse files Browse the repository at this point in the history
  • Loading branch information
dappnodedev committed Dec 27, 2023
1 parent 9c41864 commit f834715
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/src/openvpn/openvpnConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from "fs";
import { shell, shellArgs } from "../utils/shell";
import { directoryIsEmptyOrEnoent } from "../utils/fs";
import { PKI_PATH, PROXY_ARP_PATH } from "../params";
import { logs } from "../logs";

/**
* Initializes the OpenVPN configuration
Expand All @@ -14,24 +15,30 @@ export async function initalizeOpenVpnConfig(hostname: string): Promise<void> {
EASYRSA_REQ_CN: hostname
};

logs.info(`Initializing OpenVPN config, hostname: ${hostname}`);

// Initialize config and PKI
// -c: Client to Client
// -d: disable default route (disables NAT without '-N')
// -p "route 172.33.0.0 255.255.0.0": Route to push to the client
// -n "172.33.1.2": DNS server (BIND)
await shellArgs(
// -c: Enable traffic among the clients connected to the VPN
// -d: Disable default route (disables NAT without '-N'). Only specific traffic will go through the VPN
// -u "udp://<hostname>": Hostname the clients will use to connect to the VPN
// -s Subnet the server will use to assign IPs to the clients
// -p "route 10.20.0.0 255.255.255.0": Route to push to the client
// -n "bind.dappnode": DNS server (BIND)
const output = await shellArgs(
"ovpn_genconfig",
{
c: true,
d: true,
u: `udp://"${hostname}"`,
s: "172.33.8.0/22",
p: `"route 172.33.0.0 255.255.0.0"`,
n: `"172.33.1.2"`
u: `udp://${hostname}`, // DYNDNS domain
s: "10.20.0.240/28",
p: "route 10.20.0.0 255.255.255.0",
n: "10.20.0.2"
},
{ env: { ...process.env, ...openVpnEnv } }
);

logs.info(output);

// Check if PKI is initalized already, if not use hostname as CN
if (directoryIsEmptyOrEnoent(PKI_PATH))
await shell("ovpn_initpki nopass", {
Expand Down

0 comments on commit f834715

Please sign in to comment.