mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-02-17 10:14:24 +01:00
More comments, cleaned code
This commit is contained in:
@@ -12,6 +12,8 @@ main() {
|
||||
local response
|
||||
local response_topic
|
||||
|
||||
# Messages should have this form:
|
||||
# {"response-topic":"response/5541","cmd":"web","url":"2557df870b9a:1111/callback1conf","body":"eyJpZCI6IjUxIiwiYWRkc...dCI6MTUxNzYwMH0K"}
|
||||
while read msg; do
|
||||
trace "[main] New msg just arrived!"
|
||||
trace "[main] msg=${msg}"
|
||||
|
||||
@@ -13,7 +13,6 @@ publish_response() {
|
||||
trace "[publish_response] response_topic=${response_topic}"
|
||||
trace "[publish_response] returncode=${returncode}"
|
||||
|
||||
# response=$(echo "${response}" | base64 | tr -d '\n')
|
||||
trace "[publish_response] mosquitto_pub -h broker -t \"${response_topic}\" -m \"${response}\""
|
||||
mosquitto_pub -h broker -t "${response_topic}" -m "${response}"
|
||||
returncode=$?
|
||||
|
||||
@@ -20,6 +20,7 @@ web() {
|
||||
# jq -e will have a return code of 1 if the supplied tag is null.
|
||||
if [ "$?" -eq "0" ]; then
|
||||
# body tag not null, so it's a POST
|
||||
# The body field has been based-64 to avoid dealing with escaping special chars
|
||||
body=$(echo "${body}" | base64 -d)
|
||||
trace "[web] body=${body}"
|
||||
else
|
||||
@@ -31,16 +32,7 @@ web() {
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
|
||||
if [ "${returncode}" -eq "0" ]; then
|
||||
# {"result":"success", "response":"<html></html>"}
|
||||
result="success"
|
||||
else
|
||||
# {"result":"error", "response":"<html></html>"}
|
||||
result="error"
|
||||
fi
|
||||
|
||||
echo "${response}"
|
||||
# echo "{\"result\":\"${result}\",\"http_code\":\"${http_code}\"}"
|
||||
|
||||
return ${returncode}
|
||||
}
|
||||
@@ -55,8 +47,8 @@ curl_it() {
|
||||
local rnd=$(dd if=/dev/urandom bs=5 count=1 | xxd -pc 5)
|
||||
|
||||
if [ -n "${data}" ]; then
|
||||
trace "[curl_it] curl -o webresponse-${rnd} -w \"%{http_code}\" -H \"Content-Type: application/json\" -H \"X-Forwarded-Proto: https\" -d ${data} ${url}"
|
||||
rc=$(curl -o webresponse-${rnd} -w "%{http_code}" -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d ${data} ${url})
|
||||
trace "[curl_it] curl -o webresponse-${rnd} -w \"%{http_code}\" -H \"Content-Type: application/json\" -H \"X-Forwarded-Proto: https\" -d \"${data}\" ${url}"
|
||||
rc=$(curl -o webresponse-${rnd} -w "%{http_code}" -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d "${data}" ${url})
|
||||
returncode=$?
|
||||
else
|
||||
trace "[curl_it] curl -o webresponse-$$ -w \"%{http_code}\" ${url}"
|
||||
|
||||
Reference in New Issue
Block a user