Initial Commit, updated function names and created some comments to better explain the code
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
#!/bin/ucode
|
#!/bin/ucode
|
||||||
import * as uloop from 'uloop';
|
import * as uloop from 'uloop';
|
||||||
import { readfile, popen, pipe } from 'fs';
|
import { readfile, popen, pipe } from 'fs';
|
||||||
import { event_fns } from './set_endpoint_events.uc'
|
//import { event_fns } from './set_endpoint_events.uc'
|
||||||
// 1. Aggregate all Endpoints
|
// Aggregate all Endpoints
|
||||||
// 2. Start pipe and loop and listen for set_endpoint commands
|
// Start pipe and loop and listen for set_endpoint commands
|
||||||
// 3. set_endpoint command structure: tunnel_ip,endpoint_type,endpoint_selector
|
// set_endpoint command structure: userId,endpoint
|
||||||
// 4. Wenn der befehl failed dann werden alle endpoints zurückgegeben #}
|
//
|
||||||
|
// The User fetches vendor endpoints over the vendors backend directly from the provider, if not possible if will be fetchable over our service
|
||||||
|
// If the User has a matching plan, the user can provide thier wireguard backend / socks proxy
|
||||||
|
|
||||||
function log(msg,code) {
|
function log(msg,code) {
|
||||||
let prefix = "[+] ";
|
let prefix = "[+] ";
|
||||||
@@ -66,23 +68,13 @@ function nm_unified_format(provider, data) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const provider_parser = {
|
|
||||||
config: function(provider_name) {
|
|
||||||
const conf = json(readfile("/etc/nm_providers/config_"+provider_name+".json"));
|
|
||||||
return conf;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function wireguard_connect(ctx,args) {
|
function wireguard_connect(ctx,args) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let wireguard = {
|
|
||||||
connect: wireguard_connect,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Converts mullvad config to wireguard endpoint obj
|
// Converts mullvad config to wireguard endpoint obj
|
||||||
function mullvad_fn(config) {
|
function mullvad_parse() {
|
||||||
let raw_apiresp = readfile('/tmp/mullvad_endpoints');
|
let raw_apiresp = readfile('/tmp/mullvad_endpoints');
|
||||||
let wg_part = {};
|
let wg_part = {};
|
||||||
|
|
||||||
@@ -105,7 +97,7 @@ function mullvad_fn(config) {
|
|||||||
wg_part = parsed_resp['wireguard'];
|
wg_part = parsed_resp['wireguard'];
|
||||||
|
|
||||||
const port = 51820;
|
const port = 51820;
|
||||||
let content = [];
|
let data = [];
|
||||||
|
|
||||||
for (relay in wg_part['relays']) {
|
for (relay in wg_part['relays']) {
|
||||||
log("Creating endpoint obj for " + relay);
|
log("Creating endpoint obj for " + relay);
|
||||||
@@ -116,32 +108,18 @@ function mullvad_fn(config) {
|
|||||||
log("Created tunnel->"+ e_v4 + e_v6 + "\n"+ tunnel);
|
log("Created tunnel->"+ e_v4 + e_v6 + "\n"+ tunnel);
|
||||||
|
|
||||||
print(tunnel);
|
print(tunnel);
|
||||||
push(content,wireguard_format(relay['hostname'], relay['public_key'], config.private_key_path, tunnel));
|
push(data,wireguard_format(relay['hostname'], relay['public_key'], config.private_key_path, tunnel));
|
||||||
}
|
}
|
||||||
|
|
||||||
return nm_unified_format('mullvad',content);
|
return nm_unified_format('mullvad',content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const endpoint_providers = {
|
mullvad_endpoints = {
|
||||||
'mullvad': { ...wireguard, ...mullvad }
|
nm_unified: mullvad_parse(),
|
||||||
|
date: time()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let endpoints = [];
|
|
||||||
|
|
||||||
for (provider_name in keys(endpoint_providers)) {
|
|
||||||
let provider = endpoint_providers[provider_name];
|
|
||||||
let curr_ep = provider.get(provider.config);
|
|
||||||
|
|
||||||
curr_ep['provider'] = provider;
|
|
||||||
endpoints[provider_name] = curr_ep;
|
|
||||||
|
|
||||||
log(curr_ep);
|
|
||||||
|
|
||||||
print("[+] Endpoint for " + provider_name + " created\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
const mainPipeHandle = pipe();
|
const mainPipeHandle = pipe();
|
||||||
|
|
||||||
let success = uloop.init();
|
let success = uloop.init();
|
||||||
|
|||||||
Reference in New Issue
Block a user