Skip to content

Commit

Permalink
only update on port change
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhotio committed Jan 22, 2024
1 parent b0ebbc8 commit 9450e39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/service-proton/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/command/with-contenv bash
# shellcheck shell=bash

rm -rf "${CONFIG_DIR}/forwarded_port"
17 changes: 11 additions & 6 deletions root/etc/s6-overlay/s6-rc.d/service-proton/run
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ while true; do
port=$(natpmpc -g "${vpn_gw}" -a 1 0 udp 60 | grep -P -o -m 1 '(?<=Mapped public port\s)\d+')
if [[ -n "${port}" ]]; then
natpmpc -g "${vpn_gw}" -a 1 0 tcp 60 &> /dev/null
webui_https="http"
if grep -q 'WebUI\\HTTPS\\Enabled=true' "${CONFIG_DIR}/config/qBittorrent.conf"; then
webui_https="https"
touch "${CONFIG_DIR}/forwarded_port"
old_port=$(cat "${CONFIG_DIR}/forwarded_port")
if [[ "${port}" != "${old_port}" ]]; then
echo "${port}" > "${CONFIG_DIR}/forwarded_port"
webui_https="http"
if grep -q 'WebUI\\HTTPS\\Enabled=true' "${CONFIG_DIR}/config/qBittorrent.conf"; then
webui_https="https"
fi
curl -fsSL --insecure -X POST -d "json={\"upnp\": false}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences"
curl -fsSL --insecure -X POST -d "json={\"random_port\": false}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences"
curl -fsSL --insecure -X POST -d "json={\"listen_port\": ${port}}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences"
fi
curl -fsSL --insecure -X POST -d "json={\"upnp\": false}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences"
curl -fsSL --insecure -X POST -d "json={\"random_port\": false}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences"
curl -fsSL --insecure -X POST -d "json={\"listen_port\": ${port}}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences"
echo "[INFO] [$(date '+%Y-%m-%d %H:%M:%S')] ProtonVPN forwarded port is \"${port}\"."
else
echo "[WARNING] [$(date '+%Y-%m-%d %H:%M:%S')] ProtonVPN port forwarding failed!"
Expand Down

0 comments on commit 9450e39

Please sign in to comment.