mirror of
https://github.com/WeeJeWel/wg-easy.git
synced 2025-01-02 19:15:37 +08:00
better logging (fixes #100)
This commit is contained in:
parent
5895b986fc
commit
c19cb72b6d
@ -19,7 +19,7 @@ module.exports = class Util {
|
|||||||
|
|
||||||
static promisify(fn) {
|
static promisify(fn) {
|
||||||
// eslint-disable-next-line func-names
|
// eslint-disable-next-line func-names
|
||||||
return function(req, res) {
|
return function (req, res) {
|
||||||
Promise.resolve().then(async () => fn(req, res))
|
Promise.resolve().then(async () => fn(req, res))
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (res.headersSent) return;
|
if (res.headersSent) return;
|
||||||
@ -52,9 +52,16 @@ module.exports = class Util {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static async exec(cmd) {
|
static async exec(cmd, {
|
||||||
// eslint-disable-next-line no-console
|
log = true,
|
||||||
console.log(`$ ${cmd}`);
|
} = {}) {
|
||||||
|
if (typeof log === 'string') {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`$ ${log}`);
|
||||||
|
} else if (log === true) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`$ ${cmd}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (process.platform !== 'linux') {
|
if (process.platform !== 'linux') {
|
||||||
return '';
|
return '';
|
||||||
|
@ -37,7 +37,9 @@ module.exports = class WireGuard {
|
|||||||
debug('Configuration loaded.');
|
debug('Configuration loaded.');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const privateKey = await Util.exec('wg genkey');
|
const privateKey = await Util.exec('wg genkey');
|
||||||
const publicKey = await Util.exec(`echo ${privateKey} | wg pubkey`);
|
const publicKey = await Util.exec(`echo ${privateKey} | wg pubkey`, {
|
||||||
|
log: `echo ***hidden*** | wg pubkey`
|
||||||
|
});
|
||||||
const address = WG_DEFAULT_ADDRESS.replace('x', '1');
|
const address = WG_DEFAULT_ADDRESS.replace('x', '1');
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
@ -52,7 +54,7 @@ module.exports = class WireGuard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.__saveConfig(config);
|
await this.__saveConfig(config);
|
||||||
await Util.exec('wg-quick down wg0').catch(() => {});
|
await Util.exec('wg-quick down wg0').catch(() => { });
|
||||||
await Util.exec('wg-quick up wg0');
|
await Util.exec('wg-quick up wg0');
|
||||||
await Util.exec(`iptables -t nat -A POSTROUTING -s ${WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o eth0 -j MASQUERADE`);
|
await Util.exec(`iptables -t nat -A POSTROUTING -s ${WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o eth0 -j MASQUERADE`);
|
||||||
await Util.exec('iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT');
|
await Util.exec('iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT');
|
||||||
@ -127,7 +129,9 @@ AllowedIPs = ${client.address}/32`;
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// Loop WireGuard status
|
// Loop WireGuard status
|
||||||
const dump = await Util.exec('wg show wg0 dump');
|
const dump = await Util.exec('wg show wg0 dump', {
|
||||||
|
log: false,
|
||||||
|
});
|
||||||
dump
|
dump
|
||||||
.trim()
|
.trim()
|
||||||
.split('\n')
|
.split('\n')
|
||||||
|
Loading…
Reference in New Issue
Block a user