Search code examples
xmppejabberd

ejabberd: Manipulate bookmarks with ejabberdctl


I am currently writing shell code that pushes data from LDAP into ejabberd, concerning MUC rooms. The last step I need to do is add some MUC rooms to users' bookmarks so they are auto-joined in their clients. There does not seem to be a module for that like there is in Prosody.

So I assume I need to mnipulate the users' private XML storage, in particular the storage:bookmarks part. I can get all existing bookmarks with:

ejabberdctl private_get user host storage storage:bookmarks

Then, there is ejabberdctl private_set, but I do not really understand it. From what I get, it seems that I need to replace the entire storage element at once, with old and new entries merged together.

Is there another way to add conference sub-elements to the node, or add bookmarks in some other way?

I tried to use private_set, but it seems to break on spaces in the element string. I tried escaping them in all possible ways, but to no avail.


Solution

  • OK, I found out for sure that adding new conferences to bookmarks requires re-uploading the entire bookmark storage set. That means the correct way is using private_get as shown in the question, then modify the XML to add a new entry and then use private_set to re-upload all of it.

    As to the issue with spaces: Erlang shell (that's what ejabberdctl is) needs another level of quoting with single quotes, so some XML would become "'<storage xmlns="storage:bookmarks"><conference jid=…'" and so on in a shell argument.

    You can find a shell script that does this and much more with ejabberdctl here: https://www.teckids.org/gitweb/?p=verein.git;a=blob;f=sysadmin/scripts/teckids-ejmaint