fediverse-scripts/instanceinfo.sh

127 lines
4.5 KiB
Bash
Executable File

#!/bin/bash
# Print some basic info about fediverse instances.
# Version: 2019-06-24_4
if [[ -z "${1}" ]]; then
echo "usage: ${0} DOMAIN" >&2
exit 1
fi
if ! command -v jq > /dev/null; then
echo "You need to install jq (https://stedolan.github.com/jq/)" >&2
exit 2
fi
function pretty()
{
local extract="${*}"
if command -v json_pp > /dev/null; then
echo "{${extract}}" | json_pp
else
echo "${extract}"
fi
}
function striphtml()
{
local extract="${*}"
echo "${extract}" | sed 's/\\u003c/</g' | sed 's/\\u003e/>/g' | sed -E 's/<[^>]+>//g' | sed 's/\\r\\n/ /g'
}
function main()
{
local instance="${1}"
# shellcheck disable=SC2155
local nodeinfo=$(curl -s "https://${instance}/.well-known/nodeinfo" | jq -r '.links[-1].href' 2> /dev/null)
local mastoinfo="https://${instance}/api/v1/instance"
local misskeyinfo="https://${instance}/api/meta"
if curl -sIf -X POST "${misskeyinfo}" | grep -iq 'Content-Type: application/json'; then
echo "Misskey API found."
json=$(curl -s -X POST "${misskeyinfo}")
# shellcheck disable=SC2155
local email=$(grep -Eo '"maintainerEmail":"[^"]+"' <<<"${json}" | cut -d: -f2 | sed 's/"//g')
[[ -n "${email}" ]] && echo "E-Mail: ${email}"
# shellcheck disable=SC2155
local users=$(curl -s -X POST "https://${instance}/api/stats" | grep -Eo '"usersCount":[0-9]+' | cut -d: -f2)
[[ -n ${users} ]] && echo "Number of users: ${users}"
# NOTE: I'm not sure what the returned data means exactly and I couldn't find the API-documentation. So I commented it out for now.
# # shellcheck disable=SC2155
# local federation=$(curl -s -X POST "https://${instance}/api/federation/instances" | grep -Eo '"host":"[^"]+",' | sed 's/"host"://g')
# # shellcheck disable=SC2046
# [[ -n ${federation} ]] && echo -n "Federates with: " && pretty '"":['"${federation}"'""]'
# shellcheck disable=SC2155
local tos=$(grep -Eo '"ToSUrl":"[^"]+"' <<<"${json}" | cut -d: -f2,3 | sed 's/"//g')
[[ -n "${tos}" ]] && echo "ToS: ${tos}"
elif curl -sIf "${nodeinfo}" | grep -iq 'Content-Type: application/json'; then
echo "Nodeinfo found."
json=$(curl -s "${nodeinfo}")
local implementation=""
if grep -q pleroma <<<"${json}"; then
implementation="Pleroma"
fi
[[ -n "${implementation}" ]] && echo "${implementation} detected."
echo -n "Description: "
grep -Eo '"nodeDescription":"[^"]+"' <<<"${json}" | cut -d: -f2
echo "Admins: "
# shellcheck disable=SC2046
pretty $(grep -Eo '"staffAccounts":\[[^]]+\]' <<<"${json}")
echo -n "Number of users: "
grep -Eo '"total":[0-9]+' <<<"${json}" | cut -d: -f2
echo "Blocked instances: "
# shellcheck disable=SC2046
pretty $(grep -Eo '"reject":\[[^]]+\]' <<<"${json}" | head -n1)
if [[ "${implementation}" == "Pleroma" ]]; then
echo "Further info, maybe: https://${instance}/static/terms-of-service.html"
fi
elif curl -sIf "${mastoinfo}" | grep -iq 'Content-Type: application/json'; then
echo "Mastodon API found."
json=$(curl -s "${mastoinfo}")
local implementation=""
if grep -Eq '"is_(pro|verified)"' <<<"${json}"; then
implementation="Gab"
elif grep -Eq '"version":"[0-9]+\.[0-9]+\.[0-9]+"' <<<"${json}"; then
implementation="Mastodon"
fi
[[ -n "${implementation}" ]] && echo "${implementation} detected."
echo -n "Description: "
# shellcheck disable=SC2046
striphtml $(grep -Eo '"description":"[^,]+",' <<<"${json}") | cut -d: -f2,3,4,5,6,7,8,9
# shellcheck disable=SC2155
local admin=$(grep -Eo '"acct":"[^"]+"' <<<"${json}" | cut -d: -f2 | sed 's/"//g')
[[ -n "${admin}" ]] && echo "Admin: https://${instance}/users/${admin}"
# shellcheck disable=SC2155
local email=$(grep -Eo '"email":"[^"]+"' <<<"${json}" | cut -d: -f2)
[[ -n "${email}" ]] && echo "E-Mail: ${email}"
echo -n "Number of users: "
grep -Eo '"user_count":[0-9]+' <<<"${json}" | cut -d: -f2
if [[ "${implementation}" == "Mastodon" ]]; then
echo "Further info, maybe: https://${instance}/about/more"
fi
else
echo "Could not detect type of server."
curl -I "https://${instance}/"
fi
echo "See also: https://fediverse.network/${instance}"
}
main "${1}"