social_stream-presence 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
@@ -34,36 +34,56 @@ end
|
|
34
34
|
$domain = getOption("server_domain=")
|
35
35
|
|
36
36
|
PARAMS_FOR_COMMANDS = {
|
37
|
-
'
|
38
|
-
'removeBuddyFromRoster' => 2,
|
39
|
-
'
|
40
|
-
'
|
41
|
-
'
|
42
|
-
'
|
43
|
-
'
|
44
|
-
'
|
45
|
-
'
|
46
|
-
'
|
47
|
-
'
|
48
|
-
'
|
49
|
-
'
|
37
|
+
'addBuddyToRoster' => 5,
|
38
|
+
'removeBuddyFromRoster' => 2,
|
39
|
+
'setBidireccionalBuddys' => 6,
|
40
|
+
'unsetBidireccionalBuddys' => 4,
|
41
|
+
'getRoster' => 1,
|
42
|
+
'removeRoster' => 1,
|
43
|
+
'removeAllRosters' => 0,
|
44
|
+
'getBuddysFromRoster' => 1,
|
45
|
+
'getAllUsersWithRoster' => 0,
|
46
|
+
'getAllRosters' => 0,
|
47
|
+
'printAllRosters' => 0,
|
48
|
+
'printAllBidirecctionalBuddys' => 0,
|
49
|
+
'checkUser' => 1,
|
50
|
+
'checkBidirecctionalBuddys' => 2,
|
51
|
+
'sendPresence' => 2,
|
52
|
+
'setPresence' => 1,
|
53
|
+
'unsetPresence' => 1,
|
54
|
+
'sendMessageToUser' => 3,
|
55
|
+
'getUserResource' => 1,
|
56
|
+
'isEjabberdNodeStarted' => 0,
|
57
|
+
'help' => 0,
|
50
58
|
}
|
51
59
|
|
52
60
|
SYNTAX_FOR_COMMANDS = {
|
53
|
-
'
|
54
|
-
'removeBuddyFromRoster' =>
|
55
|
-
'
|
56
|
-
'
|
57
|
-
'
|
58
|
-
'
|
59
|
-
'
|
60
|
-
'
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'
|
64
|
-
'
|
61
|
+
'addBuddyToRoster' => 'addBuddyToRoster userSid buddySid buddyNick buddyGroup subscription_type',
|
62
|
+
'removeBuddyFromRoster' => 'removeBuddyFromRoster userSid buddySid',
|
63
|
+
'setBidireccionalBuddys' => 'setBidireccionalBuddys userASid userBSid userANick userBNick groupForA groupForB',
|
64
|
+
'unsetBidireccionalBuddys' => 'unsetBidireccionalBuddys userSid oldFriendSid oldFriendNick groupForOldFriend',
|
65
|
+
'getRoster' => 'getRoster username',
|
66
|
+
'removeRoster' => 'removeRoster username',
|
67
|
+
'removeAllRosters' => 'removeAllRosters',
|
68
|
+
'getBuddysFromRoster' => 'getBuddysFromRoster roster',
|
69
|
+
'getAllUsersWithRoster' => 'getAllUsersWithRoster',
|
70
|
+
'getAllRosters' => 'getAllRosters',
|
71
|
+
'printAllRosters' => 'printAllRosters',
|
72
|
+
'printAllBidirecctionalBuddys' => 'printAllBidirecctionalBuddys',
|
73
|
+
'checkUser' => 'checkUser user',
|
74
|
+
'checkBidirecctionalBuddys' => 'checkBidirecctionalBuddys userASid userBSid',
|
75
|
+
'sendPresence' => 'sendPresence username show',
|
76
|
+
'setPresence' => 'setPresence username',
|
77
|
+
'unsetPresence' => 'unsetPresence username',
|
78
|
+
'sendMessageToUser' => 'sendMessageToUser from_name to_name msg',
|
79
|
+
'getUserResource' => 'getUserResource username',
|
80
|
+
'isEjabberdNodeStarted' => 'isEjabberdNodeStarted',
|
81
|
+
'help' => 'help',
|
65
82
|
}
|
66
83
|
|
84
|
+
|
85
|
+
|
86
|
+
#Debug methods
|
67
87
|
def log(msg)
|
68
88
|
logWithTitle(msg,nil)
|
69
89
|
end
|
@@ -78,29 +98,60 @@ def logWithTitle(msg,title)
|
|
78
98
|
end
|
79
99
|
|
80
100
|
|
81
|
-
|
82
|
-
|
83
|
-
|
101
|
+
|
102
|
+
#Methods to manage rosters from Social Stream Rails App
|
103
|
+
|
104
|
+
def setBidireccionalBuddys(userASid,userBSid,userANick,userBNick,groupForA,groupForB)
|
105
|
+
addBuddyToRoster(userASid,userBSid,userBNick,groupForB,"both")
|
106
|
+
addBuddyToRoster(userBSid,userASid,userANick,groupForA,"both")
|
107
|
+
return "Done"
|
108
|
+
end
|
109
|
+
|
110
|
+
def unsetBidireccionalBuddys(userSid,oldFriendSid,oldFriendNick,groupForOldFriend)
|
111
|
+
if checkBidirecctionalBuddys(userSid,oldFriendSid)
|
112
|
+
removeBuddyFromRoster(userSid,oldFriendSid)
|
113
|
+
removeBuddyFromRoster(oldFriendSid,userSid)
|
114
|
+
addBuddyToRoster(userSid,oldFriendSid,oldFriendNick,groupForOldFriend,"to")
|
115
|
+
return "Done"
|
116
|
+
else
|
117
|
+
return userSid + " and " + oldFriendSid + " aren't bidireccional buddys"
|
118
|
+
end
|
84
119
|
end
|
85
120
|
|
86
|
-
def
|
87
|
-
|
121
|
+
def addBuddyToRoster(userSid,buddySid,buddyNick,buddyGroup,subscription_type)
|
122
|
+
user = userSid.split("@")[0]
|
123
|
+
buddy = buddySid.split("@")[0]
|
124
|
+
userDomain = userSid.split("@")[1]
|
125
|
+
buddyDomain = buddySid.split("@")[1]
|
126
|
+
command = "ejabberdctl add-rosteritem " + user + " " + userDomain + " " + buddy + " " + buddyDomain + " " + buddyNick + " " + buddyGroup + " " + subscription_type
|
88
127
|
%x[#{command}];
|
128
|
+
return "Done"
|
89
129
|
end
|
90
130
|
|
91
|
-
def
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
131
|
+
def removeBuddyFromRoster(userSid,buddySid)
|
132
|
+
user = userSid.split("@")[0]
|
133
|
+
buddy = buddySid.split("@")[0]
|
134
|
+
userDomain = userSid.split("@")[1]
|
135
|
+
buddyDomain = buddySid.split("@")[1]
|
136
|
+
if checkUserInRoster(buddy,getRoster(user))
|
137
|
+
command = "ejabberdctl delete_rosteritem " + user + " " + userDomain + " " + buddy + " " + buddyDomain
|
138
|
+
%x[#{command}];
|
139
|
+
return "Done"
|
140
|
+
else
|
141
|
+
return "User " + buddy + " not found in " + user + " roster."
|
96
142
|
end
|
97
|
-
return "Done"
|
98
143
|
end
|
99
144
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
145
|
+
|
146
|
+
#Roster Utilities
|
147
|
+
|
148
|
+
def getRoster(username)
|
149
|
+
if checkUser(username)
|
150
|
+
command = "ejabberdctl get_roster " + username + " " + $domain
|
151
|
+
%x[#{command}];
|
152
|
+
else
|
153
|
+
return "User " + username + " not found"
|
154
|
+
end
|
104
155
|
end
|
105
156
|
|
106
157
|
def getBuddysFromRoster(roster)
|
@@ -112,22 +163,126 @@ def getBuddysFromRoster(roster)
|
|
112
163
|
buddys
|
113
164
|
end
|
114
165
|
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
-
|
166
|
+
def removeRoster(username)
|
167
|
+
if checkUser(username)
|
168
|
+
user_sid = username + "@" + $domain
|
169
|
+
user_roster = getRoster(username);
|
170
|
+
user_buddys = getBuddysFromRoster(user_roster);
|
171
|
+
user_buddys.each do |buddy|
|
172
|
+
buddy_sid = buddy + "@" + $domain
|
173
|
+
removeBuddyFromRoster(user_sid,buddy_sid)
|
174
|
+
end
|
175
|
+
return "Done"
|
176
|
+
else
|
177
|
+
return "User " + username + " not found"
|
178
|
+
end
|
119
179
|
end
|
120
180
|
|
121
|
-
def
|
122
|
-
|
123
|
-
buddy = buddySid.split("@")[0]
|
124
|
-
userDomain = userSid.split("@")[1]
|
125
|
-
buddyDomain = buddySid.split("@")[1]
|
126
|
-
command = "ejabberdctl add-rosteritem " + user + " " + userDomain + " " + buddy + " " + buddyDomain + " " + buddyNick + " " + buddyGroup + " " + subscription_type
|
127
|
-
puts command
|
181
|
+
def removeAllRosters()
|
182
|
+
command = "ejabberdctl process_rosteritems delete any any any any"
|
128
183
|
%x[#{command}];
|
184
|
+
return "Done";
|
129
185
|
end
|
130
186
|
|
187
|
+
def getAllUsersWithRoster()
|
188
|
+
command = "ejabberdctl process_rosteritems list any any any any"
|
189
|
+
output = %x[#{command}];
|
190
|
+
|
191
|
+
i = 0
|
192
|
+
users = []
|
193
|
+
|
194
|
+
lines = output.split("\n");
|
195
|
+
items = lines[0].split(" ")[2]
|
196
|
+
|
197
|
+
#test if items string contains a correct number
|
198
|
+
if items.to_i.to_s == items
|
199
|
+
if items.to_i > 0
|
200
|
+
lines.each do |line|
|
201
|
+
if i%2==1
|
202
|
+
user = line.split(" ")[1].split("@")[0]
|
203
|
+
#puts i.to_s() + " :" + line
|
204
|
+
unless users.include?(user)
|
205
|
+
users << user
|
206
|
+
end
|
207
|
+
end
|
208
|
+
i=i+1
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
return users;
|
214
|
+
end
|
215
|
+
|
216
|
+
def getAllRosters()
|
217
|
+
rosterList = { }
|
218
|
+
|
219
|
+
users = getAllUsersWithRoster()
|
220
|
+
|
221
|
+
users.each do |user|
|
222
|
+
roster = getRoster(user)
|
223
|
+
rosterList.store(user,roster)
|
224
|
+
end
|
225
|
+
return rosterList
|
226
|
+
end
|
227
|
+
|
228
|
+
def printAllRosters()
|
229
|
+
rosterList = getAllRosters()
|
230
|
+
rosterList.keys.each do |user|
|
231
|
+
puts "\n"
|
232
|
+
puts "-------------------------------------"
|
233
|
+
puts user + " Roster"
|
234
|
+
puts "-------------------------------------"
|
235
|
+
puts rosterList[user]
|
236
|
+
puts "-------------------------------------"
|
237
|
+
puts "\n"
|
238
|
+
end
|
239
|
+
return "Done"
|
240
|
+
end
|
241
|
+
|
242
|
+
def getAllBidirecctionalBuddys()
|
243
|
+
b_buddys = []
|
244
|
+
users = getAllUsersWithRoster()
|
245
|
+
nonCheckedUsers = users
|
246
|
+
users.each do |user|
|
247
|
+
nonCheckedUsers.delete(user)
|
248
|
+
nonCheckedUsers.each do |checkUser|
|
249
|
+
if checkBidirecctionalBuddys(user + "@" + $domain,checkUser + "@" + $domain)
|
250
|
+
b_buddys << [user,checkUser]
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
return b_buddys
|
255
|
+
end
|
256
|
+
|
257
|
+
def printAllBidirecctionalBuddys()
|
258
|
+
puts "This may take a while..."
|
259
|
+
b_buddys = getAllBidirecctionalBuddys
|
260
|
+
b_buddys.each do |contact|
|
261
|
+
puts "[" + contact[0] + "," + contact[1] + "]"
|
262
|
+
end
|
263
|
+
return "Done"
|
264
|
+
end
|
265
|
+
|
266
|
+
#Check if the user have a roster
|
267
|
+
def checkUser(user)
|
268
|
+
return getAllUsersWithRoster().include?(user)
|
269
|
+
end
|
270
|
+
|
271
|
+
def checkUserInRoster(user,roster)
|
272
|
+
return getBuddysFromRoster(roster).include?(user)
|
273
|
+
end
|
274
|
+
|
275
|
+
def checkBidirecctionalBuddys(userASid,userBSid)
|
276
|
+
userA = userASid.split("@")[0]
|
277
|
+
userB = userBSid.split("@")[0]
|
278
|
+
rosterA = getRoster(userA)
|
279
|
+
rosterB = getRoster(userB)
|
280
|
+
return (checkUserInRoster(userA,rosterB) and checkUserInRoster(userB,rosterA))
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
#Manage stanzas Utilities
|
285
|
+
|
131
286
|
def sendStanzaUserMessage(username,msg)
|
132
287
|
resource = getUserResource(username);
|
133
288
|
stanza = "\\<\\'message\\'\\>\\<\\'body\\'\\>\\'" + msg + "\\'\\<\\'/body\\'\\>\\<\\'/message\\'\\>"
|
@@ -137,17 +292,16 @@ def sendStanzaUserMessage(username,msg)
|
|
137
292
|
return "Done"
|
138
293
|
end
|
139
294
|
|
140
|
-
|
141
|
-
|
142
|
-
sendPresenceWithShow(username,username,show)
|
295
|
+
def setPresence(username)
|
296
|
+
sendPresenceStanzaWithType(username,username,"available")
|
143
297
|
end
|
144
298
|
|
145
299
|
def unsetPresence(username)
|
146
300
|
sendPresenceStanzaWithType(username,username,"unavailable")
|
147
301
|
end
|
148
302
|
|
149
|
-
def
|
150
|
-
|
303
|
+
def sendPresence(username,show)
|
304
|
+
sendPresenceWithShow(username,username,show)
|
151
305
|
end
|
152
306
|
|
153
307
|
def sendPresenceWithShow(from_name,to_name,show)
|
@@ -198,6 +352,22 @@ def getUserResource(username)
|
|
198
352
|
return username + " no have any active session"
|
199
353
|
end
|
200
354
|
|
355
|
+
|
356
|
+
#More utilities
|
357
|
+
|
358
|
+
def isEjabberdNodeStarted
|
359
|
+
command = "ejabberdctl status"
|
360
|
+
output = %x[#{command}]
|
361
|
+
if firstLine = output.split("\n")[0]
|
362
|
+
return ((firstLine.split(":")[1]).strip()=="started")
|
363
|
+
end
|
364
|
+
return false
|
365
|
+
end
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
#Help & Support methods
|
370
|
+
|
201
371
|
def help
|
202
372
|
log("Command list")
|
203
373
|
SYNTAX_FOR_COMMANDS.values.each do |command|
|
@@ -206,6 +376,10 @@ def help
|
|
206
376
|
puts ""
|
207
377
|
end
|
208
378
|
|
379
|
+
|
380
|
+
|
381
|
+
#Main thread
|
382
|
+
|
209
383
|
log("Init Ejabberd Maintenance script")
|
210
384
|
|
211
385
|
begin
|
@@ -235,15 +409,16 @@ begin
|
|
235
409
|
end
|
236
410
|
puts ""
|
237
411
|
else
|
238
|
-
|
239
|
-
|
412
|
+
puts "Error: Params required for command " + (ARGV[0]).to_s() + ": " + (PARAMS_FOR_COMMANDS[ARGV[0]]).to_s()
|
413
|
+
puts "Syntax for command " + (ARGV[0]).to_s() + "\n" + (SYNTAX_FOR_COMMANDS[ARGV[0]]).to_s()
|
414
|
+
puts "Use 'help' to get information about command syntax"
|
240
415
|
end
|
241
416
|
else
|
242
|
-
|
243
|
-
|
244
|
-
log("Use 'help' to get information about command syntax")
|
417
|
+
puts "Error: Command not recognized"
|
418
|
+
puts "Use 'help' to get information about command syntax"
|
245
419
|
end
|
246
420
|
rescue
|
247
|
-
puts "
|
421
|
+
puts "Syntax error"
|
422
|
+
puts "Use 'help' to get information about command syntax"
|
248
423
|
end
|
249
424
|
|
Binary file
|
@@ -6,6 +6,7 @@ module SocialStream
|
|
6
6
|
|
7
7
|
included do
|
8
8
|
after_create :save_buddy
|
9
|
+
after_destroy :remove_buddy
|
9
10
|
end
|
10
11
|
|
11
12
|
module InstanceMethods
|
@@ -42,6 +43,38 @@ module SocialStream
|
|
42
43
|
|
43
44
|
end
|
44
45
|
|
46
|
+
|
47
|
+
def remove_buddy
|
48
|
+
|
49
|
+
unless SocialStream::Presence.enable
|
50
|
+
return
|
51
|
+
end
|
52
|
+
|
53
|
+
unless self.receiver.subject_type == "User" and self.sender.subject_type == "User"
|
54
|
+
return
|
55
|
+
end
|
56
|
+
|
57
|
+
#XMPP DOMAIN
|
58
|
+
domain = SocialStream::Presence.domain
|
59
|
+
user_sid = self.sender.slug + "@" + domain
|
60
|
+
user_name = self.sender.name
|
61
|
+
buddy_sid = self.receiver.slug + "@" + domain
|
62
|
+
buddy_name = self.receiver.name
|
63
|
+
|
64
|
+
#Check if is a positive and replied tie
|
65
|
+
if self.bidirectional?
|
66
|
+
#Execute unsetRosterForBidirectionalTie(user_sid,oldfriend_sid,oldfriendNick,oldfriendGroup)
|
67
|
+
SocialStream::Presence::XmppServerOrder::unsetRosterForBidirectionalTie(user_sid,buddy_sid,buddy_name,"SocialStream")
|
68
|
+
elsif self.positive?
|
69
|
+
#Case: Possitive tie unidirectional
|
70
|
+
#Execute removeBuddyFromRoster(user_sid,buddy_sid)
|
71
|
+
SocialStream::Presence::XmppServerOrder::removeBuddyFromRoster(user_sid,buddy_sid)
|
72
|
+
else
|
73
|
+
return
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
45
78
|
end
|
46
79
|
end
|
47
80
|
end
|
@@ -20,13 +20,33 @@ module SocialStream
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def unsetRosterForBidirectionalTie(userSid,oldfriendSid,oldfriendNick,oldfriendGroup)
|
24
|
+
if SocialStream::Presence.remote_xmpp_server
|
25
|
+
puts "Not implemented unsetRosterForBidirectionalTie(user_sid,oldfriend_sid,oldfriendNick,oldfriendGroup) for remote_xmpp_server"
|
26
|
+
return
|
27
|
+
else
|
28
|
+
#SocialStream::Presence.remote_xmpp_server=false
|
29
|
+
executeEmanagementLocalCommand("unsetBidireccionalBuddys",[userSid,oldfriendSid,oldfriendNick,oldfriendGroup])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def addBuddyToRoster(userSid,buddySid,buddyNick,buddyGroup,subscription_type)
|
24
34
|
if SocialStream::Presence.remote_xmpp_server
|
25
35
|
puts "Not implemented addBuddyToRoster(userSID,buddySID,buddyNick,buddyGroup,subscription_type) for remote_xmpp_server"
|
26
36
|
return
|
27
37
|
else
|
28
38
|
#SocialStream::Presence.remote_xmpp_server=false
|
29
|
-
executeEmanagementLocalCommand("addBuddyToRoster",[
|
39
|
+
executeEmanagementLocalCommand("addBuddyToRoster",[userSid,buddySid,buddyNick,buddyGroup,subscription_type])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def removeBuddyFromRoster(userSid,buddySid)
|
44
|
+
if SocialStream::Presence.remote_xmpp_server
|
45
|
+
puts "Not implemented removeBuddyFromRoster(userSid,buddySid) for remote_xmpp_server"
|
46
|
+
return
|
47
|
+
else
|
48
|
+
#SocialStream::Presence.remote_xmpp_server=false
|
49
|
+
executeEmanagementLocalCommand("removeBuddyFromRoster",[userSid,buddySid])
|
30
50
|
end
|
31
51
|
end
|
32
52
|
|
@@ -50,18 +70,27 @@ module SocialStream
|
|
50
70
|
else
|
51
71
|
#SocialStream::Presence.remote_xmpp_server=false
|
52
72
|
|
53
|
-
#Get connected users locally
|
54
|
-
|
55
|
-
|
56
|
-
|
73
|
+
#Get connected users locally
|
74
|
+
output = executeEmanagementLocalCommand("isEjabberdNodeStarted",[])
|
75
|
+
nodeUp = output.split("\n")[3]
|
76
|
+
|
77
|
+
if nodeUp and nodeUp.strip() == "true"
|
78
|
+
users = []
|
79
|
+
output = %x[ejabberdctl connected-users]
|
80
|
+
sessions = output.split("\n")
|
57
81
|
|
58
|
-
|
59
|
-
|
60
|
-
|
82
|
+
sessions.each do |session|
|
83
|
+
users << session.split("@")[0]
|
84
|
+
puts session.split("@")[0]
|
85
|
+
end
|
86
|
+
|
87
|
+
synchronize_presence_for_slugs(users)
|
88
|
+
|
89
|
+
else
|
90
|
+
reset_presence
|
91
|
+
return "Xmpp Server Down: Reset Connected Users"
|
61
92
|
end
|
62
93
|
|
63
|
-
synchronize_presence_for_slugs(users)
|
64
|
-
|
65
94
|
end
|
66
95
|
end
|
67
96
|
|
@@ -170,8 +199,8 @@ module SocialStream
|
|
170
199
|
command = command + " " + param.split(" ")[0]
|
171
200
|
end
|
172
201
|
puts "Executing " + command
|
173
|
-
|
174
|
-
|
202
|
+
output = %x[#{command}];
|
203
|
+
return output
|
175
204
|
end
|
176
205
|
|
177
206
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: social_stream-presence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.13
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Aldo Gordillo
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-10-
|
13
|
+
date: 2011-10-28 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|