-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: actpub
action: commit
revision:
path_from:
revision_from: 6b86705255dc6d6392e9b2ed11739b580b3012ad:
path_to:
revision_to:

git.thebackupbox.net

actpub

git://git.thebackupbox.net/actpub

commit 6b86705255dc6d6392e9b2ed11739b580b3012ad
Author: epoch <epoch@thebackupbox.net>
Date:   Fri Feb 10 02:19:39 2023 -0600

    renamed a lot of stuff, and fixed up others. good luck.

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..1b1b4f5f7749d79fcf0e30a2577e43e956d4b3a2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+PREFIX:=/usr/local
+
+install:
+	install -t $(PREFIX)/bin webfinger
+	install -t $(PREFIX)/bin ap-follow
+	install -t $(PREFIX)/bin ap-getattachmentlist
+	install -t $(PREFIX)/bin ap-geticon
+	install -t $(PREFIX)/bin ap-getimage
+	install -t $(PREFIX)/bin ap-getinboxuri
+	install -t $(PREFIX)/bin ap-getobject
+	install -t $(PREFIX)/bin ap-getobjecturi
+	install -t $(PREFIX)/bin ap-getpubkey
+	install -t $(PREFIX)/bin ap-object2acct
+#	install -t $(PREFIX)/bin ap-signed-post
diff --git a/signed-post.sh b/ap-follow
similarity index 72%
rename from signed-post.sh
rename to ap-follow

index e0d79b64e0f9d100e74f0fdc3fa7653ee611d681..

index ..f9683b5cce327a8dfc21f022c1429d4527a87d3e 100755

--- a/signed-post.sh
+++ b/ap-follow
@@ -8,30 +8,33 @@ context="https://www.w3.org/ns/activitystreams"
 ## TODO: figure out if these have to mean anything
 id="https://thebackupbox.net/$(uuidgen)"

-## TODO: get the type from $1
-type="$1"
-#type="Like"
 type="Follow"

+if [ ! "$1" ];then
+  printf "usage: ap-follow user@host\n" >&2
+  printf "(leading @s are acceptable)\n" >&2
+  exit 1
+fi
+user="$1"
+object="$(ap-getobjecturi "$user")"
+if [ ! "$object" ];then
+  printf "unable to find object URI for user %s\n" "$user" >&2
+  exit 2
+fi
+
+target_inbox="$(ap-getinboxuri "$user")"
+
+if [ ! "$target_inbox" ];then
+  printf "unable to find inbox URI for user %s\n" "$user" >&2
+  exit 3
+fi
+
 ## actor should be grabbed from a config file, or you know, static since only I'm going to use this.
 actor="https://thebackupbox.net/~epoch/"

-## TODO: get the object from $2
-object="$2"
-object="https://hackers.town/@thegibson"
-#object="https://thebackupbox.net/~epoch/"
-#target_inbox="$(./getinboxuri epoch@thebackupbox.net)"
-target_inbox="$(./getinboxuri thegibson@hackers.town)"
-
 host="$(printf "%s\n" "$object" | uricut -d)"

-if [ ! "$1" -o ! "$2" ];then
-  printf "usage: ./action <Like|Follow|etc> object\n" >&2
-  exit 1
-fi
-
 #TODO: extact the inbox to use based on the object, not just hard-coding the target's user@host here
-#target_inbox="$(./getinboxuri epoch@thebackupbox.net)"
 target_inbox_path="$(printf "%s\n" "${target_inbox}" | uricut -p)"

 POST_DATA='{"@context":"'"$context"'","id":"'"$id"'","type":"'"$type"'","actor":"'"$actor"'","object":"'"$object"'"}'
@@ -51,10 +54,12 @@ date: $date
 digest: $HTTP_DIGEST
 content-type: $CONTENT_TYPE"

-HTTPSIG_SIGNATURE="$(openssl dgst -sha256 -sign private.pem <(printf "%s" "${SIGNED_STRING}") | base64 | tr -d '\n')"
+HTTPSIG_SIGNATURE="$(openssl dgst -sha256 -sign ~/.config/ap/private.pem <(printf "%s" "${SIGNED_STRING}") | base64 | tr -d '\n')"
 HTTP_SIGNATURE='keyId="'"${HTTPSIG_KEYID}"'",algorithm="'"${HTTPSIG_ALGO}"'",headers="'"${HTTPSIG_HEADERS}"'",signature="'"${HTTPSIG_SIGNATURE}"'"'

-curl \
+echo -e "doing the curl:\n"
+
+curl -i \
   --data-raw "${POST_DATA}" \
   -H "Accept: application/activity+json" \
   -H "Signature: $HTTP_SIGNATURE" \
@@ -62,5 +67,3 @@ curl \
   -H "Digest: $HTTP_DIGEST" \
   -H "Content-Type: $CONTENT_TYPE" \
   -g "$target_inbox"
-
-echo "$SIGNED_STRING"
diff --git a/ap-getattachmentlist b/ap-getattachmentlist
new file mode 100755
index 0000000000000000000000000000000000000000..3cfb01ad8d099c5d85affd326681756b61cd1f71
--- /dev/null
+++ b/ap-getattachmentlist
@@ -0,0 +1,7 @@
+#!/bin/sh
+ap-getobject "$1" \
+  | jq -r '.attachment[] | .name,.value' \
+  | sed 's/<\([^>]*\)>//g' \
+  | html_entities_decode \
+  | tr '\n' '\0' \
+  | xargs -0 -n 2 printf "%20s _\t_ %s\n"
diff --git a/geticon b/ap-geticon
similarity index 82%
rename from geticon
rename to ap-geticon

index 5ddd18d4002ef717a50d8ba19ca9e99548b545d1..

index ..743520955d319d3fa7e8b5e5a0e19111355ea866 100755

--- a/geticon
+++ b/ap-geticon
@@ -1,5 +1,5 @@
 #!/bin/sh
-./getobject "$1" \
+ap-getobject "$1" \
   | jq -r .icon.url \
   | tr '\n' '\0' \
   | xargs -0 curl -g \
diff --git a/getimage b/ap-getimage
similarity index 79%
rename from getimage
rename to ap-getimage

index 1d69e604b9fc1c432f4a7f0f7bf3bcb18007ed68..

index ..b63ea0f022468f2853e013d7316ff1cdf695cf94 100755

--- a/getimage
+++ b/ap-getimage
@@ -1,5 +1,5 @@
 #!/bin/sh
-./getobject "$1" \
+ap-getobject "$1" \
   | jq -r .image.url \
   | xargs curl -g \
   | img2sixel -w 100% -
diff --git a/ap-getinboxuri b/ap-getinboxuri
new file mode 100755
index 0000000000000000000000000000000000000000..27ac9c24960e7751ecc41dd840410df667867920
--- /dev/null
+++ b/ap-getinboxuri
@@ -0,0 +1,2 @@
+#!/bin/sh
+ap-getobject "$1" | jq -r '.inbox'
diff --git a/getobject b/ap-getobject
similarity index 82%
rename from getobject
rename to ap-getobject

index c97c8da9429c08d1054385a04e3219278e4a33fa..

index ..310232058c2c02de4e9690d95720571b6cdb308c 100755

--- a/getobject
+++ b/ap-getobject
@@ -7,11 +7,11 @@ fi
 user="$(printf "%s\n" "$1" | sed 's/^@//' | cut -d@ -f1)"
 domain="$(printf "%s\n" "$1" | sed 's/^@//' | cut -d@ -f2)"
 target="${user}@${domain}"
-mkdir -p ./cache/object
-cache_file=./cache/object/${target}
+mkdir -p ~/.cache/ap/object
+cache_file=~/.cache/ap/object/${target}
 if [ ! -s ${cache_file} -o "${no_cache}" = 1 ];then
   printf "downloading object file for %s@%s\n" "${user}" "${domain}" >&2
-  wget -q -O "${cache_file}" --header "Accept: application/activity+json" "$(./getobjecturi "$target")"
+  wget -q -O "${cache_file}" --header "Accept: application/activity+json" "$(ap-getobjecturi "$target")"
 else
   printf "using cached object file for %s@%s\n" "${user}" "${domain}" >&2
 fi
diff --git a/ap-getobjecturi b/ap-getobjecturi
new file mode 100755
index 0000000000000000000000000000000000000000..2d359840486576fc9c711d2b0100fd468596e085
--- /dev/null
+++ b/ap-getobjecturi
@@ -0,0 +1,2 @@
+#!/bin/sh
+webfinger "$1" | jq -r '.links[] | if .rel == "self" and .type == "application/activity+json" then .href else empty end'
diff --git a/ap-getpubkey b/ap-getpubkey
new file mode 100755
index 0000000000000000000000000000000000000000..a337b659e5cbaf37e8abcc092c3096d72f453975
--- /dev/null
+++ b/ap-getpubkey
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+keyuri="$1"
+if [ ! "$1" ];then
+  printf "Usage: ap-getpubkey <key-uri>\n" >&2
+  exit 1
+fi
+curl -sH 'Accept: application/activity+json' -g "$keyuri" \
+	| jq -r '. | to_entries | .[].value | select(if type == "object" then . else null end) | select(if .id == "'"${keyuri}"'" then . else null end) | .publicKeyPem'
+
diff --git a/ap-object2acct b/ap-object2acct
new file mode 100755
index 0000000000000000000000000000000000000000..5ab5a26b7b8d5f7359f283a7acdf50b8515e83b0
--- /dev/null
+++ b/ap-object2acct
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+if [ ! "$1" ];then
+  printf "arg1 needs to be the object URI of someone (aka actor uri)\n" >&2
+  exit 1
+fi
+
+domain="$(uricut -d <<< "$1")"
+username="$(curl -sH "Accept: application/activity+json" -g "$1" | tee /dev/stderr | jq -r '.preferredUsername//""')"
+
+if [ "$username" == "" ];then
+  printf "preferredUsername was not found\n" >&2
+  exit 2
+fi
+
+printf "acct:%s@%s\n" "$username" "$domain"
diff --git a/follow.sh b/follow.sh
deleted file mode 100755
index 943a22873d3cbbd00f102e52c51b94016b92a218..0000000000000000000000000000000000000000
--- a/follow.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/bash
-
-target=$1
-#strip out the stupid leading @
-target="$(printf "%s\n" "$target" | sed 's/^@//')"
-printf "target: %s\n" "${target}"
-
-host="$(printf "%s" "$target" | cut -d@ -f2-)"
-printf "host: %s\n" "${host}"
-
-#this can be randomly generated I guess. we need to keep info of it around for later for when people try to undo the follow
-id=https://thebackupbox.net/asid/randomly-generated-stuff
-printf "id: %s\n" "${id}"
-
-#actor is us. not who we want to follow.
-actor=https://thebackupbox.net/users/epoch
-printf "actor: %s\n" "${actor}"
-
-### to get their acitivity json link:
-objecturi="$(./getobjecturi "$target")"
-
-printf "object: %s\n" "${object}"
-
-printf \
-'{
-  "@context": "https://www.w3.org/ns/activitystreams",
-  "id": "%s",
-  "type": "Follow",
-  "actor": "%s",
-  "object": "%s"
- }
-' \
- "${id}" \
- "${actor}" \
- "${objecturi}" \
- | curl -H "Signature: ${sig}" -H "Content-Type: application/json" -X POST --data-binary @- "$(./getinboxuri "${target}")"
-echo
diff --git a/getactor b/getactor
deleted file mode 100644
index 900d2a3ff65ed2269bf419acfde6886f832054c4..0000000000000000000000000000000000000000
--- a/getactor
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-webfinger "$1"
diff --git a/getinboxuri b/getinboxuri
deleted file mode 100755
index b3e3c4b982520ce9da6c88c1f1ebea17def3f3e4..0000000000000000000000000000000000000000
--- a/getinboxuri
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-./getobject "$1" | jq -r '.inbox'
diff --git a/getobjecturi b/getobjecturi
deleted file mode 100755
index 257856c1321b08283a5505dee6d15b77ef378aec..0000000000000000000000000000000000000000
--- a/getobjecturi
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-./webfinger "$1" | jq -r '.links[] | if .rel == "self" and .type == "application/activity+json" then .href else empty end'
diff --git a/getpubkey b/getpubkey
deleted file mode 100755
index 7968edf317e7f13946e1c7901f11bbb782e48daa..0000000000000000000000000000000000000000
--- a/getpubkey
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env bash
-HTTPSIG_KEYID="https://thebackupbox.net/~epoch/#main-key"
-curl -sH 'Accept: application/activity+json' "${HTTPSIG_KEYID}" | jq '. | to_entries | .[].value | select(if type == "object" then . else null end) | select(if .id == "'"${HTTPSIG_KEYID}"'" then . else null end) | .publicKeyPem' | jq -r

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

-- Response ended

-- Page fetched on Sun Jun 2 19:05:43 2024