Configured env for c9, added block for unlisted requesters, minor updates

master
wgapi Cloud9 2021-10-15 12:53:05 -06:00
parent a1b4643774
commit 80d71c6dad
1 changed files with 9 additions and 4 deletions

View File

@ -4,7 +4,7 @@ const app = require('express')()
const wg = require('./wireguard')
// Variables
const PORT = 80
const PORT = 8080
const IPV4_CIDR = 16
const IPV4_NET = '10.4'
const IPV6_CIDR = 80
@ -37,11 +37,12 @@ const DNS_SERVERS = '10.4.0.1, fd69:1337:0:420:f4:f4::1, 10.4.0.3, fd69:1337:0:4
app.get('/', async (req,res) => {
const privkey = req.query['del']
const hostname = req.query['add']
const requester = req.ip.replace('::ffff:','')
//const requester = req.ip.replace('::ffff:','')
const requester = '10.4.9.1'
// Delete a peer
if (privkey) {
console.log(`Deleting ${privkey} from ${req.ip}`)
console.log(`Received request from ${requester} to delete ${privkey}`)
res.setHeader('content-type', 'text/plain')
res.send(`Delete ${privkey}`)
}
@ -92,6 +93,11 @@ app.get('/', async (req,res) => {
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`)
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] )) {
@ -120,7 +126,6 @@ app.get('/', async (req,res) => {
// Create [Peer] sections for each SERVERS
let client_peers = []
let server_peers = {}
for (const server of SERVERS) {
const psk = await wg.generatePSK()
client_peers.push(`