Skip to content

Commit

Permalink
Tor + Callbacks fix, thanks @Tomtibo
Browse files Browse the repository at this point in the history
  • Loading branch information
Kexkey committed Apr 2, 2020
1 parent 874c42d commit ed06a00
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cyphernodeconf_docker/templates/installer/testfeatures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
30 changes: 15 additions & 15 deletions notifier_docker/script/web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ web() {
local msg=${1}
local url
local body
local torbypass
local tor
local returncode
local response
local result
Expand All @@ -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}

Expand All @@ -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}"
Expand Down
6 changes: 3 additions & 3 deletions proxy_docker/app/script/notify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions proxy_docker/app/script/requesthandler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
#

. ./db/config.sh
. ./sendtobitcoinnode.sh
. ./callbacks_job.sh
. ./watchrequest.sh
Expand Down

0 comments on commit ed06a00

Please sign in to comment.