Project

General

Profile

Broadcast to a specific domain

Steffen Larsen
Added over 4 years ago

Hi guys,

I've been using the groovy script BroadcastToOnline.groovy to broadcast to the online users. This seems to broadcast to every connected user on ALL of my domains.

E.g.

I have these users:

admin@d1.tld

user1@d1.tld

user1@d2.tld

user2@d2.tld

When admin is sending a broadcast (through REST service): every users is getting the message, where I expected only d1 users to have it.

How is it possible to separate the domains when broadcasting?.

I've tried to use the

--domain-filter-policy = OWN

But that did not work. It still ends up on every domain.

I've also tried to alter the message fields "to" in the broadcast script (setting the to field to "d1.tld"), but that didn't help either. Normally the to and from fields are null when using broadcast.

I hope you can help, it really bothers me :-)

PS: I am running 5.2.1 in a cluster (with broadcast script updated to work in cluster)

/Steffen


Replies (10)

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

You need a modified version of the BroadcastToOnline.groovy script. I would suggest to create own command: BroadcastToOnlineForDomain.groovy. The change you need to make is quite simple.

There is a loop, at the end of the script, which goes through userConnections map and sends a message to all online users. You need to add a condition there which checks for which domain the user is connected and then decide whether to send the broadcast to the user or not.

You most likely also need a one extra field in the form to provide domain for which to broadcast message. Alternatively you could take the domain from the "from" address.

Added by Steffen Larsen over 4 years ago

Hi Artur,

That just worked like a charm.

I added on the fromJid (makes the most sense for me)..

if (value.isAuthorized() && value.getJID().getDomain().equals(fromJid)) {
... // send
}

you want a patch to put it into master branch of tigase?

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

Yes, please send us a patch. You can create a new issue with patch submission.

Added by Steffen Larsen over 4 years ago

Cool stuff.

I was thinking about once more.

At the moment I am using the fromJid as the domain to broadcast to, but might it be better (for security reasons) to use p.getStanzaFrom().getDomain() and thereby the admin users domain?

I am just thinking if any are using tigase as a cloud server and have multiple domains for multiple users, then it would be quite nasty to have admins of other domains to be able to send broadcast to your domain.

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

There are 4 use-cases I can think of:

  1. The installation wide admin sends a broadcast to all online users

  2. The installation wide admin sends a broadcast to users in selected domains only

  3. A lower-level admin send a broadcast to 'all' online users, in this case the script should automatically restrict it only to domains for which the admin has 'admin' permissions only

  4. A lower-level admin sends a broadcast to online users in selected domains only - the system should automatically check if the admin has 'admin' permissions for all selected domains.

So, ideally the Groovy script should take into consideration all 4 cases.

Added by Steffen Larsen over 4 years ago

ok super. I'll make the rest of the use cases later and provide you guys with a patch.

Added by Wojciech Kapcia TigaseTeam over 4 years ago

Artur: if I may add my 3 cents while we are on the subject on modifying the script - would it make sense to extend it to also include boolean option "Include offline"?

Added by Steffen Larsen over 4 years ago

Ive already done that. I believe that you guys can have a patch of mine. It includes domain filtering and offline AMP messages.

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

I would prefer to have a separate command/script to send a message to online users and another to offline users. This is, because the code for sending message to offline users has to go through database and can potentially execute for a long time. Also, we can have millions users in DB, so the script sending message to offline users must be implemented very carefully to not blow up the server.

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

Actually, I think, it might be a better option to use PubSub for delivering messages to offline users (or just to all users). Everybody could be subscribed to one particular PubSub node. Once the user comes online, the message would be delivered to him, it would be then more like a MOTD then a broadcast.

    (1-10/10)