repo: shorten
action: commit
revision: 
path_from: 
revision_from: 5255e90753e12f941de132589d96e8c13b90273a:
path_to: 
revision_to: 
git.thebackupbox.net
shorten
git clone git://git.thebackupbox.net/shorten
commit 5255e90753e12f941de132589d96e8c13b90273a
Author: epoch 
Date:   Sat Oct 14 01:57:58 2023 +0000

    first

diff --git a/index.cgi b/index.cgi
new file mode 100755
index 0000000000000000000000000000000000000000..5987cdab77ba55b9a5078eec2d7e436e9145f215
--- /dev/null
+++ b/index.cgi
@@ -0,0 +1,116 @@
+#!/bin/bash
+if [ "$QUERY_STRING" ];then
+  case "$SERVER_PROTOCOL" in
+    HTTP*)
+      uri="$(query_param uri)"
+      short="$(shorten "$(uriunescape "${uri}")")"
+      printf "Status: 302 Temporary Redirect\r\n"
+      printf "Location: /%s+\r\n\r\n" "${short}"
+      ;;
+    gemini*)
+      uri="${QUERY_STRING}"
+      short="$(shorten "$(uriunescape "${uri}")")"
+      printf '30 /%s+\r\n' "${short}"
+      ;;
+    *)
+      printf "wtf? gopher?"
+      ;;
+  esac
+  exit 0
+fi
+
+if [ ! "$PATH_INFO" ];then
+  case "$SERVER_PROTOCOL" in
+    HTTP*)
+      printf "Content-Type: text/html\r\n\r\n"
+      printf '***EPHEMERAL*** LINK SHORTENER'
+      printf '\n'
+      printf "\n"
+      printf '
' +cat < +function become_handler() { + navigator.registerProtocolHandler( + "web+share", + "https://epo.k.vu/?uri=%s", + ); +} + +let epo.k.vu become your web+share: handler! +EOF + printf "" + ;; + gemini*) + printf '10 URI to ***EPHEMERALLY*** shorten\r\n' + ;; + *) + printf "wtf? gopher?" + ;; + esac + exit 0 +fi + +if grep '+$' <<< "${PATH_INFO}" 2>&1 >/dev/null;then + slow_your_roll=1 + noob="$(printf '%s\n' "${PATH_INFO}" | cut -d+ -f1)" +else + noob="${PATH_INFO}" +fi + +target="$(cat "/var/cache/shorten/${noob}" 2>/dev/null)" +fucked_with_si="$(head -c12 /dev/urandom | enb64url)" +target="$(printf "%s" "$target" | sed 's/si=[A-Za-z0-9_-]*/si='"${fucked_with_si}"'/')" + +if [ "$target" ];then + if [ "$slow_your_roll" ];then + case "$SERVER_PROTOCOL" in + HTTP*) + printf "Status: 200\r\nContent-Type: text/html\r\n\r\n" + printf 'shortened link for: %s\n' + printf 'shortened link https://epo.k.vu%s goes to ' "${noob}" "${noob}" + printf '%s
' "${target}" "${target}" + printf '
the above QR code goes to https://epo.k.vu%s
' "${noob}" "${noob}" + printf '
the above QR code goes to https://epo.k.vu%s+ (this page)' "${noob}" "${noob}" + ;; + gemini*) + printf "20 text/gemini\r\n" + printf "# shortened link for: %s\r\n" "${target}" + printf "=> %s\r\n" "${target}" + printf "=> /qr.cgi?gemini://epo.k.vu%s QR code to gemini://epo.k.vu%s" "${noob}" "${noob}" + printf "=> /qr.cgi?gemini://epo.k.vu%s+ QR code to gemini://epo.k.vu%s+ (this page)" "${noob}" "${noob}" + ;; + *) + printf "wtf? gopher?\n" + ;; + esac + exit 0 + fi + case "$SERVER_PROTOCOL" in + HTTP*) + printf "Status: 302 Temporary Redirect\r\nLocation: %s\r\nContent-Type: text/plain\r\n\r\n" "$target" + printf "%s\n" "$target" + ;; + gemini*) + printf "30 %s\r\n" "${target}" + ;; + *) + printf "wtf? gopher?\n" + ;; + esac + exit 0 +fi + +case "$SERVER_PROTOCOL" in + HTTP*) + printf "HTTP/1.1 404 OK\r\nContent-type: text/html\r\n\r\n" + printf "shortened link not found." + cat index.html + ;; + gemini*) + printf "20 text/plain\r\n" + printf "this redirect does not exist anymore. or never existed. I dunno.\n" + ;; + *) + printf "wtf? gopher?\n" + ;; +esac diff --git a/qr.cgi b/qr.cgi new file mode 100755 index 0000000000000000000000000000000000000000..01042e37f3a4f78c38414337ddb1d8a7f15eec81 --- /dev/null +++ b/qr.cgi @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + + +#printf "Content-Type: images/svg+xml\r\n\r\n" +#printf "Content-Type: text/html\r\n\r\n" +case "${SERVER_PROTOCOL}" in +HTTP*) + uri="$(uriunescape "$(query_param uri)")" + printf "Content-Type: image/png\r\n\r\n" + ;; +gemini*) + uri="$(uriunescape "${QUERY_STRING}")" + printf "20 image/png\r\n" + ;; +*) + printf "wtf? gopher?\n" + exit 0 + ;; +esac + +qr --optimize=0 --factory=pil "$uri" diff --git a/share.xml b/share.xml new file mode 100644 index 0000000000000000000000000000000000000000..589959cd40f1c9d5be1b6bdc86d1b3daa078a5f6 --- /dev/null +++ b/share.xml @@ -0,0 +1,15 @@ + + epo.k.vu link shorten + epo.k.vu link shorten + UTF-8 + https://epo.k.vu/favicon.ico + + + + + + https://epo.k.vu/ + diff --git a/upload/index.cgi b/upload/index.cgi new file mode 100755 index 0000000000000000000000000000000000000000..0d3d3e23fcf4ba1fa52072fb91a3652dbd2a9b32 --- /dev/null +++ b/upload/index.cgi @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +export boundary="$(printf "%s\n" "${HTTP_CONTENT_TYPE}" \ + | tr ';' '\n' \ + | sed 's/^ *//g;s/ *$//g' \ + | grep ^boundary= \ + | cut -d= -f2-)" + +if [ "$REQUEST_METHOD" = "POST" ];then + TMPFILE="$(mktemp -p /var/cache/upload/ XXXXXXXX)" + stdbuf -o0 -i0 head -c "${CONTENT_LENGTH}" 2>/dev/null \ + | XuntilY "$boundary" "$boundary" \ + | tac \ + | tail -n+2 \ + | tac \ + | /usr/local/libexec/read_headers `which cat` \ + > "$TMPFILE" + HASH="$(md5sum "$TMPFILE" | cut '-d ' -f1)" + mv "$TMPFILE" "/var/www/sites/shorten/uploads/$HASH" + chmod 644 "/var/www/sites/shorten/uploads/$HASH" + TMPURL="$(basename "$TMPFILE")" + SHORT="$(shorten "/uploads/${HASH}")" + printf "Status: 301 Found\r\n" + printf "Location: /%s+\r\n\r\n" "$SHORT" + exit 0 +fi + +printf "Content-Type: text/html\r\n\r\n" +cat < + + upload to epoch's computer + + + +
+ + +
+ + +EOF diff --git a/uploads/index.html b/uploads/index.html new file mode 100644 index 0000000000000000000000000000000000000000..9795c0a2da838b701242142e8176c2f008726053 --- /dev/null +++ b/uploads/index.html @@ -0,0 +1 @@ +no file list for you. :)

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