Initial Commit, updated function names and created some comments to better explain the code

This commit is contained in:
king
2026-02-01 22:17:41 +01:00
parent d7a9a4fb19
commit 6d84925e9c

View File

@@ -1,11 +1,13 @@
#!/bin/ucode
import * as uloop from 'uloop';
import { readfile, popen, pipe } from 'fs';
import { event_fns } from './set_endpoint_events.uc'
// 1. Aggregate all Endpoints
// 2. Start pipe and loop and listen for set_endpoint commands
// 3. set_endpoint command structure: tunnel_ip,endpoint_type,endpoint_selector
// 4. Wenn der befehl failed dann werden alle endpoints zurückgegeben #}
//import { event_fns } from './set_endpoint_events.uc'
// Aggregate all Endpoints
// Start pipe and loop and listen for set_endpoint commands
// set_endpoint command structure: userId,endpoint
//
// 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) {
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) {
}
let wireguard = {
connect: wireguard_connect,
};
// Converts mullvad config to wireguard endpoint obj
function mullvad_fn(config) {
function mullvad_parse() {
let raw_apiresp = readfile('/tmp/mullvad_endpoints');
let wg_part = {};
@@ -105,7 +97,7 @@ function mullvad_fn(config) {
wg_part = parsed_resp['wireguard'];
const port = 51820;
let content = [];
let data = [];
for (relay in wg_part['relays']) {
log("Creating endpoint obj for " + relay);
@@ -116,32 +108,18 @@ function mullvad_fn(config) {
log("Created tunnel->"+ e_v4 + e_v6 + "\n"+ 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);
}
const endpoint_providers = {
'mullvad': { ...wireguard, ...mullvad }
mullvad_endpoints = {
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();
let success = uloop.init();