From 9cce98e737b1c42612cb18ecb30e0648ffa1dafb Mon Sep 17 00:00:00 2001 From: wgapi Cloud9 Date: Fri, 15 Oct 2021 14:10:39 -0600 Subject: [PATCH] Fixed found_ipvx filters --- index.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 7ac6783..08259cc 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,7 @@ app.get('/', async (req,res) => { const privkey = req.query['del'] const hostname = req.query['add'] //const requester = req.ip.replace('::ffff:','') - const requester = '10.4.9.1' + const requester = '10.4.1.1' // Delete a peer if (privkey) { @@ -79,8 +79,8 @@ app.get('/', async (req,res) => { } else if (line.includes('AllowedIPs')) { const ips = line.split('=')[1].split(',') - found_ipv4s.push(ips.filter( (ip) => ip.includes(IPV4_NET) )) - found_ipv6s.push(ips.filter( (ip) => ip.includes(IPV6_NET) )) + found_ipv4s.push(ips.filter( (ip) => ip.includes(IPV4_NET) )[0].trim()) + found_ipv6s.push(ips.filter( (ip) => ip.includes(IPV6_NET) )[0].trim()) } } } @@ -90,25 +90,26 @@ app.get('/', async (req,res) => { console.log(`Found unmatching IPv4 address subnets for ${requester}: ${found_ipv4s}`) res.sendStatus(500); return } else if (!found_ipv6s.every((found_ipv6) => - found_ipv6.toString().includes(`${IPV6_NET}:${subnet}:`))) { - console.log(`Found unmatching IPv6 address subnets for ${requester}: ${found_ipv6s}`) - res.sendStatus(500); return - - // Check that the requester is "on the list" - } else if (found_usernames.length ===0) { - console.log(`Requester ${requester} is not in the network yet`) + found_ipv6.toString().includes(`${IPV6_NET}:${subnet}:`))) { + console.log(`Found unmatching IPv6 address subnets for ${requester}: ${found_ipv6s}`) + res.sendStatus(500); return + + // Check that the requester is "on the list" + // Should never get here because this requester can't access this IP! + } else if (found_usernames.length ===0) { + console.log(`Received request from ${requester} not in wg.conf!`) res.sendStatus(500); return // Check that all usernames are correct or error out // https://stackoverflow.com/a/35568895 } else if (!found_usernames.every( (v,i,r) => v === r[0] )) { console.log(`Found unmatching usernames for ${requester}: ${found_usernames.toString()}`) res.sendStatus(500); return - + // Everything looks good! Proceed } else { const username = found_usernames[0] console.log(`${requester} must be ${username}`) - + // Find next available host part in config const used_ipv4_hosts = found_ipv4s.map((found_ipv4) => found_ipv4.toString().split('.')[3].split('/')[0])