Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(configuration): reconfigure xmpp servers on a running jigasi from configuration file #547

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions debian/install
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ jigasi.jar usr/share/jigasi
jigasi.sh usr/share/jigasi
script/graceful_shutdown.sh usr/share/jigasi
script/collect-dump-logs.sh usr/share/jigasi
script/reconfigure_xmpp.sh usr/share/jigasi
62 changes: 62 additions & 0 deletions script/reconfigure_xmpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

[ -z "$DRY_RUN" ] && DRY_RUN="false"
# path of file to parse for intended configuration
[ -z "$CONFIG_PATH" ] && CONFIG_PATH="/etc/jitsi/jigasi/sip-communicator.properties"

CC_MUC_BASE_URL="http://localhost:8788/configure/call-control-muc"
CC_MUC_LIST_URL="$CC_MUC_BASE_URL/list"
CC_MUC_ADD_URL="$CC_MUC_BASE_URL/add"
CC_MUC_REMOVE_URL="$CC_MUC_BASE_URL/remove"

CC_MUC_PREFIX="net.java.sip.communicator.impl.protocol.jabber"
ESCAPE_PREFIX="${CC_MUC_PREFIX//\./\\.}"

# get all server ids from the configuration files
CONFIG_SERVER_IDS="$(grep "$CC_MUC_PREFIX.acc" /etc/jitsi/jigasi/sip-communicator.properties \
| cut -d '.' -f 8 \
| grep '=' \
| cut -d '=' -f2)"

[[ "$DRY_RUN" == "true" ]] && echo "Found Server IDs: $CONFIG_SERVER_IDS"

# init processed server ids list
SERVER_IDS="[]"
for SERVER_ID in $CONFIG_SERVER_IDS; do
SERVER_IDS="$(echo "[\"$SERVER_ID\"]" $SERVER_IDS | jq -s add)"
# munge the properties file for this server into json
CONFIG_JSON="$(grep "$CC_MUC_PREFIX.$SERVER_ID\." $CONFIG_PATH \
| grep -v '^#' \
| sed "s/$ESCAPE_PREFIX\.$SERVER_ID\./\"/g" \
| sed 's/=/":"/' \
| sed 's/$/",/')"
# build the json for the configuration call
echo "{$CONFIG_JSON\"id\":\"$SERVER_ID\"}" > /tmp/cc-muc.json
if [ "$DRY_RUN" == "true" ]; then
echo "Would Add MUC: $SERVER_ID"
cat /tmp/cc-muc.json | grep -v 'PASSWORD' | jq
else
echo "Adding MUC: $SERVER_ID"
curl -s -X POST -d @/tmp/cc-muc.json $CC_MUC_ADD_URL
fi
rm /tmp/cc-muc.json
i=$((i+1))
done

MUC_LIST=$(curl -s $CC_MUC_LIST_URL)
# set empty list if no MUCs are found
if [[ $? -gt 0 ]]; then
echo "Failed to get muc list, setting to empty list"
MUC_LIST="[]"
fi

CC_MUC_REMOVE_LIST=$(echo "$MUC_LIST" | jq -r ". - $SERVER_IDS | .[]")

for MUC in $CC_MUC_REMOVE_LIST; do
if [ "$DRY_RUN" == "true" ]; then
echo "Would Remove MUC: $MUC"
else
echo "Removing MUC: $MUC"
curl -s -X POST -d "{\"id\":\"$MUC\"}" $CC_MUC_REMOVE_URL
fi
done
Loading