-- 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: a35e41907c4a8da772ea9cfc1f9b91154197e9ba:
path_to:
revision_to:

git.thebackupbox.net

actpub

git://git.thebackupbox.net/actpub

commit a35e41907c4a8da772ea9cfc1f9b91154197e9ba
Author: epoch <epoch@thebackupbox.net>
Date:   Tue Jun 20 20:35:52 2023 +0000

    factored out the common code and merged features in ap-inbox.cgi and ap-outbox.cgi into ap-collection.cgi and make both call that now.

diff --git a/ap-collection.cgi b/ap-collection.cgi
new file mode 100755
index 0000000000000000000000000000000000000000..fa7cd77b15089bb28f7cbae403cbcd01384ff92e
--- /dev/null
+++ b/ap-collection.cgi
@@ -0,0 +1,363 @@
+#!/usr/bin/env bash
+
+### THIS SCRIPT ASSUMES IT IS BEING RAN FROM INSIDE OF THE DIR OF THE COLLECTION IT IS BEING USED FOR
+### ALSO PUT THE COLLECTION PATH AS $1 !!!
+### it should be the stuff between https://${SERVER_NAME}/${1}/
+### so, for the collection https://thebackupbox.net/~epoch/outbox/ the value should be ~epoch/outbox
+### got it? good.
+
+if [ ! "$1" ];then
+	printf "Status: 501 Internal Server Error\r\n\r\n"
+	logger -p crit "ap-collection.cgi was ran without the required first argument!"
+	exit 0
+fi
+
+collection_id="$1"
+
+#logger "ap-inbox at ${SCRIPT_NAME} requested! HTTP_ACCEPT: ${HTTP_ACCEPT}"
+
+per_page=1
+reload=30
+
+### we are only going to bother to ident against localhost and my desktop for now
+if [ "$REMOTE_ADDR" = "127.0.0.1" -o "$REMOTE_ADDR" = "21.41.41.4" ];then
+	export REMOTE_IDENT="$(ident "$SERVER_ADDR" "$REMOTE_ADDR" 113 "$REMOTE_PORT" "$SERVER_PORT")"
+else
+	export REMOTE_IDENT=""
+fi
+
+#logger -p crit "got to here: $LINENO"
+
+### only check ident if it is a user's collection, and not the server's.
+### server collections are public I guess.
+#if [ "$REQUEST_METHOD" = "GET" -a "$USER" != "www" ];then
+#	if [ "$REMOTE_IDENT" != "$USER" ];then
+#		logger "REMOTE_IDENT: '$REMOTE_IDENT' requested ${collection_id} with GET. nope."
+#		printf "Content-Type: text/html\r\n\r\n"
+#		printf "not showing ${collection_id} to someone not the user.<br/>"
+#		printf "you are, %s, target user is %s<br/>" "$REMOTE_IDENT" "$USER"
+#		exit 0
+#	fi
+#fi
+### fuck it. I'll have a public outbox for now.
+
+#logger -p crit "got to here: $LINENO"
+
+############## START OF OLD OUTBOX CODE ####################
+
+if [ "$PATH_INFO" = "" ];then
+	if [ "$REQUEST_METHOD" = "POST" ];then
+		id="$(uuidgen -t)" ### should probably use hash of content
+		export POST_DATA="$(head -c "$CONTENT_LENGTH")"
+		if [ "$POST_DATA" ];then # make sure to check for conditions that'd cause this to be ran from outside of this script and prevent it from running.
+			logger "ACTUALLY ATTEMPTING TO VERIFY SIGNATURES AGAIN"
+			### let's just start skipping the deletes. they're annoying and I don't handle them anyway.
+			activity_type="$(jq -r .type <<< "$POST_DATA")"
+			actor="$(jq -r .actor <<< "${POST_DATA}")"
+			if [ "$activity_type" = "Delete" ];then
+				printf 'Status: 200 Ok\r\n'
+				printf 'Content-Type: text/plain; charset=utf-8\r\n\r\n'
+				printf 'I dont handle deletes yet, but thank you anyway.\n'
+				logger -t actpub "ignoring a Delete activity to $collection_id from $actor"
+				exit 0
+			fi
+			content_type="$(jq -r '.object | type' <<< ${POST_DATA})"
+			if [ "$content_type" = "string" ];then
+				content="$(jq -r '.object' <<< "$POST_DATA")"
+			else
+				content="$(jq -r '.object.content' <<< "${POST_DATA}" | sed 's|<br */* *>| |g' | sed 's/<[^>]*>//g' | html_entities_decode | tr '\n' ' ')"
+			fi
+			remote_id="$(jq -r '.id' <<< "${POST_DATA}")"
+			logger -t actpub "<$remote_id>"
+			logger -t actpub "${activity_type} <$actor> $content"
+			if ap-verifysignature;then
+				printf "%s" "$POST_DATA" > "$id"
+				printf "Status: 200 Ok\r\n"
+				printf "Content-Type: text/plain; charset=utf-8\r\n\r\n"
+				printf "All Good.\n"
+				logger -t actpub "signature verified and POST accepted to ${collection_id}."
+				exit 0
+			else
+				printf "%s" "$POST_DATA" > "$id"
+				printf "Status: 200 OK\r\n"
+				printf "Content-Type: text/plain; charset=utf-8\r\n\r\n"
+				printf "your signature didn't verify, but we accepted it anyway."
+				logger -t actpub "signature did not verify, but POST accepted to $collection_id anyway."
+				exit 0 #an exit here makes sense I guess.
+			fi
+		fi
+		printf "Status: 401 Unauthorized\r\n"
+		printf "Content-Type: text/plain\r\n\r\n"
+		printf "POST_DATA is empty for some reason. Content-Length: %s\n" "${CONTENT_LENGTH}"
+		#logger -p crit "got to here: $LINENO"
+		exit 0
+	fi
+	if grep -E "application/activity\+json|application/ld\+json" <<< "${HTTP_ACCEPT}" >/dev/null 2>&1;then
+		per_page=1
+		totalItems="$(ls -t | grep -c '^[0-9a-f]')"
+		if [ "$REQUEST_METHOD" = "GET" ];then
+			at="$(query_param at)"
+			if [ ! "$at" ];then
+				first="$(ls -t | grep '^[0-9a-f]' | head -n1)"
+				start_of_last="$(ls -t | grep '^[0-9a-f]' | tail "-n${per_page}" | head -n1)"
+				printf "Content-Type: application/json\r\n\r\n"
+				### TODO: figure out how to find the uh, id? probably an argument to this. or using pwd. or something.
+				cat <<EOF
+{
+  "@context": "https://www.w3.org/ns/activitystreams",
+  "id": "https://thebackupbox.net/${collection_id}/",
+  "type": "OrderedCollection",
+  "totalItems": ${totalItems},
+  "first": "https://thebackupbox.net/${collection_id}/?at=${first}",
+  "last": "https://thebackupbox.net/${collection_id}/?at=${start_of_last}"
+}
+EOF
+				exit 0
+			fi
+			prev_at="$(ls -t | grep '^[0-9a-f]' | grep -B3 -F "$at" | head -n1)"
+			next_at="$(ls -t | grep '^[0-9a-f]' | grep -A1 -F "$at" | tail -n1)"
+			printf "Content-Type: application/json\r\n\r\n"
+			cat <<EOF
+{
+  "@context": [
+    "https://www.w3.org/ns/activitystreams",
+    {
+      "ostatus": "http://ostatus.org#",
+      "atomUri": "ostatus:atomUri",
+      "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+      "conversation": "ostatus:conversation",
+      "sensitive": "as:sensitive",
+      "toot": "http://joinmastodon.org/ns#",
+      "votersCount": "toot:votersCount",
+      "litepub": "http://litepub.social/ns#",
+      "directMessage": "litepub:directMessage",
+      "blurhash": "toot:blurhash",
+      "focalPoint": {
+        "@container": "@list",
+        "@id": "toot:focalPoint"
+      }
+    }
+  ],
+  "id": "https://thebackupbox.net/${collection_id}/?at=${at}",
+  "type": "OrderedCollectionPage",
+  "next": "https://thebackupbox.net/${collection_id}/?at=${next_at}&page=true",
+  "prev": "https://thebackupbox.net/${collection_id}/?at=${prev_at}&page=true",
+  "partOf": "https://thebackupbox.net/${collection_id}/",
+  "orderedItems":
+EOF
+			ls -t | grep '^[0-9a-f]' | grep -A "$[${per_page}-1]" -F "${at}" | xargs cat | jq -s
+			cat <<EOF
+}
+EOF
+		fi #end of if [ "$REQUEST_METHOD" = "GET" ]
+		#logger -p crit "got to here: $LINENO"
+		exit 0 ### the exit needs to be here, or it falls back into outputing HTML for JSON requests.
+	fi # end of Accept: json-stuff
+
+################### END OF OLD OUTBOX CODE ############################
+
+	if [ "$REQUEST_METHOD" = "GET" ];then #this is kind of a crappy way to do it :/
+		### will probably let any URI be passed as the argument?
+		puri="$(uriunescape "$(query_param "puri")")"
+		if [ "$puri" ];then
+			phash="$(sha256sum <<< "$puri" | cut '-d ' -f1)"
+			pcache_file=~/.cache/ap/object/"${phash}"
+			if [ ! -e "${pcache_file}" ];then
+				printf "Content-Type: text/html; charset=utf-8\r\n\r\n"
+				printf "ERROR: parent object hasn't been cached already.\n"
+				#logger -p crit "got to here: $LINENO"
+				exit 0
+			fi
+			uri="$(jq -r .inReplyTo < "${pcache_file}" )"
+			cache_file="$(ap-cacheobject "${uri}")"
+			printf "Content-Type: text/html; charset=utf-8\r\n\r\n"
+			if [ "${HTTP_HX_REQUEST}" != "true" ];then
+				printf '<html><head>'
+				printf '<link rel="stylesheet" type="text/css" href="/ap-style.css" />'
+				printf '<script src="/htmx.min.js"></script><title>object viewer</title></head><body>\n'
+				ap-object2html "$pcache_file"
+			else
+			  ap-object2html "$cache_file"
+			fi
+			if [ "${HTTP_HX_REQUEST}" != "true" ];then
+				printf "</body></html>\n"
+			fi
+			#logger -p crit "got to here: $LINENO"
+			exit 0
+		fi
+		first="$(ls -t | grep '^[0-9a-f]' | head -n1)"
+		at="$(query_param "at")"
+		before="$(query_param "before" | tr -cd '0-9a-f-')"
+		new_reload="$(query_param "reload" | tr -cd '0-9')"
+		if [ "$new_reload" ];then
+			reload=$new_reload
+		fi
+		perpage="$(query_param "perpage" | tr -cd '0-9')"
+		if [ "${before}" ];then
+			export do_notification=true #we only want notifications of newer posts.
+			printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
+			if [ "${HTTP_HX_REQUEST}" != "true" ];then
+				printf '<html><head>'
+				printf '<link rel="stylesheet" type="text/css" href="/ap-style.css" />'
+				printf '<script src="/htmx.min.js"></script><title>object viewer</title></head><body>\n'
+			fi
+			if [ "$reload" ];then
+				printf '<div hx-get="?before=%s&amp;reload=%s" hx-trigger="load delay:%ss once" hx-swap="outerHTML" hx-indicator="#before-indicator">' "${first}" "${reload}" "${reload}"
+				printf 'last check %s<br/>' "$(date)"
+				printf 'next check in %s seconds<br/>' "${reload}"
+			fi
+			printf '<a href="?before=%s">click here for only the newer posts than currently displayed.</a><br/>' "${first}"
+			newer_posts="$(ls -t | grep '^[0-9a-f]' | grep -B 1000 -F "${before}" | tac | tail -n+2 | tac)"
+			printf 'newer posts than %s: %s' "${before}" "$newer_posts"
+			printf '</div>'
+			ls -t \
+				| grep '^[0-9a-f]' \
+				| grep -B 1000 -F "${before}" \
+				| tac \
+				| tail -n+2 \
+				| tac \
+				| while read -r derp;do
+					ap-activity2html "$derp"
+				  done
+			if [ "${HTTP_HX_REQUEST}" != "true" ];then
+				printf '</body></html>\n'
+			fi
+			#logger -p crit "got to here: $LINENO"
+			exit 0
+		fi
+		if [ "${at}" ] ;then
+			total="$(ls -t | grep -c '^[0-9a-f]')"
+			at="$(query_param at | tr -cd '0-9a-f-')"
+			if [ ! "$at" ];then
+				at="$(ls -t | head -n1)"
+			else
+				if [ ! -e "$at" ];then
+					printf "Status: 404 Not Found\r\n"
+					printf "Content-Type: text/plain\r\n\r\n"
+					printf "the note you are looking for can not be found."
+				fi
+			fi
+			next_at="$(ls -t | grep '^[0-9a-f]' | grep -A "${per_page}" -F "${at}" | tail -n+$[${per_page}+1])"
+
+			printf "Content-Type: text/html; charset=utf-8\r\n\r\n"
+			if [ "${HTTP_HX_REQUEST}" != "true" ];then
+				printf '<html><head>'
+				printf '<link rel="stylesheet" type="text/css" href="/ap-style.css" />'
+				printf '<script src="/htmx.min.js"></script><title>object viewer</title></head><body>\n'
+			fi
+
+			ls -t \
+				| grep '^[0-9a-f]' \
+				| grep -A "$[${per_page}-1]" -F "${at}" \
+				| while read -r derp;do ap-activity2html "$derp";done
+			if [ "${next_at}" ];then
+				printf '<div hx-get="?at=%s" hx-trigger="intersect once" hx-swap="outerHTML" hx-indicator="#after-indicator">' "${next_at}"
+				printf '<div id="after-indicator" class="spinner"></div>'
+				printf '<a href="?at=%s">no javascript? load the next %s posts</a>' "${next_at}" "${per_page}"
+				printf '</div>\n'
+			else
+				printf "this is the end. total of %s things\n" "$total"
+			fi
+			if [ "${HTTP_HX_REQUEST}" != "true" ];then
+				printf '</body></html>\n'
+			fi
+			#logger -p crit "got to here: $LINENO"
+			exit 0
+		fi
+		printf "Content-Type: text/html; charset=utf-8\r\n\r\n"
+cat <<EOF
+<html id="top">
+  <head>
+  <title>htmx fediverse inbox infinite scroll</title>
+  <script src="/htmx.min.js"></script>
+  <script>
+function enable_notif() {
+  if(Notification.permission == "default") {
+    Notification.requestPermission(function(p) {
+      if(p == "granted") {
+        new Notification("plzhold",{"body":"thanks for permission.","icon":"/epoch.png"});
+      }
+    });
+  }
+}
+
+  </script>
+  <link rel="stylesheet" type="text/css" href="/ap-style.css" />
+  </head>
+  <body onload="enable_notif()">
+    <div class="stick">
+      <span>
+EOF
+if [ "$REMOTE_IDENT" ];then
+	printf "Hello, %s. " "$REMOTE_IDENT"
+else
+	printf "viewing public posts only."
+fi
+cat <<EOF
+        <a href="#top">top</a>
+        <a href="#center">center</a>
+        <a href="#bottom">bottom</a>
+        <a href="actpub:create">new post</a>
+      </span>
+    </div>
+    <div id="before-indicator" class="spinner"></div>
+    <div id="before" hx-get="?before=${first}&amp;reload=${reload}" hx-trigger="load delay:${reload}s once" hx-swap="outerHTML" hx-indicator="#before-indicator">
+<a href="?before=${first}">no javascript? load the newer posts than when the page loaded.</a>
+    </div>
+    <hr/>
+    <div id="center">page loaded here.</div>
+    <hr/>
+    <div hx-get="?at=${first}" hx-trigger="intersect once" hx-swap="outerHTML" hx-indicator="#after-indicator">
+      <div id="after-indicator" class="spinner"></div>
+      <a href="?at=${first}">no javascript? load the next ${per_page} posts</a>
+    </div>
+    <a href="#top">top</a> <a id="bottom" href="#bottom">bottom</a>
+  </body>
+</html>
+EOF
+		exit 0
+	fi
+	### error about unexpect request method
+	printf "Status: 200 OK\r\n"
+	printf "Content-Type: text/plain\r\n\r\n"
+	#logger -p crit "got to here: $LINENO"
+	exit 0
+fi
+
+### if we're here, a specific inbox item is being requested most likely.
+
+if [ -e "${PATH_INFO}" ];then
+  if grep -E "application/activity\+json|application/ld\+json" <<< "${HTTP_ACCEPT}" >/dev/null 2>/dev/null;then
+    printf 'Status: 200 OK\r\n'
+    printf "Content-Type: application/activity+json\r\n\r\n"
+    cat "${PATH_INFO}"
+    logger -p crit "got to here: $LINENO path_info: $PATH_INFO pwd: $(pwd) file: $(file ${PATH_INFO})"
+    sleep 1
+    exit 0
+  fi
+  printf "Content-Type: text/html; charset=utf-8\r\n\r\n"
+cat <<EOF
+<html>
+  <head>
+    <script src="/htmx.min.js"></script>
+    <title>collection item viewer</title>
+    <link rel="stylesheet" type="text/css" href="/ap-style.css" />
+  </head>
+  <body>
+EOF
+  echo "${PATH_INFO}"
+  ap-activity2html "${PATH_INFO}"
+cat <<EOF
+  </body>
+</html>
+EOF
+  exit 0
+fi
+
+
+printf "Status: 404 Not Found\r\n"
+printf "Content-Type: text/plain\r\n\r\n"
+printf "I can't find %s%s. :/\n" "$(pwd)" "${PATH_INFO}"
+
+
+logger -p crit "got to here: $LINENO"
diff --git a/ap-inbox.cgi b/ap-inbox.cgi
old mode 100755
new mode 100644
index c32cbe9ed4ece3cf18346443a01669d69c6943fd..59f578d1b4e8e61358b17d71c963799d45509ff5
--- a/ap-inbox.cgi
+++ b/ap-inbox.cgi
@@ -1,224 +1,4 @@
 #!/usr/bin/env bash

-#logger "ap-inbox at ${SCRIPT_NAME} requested! HTTP_ACCEPT: ${HTTP_ACCEPT}"
-per_page=4
-reload=30
-
-if [ "$REMOTE_ADDR" = "127.0.0.1" -o "$REMOTE_ADDR" = "21.41.41.4" ];then
-	export REMOTE_IDENT="$(ident "$SERVER_ADDR" "$REMOTE_ADDR" 113 "$REMOTE_PORT" "$SERVER_PORT")"
-else
-	export REMOTE_IDENT=""
-fi
-
-if [ "$REQUEST_METHOD" = "GET" -a "$USER" != "www" ];then ### ooof. this exits out too soon and doesn't check for POSTS first! GAhHH
-	if [ "$REMOTE_IDENT" != "$USER" ];then
-		logger "REMOTE_IDENT: '$REMOTE_IDENT' requested inbox with GET. nope."
-		printf "Content-Type: text/html\r\n\r\n"
-		printf "not showing a user's inbox to someone not the user.<br/>"
-		printf "you are, %s, target user is %s<br/>" "$REMOTE_IDENT" "$USER"
-		exit 0
-	fi
-fi
-
-
-#if grep -E '' <<< "${HTTP_ACCEPT}";then
-
-if [ "$PATH_INFO" = "" ];then
-	if [ "$REQUEST_METHOD" = "POST" ];then
-		id="$(uuidgen -t)"
-		export POST_DATA="$(head -c "$CONTENT_LENGTH")"
-		if [ "$POST_DATA" ];then
-			logger "ACTUALLY ATTEMPTING TO VERIFY SIGNATURES AGAIN"
-			if ap-verifysignature;then
-				printf "%s" "$POST_DATA" > "$id"
-				printf "Status: 200 Ok\r\n"
-				printf "Content-Type: text/plain; charset=utf-8\r\n\r\n"
-				printf "All Good.\n"
-				logger "signature verified and POST accepted to inbox."
-				exit 0
-			else
-				printf "%s" "$POST_DATA" > "$id"
-				printf "Status: 200 OK\r\n"
-				printf "Content-Type: text/plain; charset=utf-8\r\n\r\n"
-				printf "your signature didn't verify, but we accepted it anyway."
-				logger "signature did not verify, but POST accepted to inbox anyway."
-			fi
-		fi
-		printf "Status: 401 Unauthorized\r\n"
-		exit 0
-	fi
-	if [ "$REQUEST_METHOD" = "GET" ];then
-		puri="$(uriunescape "$(query_param "puri")")"
-		if [ "$puri" ];then
-			phash="$(sha256sum <<< "$puri" | cut '-d ' -f1)"
-			pcache_file=~/.cache/ap/object/"${phash}"
-			if [ ! -e "${pcache_file}" ];then
-				printf "Content-Type: text/html; charset=utf-8\r\n\r\n"
-				printf "ERROR: parent object hasn't been cached already.\n"
-				exit 0
-			fi
-			uri="$(jq -r .inReplyTo < "${pcache_file}" )"
-			cache_file="$(ap-cacheobject "${uri}")"
-			printf "Content-Type: text/html; charset=utf-8\r\n\r\n"
-			if [ "${HTTP_HX_REQUEST}" != "true" ];then
-				printf '<html><head>'
-				printf '<link rel="stylesheet" type="text/css" href="/ap-style.css" />'
-				printf '<script src="/htmx.min.js"></script><title>object viewer</title></head><body>\n'
-				ap-object2html "$pcache_file"
-			else
-			  ap-object2html "$cache_file"
-			fi
-			if [ "${HTTP_HX_REQUEST}" != "true" ];then
-				printf "</body></html>\n"
-			fi
-			exit 0
-		fi
-		first="$(ls -t | grep '^[0-9a-f]' | head -n1)"
-		at="$(query_param "at")"
-		before="$(query_param "before" | tr -cd '0-9a-f-')"
-		new_reload="$(query_param "reload" | tr -cd '0-9')"
-		if [ "$new_reload" ];then
-			reload=$new_reload
-		fi
-		perpage="$(query_param "perpage" | tr -cd '0-9')"
-		if [ "${before}" ];then
-			export do_notification=true #we only want notifications of newer posts.
-			printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
-			if [ "${HTTP_HX_REQUEST}" != "true" ];then
-				printf '<html><head>'
-				printf '<link rel="stylesheet" type="text/css" href="/ap-style.css" />'
-				printf '<script src="/htmx.min.js"></script><title>object viewer</title></head><body>\n'
-			fi
-			if [ "$reload" ];then
-				printf '<div hx-get="?before=%s&amp;reload=%s" hx-trigger="load delay:%ss once" hx-swap="outerHTML" hx-indicator="#before-indicator">' "${first}" "${reload}" "${reload}"
-				printf 'last check %s<br/>' "$(date)"
-				printf 'next check in %s seconds<br/>' "${reload}"
-			fi
-			printf '<a href="?before=%s">click here for only the newer posts than currently displayed.</a><br/>' "${first}"
-			newer_posts="$(ls -t | grep '^[0-9a-f]' | grep -B 1000 -F "${before}" | tac | tail -n+2 | tac)"
-			printf 'newer posts than %s: %s' "${before}" "$newer_posts"
-			printf '</div>'
-			ls -t \
-				| grep '^[0-9a-f]' \
-				| grep -B 1000 -F "${before}" \
-				| tac \
-				| tail -n+2 \
-				| tac \
-				| while read -r derp;do
-					ap-activity2html "$derp"
-				  done
-			if [ "${HTTP_HX_REQUEST}" != "true" ];then
-				printf '</body></html>\n'
-			fi
-			exit 0
-		fi
-		if [ "${at}" ] ;then
-			total="$(ls -t | grep -c '^[0-9a-f]')"
-			at="$(query_param at | tr -cd '0-9a-f-')"
-			if [ ! "$at" ];then
-				at="$(ls -t | head -n1)"
-			else
-				if [ ! -e "$at" ];then
-					printf "Status: 404 Not Found\r\n"
-					printf "Content-Type: text/plain\r\n\r\n"
-					printf "the note you are looking for can not be found."
-				fi
-			fi
-			next_at="$(ls -t | grep '^[0-9a-f]' | grep -A "${per_page}" -F "${at}" | tail -n+$[${per_page}+1])"
-
-			printf "Content-Type: text/html; charset=utf-8\r\n\r\n"
-			if [ "${HTTP_HX_REQUEST}" != "true" ];then
-				printf '<html><head>'
-				printf '<link rel="stylesheet" type="text/css" href="/ap-style.css" />'
-				printf '<script src="/htmx.min.js"></script><title>object viewer</title></head><body>\n'
-			fi
-
-			ls -t \
-				| grep '^[0-9a-f]' \
-				| grep -A "$[${per_page}-1]" -F "${at}" \
-				| while read -r derp;do ap-activity2html "$derp";done
-			if [ "${next_at}" ];then
-				printf '<div hx-get="?at=%s" hx-trigger="intersect once" hx-swap="outerHTML" hx-indicator="#after-indicator">' "${next_at}"
-				printf '<div id="after-indicator" class="spinner"></div>'
-				printf '<a href="?at=%s">no javascript? load the next %s posts</a>' "${next_at}" "${per_page}"
-				printf '</div>\n'
-			else
-				printf "this is the end. total of %s things\n" "$total"
-			fi
-			if [ "${HTTP_HX_REQUEST}" != "true" ];then
-				printf '</body></html>\n'
-			fi
-			exit 0
-		fi
-		printf "Content-Type: text/html; charset=utf-8\r\n\r\n"
-cat <<EOF
-<html id="top">
-  <head>
-  <title>htmx fediverse inbox infinite scroll</title>
-  <script src="/htmx.min.js"></script>
-  <script>
-function enable_notif() {
-  if(Notification.permission == "default") {
-    Notification.requestPermission(function(p) {
-      if(p == "granted") {
-        new Notification("plzhold",{"body":"thanks for permission.","icon":"/epoch.png"});
-      }
-    });
-  }
-}
-
-  </script>
-  <link rel="stylesheet" type="text/css" href="/ap-style.css" />
-  </head>
-  <body onload="enable_notif()">
-    <div class="stick">
-      <span>
-EOF
-if [ "$REMOTE_IDENT" ];then
-	printf "Hello, %s. " "$REMOTE_IDENT"
-else
-	printf "viewing public posts only."
-fi
-cat <<EOF
-        <a href="#top">top</a>
-        <a href="#center">center</a>
-        <a href="#bottom">bottom</a>
-        <a href="actpub:create">new post</a>
-      </span>
-    </div>
-    <div id="before-indicator" class="spinner"></div>
-    <div id="before" hx-get="?before=${first}&amp;reload=${reload}" hx-trigger="load delay:${reload}s once" hx-swap="outerHTML" hx-indicator="#before-indicator">
-<a href="?before=${first}">no javascript? load the newer posts than when the page loaded.</a>
-    </div>
-    <hr/>
-    <div id="center">page loaded here.</div>
-    <hr/>
-    <div hx-get="?at=${first}" hx-trigger="intersect once" hx-swap="outerHTML" hx-indicator="#after-indicator">
-      <div id="after-indicator" class="spinner"></div>
-      <a href="?at=${first}">no javascript? load the next ${per_page} posts</a>
-    </div>
-    <a href="#top">top</a> <a id="bottom" href="#bottom">bottom</a>
-  </body>
-</html>
-EOF
-		exit 0
-	fi
-	### error about unexpect request method
-	printf "Status: 200 OK\r\n"
-	printf "Content-Type: text/plain\r\n\r\n"
-	exit 0
-fi
-
-### if we're here, a specific inbox item is being requested most likely.
-
-if [ -e "../inbox2/${PATH_INFO}" ];then
-  printf "Content-Type: application/activity+json\r\n\r\n"
-  cat "../inbox2/$PATH_INFO"
-  exit 0
-fi
-
-
-printf "Status: 404 Not Found\r\n"
-printf "Content-Type: text/plain\r\n\r\n"
-printf "I can't find it. :/\n"
-
+### put any extra restrictions on inboxes here I guess?
+exec ap-collection.cgi "$@"
diff --git a/ap-outbox.cgi b/ap-outbox.cgi

index 00d6273a8821b494aaf8cb31520f10058c00c9ac..

index ..6011e3856ef39709009aabae6bdb536071083e93 100755

--- a/ap-outbox.cgi
+++ b/ap-outbox.cgi
@@ -1,113 +1,10 @@
 #!/usr/bin/env bash

-if [ "$REMOTE_ADDR" = "127.0.0.1" -o "$REMOTE_ADDR" = "21.41.41.4" ];then
-        export REMOTE_IDENT="$(ident "$SERVER_ADDR" "$REMOTE_ADDR" 113 "$REMOTE_PORT" "$SERVER_PORT")"
-else
-        export REMOTE_IDENT=""
-fi
-
-cd ../outbox2
-
-if [ "$PATH_INFO" = "" ];then
-
-	if grep -E "application/activity\+json|application/ld\+json" <<< "${HTTP_ACCEPT}" 2>&1 >/dev/null;then
-
-	per_page=3
-	totalItems="$(ls -t | grep -c '^[0-9a-f]')"
-
-	if [ "$REQUEST_METHOD" = "GET" ];then
-
-		at="$(query_param at)"
-		if [ ! "$at" ];then
-
-			first="$(ls -t | grep '^[0-9a-f]' | head -n1)"
-			start_of_last="$(ls -t | grep '^[0-9a-f]' | tail "-n${per_page}" | head -n1)"
-			printf "Content-Type: application/json\r\n\r\n"
-
-cat <<EOF
-{
-  "@context": "https://www.w3.org/ns/activitystreams",
-  "id": "https://thebackupbox.net/~epoch/outbox/",
-  "type": "OrderedCollection",
-  "totalItems": ${totalItems},
-  "first": "https://thebackupbox.net/~epoch/outbox/?at=${first}",
-  "last": "https://thebackupbox.net/~epoch/outbox/?at=${start_of_last}"
-}
-EOF
-  exit 0
-fi
-
-			prev_at="$(ls -t | grep '^[0-9a-f]' | grep -B3 -F "$at" | head -n1)"
-			next_at="$(ls -t | grep '^[0-9a-f]' | grep -A1 -F "$at" | tail -n1)"
-
-			printf "Content-Type: application/json\r\n\r\n"
-
-cat <<EOF
-{
-  "@context": [
-    "https://www.w3.org/ns/activitystreams",
-    {
-      "ostatus": "http://ostatus.org#",
-      "atomUri": "ostatus:atomUri",
-      "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
-      "conversation": "ostatus:conversation",
-      "sensitive": "as:sensitive",
-      "toot": "http://joinmastodon.org/ns#",
-      "votersCount": "toot:votersCount",
-      "litepub": "http://litepub.social/ns#",
-      "directMessage": "litepub:directMessage",
-      "blurhash": "toot:blurhash",
-      "focalPoint": {
-        "@container": "@list",
-        "@id": "toot:focalPoint"
-      }
-    }
-  ],
-  "id": "https://thebackupbox.net/~epoch/outbox/?at=${at}",
-  "type": "OrderedCollectionPage",
-  "next": "https://thebackupbox.net/~epoch/outbox/?at=${next_at}&page=true",
-  "prev": "https://thebackupbox.net/~epoch/outbox/?at=${prev_at}&page=true",
-  "partOf": "https://thebackupbox.net/~epoch/outbox/",
-  "orderedItems":
-EOF
-
-ls -t | grep '^[0-9a-f]' | grep -A "$[${per_page}-1]" -F "${at}" | xargs cat | jq -s
-
-cat <<EOF
-}
-EOF
-
-fi
-
-  exit 0
-fi
-
-## if we got here, they requested / and aren't looking for json, so, graphical display of our outbox :)
-	printf "Content-Type: text/html; charset=utf-8\r\n\r\n"
-	printf "<html><head><title>epoch@thebackupbox.net actpub outbox</title>\n"
-	printf '<link href="/ap-style.css" type="text/css" rel="stylesheet" />'
-	printf "</head><body>\n"
-	if [ "$REMOTE_IDENT" = "$USER" -a ! "$(query_param PUBLIC)" ];then
-		ls -t | while read next_file;do
-			ap-activity2html "${next_file}"
-		done
-	else
-		ls -t | while read next_file;do
-			type="$(jq -r .type < "$next_file")"
-			#echo $type
-			if [ "$type" = "Create" ];then
-				ap-activity2html "${next_file}"
-			fi
-		done
-	fi
-	printf "</body></html>\n"
+if [ "$REQUEST_METHOD" != "GET" ];then
+	logger -p crit "told someone to 403 the fuck off!"
+	printf "Status: 403 Method Not Allowed\r\n"
+	printf "Content-Type: text/plain\r\n\r\n"
+	printf "only allowed to GET to outboxes atm.\n"
 	exit 0
-
 fi
-
-
-## if we got here, PATH_INFO is set. probably requesting a specific activity.
-
-printf "Content-Type: application/activity+json\r\n\r\n"
-cat "../outbox2/${PATH_INFO}"
-
+exec ap-collection.cgi "$@"

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

-- Response ended

-- Page fetched on Sun Jun 2 15:04:50 2024