diff --git a/qbittorrent/CHANGELOG.md b/qbittorrent/CHANGELOG.md index e63c009c3..9c9be503f 100644 --- a/qbittorrent/CHANGELOG.md +++ b/qbittorrent/CHANGELOG.md @@ -1,5 +1,7 @@ +- Feat (potential breaking change) : previously, "auth-user-pass" fields were removed to use the addon username & password. Now, the addon will respect those fields if the file exists to allow for multiple configurations storing different credentials in local files. If the referenced file doesn't exists, or if this field is not referenced, the normal addon username & password will be used +- Feat : use ovpn files directly in /config/openvpn instead of doing a copy in /etc/openvpn as before. This will make any change more obvious to the user. + ### 4.6.2_30 (30-12-2023) -- Minor bugs fixed - Feat : sanitize ovpn files (disabling ipv6 as not supported by HA, ensuring CRLF, ensure trailing new line, checking paths of referenced static files...) - Feat : if no ovpn is referred in the option, it will use a random one from the openvpn folder (from https://github.com/Trigus42/alpine-qbittorrentvpn) - Fix : avoid addon restart at each start (due to blanks being cleaned in the whitelist field) diff --git a/qbittorrent/config.json b/qbittorrent/config.json index a8c04d72a..21f1beba3 100644 --- a/qbittorrent/config.json +++ b/qbittorrent/config.json @@ -139,5 +139,5 @@ "slug": "qbittorrent", "udev": true, "url": "https://github.com/alexbelgium/hassio-addons", - "version": "4.6.2_30" + "version": "4.6.2_31" } diff --git a/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh b/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh index 34bebaf2b..aa7c49d08 100755 --- a/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh @@ -35,7 +35,7 @@ if bashio::config.true 'openvpn_enabled'; then while read -r line do # Check if the line contains a txt file - if [[ "$line" =~ \.txt ]] || [[ "$line" =~ \.crt ]]; then + if [[ "$line" =~ \.txt ]] || [[ "$line" =~ \.crt ]] || [[ "$line" =~ auth-user-pass ]]; then # Extract the txt file name from the line file_name="$(echo "$line" | awk -F' ' '{print $2}')" # Check if the txt file exists @@ -59,6 +59,9 @@ if bashio::config.true 'openvpn_enabled'; then # Standardize lf dos2unix "$file" + # Remove blank lines + sed -i '/^[[:blank:]]*$/d' "$file" + # Ensure config ends with a line feed sed -i "\$q" "$file" @@ -81,10 +84,6 @@ if bashio::config.true 'openvpn_enabled'; then echo "... configured ovpn file : using /addon_configs/$HOSTNAME/openvpn/$openvpn_config" # Check path check_path /config/openvpn/"$openvpn_config" - # Copy potential additional files - cp /config/openvpn/* /etc/openvpn/ - # Standardize file - cp /config/openvpn/"${openvpn_config}" /etc/openvpn/config.ovpn # Not correct type else bashio::exit.nok "Configured ovpn file : $openvpn_config is set but does not end by .ovpn ; it can't be used!" @@ -102,19 +101,18 @@ if bashio::config.true 'openvpn_enabled'; then VPN_CONFIG="${VPN_CONFIGS[$RANDOM % ${#VPN_CONFIGS[@]}]}" # Get the VPN_CONFIG name without the path and extension openvpn_config="${VPN_CONFIG##*/}" - echo "... Openvpn enabled, but openvpn_config option empty. Selecting a random ovpn file : ${openvpn_config}" + echo "... Openvpn enabled, but openvpn_config option empty. Selecting a random ovpn file : ${openvpn_config}. Other available files :" + printf '%s\n' "${VPN_CONFIGS[@]}" # Check path check_path /config/openvpn/"${openvpn_config}" - # Copy potential additional files - cp /config/openvpn/* /etc/openvpn/ - # Standardize file - cp /config/openvpn/"${openvpn_config}" /etc/openvpn/config.ovpn - # If openvpn_enabled set, config not set, and openvpn folder empty else bashio::exit.nok "openvpn_enabled is set, however, your openvpn folder is empty ! Are you sure you added it in /addon_configs/$HOSTNAME/openvpn using the Filebrowser addon ?" fi + # Send to openvpn script + sed -i "s|/config/openvpn/config.ovpn|/config/openvpn/$openvpn_config|g" /etc/s6-overlay/s6-rc.d/svc-qbittorrent + # Set credentials if bashio::config.has_value "openvpn_username"; then openvpn_username=$(bashio::config 'openvpn_username') @@ -130,11 +128,32 @@ if bashio::config.true 'openvpn_enabled'; then fi # Add credentials file - if grep -q auth-user-pass /etc/openvpn/config.ovpn; then - sed -i "s/auth-user-pass.*/auth-user-pass \/etc\/openvpn\/credentials/g" /etc/openvpn/config.ovpn - bashio::log.warning "auth-user-pass specified, will be replaced by the addon options' username and password" + file_name="$(echo "$(sed -n "/^auth-user-pass/p" /config/openvpn/"$openvpn_config")" | awk -F' ' '{print $2}')" + file_name="${file_name:-null}" + if grep -q auth-user-pass /config/openvpn/"$openvpn_config"; then + # Credentials specified are they custom ? + if [[ "$file_name" != *"/etc/openvpn/credentials"* ]]; then + if [ -f "$file_name" ]; then + # If credential specified, exists, and is not the addon default + bashio::log.warning "auth-user-pass specified in the ovpn file, addon username and passwords won't be used !" + else + # Credential referenced but doesn't exist + bashio::log.warning "auth-user-pass $file_name is referenced in your ovpn file but does not exist, and can't be found either in the /config/openvpn/ directory. The addon will attempt to use it's own username and password instead." + # Comment previous lines + sed -i '/^auth-user-pass/i # specified auth-user-pass file not found, disabling' /config/openvpn/"$openvpn_config" + sed -i '/^auth-user-pass/s/^/#/' /config/openvpn/"$openvpn_config" + # No credentials specified, using addons username and password + echo "# Please do not remove the line below, it allows using the addon username and password" >> /config/openvpn/"$openvpn_config" + echo "auth-user-pass /etc/openvpn/credentials" >> /config/openvpn/"$openvpn_config" + fi + else + # Standardize just to be sure + sed -i "/\/etc\/openvpn\/credentials/c auth-user-pass \/etc\/openvpn\/credentials" /config/openvpn/"$openvpn_config" + fi else - echo "auth-user-pass /etc/openvpn/credentials" >> /etc/openvpn/config.ovpn + # No credentials specified, using addons username and password + echo "# Please do not remove the line below, it allows using the addon username and password" >> /config/openvpn/"$openvpn_config" + echo "auth-user-pass /etc/openvpn/credentials" >> /config/openvpn/"$openvpn_config" fi # Permissions @@ -165,9 +184,9 @@ if bashio::config.true 'openvpn_enabled'; then sed -i '/Interface/d' "$QBT_CONFIG_FILE" # Modify ovpn config - if grep -q route-nopull /etc/openvpn/config.ovpn; then + if grep -q route-nopull /config/openvpn/"$openvpn_config"; then echo "... removing route-nopull from your config.ovpn" - sed -i '/route-nopull/d' /etc/openvpn/config.ovpn + sed -i '/route-nopull/d' /config/openvpn/"$openvpn_config" fi # Exit @@ -203,9 +222,9 @@ if bashio::config.true 'openvpn_enabled'; then fi # Modify ovpn config - if ! grep -q route-nopull /etc/openvpn/config.ovpn; then + if ! grep -q route-nopull /config/openvpn/"$openvpn_config"; then echo "... adding route-nopull to your config.ovpn" - sed -i "1a route-nopull" /etc/openvpn/config.ovpn + sed -i "1a route-nopull" /config/openvpn/"$openvpn_config" fi else diff --git a/qbittorrent/rootfs/etc/s6-overlay/s6-rc.d/svc-qbittorrent/run b/qbittorrent/rootfs/etc/s6-overlay/s6-rc.d/svc-qbittorrent/run index b8311578c..490bb2949 100644 --- a/qbittorrent/rootfs/etc/s6-overlay/s6-rc.d/svc-qbittorrent/run +++ b/qbittorrent/rootfs/etc/s6-overlay/s6-rc.d/svc-qbittorrent/run @@ -8,7 +8,7 @@ if bashio::config.true 'silent'; then fi if bashio::config.true 'openvpn_enabled'; then - exec /usr/sbin/openvpn --config /etc/openvpn/config.ovpn --script-security 2 --up /etc/openvpn/up.sh --down /etc/openvpn/down.sh --pull-filter ignore "route-ipv6" --pull-filter ignore "ifconfig-ipv6" --pull-filter ignore "tun-ipv6" --pull-filter ignore "redirect-gateway ipv6" --pull-filter ignore "dhcp-option DNS6" + exec /usr/sbin/openvpn --config /config/openvpn/config.ovpn --script-security 2 --up /etc/openvpn/up.sh --down /etc/openvpn/down.sh --pull-filter ignore "route-ipv6" --pull-filter ignore "ifconfig-ipv6" --pull-filter ignore "tun-ipv6" --pull-filter ignore "redirect-gateway ipv6" --pull-filter ignore "dhcp-option DNS6" else if bashio::config.true 'silent'; then exec \