Invert openvpn_alt_mode binding behavior

This commit is contained in:
Alexandre
2025-11-25 13:24:10 +01:00
parent fa45da21a3
commit aa19627ee7
6 changed files with 56 additions and 54 deletions

View File

@@ -1,3 +1,6 @@
## 5.1.2-24 (30-11-2025)
- Reverse `openvpn_alt_mode`: enabled now binds only qBittorrent to the VPN interface; default keeps container-wide binding for OpenVPN and WireGuard.
## 5.1.2-23 (29-11-2025) ## 5.1.2-23 (29-11-2025)
- Default VPN container binding for OpenVPN and WireGuard with optional qBittorrent-only interface binding. - Default VPN container binding for OpenVPN and WireGuard with optional qBittorrent-only interface binding.

View File

@@ -77,14 +77,14 @@ Network disk is mounted to `/mnt/<share_name>`. You need to map the exposed port
| `openvpn_config` | str | | OpenVPN config file name (in `/config/openvpn/`) | | `openvpn_config` | str | | OpenVPN config file name (in `/config/openvpn/`) |
| `openvpn_username` | str | | OpenVPN username | | `openvpn_username` | str | | OpenVPN username |
| `openvpn_password` | str | | OpenVPN password | | `openvpn_password` | str | | OpenVPN password |
| `openvpn_alt_mode` | bool | `true` | Container binding for VPN traffic (disable to bind qBittorrent only) | | `openvpn_alt_mode` | bool | `false` | Bind only qBittorrent to the VPN interface (leave disabled for container-wide binding) |
| `wireguard_enabled` | bool | `false` | Enable WireGuard tunnel | | `wireguard_enabled` | bool | `false` | Enable WireGuard tunnel |
| `wireguard_config` | str | _(empty)_ | WireGuard config file name (in `/config/wireguard/`) | | `wireguard_config` | str | _(empty)_ | WireGuard config file name (in `/config/wireguard/`) |
| `qbit_manage` | bool | `false` | Enable qBit Manage integration | | `qbit_manage` | bool | `false` | Enable qBit Manage integration |
| `run_duration` | str | | Run duration (e.g., `12h`, `5d`) | | `run_duration` | str | | Run duration (e.g., `12h`, `5d`) |
| `silent` | bool | `false` | Suppress debug messages | | `silent` | bool | `false` | Suppress debug messages |
By default, VPN traffic is container-bound (OpenVPN and WireGuard). Disable `openvpn_alt_mode` only if you prefer binding qBittorrent itself to the VPN interface while exposing the rest of the container on the host network. By default, VPN traffic is container-bound (OpenVPN and WireGuard). Enable `openvpn_alt_mode` only if you prefer binding qBittorrent itself to the VPN interface while exposing the rest of the container on the host network.
### WireGuard Setup ### WireGuard Setup

View File

@@ -89,7 +89,7 @@ options:
certfile: fullchain.pem certfile: fullchain.pem
customUI: vuetorrent customUI: vuetorrent
keyfile: privkey.pem keyfile: privkey.pem
openvpn_alt_mode: true openvpn_alt_mode: false
openvpn_config: "" openvpn_config: ""
openvpn_enabled: false openvpn_enabled: false
openvpn_password: "" openvpn_password: ""
@@ -150,4 +150,4 @@ schema:
slug: qbittorrent slug: qbittorrent
udev: true udev: true
url: https://github.com/alexbelgium/hassio-addons url: https://github.com/alexbelgium/hassio-addons
version: 5.1.2-23 version: 5.1.2-24

View File

@@ -197,29 +197,10 @@ if bashio::config.true 'openvpn_enabled'; then
# CONFIGURE QBITTORRENT # # CONFIGURE QBITTORRENT #
######################### #########################
# WITH CONTAINER BINDING
#########################
# If alternative mode enabled, bind container
if bashio::config.true 'openvpn_alt_mode'; then
echo "Using container binding"
# Remove interface
echo "... deleting previous interface settings"
sed -i '/Interface/d' "$QBT_CONFIG_FILE"
# Modify ovpn config
if grep -q route-nopull /config/openvpn/"$openvpn_config"; then
echo "... removing route-nopull from your config.ovpn"
sed -i '/route-nopull/d' /config/openvpn/"$openvpn_config"
fi
# Exit
exit 0
fi
# WITH INTERFACE BINDING # WITH INTERFACE BINDING
######################### #########################
# Connection with interface binding # If alternative mode enabled, bind only the app
if bashio::config.true 'openvpn_alt_mode'; then
echo "Using interface binding in the qBittorrent app" echo "Using interface binding in the qBittorrent app"
# Define preferences line # Define preferences line
@@ -251,6 +232,25 @@ if bashio::config.true 'openvpn_enabled'; then
sed -i "1a route-nopull" /config/openvpn/"$openvpn_config" sed -i "1a route-nopull" /config/openvpn/"$openvpn_config"
fi fi
# Exit
exit 0
fi
# WITH CONTAINER BINDING
#########################
# Default: bind whole container
echo "Using container binding"
# Remove interface
echo "... deleting previous interface settings"
sed -i '/Interface/d' "$QBT_CONFIG_FILE"
# Modify ovpn config
if grep -q route-nopull /config/openvpn/"$openvpn_config"; then
echo "... removing route-nopull from your config.ovpn"
sed -i '/route-nopull/d' /config/openvpn/"$openvpn_config"
fi
else else
################## ##################

View File

@@ -63,16 +63,7 @@ echo "${wireguard_runtime_config}" > "${WIREGUARD_STATE_DIR}/config"
echo "${interface_name}" > "${WIREGUARD_STATE_DIR}/interface" echo "${interface_name}" > "${WIREGUARD_STATE_DIR}/interface"
if bashio::config.true 'openvpn_alt_mode'; then if bashio::config.true 'openvpn_alt_mode'; then
bashio::log.info 'Using container-wide WireGuard binding (default).' bashio::log.info 'Using qBittorrent interface binding for WireGuard.'
if bashio::fs.file_exists "${QBT_CONFIG_FILE}"; then
sed -i '/Interface/d' "${QBT_CONFIG_FILE}"
else
bashio::log.warning 'qBittorrent config file not found. Unable to remove interface binding entries.'
fi
bashio::log.info "WireGuard prepared with interface ${interface_name} using configuration ${wireguard_config##*/}."
exit 0
fi
if bashio::fs.file_exists "${QBT_CONFIG_FILE}"; then if bashio::fs.file_exists "${QBT_CONFIG_FILE}"; then
sed -i '/Interface/d' "${QBT_CONFIG_FILE}" sed -i '/Interface/d' "${QBT_CONFIG_FILE}"
sed -i "/\\[Preferences\\]/ i\\Connection\\\\Interface=${interface_name}" "${QBT_CONFIG_FILE}" sed -i "/\\[Preferences\\]/ i\\Connection\\\\Interface=${interface_name}" "${QBT_CONFIG_FILE}"
@@ -82,5 +73,13 @@ if bashio::fs.file_exists "${QBT_CONFIG_FILE}"; then
else else
bashio::log.warning "qBittorrent config file not found. Bind the client manually to interface ${interface_name}." bashio::log.warning "qBittorrent config file not found. Bind the client manually to interface ${interface_name}."
fi fi
else
bashio::log.info 'Using container-wide WireGuard binding (default).'
if bashio::fs.file_exists "${QBT_CONFIG_FILE}"; then
sed -i '/Interface/d' "${QBT_CONFIG_FILE}"
else
bashio::log.warning 'qBittorrent config file not found. Unable to remove interface binding entries.'
fi
fi
bashio::log.info "WireGuard prepared with interface ${interface_name} using configuration ${wireguard_config##*/}." bashio::log.info "WireGuard prepared with interface ${interface_name} using configuration ${wireguard_config##*/}."

View File

@@ -133,7 +133,7 @@ if bashio::config.true 'wireguard_enabled'; then
vpn_wireguard=true vpn_wireguard=true
fi fi
if ! bashio::config.true 'openvpn_alt_mode'; then if bashio::config.true 'openvpn_alt_mode'; then
if [[ "${vpn_openvpn}" == true ]]; then if [[ "${vpn_openvpn}" == true ]]; then
VPN_INTERFACE="tun0" VPN_INTERFACE="tun0"
bashio::log.info "VPN monitor set to query external IP through interface ${VPN_INTERFACE} (interface binding)." bashio::log.info "VPN monitor set to query external IP through interface ${VPN_INTERFACE} (interface binding)."