From 4ff0187f979a2054122826fe6e3b4713dced6ba4 Mon Sep 17 00:00:00 2001 From: Shahrad Elahi Date: Wed, 27 Sep 2023 05:30:23 +0330 Subject: [PATCH] fix --- config/torrc | 4 ++-- docker-compose.yml | 7 +++++-- docker-entrypoint.sh | 4 ++-- src/lib/wireguard-utils.ts | 3 ++- src/lib/wireguard.ts | 6 +++--- src/next.config.js | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/config/torrc b/config/torrc index ad6b7cc..1973485 100644 --- a/config/torrc +++ b/config/torrc @@ -1,5 +1,5 @@ VirtualAddrNetwork 10.192.0.0/10 SOCKSPort 9055 ControlPort 9051 -DNSPort 10.8.0.1:53530 -TransPort 10.8.0.1:9040 \ No newline at end of file +DNSPort 53530 +TransPort 9040 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9b1781a..7d8eb00 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,13 +3,13 @@ services: wireadmin: environment: # ⚠️ Required: - # Change this to your host's public address + # Make sure change this to your host's public address - WG_HOST=raspberrypi.local image: shahradel/wireadmin container_name: wireadmin volumes: - - ~/.wg-data:/data + - redis-data:/data ports: - "51820:51820/udp" - "3000:3000/tcp" @@ -21,3 +21,6 @@ services: - net.ipv4.ip_forward=1 - net.ipv4.conf.all.src_valid_mark=1 +volumes: + redis-data: + driver: local \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4c3177c..db63911 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,4 +1,4 @@ -#!/usr/bin/dumb-init /bin/sh +#!/usr/bin/dumb-init /bin/bash set -e # Note above that we run dumb-init as PID 1 in order to reap zombie processes @@ -24,6 +24,6 @@ screen -L -Logfile /var/vlogs/tor -dmS tor bash -c "tor" screen -L -Logfile /var/vlogs/redis -dmS redis bash -c "redis-server --port 6479 --daemonize no --dir /data --appendonly yes" # After 5 seconds, export the database to the WireGuard config file -screen -dm bash -c "sleep 5; curl -s -o /dev/null http://127.0.0.1:3000/api/wireguard/regen" +bash -c "sleep 5; curl -s -o /dev/null http://127.0.0.1:3000/api/wireguard/regen"& exec "$@" diff --git a/src/lib/wireguard-utils.ts b/src/lib/wireguard-utils.ts index ea54572..6ba8058 100644 --- a/src/lib/wireguard-utils.ts +++ b/src/lib/wireguard-utils.ts @@ -43,6 +43,7 @@ export async function getServerIP(): Promise { } export async function getPeerConf(params: GenPeerConParams): Promise { + const serverAddress = params.serverAddress || await getServerIP() const lines = [ '# Autogenerated by WireGuard UI (WireAdmin)', '[Interface]', @@ -55,7 +56,7 @@ export async function getPeerConf(params: GenPeerConParams): Promise { `${params.preSharedKey ? `PresharedKey = ${params.preSharedKey}` : 'OMIT'}`, `AllowedIPs = 0.0.0.0/0, ::/0`, `PersistentKeepalive = ${params.persistentKeepalive}`, - `Endpoint = ${params.serverAddress || process.env.NEXT_PUBLIC_WG_HOST}:${params.port}`, + `Endpoint = ${serverAddress}:${params.port}`, ] return lines .filter((l) => l !== 'OMIT') diff --git a/src/lib/wireguard.ts b/src/lib/wireguard.ts index 0b03285..ffb65cb 100644 --- a/src/lib/wireguard.ts +++ b/src/lib/wireguard.ts @@ -479,9 +479,9 @@ async function makeWgIptables(s: WgServer): Promise<{ up: string, down: string } const up = dynaJoin([ `iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT`, `iptables -A INPUT -i ${wgInet} -s ${source} -m state --state NEW -j ACCEPT`, - `iptables -t nat -A PREROUTING -i ${wgInet} -p udp -s ${source} --dport 53 -j DNAT --to-destination 10.8.0.1:53530`, - `iptables -t nat -A PREROUTING -i ${wgInet} -p tcp -s ${source} -j DNAT --to-destination 10.8.0.1:9040`, - `iptables -t nat -A PREROUTING -i ${wgInet} -p udp -s ${source} -j DNAT --to-destination 10.8.0.1:9040`, + `iptables -t nat -A PREROUTING -i ${wgInet} -p udp -s ${source} --dport 53 -j DNAT --to-destination 127.0.0.1:53530`, + `iptables -t nat -A PREROUTING -i ${wgInet} -p tcp -s ${source} -j DNAT --to-destination 127.0.0.1:9040`, + `iptables -t nat -A PREROUTING -i ${wgInet} -p udp -s ${source} -j DNAT --to-destination 127.0.0.1:9040`, `iptables -t nat -A OUTPUT -o lo -j RETURN`, `iptables -A OUTPUT -m conntrack --ctstate INVALID -j DROP`, `iptables -A OUTPUT -m state --state INVALID -j DROP`, diff --git a/src/next.config.js b/src/next.config.js index fb1134c..283babd 100644 --- a/src/next.config.js +++ b/src/next.config.js @@ -10,7 +10,7 @@ const nextConfig = { reactStrictMode: true, transpilePackages: [], env: publicENV({ - NEXT_PUBLIC_WG_HOST: process.env.WG_HOST + NEXT_PUBLIC_WG_HOST: process.env?.WG_HOST }) }