Skip to content

Added support for Multiple Local networks for Sabnzbd/Openvpn #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sabnzbdvpn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ docker run -d --name sabnzbdvpn \
-v /host/storage/path:/config \
-v /path/to/openvpnconfigdir:/etc/openvpn/custom
-v /etc/localtime:/etc/localtime:ro \
-e "LOCAL_NETWORK=192.168.0.0/24" \
-e "LOCAL_NETWORKS=192.168.0.0/24" \
-p 8080:8080 \
mumiehub/sabnzbdvpn
```
Expand All @@ -31,7 +31,7 @@ docker run -d --name sabnzbdvpn \
| Variable | Function | Example |
|----------|----------|---------|
|`OPENVPN_OPTS` | Will be passed to OpenVPN on startup | See [OpenVPN doc](https://openvpn.net/index.php/open-source/documentation/manuals/65-openvpn-20x-manpage.html) |
|`LOCAL_NETWORK` | Sets the local network that should have access to the GUI | `LOCAL_NETWORK=192.168.0.0/24`|
|`LOCAL_NETWORKS` | Sets the local network that should have access to the GUI | `LOCAL_NETWORKS=192.168.0.0/24,192.168.1.0/24`|


#### User configuration options
Expand All @@ -46,11 +46,11 @@ By default OpenVPN will run as the root user and SABnzbd will run as user abc `1

## Access the WebUI of SABnzbd

If you set `LOCAL_NETWORK` correctly, the WebUI of SABnzbd should be at http://containerhost:8080. If its not responding, there might be an error with your
`LOCAL_NETWORK` subnet settings.
If you set `LOCAL_NETWORKS` correctly, the WebUI of SABnzbd should be at http://containerhost:8080. If its not responding, there might be an error with your
`LOCAL_NETWORKS` subnet settings.

### How to fix this:
The container supports the `LOCAL_NETWORK` environment variable. For instance if your local network uses the subnet 192.168.0.0/24 you should pass `-e LOCAL_NETWORK=192.168.0.0/24`. It must match your subnet, else your traffic will be "non-local" traffic and therefore be routed out through the VPN interface.
The container supports the `LOCAL_NETWORKS` environment variable. For instance if your local network uses the subnet 192.168.0.0/24 you should pass `-e LOCAL_NETWORKS=192.168.0.0/24,192.168.1.0/24`. It must match your subnet and your server subnet, else your traffic will be "non-local" traffic and therefore be routed out through the VPN interface.

Alternatively you can reverse proxy the traffic through another container, as that container would be in the docker range.
Nginx with proxypass config.
Expand Down
21 changes: 13 additions & 8 deletions sabnzbdvpn/openvpn/start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

#. /etc/profile

Expand All @@ -13,12 +13,17 @@
#fi

#set routing gateway for the container
if [ -n "${LOCAL_NETWORK-}" ]; then
eval $(/sbin/ip r s 0.0.0.0/0 | awk '{if($5!="tun0"){print "GW="$3"\nINT="$5; exit}}')
if [ -n "${GW-}" -a -n "${INT-}" ]; then
echo "adding route to local network $LOCAL_NETWORK via $GW dev $INT"
/sbin/ip r a "$LOCAL_NETWORK" via "$GW" dev "$INT"
fi
IFS=',' read -ra NETWORKS <<< "$LOCAL_NETWORKS"

if [ -n "${LOCAL_NETWORKS-}" ]; then
eval $(/sbin/ip r s 0.0.0.0/0 | awk '{if($5!="tun0"){print "GW="$3"\nINT="$5; exit}}')

for LOCAL_NETWORK in "${NETWORKS[@]}"; do
if [ -n "${GW-}" -a -n "${INT-}" ]; then
echo "adding route to local network $LOCAL_NETWORK via $GW dev $INT"
/sbin/ip r a "$LOCAL_NETWORK" via "$GW" dev "$INT"
fi
done
fi

. /scripts/userSetup.sh
Expand All @@ -29,4 +34,4 @@ OPENVPN_CONFIG_PATH="$OPENVPN_CONFIG_DIR/$OPENVPN_CONFIG"
#printf "USER=${USER_NAME}\nHOST=0.0.0.0\nPORT=8080\nCONFIG=${SABNZBD_CONFIG_DIR}\n" > /etc/default/sabnzbdplus \
#/etc/init.d/sabnzbdplus start

exec openvpn $CONTROL_OPTS $OPENVPN_OPTS --config "$OPENVPN_CONFIG_PATH"
exec openvpn $CONTROL_OPTS $OPENVPN_OPTS --config "$OPENVPN_CONFIG_PATH"