social_stream-presence 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. data/app/assets/javascripts/chat_interface_manager.js.erb +43 -5
  2. data/app/assets/javascripts/chat_utilities.js +26 -0
  3. data/app/assets/javascripts/xmpp_client_management.js.erb +5 -1
  4. data/app/assets/stylesheets/chat.css +24 -0
  5. data/app/views/chat/_off.html.erb +0 -3
  6. data/app/views/xmpp/active_users.html.erb +1 -1
  7. data/config/locales/en.yml +4 -2
  8. data/config/locales/es.yml +3 -1
  9. data/config/routes.rb +3 -3
  10. data/ejabberd/conf/ssconfig_example.cfg +14 -20
  11. data/ejabberd/ejabberd_files.zip +0 -0
  12. data/ejabberd/ejabberd_scripts/authentication_script +3 -13
  13. data/ejabberd/ejabberd_scripts/development_scripts/show_config.sh +13 -9
  14. data/ejabberd/ejabberd_scripts/emanagement +65 -22
  15. data/ejabberd/ejabberd_scripts/reset_connection_script +1 -1
  16. data/ejabberd/ejabberd_scripts/set_connection_script +1 -1
  17. data/ejabberd/ejabberd_scripts/set_presence_script +1 -1
  18. data/ejabberd/ejabberd_scripts/set_script_header.sh +112 -0
  19. data/ejabberd/ejabberd_scripts/synchronize_presence_script +4 -2
  20. data/ejabberd/ejabberd_scripts/unset_connection_script +1 -1
  21. data/ejabberd/ejabberd_scripts/unset_presence_script +48 -0
  22. data/ejabberd/installer.sh +267 -0
  23. data/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
  24. data/ejabberd/mod_sspresence/mod_sspresence.erl +31 -99
  25. data/lib/generators/social_stream/presence/install_generator.rb +1 -1
  26. data/lib/generators/social_stream/presence/templates/initializer.rb +6 -4
  27. data/lib/social_stream-presence.rb +2 -1
  28. data/lib/social_stream/presence/models/buddy_manager.rb +1 -1
  29. data/lib/social_stream/presence/version.rb +1 -1
  30. data/lib/social_stream/presence/xmpp_server_order.rb +128 -28
  31. data/lib/tasks/presence/installer.rake +100 -0
  32. data/social_stream-presence.gemspec +2 -0
  33. data/vendor/assets/javascripts/jquery.ui.chatbox.js +18 -2
  34. metadata +23 -5
@@ -18,19 +18,20 @@ statusIcons['dnd'] = "dnd";
18
18
 
19
19
  var connectButtonTimer;
20
20
  var periodBetweenAttempts=15; //(seg)
21
- var connectButtonTimerCounter=periodBetweenAttempts;
21
+ var connectButtonTimerCounter=periodBetweenAttempts+1;
22
22
 
23
23
  function connectButtonTimerFunction(){
24
- if(connectButtonTimerCounter < periodBetweenAttempts){
25
- connectButtonTimerCounter++;
26
- } else if (connectButtonTimerCounter == periodBetweenAttempts) {
24
+ connectButtonTimerCounter++;
25
+ if (connectButtonTimerCounter > (periodBetweenAttempts-1)) {
26
+ clearTimeout(connectButtonTimer);
27
27
  $("#chat_header_title").html('<%=I18n.t('chat.disconnected')%>')
28
28
  }
29
29
  }
30
30
 
31
31
  function requestConnectToChat(){
32
32
  if (connectButtonTimerCounter > (periodBetweenAttempts-1)) {
33
- connectButtonTimerCounter=0;
33
+ connectButtonTimerCounter=0;
34
+ connectButtonTimer = setInterval("connectButtonTimerFunction()", 1000)
34
35
  $("#chat_header_title").html('<%=I18n.t('chat.connecting')%>')
35
36
  return true
36
37
  } else {
@@ -292,4 +293,41 @@ function putReceivedMessageOnChatWindow(from_jid,from_slug,body,msgID){
292
293
  playSound("onMessageAudio");
293
294
  }
294
295
 
296
+ }
297
+
298
+
299
+ ////////////////////
300
+ //Notifications on chat Window
301
+ ////////////////////
302
+
303
+ function showChatNotificationForSlug(slug,msg){
304
+ var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
305
+ showChatNotification(notification,msg);
306
+ }
307
+
308
+ function showChatNotification(notification,msg){
309
+ notification.html("<p class==\"ui-chatbox-notify-text\">" + msg + "</p>");
310
+ notification.css("visibility","visible");
311
+ notification.fadeIn();
312
+ }
313
+
314
+ function hideChatNotificationForSlug(slug){
315
+ var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
316
+ hideChatNotification(notification);
317
+ }
318
+
319
+ function hideChatNotification(notification){
320
+ notification.fadeOut();
321
+ notification.css("visibility","hidden");
322
+ }
323
+
324
+ function notifyWhenUsersDisconnect(){
325
+ var notification = $("div.ui-chatbox-notify");
326
+ var msg = '<%=I18n.t('chat.notify.offline')%>';
327
+ showChatNotification(notification,msg);
328
+ }
329
+
330
+ function hideAllNotifications(){
331
+ var notification = $("div.ui-chatbox-notify");
332
+ hideChatNotification(notification);
295
333
  }
@@ -65,6 +65,19 @@ function blinkTitleOnMessage(username){
65
65
 
66
66
 
67
67
 
68
+ ////////////////////
69
+ //Control user data input on the chatbox
70
+ ////////////////////
71
+
72
+ //Return true to allow user to send data to the chatbox.
73
+ function userChatDataInputControl(){
74
+ var floodControlBoolean = floodControl();
75
+ var offlineDataSendControlBoolean = offlineDataSendControl();
76
+ return (floodControlBoolean && offlineDataSendControlBoolean);
77
+ }
78
+
79
+
80
+
68
81
  ////////////////////
69
82
  //Antiflood
70
83
  ////////////////////
@@ -190,6 +203,19 @@ function mustBounceBoxForChatWindow(jqueryUIChatbox){
190
203
 
191
204
  }
192
205
 
206
+
207
+
208
+ ////////////////////
209
+ //Prevent user to send data to the chatbox when he is offline.
210
+ ////////////////////
211
+
212
+ function offlineDataSendControl(){
213
+ return ((!disconnectionFlag) && (isStropheConnected()));
214
+ }
215
+
216
+
217
+
218
+
193
219
  ////////////////////
194
220
  //Next features...
195
221
  ////////////////////
@@ -160,6 +160,7 @@ function onConnect(status) {
160
160
  log('Strophe is disconnected.');
161
161
  disconnectionFlag = true;
162
162
  clearTimeout(awayTimer);
163
+ notifyWhenUsersDisconnect();
163
164
  reconnectTimer = setTimeout ("onReconnect()", 5000);
164
165
  } else if (status == Strophe.Status.CONNECTED) {
165
166
  log('Strophe is connected.');
@@ -173,13 +174,14 @@ function onConnect(status) {
173
174
  sendStatus(userStatus);
174
175
  awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
175
176
  timer = setInterval("timerFunction()", timerPeriod);
177
+ hideAllNotifications();
176
178
  }
177
179
 
178
180
  updateChatWindow();
179
181
  }
180
182
 
181
183
  function onReconnect(){
182
- log("onReconnect!")
184
+
183
185
  if ((!isStropheConnected())&&(userStatus!="offline")) {
184
186
 
185
187
  if (reconnectAttempts>0) {
@@ -273,6 +275,7 @@ function processAvailablePresenceStanza(presence){
273
275
  setUserIconStatus(slug, status);
274
276
  if (cacheConnectedUsers.indexOf(slug) != -1) {
275
277
  showConnectionBoxFromSlug(slug);
278
+ hideChatNotificationForSlug(slug);
276
279
  }
277
280
  } else {
278
281
  setTimeout("refreshChatWindow()", 3000);
@@ -287,6 +290,7 @@ function processUnavailablePresenceStanza(presence){
287
290
  if (slug != user_slug) {
288
291
  if (getConnectionBoxFromSlug(slug)!=null){
289
292
  hideConnectionBoxFromSlug(slug)
293
+ showChatNotificationForSlug(slug,$(getConnectionBoxFromSlug(slug)).attr("name") + " is offline");
290
294
  }
291
295
  }
292
296
  }
@@ -62,6 +62,30 @@
62
62
  clear: both;
63
63
  }
64
64
 
65
+ div.ui-chatbox-notify{
66
+ visibility: hidden;
67
+ background: #E5E5E5;
68
+ background-color: #E5E5E5;
69
+ color: black;
70
+ z-index: 1;
71
+ position:absolute;
72
+ top: 0;
73
+ margin-top: 30px;
74
+ padding: 4px 0px 4px 0px;
75
+ width: 236px;
76
+ text-align: center;
77
+ border-style:solid;
78
+ border-width:1px;
79
+ border-color: #CCCCCC;
80
+ opacity:0.95;
81
+ filter:alpha(opacity=95); /* For IE8 and earlier */
82
+ }
83
+
84
+ p.ui-chatbox-notify-text{
85
+ text-align: center;
86
+ font-weight: bold;
87
+ }
88
+
65
89
 
66
90
  /* Ticks */
67
91
 
@@ -1,9 +1,6 @@
1
1
  <script type="text/javascript">
2
2
  $(document).ready(function () {
3
3
 
4
- connectButtonTimer = setInterval("connectButtonTimerFunction()", 1000)
5
- connectButtonTimerCounter=periodBetweenAttempts+1
6
-
7
4
  if (authByCookie()){
8
5
  //Authentication by cookie
9
6
 
@@ -11,7 +11,7 @@
11
11
  <p>&nbsp;</p>
12
12
  <ul>
13
13
  <%@users.each do |user| %>
14
- <li><b><%=user.name%></b></li>
14
+ <li><b><%=user.name%></b> (<%=user.status%>) </li>
15
15
  <%end%>
16
16
  </ul>
17
17
  <p>&nbsp;</p>
@@ -3,7 +3,7 @@ en:
3
3
  connecting: "Chat Connecting"
4
4
  reconnecting: "Chat Reconnecting"
5
5
  disconnected: "Chat Disconnected"
6
- unableconnect: "Chat Disconnected"
6
+ unableconnect: "Chat Out of Service"
7
7
  title: "Chat"
8
8
  password: "Password"
9
9
  status:
@@ -15,4 +15,6 @@ en:
15
15
  settings:
16
16
  title: "Enable and configure Social Stream Chat"
17
17
  checkbox: "Enable or disable Social Stream Chat"
18
- update: "Update Settings"
18
+ update: "Update Settings"
19
+ notify:
20
+ offline: "You are offline"
@@ -3,7 +3,7 @@ es:
3
3
  connecting: "Chat Conectando"
4
4
  reconnecting: "Chat Reconectando"
5
5
  disconnected: "Chat Desconectado"
6
- unableconnect: "Chat Desconectado"
6
+ unableconnect: "Chat Fuera de servicio"
7
7
  title: "Chat"
8
8
  password: "Contraseña"
9
9
  status:
@@ -16,4 +16,6 @@ es:
16
16
  title: "Activación y configuración del chat de Social Stream"
17
17
  checkbox: "Activar o desactivar chat"
18
18
  update: "Guardar configuración"
19
+ notify:
20
+ offline: "Desconectado"
19
21
 
data/config/routes.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  Rails.application.routes.draw do
2
2
  #match "/active_users" => "Xmpp#active_users"
3
3
 
4
- match '/xmpp/resetConnection' => "Xmpp#resetConnection"
5
4
  match '/xmpp/setConnection' => "Xmpp#setConnection"
6
5
  match '/xmpp/unsetConnection' => "Xmpp#unsetConecction"
7
- match '/xmpp/synchronizePresence' => "Xmpp#synchronizePresence"
8
6
  match '/xmpp/setPresence' => "Xmpp#setPresence"
9
7
  match '/xmpp/unsetPresence' => "Xmpp#unsetPresence"
10
- match '/chatWindow'=> "Xmpp#chatWindow"
8
+ match '/xmpp/resetConnection' => "Xmpp#resetConnection"
9
+ match '/xmpp/synchronizePresence' => "Xmpp#synchronizePresence"
11
10
  match '/xmpp/updateSettings'=> "Xmpp#updateSettings"
11
+ match '/chatWindow'=> "Xmpp#chatWindow"
12
12
 
13
13
  end
@@ -1,38 +1,32 @@
1
- #Social Stream Presence: ejabberd config
1
+ #Social Stream Presence: Ejabberd configuration file
2
2
 
3
3
  #Ejabberd node server domain
4
- server_domain=domain.example.com
4
+ server_domain=xmppdomain.example.com
5
5
 
6
6
  #Scripts Path
7
7
  scripts_path=/my_scripts_path
8
8
 
9
- #Source path: uncomment to compile ejabberd social stream module
10
- #source_path=/.../ejabberd_source/src
11
-
12
9
  #It is also necessary to modify the file: /etc/ejabberd/ejabberd.cfg
13
10
  #%%{auth_method, external}.
14
11
  #%%{extauth_program, "scripts_path/authentication_script"}.
15
12
 
16
- #API REST
17
- auth_api=http://localhost/users/sign_in
18
- auth_by_cookie_api=http://localhost/api/me
19
- cookie_name=_rails_server_cookie
20
- set_connection_api=http://localhost/xmpp/setConnection
21
- unset_connection_api=http://localhost/xmpp/unsetConnection
22
- reset_connection_api=http://localhost/xmpp/resetConnection
23
- synchronize_presence_api=http://localhost/xmpp/synchronizePresence
24
- set_presence_api=http://localhost/xmpp/setPresence
25
- unset_presence_api=http://localhost/xmpp/unsetPresence
13
+ #Source path: uncomment to compile ejabberd social stream module
14
+ #source_path=/.../ejabberd_source/src
15
+
26
16
 
27
- #Social Stream Login
28
- ss_login=social_stream-presence
17
+ #Web Domain for REST API
18
+ web_domain=ssdomain.example.com
19
+
20
+ #Rails Web Server Cookie name
21
+ #Check this line in your app/config/initializers/session_store.rb: Global::Application.config.session_store :cookie_store, :key => '_rails_server_cookie'
22
+ cookie_name=_rails_server_cookie
29
23
 
30
- #Social Stream PASSWORD
31
- ss_password=password
32
24
 
33
25
  #Ejabberd Server Password
34
26
  ejabberd_password=password
35
27
 
28
+
36
29
  #Emanagement configuration
37
- users_require_sudo=user1,user2,...
30
+ ejabberd_server_user=ejabberd
31
+ users_require_sudo=all
38
32
  verbose=false
Binary file
@@ -31,11 +31,9 @@ def getOption(option)
31
31
  return "Undefined"
32
32
  end
33
33
 
34
- $accessUrl = getOption("auth_api=")
35
- $accessByCookieUrl = getOption("auth_by_cookie_api=")
34
+ $accessByPasswordUrl = "http://" + getOption("web_domain=") + "/users/sign_in"
35
+ $accessByCookieUrl = "http://" + getOption("web_domain=") + "/api/me"
36
36
  $cookie_name = getOption("cookie_name=")
37
- $sslogin = getOption("ss_login=")
38
- $sspass = getOption("ss_password=")
39
37
 
40
38
 
41
39
  def auth(username, password)
@@ -48,17 +46,9 @@ def auth(username, password)
48
46
  # return true
49
47
  #end
50
48
 
51
- #Social Stream password
52
- if username == $sslogin
53
- if password == $sspass
54
- return true
55
- else
56
- return false
57
- end
58
- end
59
49
 
60
50
  begin
61
- response = RestClient.post $accessUrl, :user => { :email => username , :password => password }
51
+ response = RestClient.post $accessByPasswordUrl, :user => { :email => username , :password => password }
62
52
 
63
53
  if response.code == 201
64
54
  return true
@@ -17,17 +17,21 @@ end
17
17
  puts ""
18
18
  puts "############### Ejabberd Configuration ###############"
19
19
  puts "Config file for Social Stream Presence: /etc/ejabberd/ssconfig.cfg"
20
+ puts "Xmpp Server domain: #{getOption("server_domain=")}"
20
21
  puts "Scripts Path: #{getOption("scripts_path=")}"
21
22
  puts "mod_sspresence Path: #{getOption("source_path=")}"
22
- puts "Server domain: #{getOption("server_domain=")}"
23
- puts "API REST URLs"
24
- puts "Authentication: #{getOption("auth_api=")}"
25
- puts "onRegisterConnection: #{getOption("set_connection_api=")}"
26
- puts "onRemoveConnection: #{getOption("unset_connection_api=")}"
27
- puts "onPresence: #{getOption("set_presence_api=")}"
28
- puts "onUnsetPresence: #{getOption("unset_presence_api=")}"
29
- puts "ResetConnection: #{getOption("reset_connection_api=")}"
30
- puts "SynchronizePresence: #{getOption("synchronize_presence_api=")}"
23
+ puts "Web Domain for REST API: #{getOption("web_domain=")}"
24
+ puts "##############################"
25
+ puts "REST API"
26
+ puts "Authentication by password: http://#{getOption("web_domain=")}/users/sign_in"
27
+ puts "Authentication by cookie: http://#{getOption("web_domain=")}/api/me"
28
+ puts "onRegisterConnection: http://#{getOption("web_domain=")}/xmpp/setConnection"
29
+ puts "onRemoveConnection: http://#{getOption("web_domain=")}/xmpp/unsetConnection"
30
+ puts "onPresence: http://#{getOption("web_domain=")}/xmpp/setPresence"
31
+ puts "onUnsetPresence: http://#{getOption("web_domain=")}/xmpp/unsetPresence"
32
+ puts "ResetConnection: http://#{getOption("web_domain=")}/xmpp/resetConnection"
33
+ puts "SynchronizePresence: http://#{getOption("web_domain=")}/xmpp/synchronizePresence"
34
+ puts "##############################"
31
35
  puts "Social Stream Presence logs in var/log/ejabberd/"
32
36
  puts "######################################################"
33
37
  puts ""
@@ -31,6 +31,8 @@ end
31
31
  #Configuration variables
32
32
  $domain = getOption("server_domain=")
33
33
  $verbose = (getOption("verbose=")=="true")
34
+ $ejabberd_user = getOption("ejabberd_server_user=")
35
+ $checkEjabberdctlQuotedString = false
34
36
 
35
37
 
36
38
  PARAMS_FOR_COMMANDS = {
@@ -41,9 +43,7 @@ PARAMS_FOR_COMMANDS = {
41
43
  'getRoster' => 1,
42
44
  'removeRoster' => 1,
43
45
  'removeAllRosters' => 0,
44
- 'getBuddysFromRoster' => 1,
45
46
  'getAllUsersWithRoster' => 0,
46
- 'getAllRosters' => 0,
47
47
  'printAllRosters' => 0,
48
48
  'printAllBidirecctionalBuddys' => 0,
49
49
  'checkUser' => 1,
@@ -54,7 +54,9 @@ PARAMS_FOR_COMMANDS = {
54
54
  'sendMessageToUser' => 3,
55
55
  'getUserResource' => 1,
56
56
  'isEjabberdNodeStarted' => 0,
57
+ 'broadcast' => 2,
57
58
  'checkEjabberdctlQuotedString' => 0,
59
+ 'getConnectedUsers' => 0,
58
60
  'help' => 0,
59
61
  }
60
62
 
@@ -66,9 +68,7 @@ SYNTAX_FOR_COMMANDS = {
66
68
  'getRoster' => 'getRoster username',
67
69
  'removeRoster' => 'removeRoster username',
68
70
  'removeAllRosters' => 'removeAllRosters',
69
- 'getBuddysFromRoster' => 'getBuddysFromRoster roster',
70
71
  'getAllUsersWithRoster' => 'getAllUsersWithRoster',
71
- 'getAllRosters' => 'getAllRosters',
72
72
  'printAllRosters' => 'printAllRosters',
73
73
  'printAllBidirecctionalBuddys' => 'printAllBidirecctionalBuddys',
74
74
  'checkUser' => 'checkUser user',
@@ -79,7 +79,9 @@ SYNTAX_FOR_COMMANDS = {
79
79
  'sendMessageToUser' => 'sendMessageToUser from_name to_name msg',
80
80
  'getUserResource' => 'getUserResource username',
81
81
  'isEjabberdNodeStarted' => 'isEjabberdNodeStarted',
82
+ 'broadcast' => 'broadcast users msg (users values: "all" or slugs array)',
82
83
  'checkEjabberdctlQuotedString' => 'checkEjabberdctlQuotedString',
84
+ 'getConnectedUsers' => 'getConnectedUsers',
83
85
  'help' => 'help',
84
86
  }
85
87
 
@@ -285,13 +287,6 @@ end
285
287
 
286
288
  #Manage stanzas Utilities
287
289
 
288
- def sendStanzaUserMessage(username,msg)
289
- resource = getUserResource(username);
290
- stanza = "\\<\\'message\\'\\>\\<\\'body\\'\\>\\'" + msg + "\\'\\<\\'/body\\'\\>\\<\\'/message\\'\\>"
291
- executeCommand("ejabberdctl send_stanza_c2s " + username + " " + $domain + " " + resource + " " + stanza)
292
- return "Done"
293
- end
294
-
295
290
  def setPresence(username)
296
291
  sendPresenceStanzaWithType(username,username,"available")
297
292
  end
@@ -305,12 +300,14 @@ def sendPresence(username,show)
305
300
  end
306
301
 
307
302
  def sendPresenceWithShow(from_name,to_name,show)
308
- puts from_name
303
+ #puts from_name
309
304
  resource = getUserResource(from_name);
310
- puts resource
305
+ #puts resource
311
306
  from_sid = from_name + "@" + $domain;
312
307
  to_sid = to_name + "@" + $domain;
313
- pres_stanza = "\\<\\'presence from=\\'\\\"\\'" + from_sid + "\\'\\\"\\' to=\\'\\\"\\'" + to_sid + "\\'\\\"\\>\\<\\'show\\'\\>\\'" + show + "\\'\\<\\'/show\\'\\>\\<\\'/presence\\'\\>"
308
+ pres_stanza = "\\<" + buildQuotedString("presence from=") + "\\\"" + buildQuotedString(from_sid) + "\\\"" + buildQuotedString(" to=") + "\\\"" +
309
+ buildQuotedString(to_sid) + "\\\"\\>\\<" + buildQuotedString("show") + "\\>" + buildQuotedString(show) + "\\<" +
310
+ buildQuotedString("/show") + "\\>\\<" + buildQuotedString("/presence") + "\\>"
314
311
  executeCommand("ejabberdctl send_stanza_c2s " + from_name + " " + $domain + " " + resource + " " + pres_stanza)
315
312
  return "Done"
316
313
  end
@@ -319,7 +316,8 @@ def sendPresenceStanzaWithType(from_name,to_name,presence_type)
319
316
  resource = getUserResource(from_name);
320
317
  from_sid = from_name + "@" + $domain;
321
318
  to_sid = to_name + "@" + $domain;
322
- pres_stanza = "\\<\\'presence type=\\'\\\"\\'" + presence_type + "\\'\\\"\\' from=\\'\\\"\\'" + from_sid + "\\'\\\"\\' to=\\'\\\"\\'" + to_sid + "\\'\\\"\\>\\<\\'/presence\\'\\>"
319
+ pres_stanza = "\\<" + buildQuotedString("presence type=") + "\\\"" + buildQuotedString(presence_type) + "\\\"" + buildQuotedString(" from=") + "\\\"" +
320
+ buildQuotedString(from_sid) + "\\\"" + buildQuotedString(" to=") + "\\\"" + buildQuotedString(to_sid) + "\\\"\\>\\<" + buildQuotedString("/presence") + "\\>"
323
321
  executeCommand("ejabberdctl send_stanza_c2s " + from_name + " " + $domain + " " + resource + " " + pres_stanza)
324
322
  return "Done"
325
323
  end
@@ -356,17 +354,52 @@ def isEjabberdNodeStarted
356
354
  return false
357
355
  end
358
356
 
357
+ def getConnectedUsers
358
+ users = []
359
+ output = executeCommand("ejabberdctl connected-users")
360
+ sessions = output.split("\n")
361
+ sessions.each do |session|
362
+ users << session.split("@")[0]
363
+ end
364
+ return users
365
+ end
366
+
367
+ def broadcast(users,msg)
368
+ output = executeCommand("ejabberdctl connected-users")
369
+ lines = output.split("\n");
370
+ lines.each do |line|
371
+ username = line.split("@")[0]
372
+ if (users == "all") or (users.length > 1 and users.include?(username))
373
+ s = line.split("@")[1];
374
+ resource = s.split("/")[1];
375
+ sendMessageToUser("SocialStream",username,msg)
376
+ end
377
+ end
378
+ return "Done"
379
+ end
380
+
381
+ #Determine how to scape characters for build quoted strings
359
382
  def checkEjabberdctlQuotedString
360
383
  puts "checkForSimpleSlash: " + checkForSimpleSlash.to_s()
361
384
  puts "checkForDoubleSlash: " + checkForDoubleSlash.to_s()
362
385
  end
363
386
 
387
+ def checkAndSetEjabberdctlQuotedString
388
+ if checkForSimpleSlash
389
+ $checkForSimpleSlash = true
390
+ end
391
+ if checkForDoubleSlash
392
+ $checkForDoubleSlash = true
393
+ end
394
+ $checkEjabberdctlQuotedString = true
395
+ end
396
+
364
397
  def checkForDoubleSlash
365
398
  command = "ejabberdctl send_message_chat example@localhost example@localhost \\'Hello quoted string\\'"
366
399
  if execute_as_sudo
367
400
  command = "sudo " + command
368
401
  end
369
- #puts "Executing " + command
402
+
370
403
  output = %x[#{command}]
371
404
  firstLine = ""
372
405
  lines = output.split("\n")
@@ -414,10 +447,14 @@ def checkForSimpleSlash
414
447
  end
415
448
 
416
449
  def buildQuotedString(msg)
417
- if checkForSimpleSlash
450
+ if !$checkEjabberdctlQuotedString
451
+ checkAndSetEjabberdctlQuotedString
452
+ end
453
+
454
+ if $checkForSimpleSlash
418
455
  return "\'" + msg + "\'"
419
456
  end
420
- if checkForDoubleSlash
457
+ if $checkForDoubleSlash
421
458
  return "\\'" + msg + "\\'"
422
459
  end
423
460
  return msg
@@ -431,7 +468,8 @@ def executeCommand(command)
431
468
  command = buildCommand(command)
432
469
 
433
470
  if $verbose
434
- puts "Executing: " + command
471
+ #Logging...
472
+ #puts "Executing: " + command
435
473
  ejabberdLog("Executing (#{command})")
436
474
  end
437
475
 
@@ -442,15 +480,20 @@ end
442
480
 
443
481
  def buildCommand(command)
444
482
  if execute_as_sudo
445
- command = "sudo -u ejabberd " + command
483
+ command = "sudo -u " + $ejabberd_user + " " + command
446
484
  end
447
485
  return command
448
486
  end
449
487
 
450
488
  def execute_as_sudo
451
- current_user = %x["whoami"].split("\n")[0]
452
489
  sudo_users = getOption("users_require_sudo=")
490
+
491
+ if sudo_users=="all"
492
+ return true
493
+ end
494
+
453
495
  sudo_users_array = sudo_users.split(",")
496
+ current_user = %x["whoami"].split("\n")[0]
454
497
  if sudo_users_array.include?(current_user)
455
498
  return true
456
499
  end
@@ -468,7 +511,7 @@ end
468
511
 
469
512
  #Main thread
470
513
 
471
- log("Init Ejabberd Maintenance script")
514
+ #log("Init Ejabberd Maintenance script")
472
515
 
473
516
  begin
474
517
  if ARGV[0] and PARAMS_FOR_COMMANDS.keys.include?(ARGV[0])