Files
op-packages/openwrt-natmapt/files/client/qBittorrent
T

41 lines
1.1 KiB
Bash

#!/bin/sh
# Copyright (C) 2023-2025 muink https://github.com/muink
#
# Client listen port refresh script
#
# depends
. /usr/lib/natmap/common.sh
start() {
local retry='--connect-timeout 1 --retry 0'
local self_signed='-k'
local payload
case "$(basename "$0")" in
qBittorrent)
payload='json={"listen_port":'"${port}"'}';;
qBittorrent-announce_port)
payload='json={"announce_port":'"${port}"'}';;
*)
payload='json={"listen_port":'"${port}"'}';;
esac
local cookie="$($CURL $retry $self_signed -L -i \
-H "Referer: ${scheme}://${host}:${web_port}" \
-d "username=${username}&password=${password}" \
--url ${scheme}://${host}:${web_port}/api/v2/auth/login \
| grep -i set-cookie | sed -En 's#^.*\b((SID|QBT_SID_'"${web_port}"')=[^;]+);.*#\1#p')"
$CURL $retry $self_signed -L -X POST \
-b "$cookie" \
-d "$payload" \
--url ${scheme}://${host}:${web_port}/api/v2/app/setPreferences
$CURL $retry $self_signed -L -I \
--cookie "$cookie" \
--url ${scheme}://${host}:${web_port}/api/v2/auth/logout
}
# All external parameters required
ALL_PARAMS="host port scheme web_port username password"
eval "$(JSON_EXPORT "$1")"; shift
start "$@"