Fixed found_ipvx filters

master
wgapi Cloud9 2021-10-15 14:10:39 -06:00
parent a19b239969
commit 9cce98e737
1 changed files with 13 additions and 12 deletions

View File

@ -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])