From 04b13c670102a1ca103d5c176f8f7efb2c097af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20L=C3=BCssing?= Date: Tue, 22 Mar 2022 02:25:20 +0100 Subject: [PATCH] gluon-status-page: add generic respondd cgi-bin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding a cgi-bin script which allows to query a node's respondd over HTTP. This is especially useful when the response is expected to be large and a UDP response would lead to an unreliable transfer of multiple IP fragments, like for the upcoming "statistics-extended" respondd provider. HTTP/TCP is then the more reliable approach. Query examples with HTTP GET: $ curl --compressed "http:///cgi-bin/respondd" -> defaults to nodeinfo $ curl --compressed "http:///cgi-bin/respondd?nodeinfo+statistics" Query examples with HTTP POST: $ curl --data "" --compressed "http:///cgi-bin/respondd" -> defaults to nodeinfo $ curl --data "nodeinfo statistics" --compressed "http:///cgi-bin/respondd" Signed-off-by: Linus Lüssing --- .../gluon/status-page/www/cgi-bin/respondd | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/respondd diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/respondd b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/respondd new file mode 100755 index 00000000000..0510bebef07 --- /dev/null +++ b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/respondd @@ -0,0 +1,35 @@ +#!/bin/sh + +badrequest() { + echo 'Status: 400 Bad Request' + echo + exit 1 +} + +case "${REQUEST_METHOD}" in + GET) + ;; + POST) + QUERY_STRING="$(cat)" + ;; + *) + badrequest + ;; +esac + +if [ -z "${QUERY_STRING}" ]; then + # default to nodeinfo + QUERY_STRING="nodeinfo" +else + # replace URL encoded spaces via '+' with real space + QUERY_STRING="${QUERY_STRING//+/ }" +fi + + +# Return deflate compressed ("GET" prefix), JSON formatted response + +echo "Content-Type: application/json" +echo "Content-Encoding: deflate" +echo "" + +exec gluon-neighbour-info -i lo -d ::1 -p 1001 -r "GET ${QUERY_STRING}"