Update useful_functions/.bash_aliases, README.md
Deleted chaprilinfos/README.md, chaprilinfos/template-chaprilinfos.properties, chaprilinfos/update_chaprilinfos, fail2ban/filter.d/xmpp-flooders.conf, fail2ban/jail.d/chapril-xmpp.conf, fail2ban/README.md, metrology/collectd_exec_xmpp.sh, nodeinfo2/README.md, nodeinfo2/template-x-nodeinfo2.json, nodeinfo2/update_nodeinfo, rapport_activite/update_ticket.sh, useful_functions/functions.sh
This commit is contained in:
parent
ffbc11c74c
commit
02d7f670dc
17
README.md
17
README.md
|
@ -1,16 +1,3 @@
|
|||
# XMPP Chapril tools
|
||||
# Outils pour Chalec XMPP
|
||||
|
||||
## Quickstart guide
|
||||
|
||||
mkdir -p /srv/xmpp.chapril.org
|
||||
cd /src/xmpp.chapril.org
|
||||
git clone ssh://gitea@forge.april.org:222/Chapril/xmpp.chapril.org-tools.git tools
|
||||
cd /usr/local/sbin
|
||||
ln -s /srv/xmpp.chapril.org/tools/rapport_activite/rapport_activites.sh
|
||||
ln -s /srv/xmpp.chapril.org/tools/rapport_activite/update_ticket.sh
|
||||
cat /etc/cron.d/update-ticket-rapport-dactivite
|
||||
42 7 1 * * root API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx /usr/local/sbin/update_redmine_ticket
|
||||
|
||||
## LICENSE
|
||||
|
||||
The content of this repository is released under the GNU AGPL3+.
|
||||
Le contenu de ce répertoire est publié sous licence libre GNU AGPL3+.
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
# ChaprilInfos generator
|
||||
|
||||
Cf. https://admin.chapril.org/doku.php?id=admin:services:statoolinfos.chapril.org
|
|
@ -1,52 +0,0 @@
|
|||
# [File]
|
||||
file.class=service
|
||||
file.generator=StatoolInfos
|
||||
file.datetime=__LAST_UPDATE__
|
||||
file.protocol=StatoolInfos-0.3.0
|
||||
|
||||
# [Service]
|
||||
service.name=XMPP Chapril
|
||||
service.description=Service de messagerie instantanée.
|
||||
service.website=https://xmpp.chapril.org/
|
||||
service.logo=https://www.chapril.org/.well-known/chaprilinfos/chapril-logo-mini.png
|
||||
service.legal.url=https://www.chapril.org/cgu.html
|
||||
service.guide.technical=https://admin.chapril.org/doku.php?id=admin:services:xmpp.chapril.org
|
||||
service.guide.user=https://www.chapril.org/XMPP
|
||||
service.contact.url=https://www.chapril.org/contact.html
|
||||
service.contact.email=xmpp-support@chapril.org
|
||||
service.startDate=08/03/2020
|
||||
service.endDate=
|
||||
service.status.level=OK
|
||||
service.status.description=Nominal
|
||||
service.registration=Free
|
||||
service.registration.load=OPEN
|
||||
service.install.type=DISTRIBUTION
|
||||
|
||||
# [Host]
|
||||
host.name=Hetzner
|
||||
host.server.type=VIRTUAL
|
||||
host.provider.type=HOSTEDSERVER
|
||||
host.country.name=Allemagne
|
||||
host.country.code=DE
|
||||
|
||||
# [Software]
|
||||
software.name=ejabberd
|
||||
software.website=https://www.ejabberd.im/
|
||||
software.license.url=https://github.com/processone/ejabberd/blob/master/COPYING
|
||||
software.license.name=GPLv2
|
||||
software.version=__EJABBERD_VERSION__
|
||||
software.source.url=https://github.com/processone/ejabberd/
|
||||
|
||||
# [Metrics]
|
||||
metrics.accounts.total.name = Nombre total de comptes
|
||||
metrics.accounts.total.description = Nombre total de comptes créés
|
||||
metrics.accounts.total.count = __TOTAL_USER_ACCOUNTS__
|
||||
|
||||
metrics.accounts.active.name = Nombre de comptes actifs
|
||||
metrics.accounts.active.description = Nombre de comptes vraiment utilisés récemment
|
||||
metrics.accounts.active.lastyear = __ACTIVE_USER_YEAR__
|
||||
metrics.accounts.active.lastmonth = __ACTIVE_USER_MONTH__
|
||||
metrics.accounts.active.lastweek = __ACTIVE_USER_WEEK__
|
||||
|
||||
subs.metrics-2020=https://xmpp.chapril.org/.well-known/chaprilinfos/xmppchaprilorg-metrics-2020.properties
|
||||
subs.metrics-2021=https://xmpp.chapril.org/.well-known/chaprilinfos/xmppchaprilorg-metrics-2021.properties
|
|
@ -1,82 +0,0 @@
|
|||
#! /bin/bash
|
||||
|
||||
TEMPLATE=/srv/xmpp.chapril.org/tools/chaprilinfos/template-chaprilinfos.properties
|
||||
TARGET_FILE=/srv/chaprilinfos/well-known/xmppchaprilorg.properties
|
||||
|
||||
main() {
|
||||
cat "${TEMPLATE}" \
|
||||
| sed "s/__EJABBERD_VERSION__/$(get_ejabberd_version)/" \
|
||||
| sed "s/__LAST_UPDATE__/$(date -Iminutes)/" \
|
||||
| sed "s/__TOTAL_USER_ACCOUNTS__/$(count_user_accounts)/" \
|
||||
| sed "s/__ACTIVE_USER_WEEK__/$(user_activity 7)/" \
|
||||
| sed "s/__ACTIVE_USER_MONTH__/$(user_activity 30)/" \
|
||||
| sed "s/__ACTIVE_USER_YEAR__/$(user_activity 365)/" \
|
||||
> ${TARGET_FILE}
|
||||
|
||||
# | sed "s/__USER_QUOTA__/$(get_hard_quota)/" \
|
||||
# | sed "s/__UPLOAD_RETENTION__/1y/" \
|
||||
# | 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)/" \
|
||||
# | 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 l.username)
|
||||
from last l
|
||||
where to_timestamp(cast(l.seconds as int)) > 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
|
|
@ -1,29 +0,0 @@
|
|||
# fail2ban rules for XMPP
|
||||
|
||||
fail2ban rules created to mitigate spambots acting since April 2020.
|
||||
Random accounts are created with different IPs (probably zombie machines)
|
||||
and then always the same 3 XMPP accounts (on other XMPP servers) are targeted.
|
||||
The new chapril account ask for presence subscription to those external JIDs
|
||||
and immediately send them random messages without waiting for an answer.
|
||||
|
||||
ejabberd detects the suspicious fast presence subscriptions and logs something
|
||||
easy to capture:
|
||||
|
||||
grep Flooder /var/log/ejabberd/ejabberd.log
|
||||
|
||||
So we use these log warnings to trigger IP ban.
|
||||
|
||||
## Quickstart guide
|
||||
|
||||
```
|
||||
cd /etc/fail2ban/filter.d
|
||||
ln -s /srv/xmpp.chapril.org/tools/fail2ban/filter.d/xmpp-flooders.conf
|
||||
cd /etc/fail2ban/jail.d
|
||||
ln -s /srv/xmpp.chapril.org/tools/fail2ban/jail.d/chapril-xmpp.conf
|
||||
systemctl restart fail2ban
|
||||
```
|
||||
|
||||
Check that the jail is active:
|
||||
|
||||
fail2ban-client status
|
||||
fail2ban-client status xmpp-c2s
|
|
@ -1,10 +0,0 @@
|
|||
[INCLUDES]
|
||||
|
||||
before = common.conf
|
||||
|
||||
[Definition]
|
||||
|
||||
failregex = ^%(__prefix_line)s \[warning\] <[0-9\.]+>@mod_pres_counter:update:[0-9]+ Flooder detected: [a-zA-Z0-9\.@/-]+, on IP: <HOST> ignoring sent presence subscriptions$
|
||||
|
||||
ignoreregex =
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
# :vi ft=dosini
|
||||
[xmpp-c2s]
|
||||
enabled = false
|
||||
filter = xmpp-flooders
|
||||
port = 5222,5223
|
||||
logpath = /var/log/ejabberd/ejabberd.log
|
||||
findtime = 1d
|
||||
maxretry = 1
|
||||
bantime = 2d
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
|
||||
INTERVAL="${COLLECTD_INTERVAL:-60}"
|
||||
|
||||
# required by some ejabberdctl commands
|
||||
export HOME=/var/lib/ejabberd
|
||||
export HTTP_UPLOAD_DATADIR="/var/www/xmpp.chapril.org/upload/"
|
||||
|
||||
|
||||
main() {
|
||||
# do-while hack found here: https://stackoverflow.com/questions/24420342/is-there-a-do-while-loop-in-bash#24421013
|
||||
while
|
||||
ejabberdctl_stats
|
||||
http_upload_disk_usage
|
||||
captcha_stats
|
||||
#client_stats # XXX pas encore activée
|
||||
sleep "$INTERVAL"
|
||||
do true; done
|
||||
}
|
||||
|
||||
ejabberdctl_stats() {
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_registered_users/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl registered_users chapril.org | wc -l)"
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_active_users/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl connected_users_number)"
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_active_distinct_users/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl connected_users | cut -d@ -f1 | sort -u | wc -l)"
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_s2s_in/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl incoming_s2s_number)"
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_s2s_out/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl outgoing_s2s_number)"
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_muc_total/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl muc_online_rooms muc.chapril.org | wc -l)"
|
||||
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_accounts_created_lastday/count\" interval=$INTERVAL $(date +%s):$(_count_accounts_created_lastday)"
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_accounts_created_lasthour/count\" interval=$INTERVAL $(date +%s):$(_count_accounts_created_lasthour)"
|
||||
echo -n "PUTVAL \"${HOSTNAME}/xmpp_public_rooms_occupants/count\" interval=$INTERVAL $(date +%s):" ; _xmpp_public_rooms_total_occupants
|
||||
}
|
||||
|
||||
http_upload_disk_usage() {
|
||||
subfolders_count=$(find ${HTTP_UPLOAD_DATADIR} -mindepth 1 -maxdepth 1 -type d | wc -l)
|
||||
total_size=$(du -s ${HTTP_UPLOAD_DATADIR} | awk '{print $1}')
|
||||
avg=$(( ${total_size} / ${subfolders_count} ))
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_upload_data_total/count\" interval=$INTERVAL $(date +%s):${total_size}"
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_upload_data_avg/count\" interval=$INTERVAL $(date +%s):${avg}"
|
||||
}
|
||||
|
||||
captcha_stats() {
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_captcha_lastday/count\" interval=$INTERVAL $(date +%s):$(find /var/lib/ejabberd/chapril_captchas/ -mindepth 1 -maxdepth 1 -type f -mtime -1 | grep -v EXPERIMENTAL | wc -l)"
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_captcha_lasthour/count\" interval=$INTERVAL $(date +%s):$(find /var/lib/ejabberd/chapril_captchas/ -mindepth 1 -maxdepth 1 -type f -mmin -60 | grep -v EXPERIMENTAL | wc -l)"
|
||||
}
|
||||
|
||||
_count_accounts_created_lastday() {
|
||||
_sql_ejabberd "
|
||||
select count(*)
|
||||
from users
|
||||
where created_at > current_timestamp - interval '1 day'
|
||||
"
|
||||
}
|
||||
_count_accounts_created_lasthour() {
|
||||
_sql_ejabberd "
|
||||
select count(*)
|
||||
from users
|
||||
where created_at > current_timestamp - interval '1 hour'
|
||||
"
|
||||
}
|
||||
|
||||
_xmpp_public_rooms_total_occupants() {
|
||||
# keep results in a cache file for 5 minutes
|
||||
local cache_file=/var/tmp/cache_collectd_xmpp_rooms.data
|
||||
if [ ! -f ${cache_file} -o "$(find ${cache_file} -mmin +5 2>/dev/null)" ]; then
|
||||
_xmpp_list_public_rooms > ${cache_file}
|
||||
fi
|
||||
total_occupants=0
|
||||
while read line; do
|
||||
total_occupants=$((total_occupants+$(echo ${line} | awk '{print $2}')))
|
||||
done < ${cache_file}
|
||||
echo ${total_occupants}
|
||||
}
|
||||
|
||||
_xmpp_list_public_rooms() {
|
||||
for room in $(ejabberdctl muc_online_rooms muc.chapril.org | cut -d@ -f1) ; do
|
||||
if ejabberdctl get_room_options ${room} muc.chapril.org | egrep -q '^public\s*true' ; then
|
||||
echo -n "${room}: "
|
||||
ejabberdctl get_room_occupants ${room} muc.chapril.org | cut -d@ -f1 | sort -u | wc -l
|
||||
fi
|
||||
done | sort -k 2 -nr
|
||||
}
|
||||
|
||||
|
||||
_sql_ejabberd() {
|
||||
# XXX the psql command can only works if file /var/lib/ejabberd/.pgpass exists
|
||||
psql -U ejabberd -h localhost ejabberd -c "${1}" -t | grep -v '^$' | awk '{print $1}'
|
||||
}
|
||||
|
||||
# XXX la syntaxe de la boucle while ci-dessous fait échouer le démarrage de collectd.
|
||||
# exec plugin: exec_read_one: error = /srv/xmpp.chapril.org/tools/metrology/collectd_exec_xmpp.sh: 44: /srv/xmpp.chapril.org/tools/metrology/collectd_exec_xmpp.sh: Syntax error: redirection unexpected
|
||||
#client_stats(){
|
||||
# return 0
|
||||
# # Fonction pas encore activée car je n'aime pas l'idée de créer dans influxdb autant de noms de métriques que de clients XMPP.
|
||||
# # Il faut encore étudier le format d'envoi de collectd.
|
||||
# while read -r line ; do
|
||||
# clientname=$(echo ${line} | awk '{print $2}')
|
||||
# count=$(echo ${line} | awk '{print $1}')
|
||||
# echo "PUTVAL \"${HOSTNAME}/xmpp_client_${clientname}/count\" interval=$INTERVAL $(date +%s):${count}"
|
||||
# done < <(ejabberdctl connected_users | sed -r 's;^.*@chapril.org/([^. -]+).*;\1;' | sort | uniq -c | sort -n)
|
||||
#}
|
||||
|
||||
main
|
|
@ -1,6 +0,0 @@
|
|||
# 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/
|
|
@ -1,35 +0,0 @@
|
|||
{
|
||||
"version": "1.0",
|
||||
"openRegistrations": true,
|
||||
"organization": {
|
||||
"name": "Chapril",
|
||||
"contact": "https://www.chapril.org/contact.html"
|
||||
},
|
||||
"server": {
|
||||
"name": "chapril.org",
|
||||
"baseUrl": "https://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
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
#! /bin/bash
|
||||
|
||||
TEMPLATE=/srv/xmpp.chapril.org/tools/nodeinfo2/template-x-nodeinfo2.json
|
||||
TARGET_FILE=/srv/xmpp.chapril.org/experimental/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 l.username)
|
||||
from last l
|
||||
where to_timestamp(cast(l.seconds as int)) > 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
|
|
@ -1,46 +0,0 @@
|
|||
#! /bin/bash
|
||||
|
||||
REDMINE_BASE_URL="https://agir.april.org"
|
||||
TICKET_ID=4047
|
||||
REPORT_COMMAND="/usr/local/sbin/display_activity_report"
|
||||
|
||||
if [ 'z' = "z${API_KEY}" ]; then
|
||||
echo "Missing environment variable API_KEY" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
main() {
|
||||
post_report
|
||||
}
|
||||
|
||||
post_report() {
|
||||
datafile=$(mktemp /tmp/report_stats_$(date +%Y-%m-%d_%H%M)_XXXX.json)
|
||||
cat <<EOF > "${datafile}"
|
||||
{
|
||||
"issue": {
|
||||
"notes": "$(${REPORT_COMMAND} | sed -z 's/\n/\\n/g')"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
curl -s \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-Redmine-API-Key: ${API_KEY}" \
|
||||
-X PUT --data-binary "@${datafile}" \
|
||||
"${REDMINE_BASE_URL}/issues/${TICKET_ID}.json"
|
||||
rm "${datafile}"
|
||||
}
|
||||
|
||||
# debug function
|
||||
last_comment_date() {
|
||||
curl -H "X-Redmine-API-Key: ${API_KEY}" -s "${REDMINE_BASE_URL}/issues/${TICKET_ID}.json?include=journals" \
|
||||
| jq '.issue.journals | last | .created_on'
|
||||
}
|
||||
|
||||
# debug function
|
||||
list() {
|
||||
curl -H "X-Redmine-API-Key: ${API_KEY}" -s "${REDMINE_BASE_URL}/issues/${TICKET_ID}.json?include=journals" \
|
||||
| jq '.issue.journals[] | [.user.name, .notes]'
|
||||
}
|
||||
|
||||
main
|
|
@ -1,34 +1,34 @@
|
|||
|
||||
xmpp_user_rooms_count() {
|
||||
sudo -u ejabberd ejabberdctl get_user_rooms ${1} chapril.org | wc -l
|
||||
sudo -u ejabberd ejabberdctl get_user_rooms ${1} chalec.org | wc -l
|
||||
}
|
||||
xmpp_user_contacts_count() {
|
||||
sudo -u ejabberd ejabberdctl get_roster ${1} chapril.org | wc -l
|
||||
sudo -u ejabberd ejabberdctl get_roster ${1} chalec.org | wc -l
|
||||
}
|
||||
xmpp_user_info() {
|
||||
echo "${1}:$(xmpp_user_contacts_count ${1}):$(xmpp_user_rooms_count ${1})"
|
||||
}
|
||||
|
||||
xmpp_users() {
|
||||
for user in $(sudo -u ejabberd ejabberdctl registered_users chapril.org); do
|
||||
for user in $(sudo -u ejabberd ejabberdctl registered_users chalec.org); do
|
||||
xmpp_user_info "${user}"
|
||||
done
|
||||
}
|
||||
|
||||
xmpp_ban_user_by_patern() {
|
||||
LIST=$(sudo -u ejabberd ejabberdctl registered_users chapril.org | grep ${1} | uniq)
|
||||
LIST=$(sudo -u ejabberd ejabberdctl registered_users chalec.org | grep ${1} | uniq)
|
||||
|
||||
for ADDRESS in $LIST
|
||||
do
|
||||
sudo -u ejabberd ejabberdctl kick_user $ADDRESS chapril.org
|
||||
sudo -u ejabberd ejabberdctl unregister $ADDRESS chapril.org
|
||||
sudo -u ejabberd ejabberdctl kick_user $ADDRESS chalec.org
|
||||
sudo -u ejabberd ejabberdctl unregister $ADDRESS chalec.org
|
||||
echo Done with $ADDRESS
|
||||
done
|
||||
}
|
||||
|
||||
xmpp_send_server_notice() {
|
||||
sudo -u ejabberd ejabberdctl send_message headline xmpp-admin@chapril.org \
|
||||
chapril.org/announce/online "Annonce du Serveur" "${1}"
|
||||
sudo -u ejabberd ejabberdctl send_message headline xmpp-admin@chalec.org \
|
||||
chalec.org/announce/online "Annonce du Serveur" "${1}"
|
||||
}
|
||||
|
||||
xmpp_send_server_notice_to_connected() {
|
||||
|
@ -36,17 +36,17 @@ xmpp_send_server_notice_to_connected() {
|
|||
|
||||
for ADDRESS in $LIST
|
||||
do
|
||||
sudo -u ejabberd ejabberdctl send_message headline chapril.org "$ADDRESS" "Annonce du Serveur" "${2}"
|
||||
sudo -u ejabberd ejabberdctl send_message headline chalec.org "$ADDRESS" "Annonce du Serveur" "${2}"
|
||||
echo Done with $ADDRESS
|
||||
done
|
||||
}
|
||||
|
||||
xmpp_send_server_notice_by_pattern() {
|
||||
LIST=$(sudo -u ejabberd ejabberdctl registered_users chapril.org | grep ${1} | uniq)
|
||||
LIST=$(sudo -u ejabberd ejabberdctl registered_users chalec.org | grep ${1} | uniq)
|
||||
|
||||
for ADDRESS in $LIST
|
||||
do
|
||||
sudo -u ejabberd ejabberdctl send_message headline chapril.org "$ADDRESS" "Annonce du Serveur" "${2}"
|
||||
sudo -u ejabberd ejabberdctl send_message headline chalec.org "$ADDRESS" "Annonce du Serveur" "${2}"
|
||||
echo Done with $ADDRESS
|
||||
done
|
||||
}
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
|
||||
xmpp_user_rooms_count() {
|
||||
sudo -u ejabberd ejabberdctl get_user_rooms ${1} chapril.org | wc -l
|
||||
}
|
||||
xmpp_user_contacts_count() {
|
||||
sudo -u ejabberd ejabberdctl get_roster ${1} chapril.org | wc -l
|
||||
}
|
||||
xmpp_user_info() {
|
||||
echo "${1}:$(xmpp_user_contacts_count ${1}):$(xmpp_user_rooms_count ${1})"
|
||||
}
|
||||
|
||||
xmpp_users() {
|
||||
for user in $(sudo -u ejabberd ejabberdctl registered_users chapril.org); do
|
||||
xmpp_user_info "${user}"
|
||||
done
|
||||
}
|
||||
|
||||
xmpp_ban_users() {
|
||||
LIST=$(sudo -u ejabberd ejabberdctl registered_users chapril.org | grep ${1} | uniq)
|
||||
|
||||
for ADDRESS in $LIST
|
||||
do
|
||||
sudo -u ejabberd ejabberdctl kick_user $ADDRESS chapril.org
|
||||
sudo -u ejabberd ejabberdctl unregister $ADDRESS chapril.org
|
||||
echo Done with $ADDRESS
|
||||
done
|
||||
}
|
||||
|
||||
xmpp_send_server_notice_all() {
|
||||
sudo -u ejabberd ejabberdctl send_message headline xmpp-admin@chapril.org \
|
||||
chapril.org/announce/online "Annonce du Serveur" "${1}"
|
||||
}
|
||||
|
||||
xmpp_send_server_notice_connected() {
|
||||
LIST=$(sudo -u ejabberd ejabberdctl connected_users_info | cut -f 1 | cut -d "/" -f 1 | uniq)
|
||||
|
||||
for ADDRESS in $LIST
|
||||
do
|
||||
sudo -u ejabberd ejabberdctl send_message headline chapril.org "$ADDRESS" "Annonce du Serveur" "${2}"
|
||||
echo Done with $ADDRESS
|
||||
done
|
||||
}
|
||||
|
||||
xmpp_send_server_notice() {
|
||||
LIST=$(sudo -u ejabberd ejabberdctl registered_users chapril.org | grep ${1} | uniq)
|
||||
|
||||
for ADDRESS in $LIST
|
||||
do
|
||||
sudo -u ejabberd ejabberdctl send_message headline chapril.org "${ADDRESS}@chapril.org" "Annonce du Serveur" "${2}"
|
||||
echo Done with $ADDRESS
|
||||
done
|
||||
}
|
Loading…
Reference in New Issue