Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fear: Forcefully bind apps to 127.0.0.1 if NGINX installed #960

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions scripts/nginx/qbittorrent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
. /etc/swizzin/sources/functions/utils
users=($(_get_user_list))

if [ -z "$SWIZDB_BIND_ENFORCE" ]; then
if ! SWIZDB_BIND_ENFORCE="$(swizdb get qbittorrent/bindEnforce)"; then
SWIZDB_BIND_ENFORCE=True
swizdb set "qbittorrent/bindEnforce" "$SWIZDB_BIND_ENFORCE"
fi
else
echo_info "Setting qbittorrent/bindEnforce = $SWIZDB_BIND_ENFORCE"
swizdb set "qbittorrent/bindEnforce" "$SWIZDB_BIND_ENFORCE"
fi

if [[ ! -f /etc/nginx/apps/qbtindex.conf ]]; then
cat > /etc/nginx/apps/qbtindex.conf << DIN
location /qbittorrent.downloads {
Expand Down Expand Up @@ -59,4 +69,21 @@ upstream ${user}.qbittorrent {
server 127.0.0.1:${port};
}
QBTUC

if $(swizdb get qbittorrent/bindEnforce); then
wasActive=$(systemctl is-active qbittorrent@${user})
echo_log_only "Active: ${wasActive}"

if [[ $wasActive == "active" ]]; then
echo_log_only "Stopping qBittorrent for ${user}"
systemctl stop -q "qbittorrent@${user}"
fi

sed -i 's|WebUI\\\Address*|WebUI\\\Address=127.0.0.1|g' /home/${user}/.config/qBittorrent/qBittorrent.conf
systemctl start "qbittorrent@${user}"
if [[ $wasActive == "active" ]]; then
echo_log_only "Activating qBittorrent for ${user}"
systemctl start "qbittorrent@${user}" -q
fi
fi
done
33 changes: 32 additions & 1 deletion scripts/update/qbittorrent.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash
#shellcheck source=sources/functions/utils
. /etc/swizzin/sources/functions/utils
users=($(_get_user_list))

if [[ -f /install/.qbittorrent.lock ]]; then
#Check systemd service for updates
Expand All @@ -25,5 +28,33 @@ if [[ -f /install/.qbittorrent.lock ]]; then
sed -r 's|(rewrite .*)|\1\n proxy_cookie_path / "/qbittorrent/; Secure";|g' -i /etc/nginx/apps/qbittorrent.conf
systemctl reload nginx
fi
fi
if [ -z "$SWIZDB_BIND_ENFORCE" ]; then
if ! SWIZDB_BIND_ENFORCE="$(swizdb get qbittorrent/bindEnforce)"; then
SWIZDB_BIND_ENFORCE=True
swizdb set "qbittorrent/bindEnforce" "$SWIZDB_BIND_ENFORCE"
fi
else
echo_info "Setting qbittorrent/bindEnforce = $SWIZDB_BIND_ENFORCE"
swizdb set "qbittorrent/bindEnforce" "$SWIZDB_BIND_ENFORCE"
fi
fi
if $(swizdb get qbittorrent/bindEnforce); then
for user in ${users[@]}; do
if ! grep -q "WebUI\\\Address=127.0.0.1" /home/${user}/.config/qBittorrent/qBittorrent.conf; then
wasActive=$(systemctl is-active qbittorrent@${user})
echo_log_only "Active: ${wasActive}"
if [[ $wasActive == "active" ]]; then
echo_log_only "Stopping qBittorrent for ${user}"
systemctl stop -q "qbittorrent@${user}"
fi
sed -i 's|WebUI\\\Address*|WebUI\\\Address=127.0.0.1|g' /home/${user}/.config/qBittorrent/qBittorrent.conf
systemctl start "qbittorrent@${user}"
if [[ $wasActive == "active" ]]; then
echo_log_only "Activating qBittorrent for ${user}"
systemctl start "qbittorrent@${user}" -q
fi
fi
done
fi
fi
fi