mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-01-10 16:35:44 +01:00
Status page
This commit is contained in:
@@ -221,7 +221,7 @@ serve_ots_getfile()
|
||||
local hash=${1}
|
||||
trace "[serve_ots_getfile] hash=${hash}"
|
||||
|
||||
file_response_to_client "/otsfiles/" "${hash}.ots"
|
||||
binfile_response_to_client "/otsfiles/" "${hash}.ots"
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
. ./bitcoin.sh
|
||||
. ./call_lightningd.sh
|
||||
. ./ots.sh
|
||||
. ./statuspage.sh
|
||||
|
||||
main()
|
||||
{
|
||||
@@ -243,6 +244,12 @@ main()
|
||||
serve_ots_getfile $(echo "${line}" | cut -d ' ' -f2 | cut -d '/' -f3)
|
||||
break
|
||||
;;
|
||||
status)
|
||||
# curl (GET) http://192.168.111.152:8080/status
|
||||
|
||||
status_page
|
||||
break
|
||||
;;
|
||||
esac
|
||||
break
|
||||
fi
|
||||
|
||||
@@ -8,19 +8,47 @@ response_to_client()
|
||||
|
||||
local response=${1}
|
||||
local returncode=${2}
|
||||
local contenttype=${3}
|
||||
|
||||
[ -z "${contenttype}" ] && contenttype="application/json"
|
||||
|
||||
([ -z "${returncode}" ] || [ "${returncode}" -eq "0" ]) && echo -ne "HTTP/1.1 200 OK\r\n"
|
||||
[ -n "${returncode}" ] && [ "${returncode}" -ne "0" ] && echo -ne "HTTP/1.1 400 Bad Request\r\n"
|
||||
|
||||
echo -en "Content-Type: application/json\r\nContent-Length: ${#response}\r\n\r\n${response}"
|
||||
echo -en "Content-Type: ${contenttype}\r\nContent-Length: ${#response}\r\n\r\n${response}"
|
||||
|
||||
# Small delay needed for the data to be processed correctly by peer
|
||||
sleep 0.2s
|
||||
}
|
||||
|
||||
file_response_to_client()
|
||||
htmlfile_response_to_client()
|
||||
{
|
||||
trace "Entering file_response_to_client()..."
|
||||
trace "Entering htmlfile_response_to_client()..."
|
||||
|
||||
local path=${1}
|
||||
local filename=${2}
|
||||
local pathfile="${path}${filename}"
|
||||
local returncode
|
||||
|
||||
trace "[htmlfile_response_to_client] path=${path}"
|
||||
trace "[htmlfile_response_to_client] filename=${filename}"
|
||||
trace "[htmlfile_response_to_client] pathfile=${pathfile}"
|
||||
local file_length=$(stat -c'%s' ${pathfile})
|
||||
trace "[htmlfile_response_to_client] file_length=${file_length}"
|
||||
|
||||
[ -r "${pathfile}" ] \
|
||||
&& echo -ne "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: ${file_length}\r\n\r\n" \
|
||||
&& cat ${pathfile}
|
||||
|
||||
[ ! -r "${pathfile}" ] && echo -ne "HTTP/1.1 404 Not Found\r\n"
|
||||
|
||||
# Small delay needed for the data to be processed correctly by peer
|
||||
sleep 0.5s
|
||||
}
|
||||
|
||||
binfile_response_to_client()
|
||||
{
|
||||
trace "Entering binfile_response_to_client()..."
|
||||
|
||||
local path=${1}
|
||||
local filename=${2}
|
||||
|
||||
23
proxy_docker/app/script/statuspage.sh
Normal file
23
proxy_docker/app/script/statuspage.sh
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
|
||||
. ./trace.sh
|
||||
. ./responsetoclient.sh
|
||||
|
||||
status_page() {
|
||||
cat <<EOF > statuspage.html
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
Hello from Cyphernode!<p/>
|
||||
EOF
|
||||
|
||||
cat db/installation.json >> statuspage.html
|
||||
|
||||
cat <<EOF >> statuspage.html
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
|
||||
htmlfile_response_to_client ./ statuspage.html
|
||||
}
|
||||
Reference in New Issue
Block a user