How do I get a list of all online users in ejabberd/XMPP?

試著忘記壹切 提交于 2019-12-06 04:57:07

问题


How do I get a list of all users online in XMPP assuming that I'm an admin and XEP-133 does not work and I'm not in their roster?


回答1:


Most commands in XEP-133 do work fine with ejabberd.

You are indeed right about some particular commands not working including getting the online-users: I discovered though there are non-standard alternatives specific to ejabberd:

If you run a disco#items on the host you get some interesting items you can query:

<iq to="localhost" type="get" id="123">
    <query xmlns='http://jabber.org/protocol/disco#items' />
</iq>


<iq from="localhost" type="result" to="admin@localhost/jarnas" id="123">
    <query xmlns="http://jabber.org/protocol/disco#items">
        <item jid="conference.localhost" />
        <item jid="pubsub.localhost" />
        <item jid="riot.localhost" />
        <item jid="vjud.localhost" />
        <item node="announce" name="Announcements" jid="localhost" />
        <item node="config" name="Configuration" jid="localhost" />
        <item node="user" name="User Management" jid="localhost" />
        <item node="online users" name="Online Users" jid="localhost" />
        <item node="all users" name="All Users" jid="localhost" />
        <item node="outgoing s2s" name="Outgoing s2s Connections" jid="localhost" />
        <item node="running nodes" name="Running Nodes" jid="localhost" />
        <item node="stopped nodes" name="Stopped Nodes" jid="localhost" />
    </query>
</iq>

Now in you case you need the "Online Users" so:

<iq to="localhost" type="get" id="234">
    <query xmlns='http://jabber.org/protocol/disco#items' node="online users"/>
</iq>

<iq from="localhost" type="result" to="admin@localhost/jarnas" id="234" >
    <query xmlns="http://jabber.org/protocol/disco#items" node="online users" >
        <item name="admin@localhost" jid="admin@localhost/auto-CdB67NUOie" />
        <item name="admin@localhost" jid="admin@localhost/jarnas" />
    </query>
</iq>

will work like a charm ;)



来源:https://stackoverflow.com/questions/9610091/how-do-i-get-a-list-of-all-online-users-in-ejabberd-xmpp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!