Skip to content

Commit bebd0be

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

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ $ 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-
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 |
137140
### Run as a Docker container
138141

139142
#### Install WireGuard on the host

entrypoint.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,42 @@ cat <<WGSERVER >/data/wireguard/server.conf
163163
PrivateKey = $(cat /data/wireguard/server.private)
164164
ListenPort = ${SUBSPACE_LISTENPORT}
165165
166+
PreUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
167+
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
168+
166169
WGSERVER
170+
171+
if [ ! -z "${SUBSPACE_PREUP-}" ];
172+
then
173+
echo "PreUp = $SUBSPACE_PREUP" >> /data/wireguard/server.conf
174+
fi
175+
if [ ! -z "${SUBSPACE_PREDOWN-}" ];
176+
then
177+
echo "PreDown = $SUBSPACE_PREDOWN" >> /data/wireguard/server.conf
178+
fi
179+
if [ ! -z "${SUBSPACE_POSTUP-}" ];
180+
then
181+
echo "PostUp = $SUBSPACE_POSTUP" >> /data/wireguard/server.conf
182+
fi
183+
if [ ! -z "${SUBSPACE_POSTDOWN-}" ];
184+
then
185+
echo "PostDown = $SUBSPACE_POSTDOWN" >> /data/wireguard/server.conf
186+
fi
187+
167188
cat /data/wireguard/peers/*.conf >>/data/wireguard/server.conf
168189
umask ${umask_val}
169190
[ -f /data/config.json ] && chmod 600 /data/config.json # Special handling of file not created by start-up script
170191

171192
if ip link show wg0 2>/dev/null; then
172193
ip link del wg0
173194
fi
174-
ip link add wg0 type wireguard
195+
196+
#wg setconf wg0 /data/wireguard/server.conf
197+
#ip link set wg0 up
198+
cp /data/wireguard/server.conf /data/wireguard/wg0.conf
199+
wg-quick up /data/wireguard/wg0.conf
200+
201+
#ip link add wg0 type wireguard
175202
if [[ ${SUBSPACE_IPV4_NAT_ENABLED} -ne 0 ]]; then
176203
export SUBSPACE_IPV4_CIDR=$(echo ${SUBSPACE_IPV4_POOL-} | cut -d '/' -f2)
177204
ip addr add ${SUBSPACE_IPV4_GW}/${SUBSPACE_IPV4_CIDR} dev wg0
@@ -180,8 +207,6 @@ if [[ ${SUBSPACE_IPV6_NAT_ENABLED} -ne 0 ]]; then
180207
export SUBSPACE_IPV6_CIDR=$(echo ${SUBSPACE_IPV6_POOL-} | cut -d '/' -f2)
181208
ip addr add ${SUBSPACE_IPV6_GW}/${SUBSPACE_IPV6_CIDR} dev wg0
182209
fi
183-
wg setconf wg0 /data/wireguard/server.conf
184-
ip link set wg0 up
185210

186211
# dnsmasq service
187212
if [[ ${SUBSPACE_DISABLE_DNS} == "0" ]]; then
@@ -252,3 +277,4 @@ RUNIT
252277
fi
253278

254279
exec $@
280+

0 commit comments

Comments
 (0)