jabber_admin 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.editorconfig +30 -0
- data/.gitignore +4 -2
- data/.rubocop.yml +33 -0
- data/.simplecov +3 -0
- data/.travis.yml +7 -3
- data/.yardopts +4 -0
- data/CHANGELOG.md +30 -0
- data/Gemfile +4 -2
- data/Makefile +100 -0
- data/README.md +142 -22
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/docker-compose.yml +15 -0
- data/jabber_admin.gemspec +22 -15
- data/lib/jabber_admin.rb +100 -34
- data/lib/jabber_admin/api_call.rb +106 -20
- data/lib/jabber_admin/commands.rb +6 -5
- data/lib/jabber_admin/commands/ban_account.rb +11 -10
- data/lib/jabber_admin/commands/create_room.rb +15 -10
- data/lib/jabber_admin/commands/create_room_with_opts.rb +20 -14
- data/lib/jabber_admin/commands/muc_register_nick.rb +26 -0
- data/lib/jabber_admin/commands/register.rb +16 -11
- data/lib/jabber_admin/commands/registered_users.rb +8 -6
- data/lib/jabber_admin/commands/restart.rb +8 -5
- data/lib/jabber_admin/commands/send_direct_invitation.rb +19 -16
- data/lib/jabber_admin/commands/send_stanza.rb +12 -10
- data/lib/jabber_admin/commands/send_stanza_c2s.rb +28 -0
- data/lib/jabber_admin/commands/set_nickname.rb +22 -0
- data/lib/jabber_admin/commands/set_presence.rb +37 -0
- data/lib/jabber_admin/commands/set_room_affiliation.rb +17 -12
- data/lib/jabber_admin/commands/subscribe_room.rb +19 -12
- data/lib/jabber_admin/commands/unregister.rb +13 -7
- data/lib/jabber_admin/commands/unsubscribe_room.rb +10 -7
- data/lib/jabber_admin/configuration.rb +6 -1
- data/lib/jabber_admin/exceptions.rb +40 -0
- data/lib/jabber_admin/version.rb +3 -1
- metadata +85 -16
- data/lib/jabber_admin/initializer.rb +0 -6
@@ -2,17 +2,22 @@
|
|
2
2
|
|
3
3
|
module JabberAdmin
|
4
4
|
module Commands
|
5
|
-
|
6
|
-
#
|
7
|
-
# https://
|
5
|
+
# Create a new room (MUC).
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2rB8DFR
|
8
8
|
class CreateRoom
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# *Note:* this command should not be used in the bang-variant, due to raw
|
12
|
+
# result string in the response. (the response body is not zero/one like
|
13
|
+
# on almost all commands)
|
14
|
+
#
|
15
|
+
# @param callable [Proc, #call] the callable to call
|
16
|
+
# @param room [String] room JID (eg. +room1@conference.localhost+)
|
17
|
+
# @param host [String] the jabber host (eg. +localhost+)
|
18
|
+
def self.call(callable, room:, host:)
|
19
|
+
name, service = room.split('@')
|
20
|
+
callable.call('create_room', name: name, service: service, host: host)
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
@@ -2,21 +2,27 @@
|
|
2
2
|
|
3
3
|
module JabberAdmin
|
4
4
|
module Commands
|
5
|
-
|
6
|
-
#
|
7
|
-
# https://
|
5
|
+
# Create a new room (MUC) with additional options.
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2IBEfVO
|
8
8
|
class CreateRoomWithOpts
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @param [
|
12
|
-
# @param
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# @param callable [Proc, #call] the callable to call
|
12
|
+
# @param room [String] room JID (eg. +room1@conference.localhost+)
|
13
|
+
# @param host [String] the jabber host (eg. +localhost+)
|
14
|
+
# @param options pass additional +symbol: value+ pairs
|
15
|
+
def self.call(callable, room:, host:, **options)
|
16
|
+
name, service = room.split('@')
|
17
|
+
options = options.map do |key, value|
|
18
|
+
Hash['name', key.to_s, 'value', value.to_s]
|
19
|
+
end
|
20
|
+
|
21
|
+
callable.call('create_room_with_opts',
|
22
|
+
name: name,
|
23
|
+
service: service,
|
24
|
+
host: host,
|
25
|
+
options: options)
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JabberAdmin
|
4
|
+
module Commands
|
5
|
+
# Register a nick to a user JID in the MUC service of a server.
|
6
|
+
#
|
7
|
+
# *Note*: On ejabberd <= 18.01 this command always returns a error code,
|
8
|
+
# even when the command was successful under the hood. (See:
|
9
|
+
# https://bit.ly/2L1CpvE)
|
10
|
+
#
|
11
|
+
# @see https://bit.ly/2G9EBNQ
|
12
|
+
class MucRegisterNick
|
13
|
+
# Pass the correct data to the given callable.
|
14
|
+
#
|
15
|
+
# @param callable [Proc, #call] the callable to call
|
16
|
+
# @param user [String] user JID wo/ resource (eg. +tom@localhost+)
|
17
|
+
# @param nick [String] the user nickname (eg. +TomTom+)
|
18
|
+
def self.call(callable, user:, nick:)
|
19
|
+
callable.call('muc_register_nick',
|
20
|
+
nick: nick,
|
21
|
+
jid: user,
|
22
|
+
serverhost: user.split('@').last)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -2,18 +2,23 @@
|
|
2
2
|
|
3
3
|
module JabberAdmin
|
4
4
|
module Commands
|
5
|
-
|
6
|
-
#
|
7
|
-
# https://
|
5
|
+
# Register a new user on the XMPP service.
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2wyhAox
|
8
8
|
class Register
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @param [
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
)
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# @param callable [Proc, #call] the callable to call
|
12
|
+
# @param user [String] user JID wo/ resource (eg. +tom@localhost+)
|
13
|
+
# @param password [String] the new plain password for the user
|
14
|
+
# (eg. +secret+)
|
15
|
+
def self.call(callable, user:, password:)
|
16
|
+
uid, host = user.split('@')
|
17
|
+
callable.call('register',
|
18
|
+
check_res_body: false,
|
19
|
+
user: uid,
|
20
|
+
host: host,
|
21
|
+
password: password)
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -2,14 +2,16 @@
|
|
2
2
|
|
3
3
|
module JabberAdmin
|
4
4
|
module Commands
|
5
|
-
|
6
|
-
# List all registered users in HOST
|
5
|
+
# List all registered users on the ejabberd vhost.
|
7
6
|
#
|
8
|
-
# https://
|
7
|
+
# @see https://bit.ly/2KhwT6Z
|
9
8
|
class RegisteredUsers
|
10
|
-
#
|
11
|
-
|
12
|
-
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# @param callable [Proc, #call] the callable to call
|
12
|
+
# @param host [String] the jabber vhost (eg. +localhost+)
|
13
|
+
def self.call(callable, host:)
|
14
|
+
callable.call('registered_users', check_res_body: false, host: host)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -2,12 +2,15 @@
|
|
2
2
|
|
3
3
|
module JabberAdmin
|
4
4
|
module Commands
|
5
|
-
|
6
|
-
#
|
7
|
-
# https://
|
5
|
+
# Restart ejabberd service gracefully.
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2G7YEwd
|
8
8
|
class Restart
|
9
|
-
|
10
|
-
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# @param callable [Proc, #call] the callable to call
|
12
|
+
def self.call(callable)
|
13
|
+
callable.call('restart')
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
@@ -2,23 +2,26 @@
|
|
2
2
|
|
3
3
|
module JabberAdmin
|
4
4
|
module Commands
|
5
|
-
|
6
|
-
#
|
7
|
-
# https://
|
5
|
+
# Send a direct invitation to several destinations.
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2wuTpr2
|
8
8
|
class SendDirectInvitation
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @param [
|
12
|
-
# @param [
|
13
|
-
# @param [
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# @param callable [Proc, #call] the callable to call
|
12
|
+
# @param room [String] room JID (eg. +room1@conference.localhost+)
|
13
|
+
# @param users [Array<String>] user JIDs wo/ resource
|
14
|
+
# (eg. +tom@localhost+)
|
15
|
+
# @param password [String] a optional room password
|
16
|
+
# @param reason [String] the reason for the invitation
|
17
|
+
def self.call(callable, room:, users:, password: '', reason: '')
|
18
|
+
name, service = room.split('@')
|
19
|
+
callable.call('send_direct_invitation',
|
20
|
+
name: name,
|
21
|
+
service: service,
|
22
|
+
password: password,
|
23
|
+
reason: reason,
|
24
|
+
users: users.join(':'))
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
@@ -2,17 +2,19 @@
|
|
2
2
|
|
3
3
|
module JabberAdmin
|
4
4
|
module Commands
|
5
|
-
|
6
|
-
#
|
7
|
-
# https://
|
5
|
+
# Send a stanza; provide From JID and valid To JID.
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2rzxyK1
|
8
8
|
class SendStanza
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @param [
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# @param callable [Proc, #call] the callable to call
|
12
|
+
# @param from [String] user JID wo/ resource (eg. +tom@localhost+)
|
13
|
+
# @param to [String] user/room JID wo/ resource (eg. +bob@localhost+)
|
14
|
+
# @param stanza [String] the XML stanz to send
|
15
|
+
# (eg. <tt><message><ext attr='value'/></message></tt>)
|
16
|
+
def self.call(callable, from:, to:, stanza:)
|
17
|
+
callable.call('send_stanza', from: from, to: to, stanza: stanza)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JabberAdmin
|
4
|
+
module Commands
|
5
|
+
# Send a message (stanza) as if sent from a c2s session.
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2wwUcYr
|
8
|
+
class SendStanzaC2s
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# @param callable [Proc, #call] the callable to call
|
12
|
+
# @param user [String] user JID w/ resource (eg. +tom@localhost/bot+)
|
13
|
+
# @param stanza [String] the XML stanz to send
|
14
|
+
# (eg. <tt><message to='user1@localhost'>
|
15
|
+
# <ext attr='value'/></message></tt>)
|
16
|
+
def self.call(callable, user:, stanza:)
|
17
|
+
uid, host = user.split('@')
|
18
|
+
host, resource = host.split('/')
|
19
|
+
resource ||= 'bot'
|
20
|
+
callable.call('send_stanza_c2s',
|
21
|
+
user: uid,
|
22
|
+
host: host,
|
23
|
+
resource: resource,
|
24
|
+
stanza: stanza)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JabberAdmin
|
4
|
+
module Commands
|
5
|
+
# Set nickname in a user's vCard.
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2rBdyqc
|
8
|
+
class SetNickname
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# @param callable [Proc, #call] the callable to call
|
12
|
+
# @param user [String] user JID wo/ resource (eg. +tom@localhost+)
|
13
|
+
# @param nick [String] the user nickname (eg. +TomTom+)
|
14
|
+
def self.call(callable, user:, nick:)
|
15
|
+
uid, host = user.split('@')
|
16
|
+
callable.call(
|
17
|
+
'set_nickname', user: uid, host: host, nickname: nick
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JabberAdmin
|
4
|
+
module Commands
|
5
|
+
# Send a stanza; provide From JID and valid To JID.
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2rzxyK1
|
8
|
+
class SetPresence
|
9
|
+
# @param callable [Proc, #call] the callable to call
|
10
|
+
# @param user [String] user JID w/ resource (eg. +tom@localhost/bot+)
|
11
|
+
# @param type [String] the presence type
|
12
|
+
# (eg. +available+, +error+, +probe+)
|
13
|
+
# @param show [String] the showed presence
|
14
|
+
# (eg. +away+, +chat+, +dnd+, +xa+)
|
15
|
+
# @param status [String] the user status (eg. +I'm online+)
|
16
|
+
# @param priority [String] presence priority (eg. +7+)
|
17
|
+
#
|
18
|
+
# rubocop:disable Metrics/ParameterLists because of the mapping
|
19
|
+
# rubocop:disable Metrics/MethodLength because of the mapping
|
20
|
+
def self.call(callable, user:, type: 'available', show: 'chat',
|
21
|
+
status: '', priority: '7')
|
22
|
+
uid, host = user.split('@')
|
23
|
+
host, resource = host.split('/')
|
24
|
+
resource ||= 'bot'
|
25
|
+
callable.call('set_presence',
|
26
|
+
user: uid,
|
27
|
+
host: host,
|
28
|
+
resource: resource,
|
29
|
+
type: type,
|
30
|
+
show: show,
|
31
|
+
status: status,
|
32
|
+
priority: priority)
|
33
|
+
end
|
34
|
+
# rubocop:enable Metrics/ParameterLists, Metrics/MethodLength
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -2,19 +2,24 @@
|
|
2
2
|
|
3
3
|
module JabberAdmin
|
4
4
|
module Commands
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
5
|
+
# Change a user affiliation in a MUC room. (eg. allow him to enter a
|
6
|
+
# members-only room)
|
7
|
+
#
|
8
|
+
# @see https://bit.ly/2G5MfbW
|
8
9
|
class SetRoomAffiliation
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @param [
|
12
|
-
# @param [
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
# Pass the correct data to the given callable.
|
11
|
+
#
|
12
|
+
# @param callable [Proc, #call] the callable to call
|
13
|
+
# @param user [String] user JID wo/ resource (eg. +tom@localhost+)
|
14
|
+
# @param room [String] room JID (eg. +room1@conference.localhost+)
|
15
|
+
# @param affiliation [String] the MUC/user affiliation (eg. +member+)
|
16
|
+
def self.call(callable, user:, room:, affiliation: 'member')
|
17
|
+
name, service = room.split('@')
|
18
|
+
callable.call('set_room_affiliation',
|
19
|
+
name: name,
|
20
|
+
service: service,
|
21
|
+
jid: user,
|
22
|
+
affiliation: affiliation)
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -2,19 +2,26 @@
|
|
2
2
|
|
3
3
|
module JabberAdmin
|
4
4
|
module Commands
|
5
|
-
|
6
|
-
#
|
7
|
-
# https://
|
5
|
+
# Subscribe to a MUC conference, via the mucsub feature.
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2Ke7Zoy
|
8
8
|
class SubscribeRoom
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @param [
|
12
|
-
# @param [
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# @param callable [Proc, #call] the callable to call
|
12
|
+
# @param user [String] user JID w/ resource (eg. +tom@localhost/dummy+)
|
13
|
+
# @param nick [String] the user nickname (eg. +TomTom+)
|
14
|
+
# @param room [String] room JID (eg. +room1@conference.localhost+)
|
15
|
+
# @param nodes [Array<String>] nodes comma separated
|
16
|
+
# (eg. +urn:xmpp:mucsub:nodes:messages+,
|
17
|
+
# +urn:xmpp:mucsub:nodes:affiliations+)
|
18
|
+
def self.call(callable, user:, nick:, room:, nodes: [])
|
19
|
+
callable.call('subscribe_room',
|
20
|
+
check_res_body: false,
|
21
|
+
user: user,
|
22
|
+
nick: nick,
|
23
|
+
room: room,
|
24
|
+
nodes: nodes.join(','))
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
@@ -2,14 +2,20 @@
|
|
2
2
|
|
3
3
|
module JabberAdmin
|
4
4
|
module Commands
|
5
|
-
|
6
|
-
#
|
7
|
-
# https://
|
5
|
+
# Unregister (delete) a user from the XMPP service.
|
6
|
+
#
|
7
|
+
# @see https://bit.ly/2wwYnDE
|
8
8
|
class Unregister
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
9
|
+
# Pass the correct data to the given callable.
|
10
|
+
#
|
11
|
+
# @param callable [Proc, #call] the callable to call
|
12
|
+
# @param user [String] user JID wo/ resource (eg. +tom@localhost+)
|
13
|
+
def self.call(callable, user:)
|
14
|
+
uid, host = user.split('@')
|
15
|
+
callable.call('unregister',
|
16
|
+
check_res_body: false,
|
17
|
+
user: uid,
|
18
|
+
host: host)
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|