repo: nostr
action: commit
revision: 
path_from: 
revision_from: dcd949c36658df03c6ac2861664af7d052e8e87a:
path_to: 
revision_to: 
git.thebackupbox.net
nostr
git clone git://git.thebackupbox.net/nostr
commit dcd949c36658df03c6ac2861664af7d052e8e87a
Author: epoch 
Date:   Wed Apr 26 02:42:49 2023 +0000

    went too long without putting this in a repo

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..2ed413eb3cf75be48f5c2ff4619de17fdd691702
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+PREFIX:=/usr/local
+
+install:
+	install -Dt $(PREFIX)/libexec/ nostr-relay.sh
+	install -Dt $(PREFIX)/libexec/ nostr-relay-req.sh
diff --git a/client.html b/client.html
new file mode 100755
index 0000000000000000000000000000000000000000..ab81a722c19b4d72d649f3c7d78ff228f3d72947
--- /dev/null
+++ b/client.html
@@ -0,0 +1,183 @@
+
+  
+    
+  
+
+
+  
+    your public key: 
+    
+
+ + diff --git a/nip-05-test.cgi b/nip-05-test.cgi new file mode 100755 index 0000000000000000000000000000000000000000..8dbd725c7bd907642a83c2ce275bf15f52ef0032 --- /dev/null +++ b/nip-05-test.cgi @@ -0,0 +1,90 @@ +#!/usr/bin/env bash + +acct="$(uriunescape "$(query_param acct)")" +user="$(cut -d@ -f1 <<< "$acct")" +host="$(cut -d@ -f2 <<< "$acct")" +url="https://${host}/.well-known/nostr.json?user=${user}" + +if [ "$1" = "stage2" ];then +# env + printf 'Server: %s
' "$HTTP_SERVER" + if [ ! "$HTTP_ACCESS_CONTROL_ALLOW_ORIGIN" ];then + printf 'WARNING: missing Access-Control-Allow-Origin header
\n' + else + printf 'GOOD: Access-Control-Allow-Origin header present!
' + fi + if [ "$HTTP_ACCESS_CONTROL_ALLOW_ORIGIN" != '*' ];then + printf '
WARNING: Access-Control-Allow-Origin header has wrong value. it is "%s" and should be "*"\n' "$HTTP_ACCESS_CONTROL_ALLOW_ORIGIN" + printf 'for NGINX:
' + printf '
'
+    printf 'location /.well-known/nostr.json {\n'
+    printf '	add_header Access-Control-Allow-Origin "*";\n'
+    printf '}\n'
+    printf '
\n' + printf 'for Apache2:
' + printf '
'
+    printf 'a2enmod headers\n'
+    printf 'Header set Access-Control-Allow-Origin "*"\n'
+    printf '
\n' + printf '
' + else + printf 'GOOD: Access-Control-Allow-Origin header is set right.
\n' + fi + if [ "$HTTP_CONTENT_TYPE" != "application/json" ];then + printf 'WARNING: content-type returned is not application/json but %s
\n' "$HTTP_CONTENT_TYPE" + else + printf 'GOOD: content-type returns is application/json
\n' + fi + RESP_DATA="$(cat)" + printf '
'
+  #env
+  if jq -r . <<< "$RESP_DATA";then
+    printf '
\n' + printf 'GOOD: properly formatted JSON.
\n' + else + printf '
\n' + printf 'ERROR: JSON failed to parse. see jq error message.
\n' + fi + pubkey="$(jq -r '.names.'"$user"'//""' <<< "$RESP_DATA")" + if [ "${pubkey}" ];then + printf 'GOOD: public key found for user %s! %s
' "$user" "$pubkey" + else + printf 'WARNING: public key not found for user %s
' "$user" + fi + npub="$(bech32 -e -h npub "$pubkey")" + printf 'nostr:%s' "$npub" "$npub" + exit 0 +fi + +printf 'Content-Type: text/html\r\n\r\n' + +printf '\n' +printf 'nip-05 tester\n' +printf '\n' +printf '' + +if [ "$acct" ];then + printf 'spec: NIP-05
' + printf 'user: %s
' "$user" + printf 'host: %s
' "$host" + printf 'url: %s
' "$url" "$url" + curl -A "thebackupbox.net nip-05 tester" -sig "$url" | /usr/local/libexec/read_headers $0 stage2 +fi + +printf '' diff --git a/nostr-relay-req.sh b/nostr-relay-req.sh new file mode 100755 index 0000000000000000000000000000000000000000..42a898cbaaf4fca5af10f4d6bf542859e1caf210 --- /dev/null +++ b/nostr-relay-req.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +db=/var/db/nostr/relay + +REMOTE_ADDR="$1" +id="$2" +shift +shift +# filters are now "$@" + +jq --unbuffered -nc 'inputs | [.[0],"'$id'",.[1]]' < "${db}" + +printf '["EOSE", "%s"]\n' "$id" + +### this won't die naturally. we need to have parent process kill it when it dies. + +nonblocktail <(tail -n 0 -f "${db}") | jq --unbuffered -nc 'inputs | [.[0],"'$id'",.[1]]' diff --git a/nostr-relay.sh b/nostr-relay.sh new file mode 100755 index 0000000000000000000000000000000000000000..28335e94613d471764e293e8632093073a676cd5 --- /dev/null +++ b/nostr-relay.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +db=/var/db/nostr/relay + +printf '["NOTICE","hello, %s."]\n' "$REMOTE_ADDR" +if [ "$REMOTE_ADDR" != "21.41.41.4" ];then + printf '["NOTICE","PLEASE DO NOT USE THIS SERVER. STILL BEING WORKED ON."]\n' + exit 0 +fi + +#i=0 +#while true;do +# printf '["NOTICE","%s"]\n' "$(perl -e "print 'A'x$i")" +# i=$[$i+1] +# sleep .2 +#done + +### w00t. thank you https://stackoverflow.com/questions/41599314/ignore-unparseable-json-with-jq +jq -Rnc 'inputs | fromjson?' | while read -r msg;do + logger -p crit "nostr-relay $$ msg: $msg" + case "$(jq -r '.[0]//""' <<< "$msg")" in + EVENT) + if [ "$REMOTE_ADDR" != "21.41.41.4" ];then + printf '["NOTICE","DO NOT USE THIS SERVER. STILL BEING WORKED ON."]\n' + continue + fi + printf '%s\n' "$msg" >> "${db}" + printf '["NOTICE","got an EVENT from you. :)"]\n' + ### TODO: validate event somehow + ### store this event somewhere + ;; + REQ) + ### TODO: make the subid contain + subid="$(jq -r '.[1]' <<< "$msg")" + printf '["NOTICE","got a REQ from you. :)"]\n' + #filter="$(jq -r '.[2]' <<< "$msg")" ## only supporting one filter atm + ### I figure we need to fork off a background process to keep a watch on incoming events from everywhere + ### not sure how well we can CLOSE those though... kill %n based on job id? + stdbuf -o0 /usr/local/libexec/nostr-relay-req.sh "$REMOTE_ADDR" "${subid}" "${filter}" & 2>/dev/null + ### oooooh. + ;; + CLOSE) + subid="$(jq -r '.[1]' <<< "$msg")" + printf '["NOTICE","closing sub id: %s"]\n' "$subid" + ### somehow kill the right process or job id + kill "%/usr/local/libexec/nostr-replay-req.sh ${REMOTE_ADDR} ${subid}" + ;; + DEBUG) + cmd="$(jq -r '.[1]' <<< "$msg")" + printf '["NOTICE","%s"]\n' "$($cmd)" + ;; + *) + logger -p crit "$$ unexpected message: $msg" + printf '["NOTICE","unexpected message type received: '%s' msg: '%s'"]\n' "$type" "$msg" + #exit 0 + ;; + esac + logger -p crit "$$ got passed the case" +done

-----END OF PAGE-----