social_stream 0.12.1 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Rakefile +3 -5
  2. data/base/app/assets/javascripts/social_stream-base.js +1 -0
  3. data/base/app/models/contact.rb +3 -1
  4. data/base/config/routes.rb +14 -4
  5. data/base/lib/social_stream/base/version.rb +1 -1
  6. data/base/vendor/assets/javascripts/jquery.screw.js +188 -0
  7. data/documents/app/assets/javascripts/documents.js.erb +6 -0
  8. data/documents/app/assets/stylesheets/documents.css.scss +5 -0
  9. data/documents/app/controllers/documents_controller.rb +31 -4
  10. data/documents/app/views/common/_headers.html.erb +76 -0
  11. data/documents/app/views/common/_index.html.erb +16 -30
  12. data/documents/config/routes.rb +1 -1
  13. data/documents/lib/social_stream/documents/version.rb +1 -1
  14. data/documents/social_stream-documents.gemspec +1 -1
  15. data/events/db/migrate/20111102145626_add_more_fields_to_events.rb +24 -0
  16. data/events/lib/social_stream/events/version.rb +1 -1
  17. data/events/social_stream-events.gemspec +1 -1
  18. data/lib/social_stream/version.rb +1 -1
  19. data/presence/app/assets/javascripts/store.js +6 -0
  20. data/presence/app/assets/javascripts/{xmpp_client.js → xmpp_client.js.erb} +53 -1
  21. data/presence/app/controllers/xmpp_controller.rb +2 -2
  22. data/presence/app/views/xmpp/_chat.html.erb +22 -36
  23. data/presence/app/views/xmpp/_chat_connecting.html.erb +1 -1
  24. data/presence/app/views/xmpp/_chat_contacts.html.erb +6 -6
  25. data/presence/app/views/xmpp/_chat_off.html.erb +29 -15
  26. data/presence/app/views/xmpp/index.html +0 -1
  27. data/presence/config/locales/en.yml +11 -0
  28. data/presence/config/locales/es.yml +11 -0
  29. data/presence/config/routes.rb +1 -0
  30. data/presence/ejabberd/conf/ssconfig_example.cfg +6 -0
  31. data/presence/ejabberd/ejabberd_scripts/authentication_script +61 -5
  32. data/presence/ejabberd/ejabberd_scripts/emanagement +123 -35
  33. data/presence/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
  34. data/presence/lib/generators/social_stream/presence/templates/initializer.rb +13 -6
  35. data/presence/lib/social_stream-presence.rb +9 -4
  36. data/presence/lib/social_stream/presence/models/buddy_manager.rb +10 -2
  37. data/presence/lib/social_stream/presence/version.rb +1 -1
  38. data/presence/lib/social_stream/presence/xmpp_server_order.rb +193 -121
  39. data/presence/lib/tasks/presence/synchronize.rake +2 -2
  40. data/presence/social_stream-presence.gemspec +2 -0
  41. data/social_stream.gemspec +3 -3
  42. metadata +19 -15
  43. data/presence/app/views/xmpp/chat.html.erb +0 -13
@@ -26,12 +26,12 @@ def getOption(option)
26
26
  return "Undefined"
27
27
  end
28
28
 
29
- def ejabberdLog(text)
30
- $logger.info "Ejabberd Management Script: " + text
31
- end
29
+
32
30
 
33
31
  #Configuration variables
34
32
  $domain = getOption("server_domain=")
33
+ $verbose = (getOption("verbose=")=="true")
34
+
35
35
 
36
36
  PARAMS_FOR_COMMANDS = {
37
37
  'addBuddyToRoster' => 5,
@@ -54,6 +54,7 @@ PARAMS_FOR_COMMANDS = {
54
54
  'sendMessageToUser' => 3,
55
55
  'getUserResource' => 1,
56
56
  'isEjabberdNodeStarted' => 0,
57
+ 'checkEjabberdctlQuotedString' => 0,
57
58
  'help' => 0,
58
59
  }
59
60
 
@@ -78,12 +79,20 @@ SYNTAX_FOR_COMMANDS = {
78
79
  'sendMessageToUser' => 'sendMessageToUser from_name to_name msg',
79
80
  'getUserResource' => 'getUserResource username',
80
81
  'isEjabberdNodeStarted' => 'isEjabberdNodeStarted',
82
+ 'checkEjabberdctlQuotedString' => 'checkEjabberdctlQuotedString',
81
83
  'help' => 'help',
82
84
  }
83
85
 
84
86
 
85
87
 
86
88
  #Debug methods
89
+ def ejabberdLog(text)
90
+ $logger.info "Ejabberd Management Script: " + text
91
+ if $verbose
92
+ #puts "Writing to ejabberdLog: " + "Ejabberd Management Script: " + text
93
+ end
94
+ end
95
+
87
96
  def log(msg)
88
97
  logWithTitle(msg,nil)
89
98
  end
@@ -123,8 +132,7 @@ def addBuddyToRoster(userSid,buddySid,buddyNick,buddyGroup,subscription_type)
123
132
  buddy = buddySid.split("@")[0]
124
133
  userDomain = userSid.split("@")[1]
125
134
  buddyDomain = buddySid.split("@")[1]
126
- command = "ejabberdctl add-rosteritem " + user + " " + userDomain + " " + buddy + " " + buddyDomain + " " + buddyNick + " " + buddyGroup + " " + subscription_type
127
- %x[#{command}];
135
+ executeCommand("ejabberdctl add-rosteritem " + user + " " + userDomain + " " + buddy + " " + buddyDomain + " " + buddyNick + " " + buddyGroup + " " + subscription_type)
128
136
  return "Done"
129
137
  end
130
138
 
@@ -134,8 +142,7 @@ def removeBuddyFromRoster(userSid,buddySid)
134
142
  userDomain = userSid.split("@")[1]
135
143
  buddyDomain = buddySid.split("@")[1]
136
144
  if checkUserInRoster(buddy,getRoster(user))
137
- command = "ejabberdctl delete_rosteritem " + user + " " + userDomain + " " + buddy + " " + buddyDomain
138
- %x[#{command}];
145
+ executeCommand("ejabberdctl delete_rosteritem " + user + " " + userDomain + " " + buddy + " " + buddyDomain)
139
146
  return "Done"
140
147
  else
141
148
  return "User " + buddy + " not found in " + user + " roster."
@@ -147,10 +154,9 @@ end
147
154
 
148
155
  def getRoster(username)
149
156
  if checkUser(username)
150
- command = "ejabberdctl get_roster " + username + " " + $domain
151
- %x[#{command}];
157
+ executeCommand("ejabberdctl get_roster " + username + " " + $domain)
152
158
  else
153
- return "User " + username + " not found"
159
+ return "Roster not found for user " + username
154
160
  end
155
161
  end
156
162
 
@@ -174,21 +180,18 @@ def removeRoster(username)
174
180
  end
175
181
  return "Done"
176
182
  else
177
- return "User " + username + " not found"
183
+ return "Roster not found for user " + username
178
184
  end
179
185
  end
180
186
 
181
187
  def removeAllRosters()
182
- command = "ejabberdctl process_rosteritems delete any any any any"
183
- %x[#{command}];
188
+ executeCommand("ejabberdctl process_rosteritems delete any any any any")
184
189
  return "Done";
185
190
  end
186
191
 
187
192
  def getAllUsersWithRoster()
188
- command = "ejabberdctl process_rosteritems list any any any any"
189
- output = %x[#{command}];
193
+ output = executeCommand("ejabberdctl process_rosteritems list any any any any")
190
194
 
191
- i = 0
192
195
  users = []
193
196
 
194
197
  lines = output.split("\n");
@@ -198,14 +201,13 @@ def getAllUsersWithRoster()
198
201
  if items.to_i.to_s == items
199
202
  if items.to_i > 0
200
203
  lines.each do |line|
201
- if i%2==1
204
+ if line.split(":")[0]=="Matches"
202
205
  user = line.split(" ")[1].split("@")[0]
203
206
  #puts i.to_s() + " :" + line
204
207
  unless users.include?(user)
205
208
  users << user
206
209
  end
207
210
  end
208
- i=i+1
209
211
  end
210
212
  end
211
213
  end
@@ -286,9 +288,7 @@ end
286
288
  def sendStanzaUserMessage(username,msg)
287
289
  resource = getUserResource(username);
288
290
  stanza = "\\<\\'message\\'\\>\\<\\'body\\'\\>\\'" + msg + "\\'\\<\\'/body\\'\\>\\<\\'/message\\'\\>"
289
- command = "ejabberdctl send_stanza_c2s " + username + " " + $domain + " " + resource + " " + stanza
290
- puts "Executing: " + command
291
- %x[#{command}];
291
+ executeCommand("ejabberdctl send_stanza_c2s " + username + " " + $domain + " " + resource + " " + stanza)
292
292
  return "Done"
293
293
  end
294
294
 
@@ -311,9 +311,7 @@ def sendPresenceWithShow(from_name,to_name,show)
311
311
  from_sid = from_name + "@" + $domain;
312
312
  to_sid = to_name + "@" + $domain;
313
313
  pres_stanza = "\\<\\'presence from=\\'\\\"\\'" + from_sid + "\\'\\\"\\' to=\\'\\\"\\'" + to_sid + "\\'\\\"\\>\\<\\'show\\'\\>\\'" + show + "\\'\\<\\'/show\\'\\>\\<\\'/presence\\'\\>"
314
- command = "ejabberdctl send_stanza_c2s " + from_name + " " + $domain + " " + resource + " " + pres_stanza
315
- puts "Executing: " + command
316
- %x[#{command}];
314
+ executeCommand("ejabberdctl send_stanza_c2s " + from_name + " " + $domain + " " + resource + " " + pres_stanza)
317
315
  return "Done"
318
316
  end
319
317
 
@@ -322,24 +320,19 @@ def sendPresenceStanzaWithType(from_name,to_name,presence_type)
322
320
  from_sid = from_name + "@" + $domain;
323
321
  to_sid = to_name + "@" + $domain;
324
322
  pres_stanza = "\\<\\'presence type=\\'\\\"\\'" + presence_type + "\\'\\\"\\' from=\\'\\\"\\'" + from_sid + "\\'\\\"\\' to=\\'\\\"\\'" + to_sid + "\\'\\\"\\>\\<\\'/presence\\'\\>"
325
- command = "ejabberdctl send_stanza_c2s " + from_name + " " + $domain + " " + resource + " " + pres_stanza
326
- puts "Executing: " + command
327
- %x[#{command}];
323
+ executeCommand("ejabberdctl send_stanza_c2s " + from_name + " " + $domain + " " + resource + " " + pres_stanza)
328
324
  return "Done"
329
325
  end
330
326
 
331
327
  def sendMessageToUser(from_name,to_name,msg)
332
328
  from_sid = from_name + "@" + $domain;
333
329
  to_sid = to_name + "@" + $domain;
334
- command = "ejabberdctl send_message_chat " + from_sid + " " + to_sid + " " + "\\'" + msg + "\\'";
335
- puts "Executing: " + command
336
- %x[#{command}];
330
+ executeCommand("ejabberdctl send_message_chat " + from_sid + " " + to_sid + " " + buildQuotedString(msg))
337
331
  return "Done"
338
332
  end
339
333
 
340
334
  def getUserResource(username)
341
- command = "ejabberdctl connected-users"
342
- output = %x[#{command}];
335
+ output = executeCommand("ejabberdctl connected-users")
343
336
  lines = output.split("\n");
344
337
  lines.each do |line|
345
338
  if line.split("@")[0] == username
@@ -356,18 +349,113 @@ end
356
349
  #More utilities
357
350
 
358
351
  def isEjabberdNodeStarted
359
- command = "ejabberdctl status"
360
- output = %x[#{command}]
352
+ output = executeCommand("ejabberdctl status")
361
353
  if firstLine = output.split("\n")[0]
362
354
  return ((firstLine.split(":")[1]).strip()=="started")
363
355
  end
364
356
  return false
365
357
  end
366
358
 
359
+ def checkEjabberdctlQuotedString
360
+ puts "checkForSimpleSlash: " + checkForSimpleSlash.to_s()
361
+ puts "checkForDoubleSlash: " + checkForDoubleSlash.to_s()
362
+ end
363
+
364
+ def checkForDoubleSlash
365
+ command = "ejabberdctl send_message_chat example@localhost example@localhost \\'Hello quoted string\\'"
366
+ if execute_as_sudo
367
+ command = "sudo " + command
368
+ end
369
+ #puts "Executing " + command
370
+ output = %x[#{command}]
371
+ firstLine = ""
372
+ lines = output.split("\n")
373
+ lines.each do |line|
374
+ if line != ""
375
+ firstLine = line
376
+ break
377
+ end
378
+ end
379
+
380
+ if firstLine==""
381
+ return true
382
+ elsif firstLine.split(":")[0]=="Error"
383
+ return false
384
+ else
385
+ #Unknown error
386
+ return false
387
+ end
388
+ end
389
+
390
+ def checkForSimpleSlash
391
+ command = "ejabberdctl send_message_chat example@localhost example@localhost \'Hello quoted string\'"
392
+ if execute_as_sudo
393
+ command = "sudo " + command
394
+ end
395
+ #puts "Executing " + command
396
+ output = %x[#{command}]
397
+ firstLine = ""
398
+ lines = output.split("\n")
399
+ lines.each do |line|
400
+ if line != ""
401
+ firstLine = line
402
+ break
403
+ end
404
+ end
405
+
406
+ if firstLine==""
407
+ return true
408
+ elsif firstLine.split(":")[0]=="Error"
409
+ return false
410
+ else
411
+ #Unknown error
412
+ return false
413
+ end
414
+ end
415
+
416
+ def buildQuotedString(msg)
417
+ if checkForSimpleSlash
418
+ return "\'" + msg + "\'"
419
+ end
420
+ if checkForDoubleSlash
421
+ return "\\'" + msg + "\\'"
422
+ end
423
+ return msg
424
+ end
367
425
 
368
426
 
369
427
  #Help & Support methods
370
428
 
429
+ def executeCommand(command)
430
+ #Building...
431
+ command = buildCommand(command)
432
+
433
+ if $verbose
434
+ puts "Executing: " + command
435
+ ejabberdLog("Executing (#{command})")
436
+ end
437
+
438
+ #Executing...
439
+ output = %x[#{command}]
440
+ return output
441
+ end
442
+
443
+ def buildCommand(command)
444
+ if execute_as_sudo
445
+ command = "sudo -u ejabberd " + command
446
+ end
447
+ return command
448
+ end
449
+
450
+ def execute_as_sudo
451
+ current_user = %x["whoami"].split("\n")[0]
452
+ sudo_users = getOption("users_require_sudo=")
453
+ sudo_users_array = sudo_users.split(",")
454
+ if sudo_users_array.include?(current_user)
455
+ return true
456
+ end
457
+ end
458
+
371
459
  def help
372
460
  log("Command list")
373
461
  SYNTAX_FOR_COMMANDS.values.each do |command|
@@ -386,7 +474,7 @@ begin
386
474
  if ARGV[0] and PARAMS_FOR_COMMANDS.keys.include?(ARGV[0])
387
475
  if (ARGV.length == (PARAMS_FOR_COMMANDS[ARGV[0]]+1))
388
476
 
389
- ejabberdLog("Executing (#{ARGV[0]})")
477
+ ejabberdLog("Executing (#{ARGV})")
390
478
 
391
479
  length = ARGV.length;
392
480
  case length
@@ -3,20 +3,27 @@ SocialStream::Presence.setup do |config|
3
3
  config.domain = "localhost"
4
4
  #Configures Bosh Service Path
5
5
  #config.bosh_service = "http://xmpp-proxy/http-bind"
6
+ #Configures Authentication Method: "cookie" or "password"
7
+ config.auth_method = "cookie"
6
8
  #Configures XMPP Server Password
7
9
  config.xmpp_server_password = "password"
8
10
  #Remote or local mode
9
11
  config.remote_xmpp_server = false
12
+ #Scripts path to execute ejabberd scripts: local or remote
13
+ config.scripts_path = "/scripts_path"
10
14
  #False to disable Social Stream Presence
11
15
  #config.enable = false
12
16
 
13
17
  #Parameters for remote mode
18
+ #SSH Login
19
+ #config.ssh_domain = "domain"
20
+ #config.ssh_user = "login"
21
+ #config.ssh_password= "password"
22
+
23
+ #Configure to use a Xmpp Client on Rails App
14
24
  #Username of the the Social Stream Admin sid
15
25
  config.social_stream_presence_username = "social_stream-presence"
16
26
  #Configures Social Stream Rails App Password
17
- config.password = "password"
18
-
19
- #Parameters for local mode
20
- #Scripts path to execute local ejabberd commands
21
- config.scripts_path = "/scripts_path"
22
- end
27
+ config.password = "password"
28
+
29
+ end
@@ -9,19 +9,24 @@ module SocialStream
9
9
  autoload :BuddyManager, 'social_stream/presence/models/buddy_manager'
10
10
  end
11
11
 
12
+ mattr_accessor :domain
12
13
  mattr_accessor :bosh_service
14
+ mattr_accessor :auth_method
13
15
  mattr_accessor :xmpp_server_password
14
16
  mattr_accessor :remote_xmpp_server
17
+ mattr_accessor :scripts_path
15
18
  mattr_accessor :enable
16
19
 
17
- mattr_accessor :domain
20
+ mattr_accessor :ssh_domain
21
+ mattr_accessor :ssh_user
22
+ mattr_accessor :ssh_password
23
+
18
24
  mattr_accessor :social_stream_presence_username
19
25
  mattr_accessor :password
20
26
 
21
- mattr_accessor :scripts_path
22
-
23
- @@enable = true
27
+ @@auth_method = "cookie"
24
28
  @@remote_xmpp_server = false
29
+ @@enable = true
25
30
 
26
31
  class << self
27
32
  def setup
@@ -17,6 +17,10 @@ module SocialStream
17
17
  return
18
18
  end
19
19
 
20
+ unless self.receiver and self.sender
21
+ return
22
+ end
23
+
20
24
  unless self.receiver.subject_type == "User" and self.sender.subject_type == "User"
21
25
  return
22
26
  end
@@ -44,12 +48,16 @@ module SocialStream
44
48
  end
45
49
 
46
50
 
47
- def remove_buddy
51
+ def remove_buddy
48
52
 
49
53
  unless SocialStream::Presence.enable
50
54
  return
51
55
  end
52
56
 
57
+ unless self.receiver and self.sender
58
+ return
59
+ end
60
+
53
61
  unless self.receiver.subject_type == "User" and self.sender.subject_type == "User"
54
62
  return
55
63
  end
@@ -64,7 +72,7 @@ module SocialStream
64
72
  #Check if is a positive and replied tie
65
73
  if self.bidirectional?
66
74
  #Execute unsetRosterForBidirectionalTie(user_sid,oldfriend_sid,oldfriendNick,oldfriendGroup)
67
- SocialStream::Presence::XmppServerOrder::unsetRosterForBidirectionalTie(user_sid,buddy_sid,buddy_name,"SocialStream")
75
+ SocialStream::Presence::XmppServerOrder::unsetRosterForBidirectionalTie(buddy_sid,user_sid,user_name,"SocialStream")
68
76
  elsif self.positive?
69
77
  #Case: Possitive tie unidirectional
70
78
  #Execute removeBuddyFromRoster(user_sid,buddy_sid)
@@ -1,5 +1,5 @@
1
1
  module Socialstream
2
2
  module Presence
3
- VERSION = "0.0.13"
3
+ VERSION = "0.0.18"
4
4
  end
5
5
  end
@@ -3,114 +3,111 @@ require 'xmpp4r/muc'
3
3
  require 'xmpp4r/roster'
4
4
  require 'xmpp4r/client'
5
5
  require 'xmpp4r/message'
6
+ require 'net/ssh'
6
7
 
7
8
  module SocialStream
8
9
  module Presence
9
10
  class XmppServerOrder
10
11
 
11
12
  class << self
12
-
13
+
13
14
  def setRosterForBidirectionalTie(userASid,userBSid,userANick,userBNick,groupForA,groupForB)
14
- if SocialStream::Presence.remote_xmpp_server
15
- puts "Not implemented setRosterForBidirectionalTie(userASid,userBSid,userANick,userBNick,groupForA,groupForB) for remote_xmpp_server"
16
- return
17
- else
18
- #SocialStream::Presence.remote_xmpp_server=false
19
- executeEmanagementLocalCommand("setBidireccionalBuddys",[userASid,userBSid,userANick,userBNick,groupForA,groupForB])
20
- end
15
+ executeEmanagementCommand("setBidireccionalBuddys",[userASid,userBSid,userANick,userBNick,groupForA,groupForB])
21
16
  end
22
17
 
18
+
23
19
  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
20
+ executeEmanagementCommand("unsetBidireccionalBuddys",[userSid,oldfriendSid,oldfriendNick,oldfriendGroup])
31
21
  end
32
22
 
23
+
33
24
  def addBuddyToRoster(userSid,buddySid,buddyNick,buddyGroup,subscription_type)
34
- if SocialStream::Presence.remote_xmpp_server
35
- puts "Not implemented addBuddyToRoster(userSID,buddySID,buddyNick,buddyGroup,subscription_type) for remote_xmpp_server"
36
- return
37
- else
38
- #SocialStream::Presence.remote_xmpp_server=false
39
- executeEmanagementLocalCommand("addBuddyToRoster",[userSid,buddySid,buddyNick,buddyGroup,subscription_type])
40
- end
25
+ executeEmanagementCommand("addBuddyToRoster",[userSid,buddySid,buddyNick,buddyGroup,subscription_type])
41
26
  end
42
27
 
28
+
43
29
  def removeBuddyFromRoster(userSid,buddySid)
44
- if SocialStream::Presence.remote_xmpp_server
45
- puts "Not implemented removeBuddyFromRoster(userSid,buddySid) for remote_xmpp_server"
30
+ executeEmanagementCommand("removeBuddyFromRoster",[userSid,buddySid])
31
+ end
32
+
33
+
34
+ #Before delete contact (destroy ties) callback
35
+ def removeBuddy(contact)
36
+
37
+ unless SocialStream::Presence.enable
38
+ return
39
+ end
40
+
41
+ unless contact.receiver and contact.sender
42
+ return
43
+ end
44
+
45
+ unless contact.receiver.subject_type == "User" and contact.sender.subject_type == "User"
46
46
  return
47
- else
48
- #SocialStream::Presence.remote_xmpp_server=false
49
- executeEmanagementLocalCommand("removeBuddyFromRoster",[userSid,buddySid])
50
47
  end
48
+
49
+ #XMPP DOMAIN
50
+ domain = SocialStream::Presence.domain
51
+ user_sid = contact.sender.slug + "@" + domain
52
+ user_name = contact.sender.name
53
+ buddy_sid = contact.receiver.slug + "@" + domain
54
+ buddy_name = contact.receiver.name
55
+
56
+ #Check for bidirecctional
57
+
58
+ if contact.sender.contact_actors(:type=>:user).include?(contact.receiver)
59
+ #Bidirectional contacts
60
+ #Execute unsetRosterForBidirectionalTie(user_sid,oldfriend_sid,oldfriendNick,oldfriendGroup)
61
+ unsetRosterForBidirectionalTie(buddy_sid,user_sid,user_name,"SocialStream")
62
+ elsif contact.sender.contact_actors(:type=>:user, :direction=>:sent).include?(contact.receiver)
63
+ #Unidirectional contacts
64
+ removeBuddyFromRoster(user_sid,buddy_sid)
65
+ end
66
+
51
67
  end
52
68
 
53
- def synchronize_presence
54
- if SocialStream::Presence.remote_xmpp_server
55
-
56
- begin
57
- client = openXmppClientForSocialStreamUser
58
- if client
59
- sendXmppChatMessage(client,getSocialStreamUserSid,"Synchronize")
60
- client.close()
61
- return "Ok"
62
- else
63
- reset_presence
64
- return "Reset Connected Users"
65
- end
66
- rescue
67
- puts "Error in SocialStream::Presence::XmppServerOrder::synchronize_presence"
68
- end
69
-
69
+
70
+ def synchronizePresence
71
+
72
+ if !isEjabberdNodeUp
73
+ resetPresence
74
+ return "Xmpp Server Down: Reset Connected Users"
75
+ end
76
+
77
+ if SocialStream::Presence.remote_xmpp_server
78
+ command = buildCommand("synchronize_presence_script","",[])
79
+ executeCommand(command)
70
80
  else
71
81
  #SocialStream::Presence.remote_xmpp_server=false
72
82
 
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")
81
-
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"
83
+ #Get connected users locally
84
+ users = []
85
+ output = %x[ejabberdctl connected-users]
86
+ sessions = output.split("\n")
87
+
88
+ sessions.each do |session|
89
+ users << session.split("@")[0]
90
+ puts session.split("@")[0]
92
91
  end
93
92
 
93
+ synchronizePresenceForSlugs(users)
94
+
94
95
  end
95
96
  end
96
97
 
97
98
 
98
- def remove_all_rosters
99
- if SocialStream::Presence.remote_xmpp_server
100
- puts "Not implemented SocialStream::Presence::XmppServerOrder::remove_all_rosters for remote_xmpp_server"
101
- return
102
- else
103
- #SocialStream::Presence.remote_xmpp_server=false
104
- executeEmanagementLocalCommand("removeAllRosters",[])
105
- end
99
+ def removeAllRosters
100
+ executeEmanagementCommand("removeAllRosters",[])
106
101
  end
107
102
 
108
- def synchronize_rosters
109
- puts "Removing all rosters"
110
- remove_all_rosters
111
- puts "Rosters removed"
112
-
113
- puts "Populate rosters"
103
+
104
+ def synchronizeRosters
105
+ commands = []
106
+
107
+ #"Remove all rosters"
108
+ commands << buildCommand("emanagement","removeAllRosters",[])
109
+
110
+ #"Populate rosters"
114
111
  users = User.all
115
112
  checkedUsers = []
116
113
 
@@ -121,50 +118,17 @@ module SocialStream
121
118
  unless checkedUsers.include?(contact.slug)
122
119
  domain = SocialStream::Presence.domain
123
120
  user_sid = user.slug + "@" + domain
124
- contact_sid = contact.slug + "@" + domain
125
- setRosterForBidirectionalTie(user_sid,contact_sid,user.name,contact.name,"SocialStream","SocialStream")
121
+ contact_sid = contact.slug + "@" + domain
122
+ commands << buildCommand("emanagement","setBidireccionalBuddys",[user_sid,contact_sid,user.name,contact.name,"SocialStream","SocialStream"])
126
123
  end
127
124
  end
128
125
  end
126
+
127
+ executeCommands(commands)
129
128
  end
130
129
 
131
-
132
- #Help methods
133
-
134
- def getSocialStreamUserSid
135
- #XMPP DOMAIN
136
- domain = SocialStream::Presence.domain
137
- #SS Username
138
- ss_name = SocialStream::Presence.social_stream_presence_username
139
- return ss_name + "@" + domain
140
- end
141
-
142
- def openXmppClientForSocialStreamUser
143
- begin
144
- password= SocialStream::Presence.password
145
- client = Jabber::Client.new(Jabber::JID.new(getSocialStreamUserSid))
146
- client.connect
147
- client.auth(password)
148
- return client
149
- rescue Exception => e
150
- case e
151
- when Errno::ECONNREFUSED
152
- puts "Connection to XMPP Server refused"
153
- return nil
154
- else
155
- puts "Unknown exception: #{e.to_s}"
156
- return nil
157
- end
158
- end
159
- end
160
-
161
- def sendXmppChatMessage(client,dest_sid,body)
162
- msg = Jabber::Message::new(dest_sid, body)
163
- msg.type=:chat
164
- client.send(msg)
165
- end
166
-
167
- def synchronize_presence_for_slugs(user_slugs)
130
+
131
+ def synchronizePresenceForSlugs(user_slugs)
168
132
  #Check connected users
169
133
  users = User.find_all_by_connected(true)
170
134
 
@@ -184,7 +148,8 @@ module SocialStream
184
148
  end
185
149
  end
186
150
 
187
- def reset_presence
151
+
152
+ def resetPresence
188
153
  users = User.find_all_by_connected(true)
189
154
 
190
155
  users.each do |user|
@@ -193,18 +158,125 @@ module SocialStream
193
158
  end
194
159
  end
195
160
 
196
- def executeEmanagementLocalCommand(order,params)
197
- command = SocialStream::Presence.scripts_path + "/emanagement " + order
161
+
162
+
163
+ #Execution commands manage
164
+
165
+ def buildCommand(script,order,params)
166
+ command = SocialStream::Presence.scripts_path + "/" + script + " " + order
198
167
  params.each do |param|
199
168
  command = command + " " + param.split(" ")[0]
200
169
  end
170
+ return command
171
+ end
172
+
173
+ def executeEmanagementCommand(order,params)
174
+ command = buildCommand("emanagement",order,params)
175
+ executeCommand(command)
176
+ end
177
+
178
+ def executeCommand(command)
201
179
  puts "Executing " + command
202
- output = %x[#{command}];
180
+ if SocialStream::Presence.remote_xmpp_server
181
+ output = executeRemoteCommand(command)
182
+ else
183
+ #SocialStream::Presence.remote_xmpp_server=false
184
+ output = executeLocalCommand(command)
185
+ end
203
186
  return output
204
187
  end
188
+
189
+ def executeCommands(commands)
190
+ puts "Executing the following commands:"
191
+ commands.each do |command|
192
+ puts command
193
+ end
194
+ puts "Command list finish"
195
+ if SocialStream::Presence.remote_xmpp_server
196
+ output = executeRemoteCommands(commands)
197
+ else
198
+ #SocialStream::Presence.remote_xmpp_server=false
199
+ output = executeLocalCommands(commands)
200
+ end
201
+ return output
202
+ end
203
+
204
+ def executeLocalCommand(command)
205
+ return executeLocalCommands([command])
206
+ end
207
+
208
+ def executeLocalCommands(commands)
209
+ output="No command received";
210
+ commands.each do |command|
211
+ output = %x[#{command}];
212
+ end
213
+ return output
214
+ end
215
+
216
+ def executeRemoteCommand(command)
217
+ return executeRemoteCommands([command])
218
+ end
219
+
220
+ def executeRemoteCommands(commands)
221
+ output="No command received";
222
+ Net::SSH.start( SocialStream::Presence.ssh_domain, SocialStream::Presence.ssh_user, :password => SocialStream::Presence.ssh_password, :auth_methods => ["password"]) do |session|
223
+ commands.each do |command|
224
+ output = session.exec!(command)
225
+ end
226
+ end
227
+ return output
228
+ end
229
+
230
+
231
+
232
+ #Help methods
233
+
234
+ def isEjabberdNodeUp
235
+ output = executeEmanagementCommand("isEjabberdNodeStarted",[])
236
+ nodeUp = output.split("\n")[3]
237
+ return (nodeUp and nodeUp.strip()=="true")
238
+ end
239
+
240
+
205
241
 
242
+ #Xmpp client manage methods
243
+
244
+ def getSocialStreamUserSid
245
+ #XMPP DOMAIN
246
+ domain = SocialStream::Presence.domain
247
+ #SS Username
248
+ ss_name = SocialStream::Presence.social_stream_presence_username
249
+ return ss_name + "@" + domain
250
+ end
251
+
252
+
253
+ def openXmppClientForSocialStreamUser
254
+ begin
255
+ password= SocialStream::Presence.password
256
+ client = Jabber::Client.new(Jabber::JID.new(getSocialStreamUserSid))
257
+ client.connect
258
+ client.auth(password)
259
+ return client
260
+ rescue Exception => e
261
+ case e
262
+ when Errno::ECONNREFUSED
263
+ puts "Connection to XMPP Server refused"
264
+ return nil
265
+ else
266
+ puts "Unknown exception: #{e.to_s}"
267
+ return nil
268
+ end
269
+ end
270
+ end
271
+
272
+
273
+ def sendXmppChatMessage(client,dest_sid,body)
274
+ msg = Jabber::Message::new(dest_sid, body)
275
+ msg.type=:chat
276
+ client.send(msg)
277
+ end
278
+
206
279
  end
207
-
208
280
  end
209
281
  end
210
282
  end