commit e1820e27df20e7f904e72dcb72d82a21bdc84f02 Author: tastytea Date: Sun Jun 23 22:05:07 2019 +0200 Added instanceinfo.sh diff --git a/instanceinfo.sh b/instanceinfo.sh new file mode 100755 index 0000000..3c46b94 --- /dev/null +++ b/instanceinfo.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +if [ -z "${1}" ]; then + echo "usage: ${0} DOMAIN" >&2 + exit 1 +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 -E 's/<[^>]+>//g' | sed 's/\\r\\n/ /g' +} + +function main() +{ + local instance="${1}" + local nodeinfo="https://${instance}/nodeinfo/2.0.json" + local mastoinfo="https://${instance}/api/v1/instance" + + if curl -sIf "${nodeinfo}" | grep -q '200 OK'; 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: " + pretty $(grep -Eo '"staffAccounts":\[[^]]+\]' <<<"${json}") + + echo -n "Number of users: " + grep -Eo '"total":[0-9]+' <<<"${json}" | cut -d: -f2 + + echo "Blocked instances: " + 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}" > /dev/null; then + echo "Mastodon API found." + json="$(curl -s ${mastoinfo})" + local implementation="" + + if grep -q '"is_pro"' <<<"${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: " + striphtml $(grep -Eo '"description":"[^,]+",' <<<"${json}") | cut -d: -f2,3,4,5,6,7,8,9 + + local admin=$(grep -Eo '"acct":"[^"]+"' <<<"${json}" | cut -d: -f2 | sed 's/"//g')"@${instance}" + [[ -n "${admin}" ]] && echo "Admin: @${admin}" + + 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}"