From 4eb548d8bb98548efb7bcac5a73c5e0fda406c76 Mon Sep 17 00:00:00 2001 From: pitchum Date: Sat, 16 May 2020 18:33:24 +0200 Subject: [PATCH] Add scripts for publishing to https://the-federation.info/ --- nodeinfo2/README.md | 6 +++ nodeinfo2/template-x-nodeinfo2.json | 35 +++++++++++++++ nodeinfo2/update_nodeinfo | 67 +++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 nodeinfo2/README.md create mode 100644 nodeinfo2/template-x-nodeinfo2.json create mode 100755 nodeinfo2/update_nodeinfo diff --git a/nodeinfo2/README.md b/nodeinfo2/README.md new file mode 100644 index 0000000..bfe1b48 --- /dev/null +++ b/nodeinfo2/README.md @@ -0,0 +1,6 @@ +# Nodeinfo2 generator + +Nodeinfo2 is a JSON format for publishing meta-data about fediverse-related +services available on a DNS domain. +Among other things it makes it possible to populate and automatically +update information on https://the-federation.info/ diff --git a/nodeinfo2/template-x-nodeinfo2.json b/nodeinfo2/template-x-nodeinfo2.json new file mode 100644 index 0000000..6b3a0da --- /dev/null +++ b/nodeinfo2/template-x-nodeinfo2.json @@ -0,0 +1,35 @@ +{ + "version": "1.0", + "openRegistrations": true, + "organization": { + "name": "Chapril", + "contact": "https://www.chapril.org/contact.html" + }, + "server": { + "name": "Chapril's XMPP server", + "baseUrl": "https://xmpp.chapril.org/", + "software": "ejabberd", + "version": "__EJABBERD_VERSION__" + }, + "services": { + "outbound": [ + "xmpp" + ], + "inbound": [ + "xmpp" + ] + }, + "protocols": [ + "xmpp" + ], + "usage": { + "users": { + "total": __TOTAL_USER_ACCOUNTS__, + "activeWeek": __ACTIVE_USER_WEEK__, + "activeMonth": __ACTIVE_USER_MONTH__, + "activeHalfyear": __ACTIVE_USER_HALFYEAR__ + }, + "localPosts": __POSTS_COUNT__, + "localComments": 0 + } +} diff --git a/nodeinfo2/update_nodeinfo b/nodeinfo2/update_nodeinfo new file mode 100755 index 0000000..03381d3 --- /dev/null +++ b/nodeinfo2/update_nodeinfo @@ -0,0 +1,67 @@ +#! /bin/bash + +TEMPLATE=/srv/xmpp.chapril.org/tools/nodeinfo2/template-x-nodeinfo2.json +TARGET_FILE=/srv/x-nodeinfo2.json + +main() { + cat "${TEMPLATE}" \ + | sed "s/__TOTAL_USER_ACCOUNTS__/$(count_user_accounts)/" \ + | sed "s/__EJABBERD_VERSION__/$(get_ejabberd_version)/" \ + | sed "s/__ACTIVE_USER_WEEK__/$(user_activity 7)/" \ + | sed "s/__ACTIVE_USER_MONTH__/$(user_activity 30)/" \ + | sed "s/__ACTIVE_USER_HALFYEAR__/$(user_activity 180)/" \ + | sed "s/__POSTS_COUNT__/$(count_archived_messages)/" \ + > ${TARGET_FILE} +} + +get_ejabberd_version() { + dpkg -l ejabberd | grep ejabberd | awk '{print $3}' +} + +count_user_accounts() { + # exclude special accounts like r.giskard (for compliance tester) an bart and lisa for testing. + sudo -u ejabberd ejabberdctl registered_users chapril.org | egrep -v -e 'r\.giskard' -e '(lisa|bart)\.simpson' | wc -l +} + +get_hard_quota() { + grep hard_quota /etc/ejabberd/ejabberd.yml -A2 | grep all | sed -r 's/^\s*-\s([0-9]+).*/\1/' +} + +per_account_storage_usage() { + STORAGE_DIR="/srv/ejabberd/chapril.org/upload/" + # TODO Directories to ignore because they are used for tests accounts (bart and lisa simpsons) + IGNORE_DIRS="35eae3ddc83d72e4d3fad3160a400db688d7d936 9be859c77649f33d207cbe0d74a126b2fd31cb33" + + echo "Per user disk usage:" + tmp="$(du -sh ${STORAGE_DIR}* | sort -hr | awk '{print $1}')" + echo "** Max: "$(echo "${tmp}" | head -n 1) +# echo " Min: "$(echo "${tmp}" | tail -n 1) + + subfolders_count=$(find ${STORAGE_DIR} -mindepth 1 -maxdepth 1 -type d | wc -l) + total_size=$(du -s ${STORAGE_DIR} | awk '{print $1}') + avg=$(((${total_size} / 1024) / ${subfolders_count})) + echo "** Avg: ${avg}M" +} + +user_activity() { + days_back=${1:-30} + sql="select count(distinct username) + from archive + where peer not like 'irc%' + and kind = 'chat' + and created_at > current_timestamp - interval '${days_back} days' + and username not in ('r.giskard', 'lisa.simpson', 'bart.simpson')" + + psql -U ejabberd -h localhost ejabberd -c "${sql}" -t | grep -v '^$' | awk '{print $1}' +} + +count_archived_messages() { + sql="select count(*) + from archive + where peer not like 'irc%' + and username not in ('r.giskard', 'lisa.simpson', 'bart.simpson')" + + psql -U ejabberd -h localhost ejabberd -c "${sql}" -t | grep -v '^$' | awk '{print $1}' +} + +main