Add scripts to publish ServiceInfo metadata
This commit is contained in:
parent
c1622a265f
commit
ed22cb9147
4
serviceinfo/README.md
Normal file
4
serviceinfo/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# ServiceInfo generator
|
||||
|
||||
ServiceInfo is a JSON format for publishing meta-data about fediverse-related
|
||||
services available on a DNS domain.
|
82
serviceinfo/template-serviceinfo.json
Normal file
82
serviceinfo/template-serviceinfo.json
Normal file
@ -0,0 +1,82 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"id": "https://xmpp.chapril.org/",
|
||||
"name": "Messagerie instantanée Chapril",
|
||||
"classifiers": ["xmpp", "instant-messaging"],
|
||||
"software": {
|
||||
"name": "ejabberd",
|
||||
"version": "__EJABBERD_VERSION__",
|
||||
"repository": "https://github.com/processone/ejabberd/"
|
||||
},
|
||||
"organization": {
|
||||
"name": "Chapril",
|
||||
"contact": "https://www.chapril.org/contact.html"
|
||||
},
|
||||
"protocols": [
|
||||
{
|
||||
"name": "xmpp",
|
||||
"capabilities": [
|
||||
{
|
||||
"presence": true,
|
||||
"mam": true,
|
||||
"in-band-registration": true,
|
||||
"web-registration": false,
|
||||
"storage-quota": "__USER_QUOTA__",
|
||||
"upload-autovaccum": "__UPLOAD_RETENTION__",
|
||||
"irc-gateway": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"otherServices": {
|
||||
"outbound": [
|
||||
"irc"
|
||||
],
|
||||
"inbound": []
|
||||
},
|
||||
"signups": "open",
|
||||
"visibilityPreferences": {
|
||||
"allowCrawling": true,
|
||||
"preferUnlisted": false
|
||||
},
|
||||
"metrics": [
|
||||
{
|
||||
"type": "totalUsers",
|
||||
"value": __TOTAL_USER_ACCOUNTS__
|
||||
},
|
||||
{
|
||||
"type": "activeUsers",
|
||||
"value": __ACTIVE_USER_WEEK__,
|
||||
"periodLength": 604800,
|
||||
"startTime": "__STARTTIME_WEEK__"
|
||||
},
|
||||
{
|
||||
"type": "activeUsers",
|
||||
"value": __ACTIVE_USER_MONTH__,
|
||||
"periodLength": 2592000,
|
||||
"startTime": "__STARTTIME_MONTH__"
|
||||
},
|
||||
{
|
||||
"type": "activeUsers",
|
||||
"value": __ACTIVE_USER_HALFYEAR__,
|
||||
"periodLength": 15552000,
|
||||
"startTime": "__STARTTIME_HALFYEAR__"
|
||||
},
|
||||
{
|
||||
"type": "localMessages",
|
||||
"value": 60640
|
||||
}
|
||||
],
|
||||
"features": [
|
||||
{
|
||||
"name": "Movim",
|
||||
"type": "UI",
|
||||
"description": "Web-based XMPP client"
|
||||
},
|
||||
{
|
||||
"name": "biboumi",
|
||||
"type": "gateway",
|
||||
"description": "XMPP->IRC gateway"
|
||||
}
|
||||
]
|
||||
}
|
78
serviceinfo/update_serviceinfo
Executable file
78
serviceinfo/update_serviceinfo
Executable file
@ -0,0 +1,78 @@
|
||||
#! /bin/bash
|
||||
|
||||
TEMPLATE=/srv/xmpp.chapril.org/tools/serviceinfo/template-serviceinfo.json
|
||||
TARGET_FILE=/srv/serviceinfo.json
|
||||
|
||||
main() {
|
||||
cat "${TEMPLATE}" \
|
||||
| sed "s/__USER_QUOTA__/$(get_hard_quota)/" \
|
||||
| sed "s/__UPLOAD_RETENTION__/1y/" \
|
||||
| sed "s/__TOTAL_USER_ACCOUNTS__/$(count_user_accounts)/" \
|
||||
| sed "s/__EJABBERD_VERSION__/$(get_ejabberd_version)/" \
|
||||
| sed "s/__STARTTIME_WEEK__/$(starttime 7)/" \
|
||||
| sed "s/__STARTTIME_MONTH__/$(starttime 30)/" \
|
||||
| sed "s/__STARTTIME_HALFYEAR__/$(starttime 180)/" \
|
||||
| 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}
|
||||
# | sed "s/__AVG_DISK_USED_PER_USER__/$(TODO)/" \
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
starttime() {
|
||||
days_back=${1:-30}
|
||||
date -u +%Y-%m-%dT%H:%M:%SZ --date="08:42 ${days_back} days ago"
|
||||
}
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user