Skip to content

Commit

Permalink
Merge branch 'wg-easy:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Dartegnian committed Mar 2, 2024
2 parents f571554 + 04e6f50 commit a9c47a4
Show file tree
Hide file tree
Showing 15 changed files with 344 additions and 124 deletions.
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ FROM docker.io/library/node:18-alpine AS build_node_modules
# Copy Web UI
COPY src/ /app/
WORKDIR /app
RUN npm ci --omit=dev
RUN npm ci --omit=dev &&\
mv node_modules /node_modules

# Copy build result to a new image.
# This saves a lot of disk space.
Expand All @@ -20,13 +21,15 @@ COPY --from=build_node_modules /app /app
# Also, some node_modules might be native, and
# the architecture & OS of your development machine might differ
# than what runs inside of docker.
RUN mv /app/node_modules /node_modules

# Enable this to run `npm run serve`
RUN npm i -g nodemon

# Workaround CVE-2023-42282
RUN npm uninstall -g ip
COPY --from=build_node_modules /node_modules /node_modules

RUN \
# Enable this to run `npm run serve`
npm i -g nodemon &&\
# Workaround CVE-2023-42282
npm uninstall -g ip &&\
# Delete unnecessary files
npm cache clean --force && rm -rf ~/.npm

# Install Linux packages
RUN apk add --no-cache \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ These options can be configured by setting environment variables using `-e KEY="
| `WG_POST_UP` | `...` | `iptables ...` | See [config.js](https://github.com/wg-easy/wg-easy/blob/master/src/config.js#L20) for the default value. |
| `WG_PRE_DOWN` | `...` | - | See [config.js](https://github.com/wg-easy/wg-easy/blob/master/src/config.js#L27) for the default value. |
| `WG_POST_DOWN` | `...` | `iptables ...` | See [config.js](https://github.com/wg-easy/wg-easy/blob/master/src/config.js#L28) for the default value. |
| `LANG` | `en` | `de` | Web UI language (Supports: en, ru, tr, no, pl, fr, de, ca, es, vi, nl, is, chs, cht,). |
| `LANG` | `en` | `de` | Web UI language (Supports: en, ua, ru, tr, no, pl, fr, de, ca, es, ko, vi, nl, is, pt, chs, cht, it, th). |
| `UI_TRAFFIC_STATS` | `false` | `true` | Enable detailed RX / TX client stats in Web UI |

> If you change `WG_PORT`, make sure to also change the exposed port.
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ services:
wg-easy-m3:
environment:
# Change Language:
# (Supports: en, ua, ru, tr, no, pl, fr, de, ca, es, pt, chs, cht)
- LANG=en
# (Supports: en, ua, ru, tr, no, pl, fr, de, ca, es, ko, vi, nl, is, pt, chs, cht, it, th)
# ⚠️ Required:
# Change this to your host's public address
- WG_HOST=wg.dartegnian.com
Expand All @@ -24,7 +24,7 @@ services:
# - WG_POST_UP=echo "Post Up" > /etc/wireguard/post-up.txt
# - WG_PRE_DOWN=echo "Pre Down" > /etc/wireguard/pre-down.txt
# - WG_POST_DOWN=echo "Post Down" > /etc/wireguard/post-down.txt

# - UI_TRAFFIC_STATS=true
image: dartegnian/wg-easy-m3
container_name: wg-easy-m3
volumes:
Expand Down
8 changes: 7 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ iptables -A FORWARD -o wg0 -j ACCEPT;
`.split('\n').join(' ');

module.exports.WG_PRE_DOWN = process.env.WG_PRE_DOWN || '';
module.exports.WG_POST_DOWN = process.env.WG_POST_DOWN || '';
module.exports.WG_POST_DOWN = process.env.WG_POST_DOWN || `
iptables -t nat -D POSTROUTING -s ${module.exports.WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o ${module.exports.WG_DEVICE} -j MASQUERADE;
iptables -D INPUT -p udp -m udp --dport 51820 -j ACCEPT;
iptables -D FORWARD -i wg0 -j ACCEPT;
iptables -D FORWARD -o wg0 -j ACCEPT;
`.split('\n').join(' ');
module.exports.LANG = process.env.LANG || 'en';
module.exports.UI_TRAFFIC_STATS = process.env.UI_TRAFFIC_STATS || 'false';
4 changes: 4 additions & 0 deletions src/lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
RELEASE,
PASSWORD,
LANG,
UI_TRAFFIC_STATS,
} = require('../config');

module.exports = class Server {
Expand All @@ -44,6 +45,9 @@ module.exports = class Server {
.get('/api/lang', (Util.promisify(async () => {
return LANG;
})))
.get('/api/ui-traffic-stats', (Util.promisify(async () => {
return UI_TRAFFIC_STATS === 'true';
})))

// Authentication
.get('/api/session', Util.promisify(async (req) => {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/WireGuard.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,9 @@ Endpoint = ${WG_HOST}:${WG_PORT}`;
await this.saveConfig();
}

// Shutdown wireguard
async Shutdown() {
await Util.exec('wg-quick down wg0').catch(() => { });
}

};
56 changes: 28 additions & 28 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"bcryptjs": "^2.4.3",
"debug": "^4.3.4",
"express": "^4.18.2",
"express": "^4.18.3",
"express-session": "^1.18.0",
"qrcode": "^1.5.3",
"uuid": "^9.0.1"
Expand Down
15 changes: 15 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@ WireGuard.getConfig()
// eslint-disable-next-line no-process-exit
process.exit(1);
});

// Handle terminate signal
process.on('SIGTERM', async () => {
// eslint-disable-next-line no-console
console.log('SIGTERM signal received.');
await WireGuard.Shutdown();
// eslint-disable-next-line no-process-exit
process.exit(0);
});

// Handle interupt signal
process.on('SIGINT', () => {
// eslint-disable-next-line no-console
console.log('SIGINT signal received.');
});
11 changes: 11 additions & 0 deletions src/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,15 @@
module.exports = {
darkMode: 'media',
content: ['./www/**/*.{html,js}'],
theme: {
screens: {
xxs: '450px',
xs: '576px',
sm: '640px',
md: '768px',
lg: '1024px',
xl: '1280px',
'2xl': '1536px',
},
},
};
Loading

0 comments on commit a9c47a4

Please sign in to comment.