mirror of
https://github.com/WeeJeWel/wg-easy.git
synced 2024-12-23 01:29:24 +08:00
wip
This commit is contained in:
parent
d9901aa8a3
commit
0f220c1a78
@ -1,13 +1,14 @@
|
|||||||
FROM debian:bullseye
|
FROM node:16-buster
|
||||||
|
|
||||||
# Install Linux packages
|
# Install Linux packages
|
||||||
RUN apt-get clean
|
RUN apt-get clean
|
||||||
|
RUN echo "deb http://deb.debian.org/debian buster-backports main" > /etc/apt/sources.list.d/backports.list
|
||||||
RUN apt-get update
|
RUN apt-get update
|
||||||
RUN apt-get install -y wireguard iproute2 openresolv curl
|
RUN apt-get install -y wireguard iproute2 openresolv curl
|
||||||
|
|
||||||
# Install Node.js
|
# Install Node.js
|
||||||
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
|
# RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
|
||||||
RUN apt-get install -y nodejs
|
# RUN apt-get install -y nodejs
|
||||||
|
|
||||||
COPY src/ /app/
|
COPY src/ /app/
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
```bash
|
```bash
|
||||||
$ docker run \
|
$ docker run \
|
||||||
--name wg-easy \
|
--name wg-easy \
|
||||||
--mount type=bind,source=~/.wg-easy,target=/etc/wireguard \
|
--mount type=bind,source="$(pwd)",target=/etc/wireguard \
|
||||||
--cap-add=NET_ADMIN \
|
--cap-add=NET_ADMIN \
|
||||||
--cap-add=SYS_MODULE \
|
--cap-add=SYS_MODULE \
|
||||||
--sysctl="net.ipv4.conf.all.src_valid_mark=1" \
|
--sysctl="net.ipv4.conf.all.src_valid_mark=1" \
|
||||||
|
27
config_/wg0.conf
Normal file
27
config_/wg0.conf
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
# Note: Do not edit this file directly.
|
||||||
|
# Your changes will be overwritten!
|
||||||
|
|
||||||
|
# Server
|
||||||
|
[Interface]
|
||||||
|
PrivateKey = iOQJS7OUUGPYATsX6nqlL+sOODoiWiN5IOE8Msfw/0o=
|
||||||
|
Address = 10.8.0.1/24
|
||||||
|
ListenPort = 51820
|
||||||
|
|
||||||
|
# Client: Emile (af3111a4-7343-4380-a293-ed498d9aa3b8)
|
||||||
|
[Peer]
|
||||||
|
PublicKey = i8xWKqicnDkNL14I4B+I1zlB8od/booA1joIosWn7X4=
|
||||||
|
PresharedKey = MzplKtOQ44/IaAKri2VKqCoIlg4XiVH7TCp5bcYRTQU=
|
||||||
|
AllowedIPs = 10.8.0.2/32
|
||||||
|
|
||||||
|
# Client: Test (2ca33a1c-ed49-4bdd-b84c-adc77f1f3b2d)
|
||||||
|
[Peer]
|
||||||
|
PublicKey = 563oiA0IuQqt8JPEXHGINT4mHYKzlLx9Ol2gcV1vKCk=
|
||||||
|
PresharedKey = Q6xGB4og5Sj6M0MsHzkD16VsniT3FCqOnGmiLLilsU8=
|
||||||
|
AllowedIPs = 10.8.0.3/32
|
||||||
|
|
||||||
|
# Client: Test 3 (f1d0280c-07e7-4927-94dd-000a1723872f)
|
||||||
|
[Peer]
|
||||||
|
PublicKey =
|
||||||
|
PresharedKey =
|
||||||
|
AllowedIPs = 10.8.0.4/32
|
41
config_/wg0.json
Normal file
41
config_/wg0.json
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"privateKey": "iOQJS7OUUGPYATsX6nqlL+sOODoiWiN5IOE8Msfw/0o=",
|
||||||
|
"publicKey": "BkdntwYazhYZzEEHhcYayq6TGw9/YUDQ251s+5bTgC0=",
|
||||||
|
"address": "10.8.0.1",
|
||||||
|
"port": "51820",
|
||||||
|
"dns": "1.1.1.1"
|
||||||
|
},
|
||||||
|
"clients": {
|
||||||
|
"af3111a4-7343-4380-a293-ed498d9aa3b8": {
|
||||||
|
"name": "Emile",
|
||||||
|
"createdAt": "2021-05-22T20:02:45.372Z",
|
||||||
|
"updatedAt": "2021-05-22T20:02:45.372Z",
|
||||||
|
"privateKey": "sHUUDbaZBQshfOvvF8HeebhhXq3rDKWlW1Vm+6XMklU=",
|
||||||
|
"publicKey": "i8xWKqicnDkNL14I4B+I1zlB8od/booA1joIosWn7X4=",
|
||||||
|
"preSharedKey": "MzplKtOQ44/IaAKri2VKqCoIlg4XiVH7TCp5bcYRTQU=",
|
||||||
|
"address": "10.8.0.2",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"2ca33a1c-ed49-4bdd-b84c-adc77f1f3b2d": {
|
||||||
|
"name": "Test",
|
||||||
|
"address": "10.8.0.3",
|
||||||
|
"privateKey": "AJVOxJxEnbWyrj7SbhJxxiIIgBsRljs1fP2xrN76Kns=",
|
||||||
|
"publicKey": "563oiA0IuQqt8JPEXHGINT4mHYKzlLx9Ol2gcV1vKCk=",
|
||||||
|
"preSharedKey": "Q6xGB4og5Sj6M0MsHzkD16VsniT3FCqOnGmiLLilsU8=",
|
||||||
|
"createdAt": "2021-05-22T21:41:49.876Z",
|
||||||
|
"updatedAt": "2021-05-23T10:04:29.051Z",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"f1d0280c-07e7-4927-94dd-000a1723872f": {
|
||||||
|
"name": "Test 3",
|
||||||
|
"address": "10.8.0.4",
|
||||||
|
"privateKey": "",
|
||||||
|
"publicKey": "",
|
||||||
|
"preSharedKey": "",
|
||||||
|
"createdAt": "2021-05-23T10:21:24.607Z",
|
||||||
|
"updatedAt": "2021-05-23T10:21:24.607Z",
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "docker build --tag wg-easy ."
|
"build": "docker build --tag wg-easy .",
|
||||||
|
"start": "docker run --env WG_HOST=0.0.0.0 --name wg-easy --cap-add=NET_ADMIN --cap-add=SYS_MODULE --sysctl=\"net.ipv4.conf.all.src_valid_mark=1\" --mount type=bind,source=\"$(pwd)\"/config,target=/etc/wireguard -p 51820:51820/udp -p 51821:51821/tcp wg-easy"
|
||||||
},
|
},
|
||||||
"docker": {
|
"docker": {
|
||||||
"production": {
|
"production": {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
const debug = require('debug')('WireGuard');
|
||||||
const uuid = require('uuid');
|
const uuid = require('uuid');
|
||||||
const QRCode = require('qrcode');
|
const QRCode = require('qrcode');
|
||||||
|
|
||||||
@ -26,10 +27,12 @@ module.exports = class WireGuard {
|
|||||||
throw new Error('WG_HOST Environment Variable Not Set!');
|
throw new Error('WG_HOST Environment Variable Not Set!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug('Loading configuration...');
|
||||||
let config;
|
let config;
|
||||||
try {
|
try {
|
||||||
config = await fs.readFile(path.join(WG_PATH, 'wg0.json'), 'utf8');
|
config = await fs.readFile(path.join(WG_PATH, 'wg0.json'), 'utf8');
|
||||||
config = JSON.parse(config);
|
config = JSON.parse(config);
|
||||||
|
debug('Configuration loaded');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
config = {
|
config = {
|
||||||
server: {
|
server: {
|
||||||
@ -38,10 +41,14 @@ module.exports = class WireGuard {
|
|||||||
},
|
},
|
||||||
clients: {},
|
clients: {},
|
||||||
};
|
};
|
||||||
await this.saveConfig();
|
debug('New configuration saved');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.__saveConfig(config);
|
||||||
|
|
||||||
|
debug('Starting...');
|
||||||
await Util.exec('wg-quick up wg0');
|
await Util.exec('wg-quick up wg0');
|
||||||
|
debug('Started');
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -52,6 +59,10 @@ module.exports = class WireGuard {
|
|||||||
|
|
||||||
async saveConfig() {
|
async saveConfig() {
|
||||||
const config = await this.getConfig();
|
const config = await this.getConfig();
|
||||||
|
await this.__saveConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
async __saveConfig(config) {
|
||||||
let result = `
|
let result = `
|
||||||
# Note: Do not edit this file directly.
|
# Note: Do not edit this file directly.
|
||||||
# Your changes will be overwritten!
|
# Your changes will be overwritten!
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "DEBUG=Server WG_HOST=0.0.0.0 WG_PATH=../config/ nodemon server.js",
|
"serve": "DEBUG=Server,WireGuard WG_HOST=0.0.0.0 WG_PATH=../config/ nodemon server.js",
|
||||||
"serve-with-password": "PASSWORD=wg npm run serve"
|
"serve-with-password": "PASSWORD=wg npm run serve"
|
||||||
},
|
},
|
||||||
"author": "Emile Nijssen",
|
"author": "Emile Nijssen",
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
require('./services/Server');
|
require('./services/Server');
|
||||||
|
|
||||||
|
const WireGuard = require('./services/WireGuard');
|
||||||
|
|
||||||
|
WireGuard.getConfig()
|
||||||
|
.catch(err => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-process-exit
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user