Browse Source

working ipv6

pull/2294/head
SachinAsus 2 years ago
parent
commit
99d097dbf1
  1. 13
      src/config.js
  2. 5
      src/lib/Server.js
  3. 4
      src/lib/WireGuard.js
  4. 5
      src/server.js
  5. 17
      src/wgsh/wg0-post-up.sh
  6. 4
      src/wgsh/wg0-pre-down.sh
  7. 15
      src/www/css/app.css
  8. 43
      src/www/index.html
  9. 8
      src/www/js/api.js
  10. 18
      src/www/js/app.js
  11. 46
      src/www/js/i18n.js
  12. 8
      src/www/js/vendor/apexcharts.min.js

13
src/config.js

@ -2,6 +2,7 @@
const childProcess = require('child_process');
const { release } = require('../package.json');
const path = require('path');
module.exports.RELEASE = release;
module.exports.PORT = process.env.PORT || '51821';
@ -16,14 +17,14 @@ module.exports.WG_CONFIG_PORT = process.env.WG_CONFIG_PORT || process.env.WG_POR
module.exports.WG_MTU = process.env.WG_MTU || '1412';
module.exports.WG_PERSISTENT_KEEPALIVE = process.env.WG_PERSISTENT_KEEPALIVE || '25';
module.exports.WG_DEFAULT_ADDRESS = process.env.WG_DEFAULT_ADDRESS || '10.8.0.x';
module.exports.WG_DEFAULT_ADDRESS6 = process.env.WG_DEFAULT_ADDRESS6 || 'fdcc:ad94:bacf:61a4::cafe:x';
module.exports.WG_DEFAULT_ADDRESS6 = process.env.WG_DEFAULT_ADDRESS6 || 'fd01:1:1::x';
module.exports.WG_DEFAULT_DNS = typeof process.env.WG_DEFAULT_DNS === 'string'
? process.env.WG_DEFAULT_DNS
: '1.1.1.1';
// module.exports.WG_DEFAULT_DNS6 = typeof process.env.WG_DEFAULT_DNS6 === 'string'
// ? process.env.WG_DEFAULT_DNS6
// : '2606:4700:4700::1111';
module.exports.WG_ALLOWED_IPS = process.env.WG_ALLOWED_IPS || '10.250.0.0/22, 10.254.1.0/24, fdcc:ad94:bacf:61a4::cafe:0/64';
: '10.250.0.2';
module.exports.WG_DEFAULT_DNS6 = typeof process.env.WG_DEFAULT_DNS6 === 'string'
? process.env.WG_DEFAULT_DNS6
: 'fd01:0:1::2';
module.exports.WG_ALLOWED_IPS = process.env.WG_ALLOWED_IPS || '10.250.0.0/22, 10.254.1.0/24, fd01:1:1::0/64';
// Set WG_POST_UP to allow IPv6 NAT and forwarding only if the required kernel module is available
const modules = childProcess.execSync('lsmod', {

5
src/lib/Server.js

@ -5,6 +5,7 @@ const crypto = require('node:crypto');
const { createServer } = require('node:http');
const { stat, readFile } = require('node:fs/promises');
const { resolve, sep } = require('node:path');
const path = require('path');
const expressSession = require('express-session');
const debug = require('debug')('Server');
@ -292,7 +293,9 @@ module.exports = class Server {
}));
// Static assets
const publicDir = '/app/www';
// const publicDir = '/app/www';
// const publicDir = path.resolve(__dirname, './www');
const publicDir = '/home/ubuntu/wg-easy/src/www';
app.use(
defineEventHandler((event) => {
return serveStatic(event, {

4
src/lib/WireGuard.js

@ -95,6 +95,8 @@ module.exports = class WireGuard {
}
async __saveConfig(config) {
const isDnsSet = WG_DEFAULT_DNS || WG_DEFAULT_DNS6;
const dnsServers = [WG_DEFAULT_DNS, WG_DEFAULT_DNS6].filter((item) => !!item).join(', ');
let result = `
# Note: Do not edit this file directly.
# Your changes will be overwritten!
@ -104,7 +106,7 @@ module.exports = class WireGuard {
PrivateKey = ${config.server.privateKey}
Address = ${config.server.address}/24, ${config.server.address6}/64
ListenPort = ${WG_PORT}
${WG_DEFAULT_DNS ? `DNS = ${WG_DEFAULT_DNS}\n` : ''}\
${isDnsSet ? `DNS = ${dnsServers}\n` : ''}\
${WG_MTU ? `MTU = ${WG_MTU}\n` : ''}\
Table = 10
# DNS = ${WG_DEFAULT_ADDRESS}

5
src/server.js

@ -23,7 +23,10 @@ process.on('SIGTERM', async () => {
});
// Handle interrupt signal
process.on('SIGINT', () => {
process.on('SIGINT', () => async () => {
// eslint-disable-next-line no-console
console.log('SIGINT signal received.');
await WireGuard.Shutdown();
// eslint-disable-next-line no-process-exit
process.exit(0);
});

17
src/wgsh/wg0-post-up.sh

@ -7,10 +7,21 @@ IPT6="/sbin/ip6tables"
IN_FACE="enp0s3" # NIC connected to the internet
WG_FACE="wg0" # WG NIC
SUB_NET="10.250.1.0/24" # WG IPv4 sub/net aka CIDR
SUB_NET_6="fdcc:ad94:bacf:61a4::cafe:0/64" # Change this according
# SUB_NET_6="fdcc:abcd:abcd:abcd::cafe:0/64" # Change this according
SUB_NET_6="fd01:1:1::0/64"
WG_PORT="51820" # WG udp port
# WG_TABLE='10'
#iptables -t nat -I POSTROUTING 1 -s 10.250.1.0/24 -o ens3 -j MASQUERADE;
#iptables -I INPUT 1 -p udp -m udp --dport 51820 -j ACCEPT;
#iptables -I FORWARD 1 -i wg0 -j ACCEPT;
#iptables -I FORWARD 1 -o wg0 -j ACCEPT;
#ip6tables -t nat -I POSTROUTING 1 -o ens3 -j MASQUERADE;
#ip6tables -I INPUT 1 -p udp -m udp --dport 51820 -j ACCEPT;
#ip6tables -I FORWARD 1 -i wg0 -j ACCEPT;
#ip6tables -I FORWARD 1 -o wg0 -j ACCEPT;
## IPv4 ## working with single tunnel
$IPT -I INPUT 1 -p udp --dport $WG_PORT -j ACCEPT # for incoming connection
$IPT -I INPUT 1 -p tcp --dport 51821 -j ACCEPT # for webui
@ -29,8 +40,8 @@ $IPT6 -I FORWARD 1 -o $WG_FACE -j ACCEPT #for internet
# $IPT6 -I FORWARD 1 -i $IN_FACE -o $WG_FACE -j ACCEPT
# $IPT6 -I FORWARD 1 -i $WG_FACE -o $IN_FACE -j ACCEPT
wg-quick up wg1
systemctl start mount-mypi.service
# wg-quick up wg1
# systemctl start mount-mypi.service
# wg set wg0 fwmark 51820

4
src/wgsh/wg0-pre-down.sh

@ -7,7 +7,7 @@ IPT6="/sbin/ip6tables"
IN_FACE="enp0s3" # NIC connected to the internet
WG_FACE="wg0" # WG NIC
SUB_NET="10.250.1.0/24" # WG IPv4 sub/net aka CIDR
SUB_NET_6="fdcc:ad94:bacf:61a4::cafe:0/64" # WG IPv6 sub/net
SUB_NET_6="fd01:1:1::0/64" # WG IPv6 sub/net
WG_PORT="51820" # WG udp port
# WG_TABLE='10'
@ -21,7 +21,7 @@ $IPT -D FORWARD -o $WG_FACE -j ACCEPT #for internet
# IPv4 rules #
$IPT6 -D INPUT -p udp --dport $WG_PORT -j ACCEPT # for incoming connection
$IPT6 -D INPUT -p tcp --dport 51821 -j ACCEPT # for webui
$IPT6 -t nat -D POSTROUTING -s $SUB_NET -o $IN_FACE -j MASQUERADE
$IPT6 -t nat -D POSTROUTING -s $SUB_NET_6 -o $IN_FACE -j MASQUERADE
$IPT6 -D FORWARD -i $WG_FACE -j ACCEPT #for internet
$IPT6 -D FORWARD -o $WG_FACE -j ACCEPT #for internet

15
src/www/css/app.css

@ -1,5 +1,5 @@
/*
! tailwindcss v3.4.4 | MIT License | https://tailwindcss.com
! tailwindcss v3.4.3 | MIT License | https://tailwindcss.com
*/
/*
@ -802,11 +802,6 @@ video {
display: none;
}
.size-6 {
width: 1.5rem;
height: 1.5rem;
}
.h-1 {
height: 0.25rem;
}
@ -851,10 +846,6 @@ video {
min-height: 100vh;
}
.w-1 {
width: 0.25rem;
}
.w-10 {
width: 2.5rem;
}
@ -1463,10 +1454,6 @@ video {
border-bottom-width: 0px;
}
.hover\:cursor-pointer:hover {
cursor: pointer;
}
.hover\:border-red-800:hover {
--tw-border-opacity: 1;
border-color: rgb(153 27 27 / var(--tw-border-opacity));

43
src/www/index.html

@ -91,24 +91,6 @@
<p class="text-2xl font-medium dark:text-neutral-200">{{$t("clients")}}</p>
</div>
<div class="flex-shrink-0">
<!-- Restore configuration -->
<label for="inputRC" :title="$t('titleRestoreConfig')"
class="hover:cursor-pointer hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 dark:text-neutral-200 border-2 border-gray-100 dark:border-neutral-600 py-2 px-4 rounded inline-flex items-center transition">
<svg inline class="w-4 mr-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99"></path>
</svg>
<span class="text-sm">{{$t("restore")}}</span>
<input id="inputRC" type="file" name="configurationfile" accept="text/*,.json" @change="restoreConfig" class="hidden"/>
</label>
<!-- Backup configuration -->
<a href="./api/wireguard/backup" :title="$t('titleBackupConfig')"
class="hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 dark:text-neutral-200 border-2 border-gray-100 dark:border-neutral-600 py-2 px-4 rounded inline-flex items-center transition">
<svg inline class="w-4 mr-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M5.25 14.25h13.5m-13.5 0a3 3 0 0 1-3-3m3 3a3 3 0 1 0 0 6h13.5a3 3 0 1 0 0-6m-16.5-3a3 3 0 0 1 3-3h13.5a3 3 0 0 1 3 3m-19.5 0a4.5 4.5 0 0 1 .9-2.7L5.737 5.1a3.375 3.375 0 0 1 2.7-1.35h7.126c1.062 0 2.062.5 2.7 1.35l2.587 3.45a4.5 4.5 0 0 1 .9 2.7m0 0a3 3 0 0 1-3 3m0 3h.008v.008h-.008v-.008Zm0-6h.008v.008h-.008v-.008Zm-3 6h.008v.008h-.008v-.008Zm0-6h.008v.008h-.008v-.008Z"></path>
</svg>
<span class="text-sm">{{$t("backup")}}</span>
</a>
<!-- New client -->
<button @click="clientCreate = true; clientCreateName = '';"
class="hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 dark:text-neutral-200 border-2 border-gray-100 dark:border-neutral-600 py-2 px-4 rounded inline-flex items-center transition">
<svg class="w-4 mr-2" inline xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
@ -244,31 +226,6 @@
<div v-if="uiTrafficStats"
class="flex gap-2 items-center shrink-0 text-gray-400 dark:text-neutral-400 text-xs mt-px justify-end">
<!-- Address6 -->
<span class="group">
<!-- Show -->
<input v-show="clientEditAddress6Id === client.id" v-model="clientEditAddress6"
v-on:keyup.enter="updateClientAddress6(client, clientEditAddress6); clientEditAddress6 = null; clientEditAddress6Id = null;"
v-on:keyup.escape="clientEditAddress6 = null; clientEditAddress6Id = null;"
:ref="'client-' + client.id + '-address6'"
class="rounded border-2 border-gray-100 focus:border-gray-200 outline-none w-20 text-black" />
<span v-show="clientEditAddress6Id !== client.id"
class="inline-block border-t-2 border-b-2 border-transparent">{{client.address6}}</span>
<!-- Edit -->
<span v-show="clientEditAddress6Id !== client.id"
@click="clientEditAddress6 = client.address6; clientEditAddress6Id = client.id; setTimeout(() => $refs['client-' + client.id + '-address6'][0].select(), 1);"
class="cursor-pointer opacity-0 group-hover:opacity-100 transition-opacity">
<svg xmlns="http://www.w3.org/2000/svg"
class="h-4 w-4 inline align-middle opacity-25 hover:opacity-100" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
</svg>
</span>
</span>
<!-- Transfer TX -->
<div class="min-w-20 md:min-w-24" v-if="client.transferTx">
<span class="flex gap-1" :title="$t('totalDownload') + bytes(client.transferTx)">

8
src/www/js/api.js

@ -138,12 +138,4 @@ class API {
});
}
async restoreConfiguration(file) {
return this.call({
method: 'put',
path: '/wireguard/restore',
body: { file },
});
}
}

18
src/www/js/app.js

@ -63,8 +63,6 @@ new Vue({
clientEditNameId: null,
clientEditAddress: null,
clientEditAddressId: null,
clientEditAddress6: null,
clientEditAddress6Id: null,
qrcode: null,
currentRelease: null,
@ -301,22 +299,6 @@ new Vue({
.catch((err) => alert(err.message || err.toString()))
.finally(() => this.refresh().catch(console.error));
},
restoreConfig(e) {
e.preventDefault();
const file = e.currentTarget.files.item(0);
if (file) {
file.text()
.then((content) => {
this.api.restoreConfiguration(content)
.then((_result) => alert('The configuration was updated.'))
.catch((err) => alert(err.message || err.toString()))
.finally(() => this.refresh().catch(console.error));
})
.catch((err) => alert(err.message || err.toString()));
} else {
alert('Failed to load your file!');
}
},
toggleTheme() {
const themes = ['light', 'dark', 'auto'];
const currentIndex = themes.indexOf(this.uiTheme);

46
src/www/js/i18n.js

@ -30,10 +30,6 @@ const messages = { // eslint-disable-line no-unused-vars
donate: 'Donate',
toggleCharts: 'Show/hide Charts',
theme: { dark: 'Dark theme', light: 'Light theme', auto: 'Auto theme' },
restore: 'Restore',
backup: 'Backup',
titleRestoreConfig: 'Restore your configuration',
titleBackupConfig: 'Backup your configuration',
},
ua: {
name: 'Ім`я',
@ -197,10 +193,6 @@ const messages = { // eslint-disable-line no-unused-vars
downloadConfig: 'Télécharger la configuration',
madeBy: 'Développé par',
donate: 'Soutenir',
restore: 'Restaurer',
backup: 'Sauvegarder',
titleRestoreConfig: 'Restaurer votre configuration',
titleBackupConfig: 'Sauvegarder votre configuration',
},
de: { // github.com/florian-asche
name: 'Name',
@ -229,10 +221,6 @@ const messages = { // eslint-disable-line no-unused-vars
downloadConfig: 'Konfiguration herunterladen',
madeBy: 'Erstellt von',
donate: 'Spenden',
restore: 'Wiederherstellen',
backup: 'Sichern',
titleRestoreConfig: 'Stelle deine Konfiguration wieder her',
titleBackupConfig: 'Sichere deine Konfiguration',
},
ca: { // github.com/guillembonet
name: 'Nom',
@ -289,10 +277,6 @@ const messages = { // eslint-disable-line no-unused-vars
donate: 'Donar',
toggleCharts: 'Mostrar/Ocultar gráficos',
theme: { dark: 'Modo oscuro', light: 'Modo claro', auto: 'Modo automático' },
restore: 'Restaurar',
backup: 'Realizar copia de seguridad',
titleRestoreConfig: 'Restaurar su configuración',
titleBackupConfig: 'Realizar copia de seguridad de su configuración',
},
ko: {
name: '이름',
@ -461,27 +445,27 @@ const messages = { // eslint-disable-line no-unused-vars
password: '密碼',
signIn: '登入',
logout: '登出',
updateAvailable: '有新版本可以使用!',
updateAvailable: '有新版本可用!',
update: '更新',
clients: '使用者',
new: '建',
deleteClient: '刪除使用者',
clients: '客戶',
new: '建',
deleteClient: '刪除客戶',
deleteDialog1: '您確定要刪除',
deleteDialog2: '此作業無法復原。',
deleteDialog2: '此操作無法撤銷。',
cancel: '取消',
create: '建立',
createdOn: '建立於 ',
lastSeen: '最後存取於 ',
lastSeen: '最後訪問於 ',
totalDownload: '總下載: ',
totalUpload: '總上傳: ',
newClient: '新戶',
disableClient: '停用使用者',
enableClient: '啟用使用者',
noClients: '目前沒有使用者。',
showQR: '顯示 QR Code',
downloadConfig: '下載 Config 檔',
newClient: '新戶',
disableClient: '禁用客戶',
enableClient: '啟用客戶',
noClients: '目前沒有客戶。',
showQR: '顯示二維碼',
downloadConfig: '下載配置',
madeBy: '由',
donate: '抖內',
donate: '捐贈',
},
it: {
name: 'Nome',
@ -509,10 +493,6 @@ const messages = { // eslint-disable-line no-unused-vars
downloadConfig: 'Scarica configurazione',
madeBy: 'Realizzato da',
donate: 'Donazione',
restore: 'Ripristina',
backup: 'Backup',
titleRestoreConfig: 'Ripristina la tua configurazione',
titleBackupConfig: 'Esegui il backup della tua configurazione',
},
th: {
name: 'ชื่อ',

8
src/www/js/vendor/apexcharts.min.js

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save