WIP: Set address IPs to Wireguard interface #6
15
.vscode/c_cpp_properties.json
vendored
15
.vscode/c_cpp_properties.json
vendored
@ -25,8 +25,8 @@
|
|||||||
"includePath": [
|
"includePath": [
|
||||||
"${env:appdata}/../Local/node-gyp/Cache/18.17.0/include/node",
|
"${env:appdata}/../Local/node-gyp/Cache/18.17.0/include/node",
|
||||||
"${workspaceFolder}/node_modules/node-addon-api",
|
"${workspaceFolder}/node_modules/node-addon-api",
|
||||||
"${workspaceFolder}/addons/genKey/**",
|
"${workspaceFolder}/addons/genKey",
|
||||||
"${workspaceFolder}/addons/tools/**"
|
"${workspaceFolder}/addons/tools"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -50,8 +50,8 @@
|
|||||||
"/usr/include/node",
|
"/usr/include/node",
|
||||||
"${workspaceFolder}/node_modules/node-addon-api/**",
|
"${workspaceFolder}/node_modules/node-addon-api/**",
|
||||||
"${workspaceFolder}/node_modules/**",
|
"${workspaceFolder}/node_modules/**",
|
||||||
"${workspaceFolder}/addons/genKey/**",
|
"${workspaceFolder}/addons/genKey",
|
||||||
"${workspaceFolder}/addons/tools/**"
|
"${workspaceFolder}/addons/tools"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -59,11 +59,12 @@
|
|||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/node_modules/node-addon-api",
|
"${workspaceFolder}/node_modules/node-addon-api",
|
||||||
"/usr/local/include/node",
|
"/usr/local/include/node",
|
||||||
"${workspaceFolder}/addons/genKey/**",
|
"${workspaceFolder}/addons/genKey",
|
||||||
"${workspaceFolder}/addons/tools/**"
|
"${workspaceFolder}/addons/tools"
|
||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
"NAPI_DISABLE_CPP_EXCEPTIONS"
|
"NAPI_DISABLE_CPP_EXCEPTIONS",
|
||||||
|
"USERSPACE_GO"
|
||||||
],
|
],
|
||||||
"compilerArgs": [
|
"compilerArgs": [
|
||||||
"-fpermissive",
|
"-fpermissive",
|
||||||
|
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@ -7,6 +7,7 @@
|
|||||||
"editor.insertSpaces": true,
|
"editor.insertSpaces": true,
|
||||||
"editor.minimap.enabled": false,
|
"editor.minimap.enabled": false,
|
||||||
"editor.detectIndentation": false,
|
"editor.detectIndentation": false,
|
||||||
|
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 2 }",
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.organizeImports": "explicit"
|
"source.organizeImports": "explicit"
|
||||||
},
|
},
|
||||||
@ -23,8 +24,6 @@
|
|||||||
"PATH": "${workspaceFolder}/node_modules/.bin:${env:PATH}"
|
"PATH": "${workspaceFolder}/node_modules/.bin:${env:PATH}"
|
||||||
},
|
},
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"random": "cpp",
|
"random": "cpp"
|
||||||
"limits": "cpp",
|
},
|
||||||
"xstring": "cpp"
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,13 +1,17 @@
|
|||||||
|
/*
|
||||||
|
File just to define functions for systems not supported by the addon
|
||||||
|
*/
|
||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
|
|
||||||
#include <wginterface.hh>
|
#include <wginterface.hh>
|
||||||
|
#include <wgip.hh>
|
||||||
|
|
||||||
unsigned long maxName() {
|
unsigned long maxName() { return 16; }
|
||||||
return 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string versionDrive() {
|
std::string versionDrive() { return "Userspace"; }
|
||||||
return "Userspace";
|
|
||||||
}
|
void WgIP::deploy() {}
|
||||||
|
void WgIP::load() {}
|
||||||
|
|
||||||
void listDevices::Execute() {}
|
void listDevices::Execute() {}
|
||||||
void deleteInterface::Execute() {}
|
void deleteInterface::Execute() {}
|
||||||
|
71
addons/tools/wgip.hh
Normal file
71
addons/tools/wgip.hh
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct InterfaceIp {
|
||||||
|
std::string ipAddress;
|
||||||
|
int mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get and Set Ip address to wireguard interface
|
||||||
|
*/
|
||||||
|
class WgIP {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Interface IPs vector
|
||||||
|
*/
|
||||||
|
std::vector<InterfaceIp> InterfaceAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set ip address in interface and update local ip vector
|
||||||
|
*/
|
||||||
|
void deploy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if interface exists get current ip address and insert in interface vector
|
||||||
|
*/
|
||||||
|
void load();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set ip and mask to interface
|
||||||
|
*/
|
||||||
|
bool addIP(std::string ip, int mask) {
|
||||||
|
if (ip.length() == 0) return false;
|
||||||
|
if (ip.find("/") != std::string::npos) ip = ip.substr(0, ip.find("/"));
|
||||||
|
for (auto rIP : InterfaceAddress) {
|
||||||
|
if (rIP.ipAddress == ip) return false;
|
||||||
|
}
|
||||||
|
InterfaceIp nIp;
|
||||||
|
nIp.ipAddress = ip;
|
||||||
|
nIp.mask = mask;
|
||||||
|
InterfaceAddress.push_back(nIp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add ip to Interface vector
|
||||||
|
*
|
||||||
|
* if exist ip ignore
|
||||||
|
*/
|
||||||
|
bool addIP(std::string ip) {
|
||||||
|
if (ip.length() == 0) return false;
|
||||||
|
int mask;
|
||||||
|
if (ip.find("/") != std::string::npos) {
|
||||||
|
mask = std::to_integer(ip.substr(ip.find("/")+1));
|
||||||
|
ip = ip.substr(0, ip.find("/"));
|
||||||
|
}
|
||||||
|
for (auto rIP : InterfaceAddress) {
|
||||||
|
if (rIP.ipAddress == ip) return false;
|
||||||
|
}
|
||||||
|
InterfaceIp nIp;
|
||||||
|
nIp.ipAddress = ip;
|
||||||
|
nIp.mask = mask;
|
||||||
|
InterfaceAddress.push_back(nIp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove ip from interface vector
|
||||||
|
*/
|
||||||
|
bool removeIP(std::string ip) { return false; }
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user