This commit is contained in:
Alexandre
2023-12-30 19:18:27 +01:00
parent cf7788388e
commit 974c75ddcd
4 changed files with 43 additions and 22 deletions

View File

@@ -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) ### 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 : 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) - 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) - Fix : avoid addon restart at each start (due to blanks being cleaned in the whitelist field)

View File

@@ -139,5 +139,5 @@
"slug": "qbittorrent", "slug": "qbittorrent",
"udev": true, "udev": true,
"url": "https://github.com/alexbelgium/hassio-addons", "url": "https://github.com/alexbelgium/hassio-addons",
"version": "4.6.2_30" "version": "4.6.2_31"
} }

View File

@@ -35,7 +35,7 @@ if bashio::config.true 'openvpn_enabled'; then
while read -r line while read -r line
do do
# Check if the line contains a txt file # 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 # Extract the txt file name from the line
file_name="$(echo "$line" | awk -F' ' '{print $2}')" file_name="$(echo "$line" | awk -F' ' '{print $2}')"
# Check if the txt file exists # Check if the txt file exists
@@ -59,6 +59,9 @@ if bashio::config.true 'openvpn_enabled'; then
# Standardize lf # Standardize lf
dos2unix "$file" dos2unix "$file"
# Remove blank lines
sed -i '/^[[:blank:]]*$/d' "$file"
# Ensure config ends with a line feed # Ensure config ends with a line feed
sed -i "\$q" "$file" 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" echo "... configured ovpn file : using /addon_configs/$HOSTNAME/openvpn/$openvpn_config"
# Check path # Check path
check_path /config/openvpn/"$openvpn_config" 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 # Not correct type
else else
bashio::exit.nok "Configured ovpn file : $openvpn_config is set but does not end by .ovpn ; it can't be used!" 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[@]}]}" VPN_CONFIG="${VPN_CONFIGS[$RANDOM % ${#VPN_CONFIGS[@]}]}"
# Get the VPN_CONFIG name without the path and extension # Get the VPN_CONFIG name without the path and extension
openvpn_config="${VPN_CONFIG##*/}" 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
check_path /config/openvpn/"${openvpn_config}" 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 # If openvpn_enabled set, config not set, and openvpn folder empty
else 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 ?" 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 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 # Set credentials
if bashio::config.has_value "openvpn_username"; then if bashio::config.has_value "openvpn_username"; then
openvpn_username=$(bashio::config 'openvpn_username') openvpn_username=$(bashio::config 'openvpn_username')
@@ -130,11 +128,32 @@ if bashio::config.true 'openvpn_enabled'; then
fi fi
# Add credentials file # Add credentials file
if grep -q auth-user-pass /etc/openvpn/config.ovpn; then file_name="$(echo "$(sed -n "/^auth-user-pass/p" /config/openvpn/"$openvpn_config")" | awk -F' ' '{print $2}')"
sed -i "s/auth-user-pass.*/auth-user-pass \/etc\/openvpn\/credentials/g" /etc/openvpn/config.ovpn file_name="${file_name:-null}"
bashio::log.warning "auth-user-pass specified, will be replaced by the addon options' username and password" 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 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 fi
# Permissions # Permissions
@@ -165,9 +184,9 @@ if bashio::config.true 'openvpn_enabled'; then
sed -i '/Interface/d' "$QBT_CONFIG_FILE" sed -i '/Interface/d' "$QBT_CONFIG_FILE"
# Modify ovpn config # 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" 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 fi
# Exit # Exit
@@ -203,9 +222,9 @@ if bashio::config.true 'openvpn_enabled'; then
fi fi
# Modify ovpn config # 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" 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 fi
else else

View File

@@ -8,7 +8,7 @@ if bashio::config.true 'silent'; then
fi fi
if bashio::config.true 'openvpn_enabled'; then 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 else
if bashio::config.true 'silent'; then if bashio::config.true 'silent'; then
exec \ exec \