Skip to content

Commit

Permalink
gluon-status-page: add generic respondd cgi-bin
Browse files Browse the repository at this point in the history
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://<IP6ADDR>/cgi-bin/respondd"
  -> defaults to nodeinfo

  $ curl --compressed "http://<IP6ADDR>/cgi-bin/respondd?nodeinfo+statistics"

Query examples with HTTP POST:

  $ curl --data "" --compressed "http://<IP6ADDR>/cgi-bin/respondd"
  -> defaults to nodeinfo

  $ curl --data "nodeinfo statistics" --compressed "http://<IP6ADDR>/cgi-bin/respondd"

Signed-off-by: Linus Lüssing <[email protected]>
  • Loading branch information
T-X committed Dec 9, 2022
1 parent d0fa7dd commit c6693b7
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit c6693b7

Please sign in to comment.