Skip to content

Commit b6e948a

Browse files
Christoph SpörkDarwinsBuddy
Christoph Spörk
authored andcommitted
Add PreUp/PostUp/PreDown/PostDown to env variables for server.conf creation
Add gateway device forwarding
1 parent 872781c commit b6e948a

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ $ subspace --http-host subspace.example.com
133133
| `SUBSPACE_THEME` | `green` | The theme to use, please refer to [semantic-ui](https://semantic-ui.com/usage/theming.html) for accepted colors |
134134
| `SUBSPACE_BACKLINK` | `/` | The page to set the home button to |
135135
| `SUBSPACE_DISABLE_DNS` | `false` | Whether to disable DNS so the client uses their own configured DNS server(s). Consider disabling DNS server, if supporting international VPN clients |
136+
| `SUBSPACE_PREUP` | null | PreUp=Action for wireguard server interface |
137+
| `SUBSPACE_PREDOWN` | null | PreDown=Action for wireguard server interface |
138+
| `SUBSPACE_POSTUP` | null | PostUp=Action for wireguard server interface |
139+
| `SUBSPACE_POSTDOWN` | null | PostDown=Action for wireguard server interface |
140+
| `SUBSPACE_FORWARD_GW` | null | If set, will forward to this device (e.g. a nic in a different subnet) e.g. eth0, wlan0|
136141

137142
### Run as a Docker container
138143

entrypoint.sh

+31-3
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,44 @@ cat <<WGSERVER >/data/wireguard/server.conf
163163
PrivateKey = $(cat /data/wireguard/server.private)
164164
ListenPort = ${SUBSPACE_LISTENPORT}
165165
166+
166167
WGSERVER
168+
169+
if [ ! -z "${SUBSPACE_FORWARD_GW-}" ];
170+
then
171+
echo "PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o ${SUBSPACE_FORWARD_GW} -j MASQUERADE" >> /data/wireguard/server.conf
172+
echo "PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o ${SUBSPACE_FORWARD_GW} -j MASQUERADE" >> /data/wireguard/server.conf
173+
fi
174+
175+
if [ ! -z "${SUBSPACE_PREUP-}" ];
176+
then
177+
echo "PreUp = $SUBSPACE_PREUP" >> /data/wireguard/server.conf
178+
fi
179+
if [ ! -z "${SUBSPACE_PREDOWN-}" ];
180+
then
181+
echo "PreDown = $SUBSPACE_PREDOWN" >> /data/wireguard/server.conf
182+
fi
183+
if [ ! -z "${SUBSPACE_POSTUP-}" ];
184+
then
185+
echo "PostUp = $SUBSPACE_POSTUP" >> /data/wireguard/server.conf
186+
fi
187+
if [ ! -z "${SUBSPACE_POSTDOWN-}" ];
188+
then
189+
echo "PostDown = $SUBSPACE_POSTDOWN" >> /data/wireguard/server.conf
190+
fi
191+
167192
cat /data/wireguard/peers/*.conf >>/data/wireguard/server.conf
168193
umask ${umask_val}
169194
[ -f /data/config.json ] && chmod 600 /data/config.json # Special handling of file not created by start-up script
170195

171196
if ip link show wg0 2>/dev/null; then
172197
ip link del wg0
173198
fi
174-
ip link add wg0 type wireguard
199+
200+
cp /data/wireguard/server.conf /data/wireguard/wg0.conf
201+
wg-quick up /data/wireguard/wg0.conf
202+
203+
#ip link add wg0 type wireguard
175204
if [[ ${SUBSPACE_IPV4_NAT_ENABLED} -ne 0 ]]; then
176205
export SUBSPACE_IPV4_CIDR=$(echo ${SUBSPACE_IPV4_POOL-} | cut -d '/' -f2)
177206
ip addr add ${SUBSPACE_IPV4_GW}/${SUBSPACE_IPV4_CIDR} dev wg0
@@ -180,8 +209,6 @@ if [[ ${SUBSPACE_IPV6_NAT_ENABLED} -ne 0 ]]; then
180209
export SUBSPACE_IPV6_CIDR=$(echo ${SUBSPACE_IPV6_POOL-} | cut -d '/' -f2)
181210
ip addr add ${SUBSPACE_IPV6_GW}/${SUBSPACE_IPV6_CIDR} dev wg0
182211
fi
183-
wg setconf wg0 /data/wireguard/server.conf
184-
ip link set wg0 up
185212

186213
# dnsmasq service
187214
if [[ ${SUBSPACE_DISABLE_DNS} == "0" ]]; then
@@ -252,3 +279,4 @@ RUNIT
252279
fi
253280

254281
exec $@
282+

0 commit comments

Comments
 (0)