Skip to content

Commit

Permalink
Merge pull request #547 from jitsi/reconfigure-jigasi-xmpp
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronkvanmeerten authored Sep 17, 2024
2 parents c313601 + 74fd299 commit d6af757
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
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

0 comments on commit d6af757

Please sign in to comment.