webfinger context added

This commit is contained in:
James Tomasino 2023-03-27 20:58:31 +00:00
parent ed60e4855d
commit 9248f27290
2 changed files with 106 additions and 0 deletions

45
bin/author-index Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
run_user=$(id -un)
if [ "$run_user" = "root" ] || [ "$run_user" = "publish" ]; then
author_index="/var/www/authors/index.html"
{
printf "<!DOCTYPE html>\\n"
printf "<html lang=\"en\">\\n"
printf " <head>\\n"
printf " <meta charset=utf-8>\\n"
printf " <meta http-equiv=X-UA-Compatible content=\"IE=edge\">\\n"
printf " <meta name=viewport content=\"shrink-to-fit=no,width=device-width,height=device-height,initial-scale=1,user-scalable=1\">\\n"
printf " <title>Cosmic Voyage - Authors</title>\\n"
printf " <link rel=\"stylesheet\" href=\"/styles.css\">\\n"
printf " <link rel=\"canonical\" href=\"https://authors.cosmic.voyage\">\\n"
printf " <meta name=\"description\" content=\"Cosmic Voyage is a public-access unix system and tilde community based around a collaborative science-fiction universe. Users write stories as the people aboard ships, colonies, and outposts, using the only remaining free, interconnected network that unites the dispersed peoples of the stars.\">\\n"
printf " </head>\\n"
printf " <body>\\n"
printf " <div class=\"page-wrapper\">\\n"
printf "<pre class=\"inner-wrapper\">\\n"
printf " _. _ __._ _ * _. . , _ . _. _ _\\n"
printf " (_.(_)_) [ | )|(_. \/ (_)\_|(_](_](/,\\n"
printf " ._| ._|\\n"
printf " , .\\n"
printf " _.. .-+-|_ _ ._ __\\n"
printf " (_](_| | [ )(_)[ _)\\n"
printf "\\n\\n"
} > "${author_index}"
web_paths="/home/*/public_html"
for i in ${web_paths}; do
if [ -d "$i" ]; then
username="$(basename "$(dirname "$i")")"
printf "* <a href=\"/~%s/\">~%s</a>\\n" "${username}" "${username}" >> "${author_index}"
fi
done
{
printf "</pre>\\n"
printf "</body>\\n"
printf "</html>"
} >> "${author_index}"
else
exec sudo -u publish "$0" "$@"
fi

61
bin/webfinger Executable file
View File

@ -0,0 +1,61 @@
#!/bin/sh
die () {
msg="$1"
code="$2"
# exit code defaults to 1
if printf "%s" "$code" | grep -q '^[0-9]+$'; then
code=1
fi
# output message to stdout or stderr based on code
if [ -n "$msg" ]; then
if [ "$code" -eq 0 ]; then
printf "%s\\n" "$msg"
else
printf "%s\\n" "$msg" >&2
fi
fi
exit "$code"
}
yesno () {
old_stty_cfg=$(stty -g)
stty raw -echo
yn=$(while ! head -c 1 | grep -i '[ny]'; do true; done)
stty "$old_stty_cfg"
case $yn in
y ) result=0 ;;
* ) result=1 ;;
esac
return $result
}
printf "This script will attempt to fetch and store your fediverse account webfinger\n"
printf "information. Cosmic is set up to serve that to users who search or mention you\n"
printf "at your cosmic.voyage username. If they send a message to %s@cosmic.voyage\n" "${USER}"
printf "it will properly deliver to your real account.\n\n"
printf "This script only needs to be run once to set up your redirect.\n\n"
printf "What is your fedi address? (format @username@server.com) [Enter to cancel]: \n"
read -r fedi
if [ -z "$fedi" ]; then
die "" 2
else
fediuser=$(printf "%s" "$fedi" | awk '{split($0,a,"@"); print a[2]}')
fediserver=$(printf "%s" "$fedi" | awk '{split($0,a,"@"); print a[3]}')
if [ -z "$fediuser" ]; then
die "Improper address" 2
fi
if [ -z "$fediserver" ]; then
die "Improper address" 2
fi
echo "$fediserver" "$fediuser"
fediwebfinger="$(curl -s "https://${fediserver}/.well-known/webfinger?resource=acct:${fediuser}@${fediserver}")"
printf "Found the following:\n\n%s\n" "$fediwebfinger"
printf "\nDo you want to save it?\n"
if yesno; then
printf "%s" "$fediwebfinger" > "$HOME/.webfinger.json"
printf "SAVED!\n"
else
printf "ABORT!\n"
fi
fi