about summary refs log tree commit diff stats
path: root/bonus/magnet.cgi
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-11 18:04:50 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-11 18:38:15 +0100
commit7f974324de185e5f8e6a8b5723ac70fa8beea47f (patch)
tree6eb6043f04732b507cbe8b9896aed6b594d35072 /bonus/magnet.cgi
parent1d97cd35ba0848ced58732fe430fa0db018701e5 (diff)
downloadchawan-7f974324de185e5f8e6a8b5723ac70fa8beea47f.tar.gz
magnet.cgi: use urldec from libexec dir
Diffstat (limited to 'bonus/magnet.cgi')
-rwxr-xr-xbonus/magnet.cgi22
1 files changed, 6 insertions, 16 deletions
diff --git a/bonus/magnet.cgi b/bonus/magnet.cgi
index 085d252b..efff286a 100755
--- a/bonus/magnet.cgi
+++ b/bonus/magnet.cgi
@@ -23,13 +23,6 @@ die() {
 	exit 1
 }
 
-decode() {
-	# URL-decode the string passed as the first parameter
-	printf '%s\n' "$1" | \
-		sed 's/+/ /g;s/%/\\x/g' | \
-		xargs -0 printf "%b"
-}
-
 html_quote() {
 	sed 's/&/&amp;/g;s/</&lt;/g;s/>/&gt;/g;s/'\''/&apos;/g;s/"/&quot;/g'
 }
@@ -62,16 +55,13 @@ POST)	read line
 	esac
 	case $line in
 	URL=*) line="${line#*=}" ;;
-	*) die 'Invalid POST 2; this is probably a bug in the magnet script.'"$line" ;;
+	*) die 'Invalid POST 2; this is probably a bug in the magnet script.' ;;
 	esac
-	line="$(decode "$line")"
-	if test -n "$CHA_TRANSMISSION_AUTH"
-	then	authparam="--auth=$CHA_TRANSMISSION_AUTH"
-	fi
-	if test -n "$authparam"
-	then	output="$(transmission-remote "${CHA_TRANSMISSION_ADDRESS:-localhost:9091}" "$authparam" -a "$line" 2>&1)"
-	else	output="$(transmission-remote "${CHA_TRANSMISSION_ADDRESS:-localhost:9091}" -a "$line" 2>&1)"
-	fi
+	line=$(printf '%s' "$line" | "$CHA_LIBEXEC_DIR"/urldec)
+	auth=$CHA_TRANSMISSION_AUTH
+	address=${CHA_TRANSMISSION_ADDRESS:-localhost:9091}
+	output=$(transmission-remote "$address" ${auth:+ --auth="$auth"} \
+			-a "$line" 2>&1)
 	printf 'Content-Type: text/plain\n\n%s' "$output"
 	;;
 *)	die "Unrecognized HTTP method $HTTP_METHOD" ;;