#7 stop providing IPv4s avter .254 and IPv6 after :9999
parent
32c7c0b19a
commit
8bd30e84a4
12
app/add.js
12
app/add.js
|
@ -63,9 +63,14 @@ module.exports = async (req, res) => {
|
||||||
found_ipv6.toString().split(':')[3])
|
found_ipv6.toString().split(':')[3])
|
||||||
let host = 1
|
let host = 1
|
||||||
while ([...used_ipv4_hosts,...used_ipv6_hosts].includes(host.toString())) host++
|
while ([...used_ipv4_hosts,...used_ipv6_hosts].includes(host.toString())) host++
|
||||||
|
if (host>9999) {
|
||||||
|
console.error(`New host part for ${user.name} is higher than 9999: ${host}`)
|
||||||
|
return res.sendStatus(507)
|
||||||
|
}
|
||||||
|
|
||||||
// Create IP Addresses and keys
|
// Create IP Addresses and keys
|
||||||
const ipv4_addr = `${env.IPV4_NET}.${user.subnet}.${host}`
|
let ipv4_addr; if (host<254)
|
||||||
|
ipv4_addr = `${env.IPV4_NET}.${user.subnet}.${host}`
|
||||||
const ipv6_addr = `${env.IPV6_NET}:${user.subnet}:${host}`
|
const ipv6_addr = `${env.IPV6_NET}:${user.subnet}:${host}`
|
||||||
let keypair; try {
|
let keypair; try {
|
||||||
keypair = await wg.generateKeypair()
|
keypair = await wg.generateKeypair()
|
||||||
|
@ -96,11 +101,14 @@ Endpoint = ${server.endpoint}
|
||||||
PersistentKeepAlive = 25`)
|
PersistentKeepAlive = 25`)
|
||||||
|
|
||||||
// Add new user device to server config as [Peer]
|
// Add new user device to server config as [Peer]
|
||||||
|
const allowed_ips = ipv4_addr
|
||||||
|
? `${ipv4_addr}/32, ${ipv6_addr}/128`
|
||||||
|
: `${ipv6_addr}/128`
|
||||||
const server_config = `\n
|
const server_config = `\n
|
||||||
[Peer] # ${domain}
|
[Peer] # ${domain}
|
||||||
PublicKey = ${keypair[0]}
|
PublicKey = ${keypair[0]}
|
||||||
PresharedKey = ${psk}
|
PresharedKey = ${psk}
|
||||||
AllowedIPs = ${ipv4_addr}/32, ${ipv6_addr}/128`
|
AllowedIPs = ${allowed_ips}`
|
||||||
|
|
||||||
// Add server_config to local wg0.conf
|
// Add server_config to local wg0.conf
|
||||||
if (server.host===env.LOCAL_SERVER) {
|
if (server.host===env.LOCAL_SERVER) {
|
||||||
|
|
Loading…
Reference in New Issue