mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-01-31 02:04:27 +01:00
Tor + Callbacks fix, thanks @Tomtibo
This commit is contained in:
@@ -100,7 +100,7 @@ checknotifier() {
|
||||
local response
|
||||
local returncode
|
||||
|
||||
response=$(mosquitto_rr -h broker -W 15 -t notifier -e "response/$$" -m "{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"http://proxy:8888/helloworld\",\"torbypass\":true}")
|
||||
response=$(mosquitto_rr -h broker -W 15 -t notifier -e "response/$$" -m "{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"http://proxy:8888/helloworld\",\"tor\":false}")
|
||||
returncode=$?
|
||||
[ "${returncode}" -ne "0" ] && return 115
|
||||
http_code=$(echo "${response}" | jq -r ".http_code")
|
||||
|
||||
@@ -8,7 +8,7 @@ web() {
|
||||
local msg=${1}
|
||||
local url
|
||||
local body
|
||||
local torbypass
|
||||
local tor
|
||||
local returncode
|
||||
local response
|
||||
local result
|
||||
@@ -29,15 +29,15 @@ web() {
|
||||
trace "[web] no body, GET request"
|
||||
fi
|
||||
|
||||
torbypass=$(echo ${msg} | jq -e ".torbypass")
|
||||
tor=$(echo ${msg} | jq -e ".tor")
|
||||
# jq -e will have a return code of 1 if the supplied tag is null.
|
||||
if [ "$?" -ne "0" ]; then
|
||||
# torbypass tag null
|
||||
torbypass=false
|
||||
# tor tag null
|
||||
tor=false
|
||||
fi
|
||||
trace "[web] torbypass=${torbypass}"
|
||||
trace "[web] tor=${tor}"
|
||||
|
||||
response=$(curl_it "${url}" "${body}" "${torbypass}")
|
||||
response=$(curl_it "${url}" "${body}" "${tor}")
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
|
||||
@@ -51,25 +51,25 @@ curl_it() {
|
||||
|
||||
local url=$(echo "${1}" | tr -d '"')
|
||||
local data=${2}
|
||||
local torbypass=${3}
|
||||
local tor=${3}
|
||||
local returncode
|
||||
local response
|
||||
local rnd=$(dd if=/dev/urandom bs=5 count=1 | xxd -pc 5)
|
||||
|
||||
if [ "${torbypass}" = "true" ] || [ -z "${TOR_HOST}" ]; then
|
||||
# If we want to bypass tor or the config file doesn't exist
|
||||
torbypass=""
|
||||
if [ "${tor}" = "true" ] && [ -n "${TOR_HOST}" ]; then
|
||||
# If we want to use tor and the tor host config exists
|
||||
tor="--socks5-hostname ${TOR_HOST}:${TOR_PORT}"
|
||||
else
|
||||
torbypass="--socks5-hostname ${TOR_HOST}:${TOR_PORT}"
|
||||
tor=""
|
||||
fi
|
||||
|
||||
if [ -n "${data}" ]; then
|
||||
trace "[curl_it] curl ${torbypass} -o webresponse-${rnd} -m 20 -w \"%{http_code}\" -H \"Content-Type: application/json\" -H \"X-Forwarded-Proto: https\" -d \"${data}\" -k ${url}"
|
||||
rc=$(curl ${torbypass} -o webresponse-${rnd} -m 20 -w "%{http_code}" -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d "${data}" -k ${url})
|
||||
trace "[curl_it] curl ${tor} -o webresponse-${rnd} -m 20 -w \"%{http_code}\" -H \"Content-Type: application/json\" -H \"X-Forwarded-Proto: https\" -d \"${data}\" -k ${url}"
|
||||
rc=$(curl ${tor} -o webresponse-${rnd} -m 20 -w "%{http_code}" -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d "${data}" -k ${url})
|
||||
returncode=$?
|
||||
else
|
||||
trace "[curl_it] curl ${torbypass} -o webresponse-$$ -m 20 -w \"%{http_code}\" -k ${url}"
|
||||
rc=$(curl ${torbypass} -o webresponse-${rnd} -m 20 -w "%{http_code}" -k ${url})
|
||||
trace "[curl_it] curl ${tor} -o webresponse-$$ -m 20 -w \"%{http_code}\" -k ${url}"
|
||||
rc=$(curl ${tor} -o webresponse-${rnd} -m 20 -w "%{http_code}" -k ${url})
|
||||
returncode=$?
|
||||
fi
|
||||
trace "[curl_it] HTTP return code=${rc}"
|
||||
|
||||
@@ -6,7 +6,7 @@ notify_web() {
|
||||
trace "Entering notify_web()..."
|
||||
|
||||
local url=${1}
|
||||
local torbypass=${3}
|
||||
local tor=${3}
|
||||
|
||||
# Let's encode the body to base64 so we won't have to escape the special chars...
|
||||
local body=$(echo "${2}" | base64 | tr -d '\n')
|
||||
@@ -17,8 +17,8 @@ notify_web() {
|
||||
local curl_code
|
||||
local msg
|
||||
|
||||
if [ -n "${torbypass}" ]; then
|
||||
msg="{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"${url}\",\"body\":\"${body}\",\"torbypass\":${torbypass}}"
|
||||
if [ -n "${tor}" ]; then
|
||||
msg="{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"${url}\",\"body\":\"${body}\",\"tor\":${tor}}"
|
||||
else
|
||||
msg="{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"${url}\",\"body\":\"${body}\"}"
|
||||
fi
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#
|
||||
#
|
||||
|
||||
. ./db/config.sh
|
||||
. ./sendtobitcoinnode.sh
|
||||
. ./callbacks_job.sh
|
||||
. ./watchrequest.sh
|
||||
|
||||
Reference in New Issue
Block a user