Skip to content

Commit

Permalink
Merge pull request #232 from luguslabs/francois-dev
Browse files Browse the repository at this point in the history
#201 [CLI] wireguard public port 51820 customizable
  • Loading branch information
branciard authored Jul 21, 2020
2 parents 59e2fe1 + c179711 commit d580b65
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cli/src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ const generateConfig = async () => {

const externalIPAddresses = configData.publicIps.split(',');

const wireguardPortsList = configData.wireguardPorts ? configData.wireguardPorts.split(',') : null;

// Add name to config
config.name = configData.name.toLowerCase().replace(/\s/g, '-');

Expand Down Expand Up @@ -142,7 +144,7 @@ const generateConfig = async () => {
config = { ...config, ...await generateServiceConfig(configData, config.nodesNumber) };

// Adding wireguard config
config = { ...config, ...await generateWireguardConfig(externalIPAddresses) };
config = { ...config, ...await generateWireguardConfig(externalIPAddresses, wireguardPortsList) };

// Adding Archipel config
config = { ...config, ...await generateArchipelConfig(config.nodesNumber) };
Expand Down
1 change: 1 addition & 0 deletions cli/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
const configTemplate = {
name: 'Archipel Name',
publicIps: '1.1.1.1,2.2.2.2,3.3.3.3,4.4.4.4,5.5.5.5,6.6.6.6',
wireguardPorts : '51820,51820,51820,51820,51820,51820',
nodesRole: 'operator,operator,operator,sentryExternal,sentryExternal,sentryExternal',
nexmoApiKey :'null,null,null',
nexmoApiSecret :'null,null,null',
Expand Down
14 changes: 12 additions & 2 deletions cli/src/wireguard.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@ const generateWireguardKeys = async keysNumber => {
};

// Generate Wireguard configuration
const generateWireguardConfig = async externalIPAddresses => {
const generateWireguardConfig = async (externalIPAddresses, wireguardPortsList) => {
const config = {};

// Add port number to addresses and add to config
config.wireguardExternalAddrList = externalIPAddresses.map(element => `${element}:51820`).join(',');
config.wireguardExternalAddrList = externalIPAddresses.map((element, index) =>
{
if (wireguardPortsList && wireguardPortsList.length >= index && wireguardPortsList[index]){
const port = wireguardPortsList[index];
return `${element}:${port}`
}
else{
return `${element}:51820`
}
}
).join(',');

// Generate Wireguard keys
const wireGuardKeys = await generateWireguardKeys(externalIPAddresses.length);
Expand Down

0 comments on commit d580b65

Please sign in to comment.