diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7368f57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +"gitea_token.txt" diff --git a/set_endpoint.uc b/set_endpoint.uc index fc5d532..6d85e04 100644 --- a/set_endpoint.uc +++ b/set_endpoint.uc @@ -1,7 +1,7 @@ #!/bin/ucode import * as uloop from 'uloop'; import { readfile, popen, pipe } from 'fs'; -//import { event_fns } from './set_endpoint_events.uc' +import { cursor } from 'uci'; // Aggregate all Endpoints // Start pipe and loop and listen for set_endpoint commands // set_endpoint command structure: userId,endpoint @@ -22,55 +22,105 @@ function log(msg,code) { print(prefix + msg + "\n"); } -function endpoint_format(ip,port) { +function tunserverobj(ip_addr, endpoint_addr, endpoint_port) { + is_ipv6 = len(iptoarr(ip_addr)) == 16; + + const endpoint = { + ip: endpoint_addr, + port: endpoint_addr + }; + + if(is_ipv6) { + return { + endpoint: endpoint, + tunip_v6: ip_addr + }; + } + + is_ipv4 = len(iptoarr(ip_addr)) == 4 + if(!is_ipv4) { + log("ip is neither v6 or v4, Ignoring",1); + } + + return { + endpoint: endpoint, + tunip_v4: ip_addr + }; +} + +function tuntypeobj_wireguard(if_name, pubkey, private_key_path, tunnel_props) { return { - endpoint: { - ip: ip, - port: port - } + type: wireguard + if_name: if_name, + public_key: pubkey, + private_key: private_key + tunnel: tunserverobj(), }; } -function tunnel_ip_format(v4_addr, v6_addr, v4_endpoint, v6_endpoint) { - return { - tunnel: { - ipv4: { - if_addr: v4_addr, - endpoint: v4_endpoint + +function tuntypeobj_socks5() { + return { + type: socks5, + if_name: "", + username: "", + password: "", + tunnel: tunserverobj + }; +} + +function tuntypeobj_socks4() { + return { + type: socks4, + if_name: "", + username: "", + password: "", + tunnel: "" + }; +} + +function tuntypeobj_http() { + return { + type: http, + if_name: "", + username: "", + password: "", + cert: "", + tunnel: "" // Should be tunserverobj + }; +} + +function basic_nm_provider(name, base_api_url, requires_basic_auth, credentials) { + return { + name: name, + api_urls: { + default: base_api_url }, - ipv6: { - if_addr: v6_addr, - endpoint: v6_endpoint + auth: { + basic_auth: requires_basic_auth, + credentials: credentials } } - }; } -function wireguard_format(name, pubkey, private_key_path, tunnel_props) { - return { - wireguard: { - name: name, - tunnel: tunnel_props, - public_key: pubkey, - private_key: private_key_path - } - }; -} - -function socks5_format() {} - function nm_unified_format(provider, data) { return { nm_unified: { - provider: provider, + provider: provider, // Ein Objekt mit dem namen vom anbieter wovon die vpn tunnel stammen. Ein anbieter kann mehrere Tunnel Protokole verwenden data: data // Should be array of wireguard or openvpn or socks format } }; } +// UCI Configuration -function wireguard_connect(ctx,args) { +function wireguard_create_if() { + let ctx = uci.cursor(); +} +function nm_setup(nm_unified) { + log("nm_setup called for " + nm_unified.provider.name); + } diff --git a/set_endpoint_events.uc b/set_endpoint_events.uc index a74a054..04394d4 100644 --- a/set_endpoint_events.uc +++ b/set_endpoint_events.uc @@ -1,8 +1,10 @@ // Set endpoint options, takes a user object wich contains the userId wich is a hash formed from tunnel ip and public key + + function set_endpoint() { } -return { +return { event_fns: [set_endpoint] }