mirror of
https://github.com/WeeJeWel/wg-easy.git
synced 2024-11-18 00:19:22 +08:00
wip
This commit is contained in:
parent
01f2724518
commit
0c3217def0
18
Dockerfile
18
Dockerfile
@ -1,21 +1,19 @@
|
||||
FROM node:16-buster
|
||||
FROM node:16-alpine
|
||||
|
||||
# Install Linux packages
|
||||
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 install -y wireguard iproute2 openresolv curl
|
||||
|
||||
# Install Node.js
|
||||
# RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
|
||||
# RUN apt-get install -y nodejs
|
||||
RUN apk add -U wireguard-tools
|
||||
|
||||
# Copy Web UI
|
||||
COPY src/ /app/
|
||||
WORKDIR /app
|
||||
RUN npm ci --production
|
||||
|
||||
|
||||
# Expose Ports
|
||||
EXPOSE 51820/udp
|
||||
EXPOSE 80/tcp
|
||||
|
||||
# Set Environment
|
||||
ENV DEBUG=Server,WireGuard
|
||||
|
||||
# Run Web UI
|
||||
CMD ["node", "server.js"]
|
@ -44,7 +44,9 @@ module.exports = class Util {
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
childProcess.exec(cmd, (err, stdout) => {
|
||||
childProcess.exec(cmd, {
|
||||
shell: 'bash',
|
||||
}, (err, stdout) => {
|
||||
if (err) return reject(err);
|
||||
return resolve(String(stdout).trim());
|
||||
});
|
||||
|
@ -32,23 +32,25 @@ module.exports = class WireGuard {
|
||||
try {
|
||||
config = await fs.readFile(path.join(WG_PATH, 'wg0.json'), 'utf8');
|
||||
config = JSON.parse(config);
|
||||
debug('Configuration loaded');
|
||||
debug('Configuration loaded.');
|
||||
} catch (err) {
|
||||
const privateKey = await Util.exec('wg genkey');
|
||||
const publicKey = await Util.exec(`echo ${privateKey} | wg pubkey`);
|
||||
const address = WG_DEFAULT_ADDRESS.replace('x', '1');
|
||||
|
||||
config = {
|
||||
server: {
|
||||
privateKey: await Util.exec('wg genkey'),
|
||||
address: `${WG_DEFAULT_ADDRESS.replace('x', '1')}/24`,
|
||||
privateKey,
|
||||
publicKey,
|
||||
address,
|
||||
},
|
||||
clients: {},
|
||||
};
|
||||
debug('New configuration saved');
|
||||
}
|
||||
|
||||
await this.__saveConfig(config);
|
||||
|
||||
debug('Starting...');
|
||||
await Util.exec('wg-quick up wg0');
|
||||
debug('Started');
|
||||
await this.__syncConfig();
|
||||
|
||||
return config;
|
||||
});
|
||||
@ -60,6 +62,7 @@ module.exports = class WireGuard {
|
||||
async saveConfig() {
|
||||
const config = await this.getConfig();
|
||||
await this.__saveConfig(config);
|
||||
await this.__syncConfig();
|
||||
}
|
||||
|
||||
async __saveConfig(config) {
|
||||
@ -85,8 +88,16 @@ PresharedKey = ${client.preSharedKey}
|
||||
AllowedIPs = ${client.address}/32`;
|
||||
}
|
||||
|
||||
debug('Saving config...');
|
||||
await fs.writeFile(path.join(WG_PATH, 'wg0.json'), JSON.stringify(config, false, 2));
|
||||
await fs.writeFile(path.join(WG_PATH, 'wg0.conf'), result);
|
||||
debug('Config saved.');
|
||||
}
|
||||
|
||||
async __syncConfig() {
|
||||
debug('Syncing config...');
|
||||
await Util.exec('wg syncconf wg0 <(wg-quick strip wg0)');
|
||||
debug('Config synced.');
|
||||
}
|
||||
|
||||
async getClients() {
|
||||
@ -150,6 +161,7 @@ AllowedIPs = ${client.address}/32`;
|
||||
}
|
||||
|
||||
async getClientConfiguration({ clientId }) {
|
||||
const config = await this.getConfig();
|
||||
const client = await this.getClient({ clientId });
|
||||
|
||||
return `
|
||||
@ -159,7 +171,7 @@ Address = ${client.address}/24
|
||||
DNS = ${WG_DEFAULT_DNS}
|
||||
|
||||
[Peer]
|
||||
PublicKey = ${client.publicKey}
|
||||
PublicKey = ${config.server.publicKey}
|
||||
PresharedKey = ${client.preSharedKey}
|
||||
AllowedIPs = 0.0.0.0/0, ::/0
|
||||
Endpoint = ${WG_HOST}:${WG_PORT}`;
|
||||
|
Loading…
Reference in New Issue
Block a user