Default container VPN binding

This commit is contained in:
Alexandre
2025-11-25 10:27:47 +01:00
parent 51fd1a7404
commit fa45da21a3
5 changed files with 41 additions and 13 deletions

View File

@@ -19,10 +19,6 @@ if bashio::config.true 'openvpn_enabled'; then
bashio::exit.nok 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.'
fi
if bashio::config.true 'openvpn_alt_mode'; then
bashio::log.warning 'The openvpn_alt_mode option is ignored when WireGuard is enabled.'
fi
if bashio::config.has_value 'wireguard_config'; then
configured_name="$(bashio::config 'wireguard_config')"
configured_name="${configured_name##*/}"
@@ -66,6 +62,17 @@ bashio::log.info 'Prepared WireGuard runtime configuration for initial connectio
echo "${wireguard_runtime_config}" > "${WIREGUARD_STATE_DIR}/config"
echo "${interface_name}" > "${WIREGUARD_STATE_DIR}/interface"
if bashio::config.true 'openvpn_alt_mode'; then
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
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
sed -i '/Interface/d' "${QBT_CONFIG_FILE}"
sed -i "/\\[Preferences\\]/ i\\Connection\\\\Interface=${interface_name}" "${QBT_CONFIG_FILE}"

View File

@@ -129,17 +129,28 @@ if bashio::config.true 'openvpn_enabled'; then
vpn_openvpn=true
fi
if [[ "${vpn_openvpn}" == true ]] && ! bashio::config.true 'openvpn_alt_mode'; then
VPN_INTERFACE="tun0"
bashio::log.info "VPN monitor set to query external IP through interface ${VPN_INTERFACE} (interface binding)."
else
VPN_INTERFACE=""
fi
if bashio::config.true 'wireguard_enabled'; then
vpn_wireguard=true
fi
if ! bashio::config.true 'openvpn_alt_mode'; then
if [[ "${vpn_openvpn}" == true ]]; then
VPN_INTERFACE="tun0"
bashio::log.info "VPN monitor set to query external IP through interface ${VPN_INTERFACE} (interface binding)."
elif [[ "${vpn_wireguard}" == true ]]; then
if [[ -f /var/run/wireguard/interface ]]; then
VPN_INTERFACE="$(cat /var/run/wireguard/interface)"
else
VPN_INTERFACE="wg0"
fi
bashio::log.info "VPN monitor set to query external IP through interface ${VPN_INTERFACE} (interface binding)."
else
VPN_INTERFACE=""
fi
else
VPN_INTERFACE=""
fi
if [[ "${vpn_openvpn}" != true && "${vpn_wireguard}" != true ]]; then
bashio::log.info "VPN leak monitor not started because no VPN is enabled."
exit 0