Merge pull request #2448 from alexbelgium/qbittorrent_debug_mode

Implement logging for OpenVPN with configurable level
This commit is contained in:
Alexandre
2026-02-05 16:38:11 +01:00
committed by GitHub
3 changed files with 31 additions and 12 deletions

View File

@@ -18,7 +18,8 @@ fi
if ! bashio::config.true 'openvpn_enabled'; then
bashio::exit.ok 'OpenVPN is disabled.'
elif bashio::config.true 'wireguard_enabled'; then
bashio::exit.nok 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.'
bashio::log.fatal 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.'
bashio::addon.stop
fi
mkdir -p "${OPENVPN_STATE_DIR}"
@@ -31,12 +32,14 @@ bashio::log.info "----------------------------"
if bashio::config.has_value "openvpn_username"; then
openvpn_username=$(bashio::config 'openvpn_username')
else
bashio::exit.nok "Openvpn is enabled, but openvpn_username option is empty! Exiting"
bashio::log.fatal "Openvpn is enabled, but openvpn_username option is empty! Exiting"
bashio::addon.stop
fi
if bashio::config.has_value "openvpn_password"; then
openvpn_password=$(bashio::config 'openvpn_password')
else
bashio::exit.nok "Openvpn is enabled, but openvpn_password option is empty! Exiting"
bashio::log.fatal "Openvpn is enabled, but openvpn_password option is empty! Exiting"
bashio::addon.stop
fi
echo -e "${openvpn_username}\n${openvpn_password}" > "${OPENVPN_STATE_DIR}/credentials.conf"
@@ -50,7 +53,8 @@ if [[ -z "${openvpn_config}" ]]; then
bashio::log.info 'openvpn_config option left empty. Attempting automatic selection.'
mapfile -t configs < <(find /config/openvpn -maxdepth 1 \( -type f -name '*.conf' -o -name '*.ovpn' \) -print)
if [ "${#configs[@]}" -eq 0 ]; then
bashio::exit.nok 'OpenVPN is enabled but no .conf or .ovpn file was found in /config/openvpn.'
bashio::log.fatal 'OpenVPN is enabled but no .conf or .ovpn file was found in /config/openvpn.'
bashio::addon.stop
elif [ "${#configs[@]}" -eq 1 ]; then
openvpn_config="${configs[0]}"
bashio::log.info "OpenVPN configuration not specified. Using ${openvpn_config##*/}."
@@ -58,17 +62,20 @@ if [[ -z "${openvpn_config}" ]]; then
openvpn_config='/config/openvpn/config.conf'
bashio::log.info 'Using default OpenVPN configuration config.conf.'
else
bashio::exit.nok "Multiple OpenVPN configuration files detected. Please set the 'openvpn_config' option."
bashio::log.fatal "Multiple OpenVPN configuration files detected. Please set the 'openvpn_config' option."
bashio::addon.stop
fi
elif bashio::fs.file_exists "/config/openvpn/${openvpn_config}"; then
openvpn_config="/config/openvpn/${openvpn_config}"
else
bashio::exit.nok "OpenVPN configuration '/config/openvpn/${openvpn_config}' not found."
bashio::log.fatal "OpenVPN configuration '/config/openvpn/${openvpn_config}' not found."
bashio::addon.stop
fi
interface_name="$(sed -n "/^dev tun/p" "${openvpn_config}" | awk -F' ' '{print $2}')"
if [[ -z "${interface_name}" ]]; then
bashio::exit.nok "OpenVPN configuration '${openvpn_config}' misses device directive."
bashio::log.fatal "OpenVPN configuration '${openvpn_config}' misses device directive."
bashio::addon.stop
elif [[ ${interface_name} = "tun" ]]; then
interface_name='tun0'
elif [[ ${interface_name} = "tap" ]]; then

View File

@@ -16,7 +16,8 @@ fi
if ! bashio::config.true 'wireguard_enabled'; then
bashio::exit.ok 'WireGuard is disabled.'
elif bashio::config.true 'openvpn_enabled'; then
bashio::exit.nok 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.'
bashio::log.fatal 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.'
bashio::addon.stop
fi
mkdir -p "${WIREGUARD_STATE_DIR}"
@@ -33,7 +34,8 @@ if [[ -z "${wireguard_config}" ]]; then
bashio::log.info 'wireguard_config option left empty. Attempting automatic selection.'
mapfile -t configs < <(find /config/wireguard -maxdepth 1 -type f -name '*.conf' -print)
if [ "${#configs[@]}" -eq 0 ]; then
bashio::exit.nok 'WireGuard is enabled but no .conf file was found in /config/wireguard.'
bashio::log.fatal 'WireGuard is enabled but no .conf file was found in /config/wireguard.'
bashio::addon.stop
elif [ "${#configs[@]}" -eq 1 ]; then
wireguard_config="${configs[0]}"
bashio::log.info "WireGuard configuration not specified. Using ${wireguard_config##*/}."
@@ -41,12 +43,14 @@ if [[ -z "${wireguard_config}" ]]; then
wireguard_config='/config/wireguard/config.conf'
bashio::log.info 'Using default WireGuard configuration config.conf.'
else
bashio::exit.nok "Multiple WireGuard configuration files detected. Please set the 'wireguard_config' option."
bashio::log.fatal "Multiple WireGuard configuration files detected. Please set the 'wireguard_config' option."
bashio::addon.stop
fi
elif bashio::fs.file_exists "/config/wireguard/${wireguard_config}"; then
wireguard_config="/config/wireguard/${wireguard_config}"
else
bashio::exit.nok "WireGuard configuration '/config/wireguard/${wireguard_config}' not found."
bashio::log.fatal "WireGuard configuration '/config/wireguard/${wireguard_config}' not found."
bashio::addon.stop
fi
interface_name="$(basename "${wireguard_config}" .conf)"

View File

@@ -9,6 +9,10 @@ config["MySelf"]="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BA
declare -a dns_servers_ipv4=()
declare -a dns_servers_ipv6=()
log_level="$(bashio::config "log_level")"
[[ "$log_level" == "debug" ]] && bashio::log.warning "--- Debug mode is active ---"
[[ "$log_level" == "debug" ]] && set -x
_parse_config() {
local -n config_ref="$1"
local config_file="$2"
@@ -348,12 +352,16 @@ _openvpn_up() {
echo "${config["MySelf"]} openvpn postdown" >> ${config["PostDownScript"]}
chmod 755 ${config["PostDownScript"]}
# Define logging
log_path="/dev/null"
[[ "$log_level" == "debug" ]] && log_path="/proc/1/fd/1"
# Start OpenVPN in the background
_cmd "/usr/sbin/openvpn \
--config "${config["ConfigFile"]}" \
--client \
--daemon \
--log /dev/null \
--log "$log_path" \
--script-security 2 \
--auth-user-pass "${OPENVPN_STATE_DIR}/credentials.conf" \
--auth-retry none \