social_stream-presence 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -100,7 +100,7 @@ class XmppController < ApplicationController
100
100
  return
101
101
  end
102
102
 
103
- SocialStream::Presence::XmppServerOrder::reset_presence
103
+ SocialStream::Presence::XmppServerOrder::resetPresence
104
104
 
105
105
  render :text => "Ok"
106
106
  end
@@ -115,7 +115,7 @@ class XmppController < ApplicationController
115
115
  #Actual connected users
116
116
  user_slugs = params[:name]
117
117
 
118
- SocialStream::Presence::XmppServerOrder::synchronize_presence_for_slugs(user_slugs)
118
+ SocialStream::Presence::XmppServerOrder::synchronizePresenceForSlugs(user_slugs)
119
119
 
120
120
  render :text => "ok"
121
121
  end
@@ -125,10 +125,6 @@ class XmppController < ApplicationController
125
125
  return params[:password] == SocialStream::Presence.xmpp_server_password
126
126
  end
127
127
 
128
- def chatAuthWithCookie
129
- cookie = params[:cookie]
130
- render :text => "Ok"
131
- end
132
128
 
133
129
  def chatWindow
134
130
  if (current_user) and (current_user.status != 'disable') and (params[:userConnected]=="true")
@@ -9,16 +9,21 @@ SocialStream::Presence.setup do |config|
9
9
  config.xmpp_server_password = "password"
10
10
  #Remote or local mode
11
11
  config.remote_xmpp_server = false
12
+ #Scripts path to execute ejabberd scripts: local or remote
13
+ config.scripts_path = "/scripts_path"
12
14
  #False to disable Social Stream Presence
13
15
  #config.enable = false
14
16
 
15
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
16
24
  #Username of the the Social Stream Admin sid
17
25
  config.social_stream_presence_username = "social_stream-presence"
18
26
  #Configures Social Stream Rails App Password
19
- config.password = "password"
20
-
21
- #Parameters for local mode
22
- #Scripts path to execute local ejabberd commands
23
- config.scripts_path = "/scripts_path"
24
- end
27
+ config.password = "password"
28
+
29
+ end
@@ -14,13 +14,16 @@ module SocialStream
14
14
  mattr_accessor :auth_method
15
15
  mattr_accessor :xmpp_server_password
16
16
  mattr_accessor :remote_xmpp_server
17
+ mattr_accessor :scripts_path
17
18
  mattr_accessor :enable
18
19
 
20
+ mattr_accessor :ssh_domain
21
+ mattr_accessor :ssh_user
22
+ mattr_accessor :ssh_password
23
+
19
24
  mattr_accessor :social_stream_presence_username
20
25
  mattr_accessor :password
21
26
 
22
- mattr_accessor :scripts_path
23
-
24
27
  @@auth_method = "cookie"
25
28
  @@remote_xmpp_server = false
26
29
  @@enable = true
@@ -1,5 +1,5 @@
1
1
  module Socialstream
2
2
  module Presence
3
- VERSION = "0.0.17"
3
+ VERSION = "0.0.18"
4
4
  end
5
5
  end
@@ -3,55 +3,31 @@ 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
14
  def setRosterForBidirectionalTie(userASid,userBSid,userANick,userBNick,groupForA,groupForB)
15
- if SocialStream::Presence.remote_xmpp_server
16
- puts "Not implemented setRosterForBidirectionalTie(userASid,userBSid,userANick,userBNick,groupForA,groupForB) for remote_xmpp_server"
17
- return
18
- else
19
- #SocialStream::Presence.remote_xmpp_server=false
20
- executeEmanagementLocalCommand("setBidireccionalBuddys",[userASid,userBSid,userANick,userBNick,groupForA,groupForB])
21
- end
15
+ executeEmanagementCommand("setBidireccionalBuddys",[userASid,userBSid,userANick,userBNick,groupForA,groupForB])
22
16
  end
23
17
 
24
18
 
25
19
  def unsetRosterForBidirectionalTie(userSid,oldfriendSid,oldfriendNick,oldfriendGroup)
26
- if SocialStream::Presence.remote_xmpp_server
27
- puts "Not implemented unsetRosterForBidirectionalTie(user_sid,oldfriend_sid,oldfriendNick,oldfriendGroup) for remote_xmpp_server"
28
- return
29
- else
30
- #SocialStream::Presence.remote_xmpp_server=false
31
- executeEmanagementLocalCommand("unsetBidireccionalBuddys",[userSid,oldfriendSid,oldfriendNick,oldfriendGroup])
32
- end
20
+ executeEmanagementCommand("unsetBidireccionalBuddys",[userSid,oldfriendSid,oldfriendNick,oldfriendGroup])
33
21
  end
34
22
 
35
23
 
36
24
  def addBuddyToRoster(userSid,buddySid,buddyNick,buddyGroup,subscription_type)
37
- if SocialStream::Presence.remote_xmpp_server
38
- puts "Not implemented addBuddyToRoster(userSID,buddySID,buddyNick,buddyGroup,subscription_type) for remote_xmpp_server"
39
- return
40
- else
41
- #SocialStream::Presence.remote_xmpp_server=false
42
- executeEmanagementLocalCommand("addBuddyToRoster",[userSid,buddySid,buddyNick,buddyGroup,subscription_type])
43
- end
25
+ executeEmanagementCommand("addBuddyToRoster",[userSid,buddySid,buddyNick,buddyGroup,subscription_type])
44
26
  end
45
27
 
46
28
 
47
29
  def removeBuddyFromRoster(userSid,buddySid)
48
- if SocialStream::Presence.remote_xmpp_server
49
- puts "Not implemented removeBuddyFromRoster(userSid,buddySid) for remote_xmpp_server"
50
- return
51
- else
52
- #SocialStream::Presence.remote_xmpp_server=false
53
- executeEmanagementLocalCommand("removeBuddyFromRoster",[userSid,buddySid])
54
- end
30
+ executeEmanagementCommand("removeBuddyFromRoster",[userSid,buddySid])
55
31
  end
56
32
 
57
33
 
@@ -62,6 +38,10 @@ module SocialStream
62
38
  return
63
39
  end
64
40
 
41
+ unless contact.receiver and contact.sender
42
+ return
43
+ end
44
+
65
45
  unless contact.receiver.subject_type == "User" and contact.sender.subject_type == "User"
66
46
  return
67
47
  end
@@ -78,77 +58,56 @@ module SocialStream
78
58
  if contact.sender.contact_actors(:type=>:user).include?(contact.receiver)
79
59
  #Bidirectional contacts
80
60
  #Execute unsetRosterForBidirectionalTie(user_sid,oldfriend_sid,oldfriendNick,oldfriendGroup)
81
- SocialStream::Presence::XmppServerOrder::unsetRosterForBidirectionalTie(buddy_sid,user_sid,user_name,"SocialStream")
61
+ unsetRosterForBidirectionalTie(buddy_sid,user_sid,user_name,"SocialStream")
82
62
  elsif contact.sender.contact_actors(:type=>:user, :direction=>:sent).include?(contact.receiver)
83
63
  #Unidirectional contacts
84
- SocialStream::Presence::XmppServerOrder::removeBuddyFromRoster(user_sid,buddy_sid)
64
+ removeBuddyFromRoster(user_sid,buddy_sid)
85
65
  end
86
66
 
87
67
  end
88
68
 
89
69
 
90
- def synchronize_presence
91
- if SocialStream::Presence.remote_xmpp_server
92
-
93
- begin
94
- client = openXmppClientForSocialStreamUser
95
- if client
96
- sendXmppChatMessage(client,getSocialStreamUserSid,"Synchronize")
97
- client.close()
98
- return "Ok"
99
- else
100
- reset_presence
101
- return "Reset Connected Users"
102
- end
103
- rescue
104
- puts "Error in SocialStream::Presence::XmppServerOrder::synchronize_presence"
105
- end
106
-
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)
107
80
  else
108
81
  #SocialStream::Presence.remote_xmpp_server=false
109
82
 
110
- #Get connected users locally
111
- output = executeEmanagementLocalCommand("isEjabberdNodeStarted",[])
112
- nodeUp = output.split("\n")[3]
113
-
114
- if nodeUp and nodeUp.strip() == "true"
115
- users = []
116
- output = %x[ejabberdctl connected-users]
117
- sessions = output.split("\n")
118
-
119
- sessions.each do |session|
120
- users << session.split("@")[0]
121
- puts session.split("@")[0]
122
- end
123
-
124
- synchronize_presence_for_slugs(users)
125
-
126
- else
127
- reset_presence
128
- 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]
129
91
  end
130
92
 
93
+ synchronizePresenceForSlugs(users)
94
+
131
95
  end
132
96
  end
133
97
 
134
98
 
135
- def remove_all_rosters
136
- if SocialStream::Presence.remote_xmpp_server
137
- puts "Not implemented SocialStream::Presence::XmppServerOrder::remove_all_rosters for remote_xmpp_server"
138
- return
139
- else
140
- #SocialStream::Presence.remote_xmpp_server=false
141
- executeEmanagementLocalCommand("removeAllRosters",[])
142
- end
99
+ def removeAllRosters
100
+ executeEmanagementCommand("removeAllRosters",[])
143
101
  end
144
102
 
145
103
 
146
- def synchronize_rosters
147
- puts "Removing all rosters"
148
- remove_all_rosters
149
- puts "Rosters removed"
150
-
151
- puts "Populate rosters"
104
+ def synchronizeRosters
105
+ commands = []
106
+
107
+ #"Remove all rosters"
108
+ commands << buildCommand("emanagement","removeAllRosters",[])
109
+
110
+ #"Populate rosters"
152
111
  users = User.all
153
112
  checkedUsers = []
154
113
 
@@ -159,54 +118,17 @@ module SocialStream
159
118
  unless checkedUsers.include?(contact.slug)
160
119
  domain = SocialStream::Presence.domain
161
120
  user_sid = user.slug + "@" + domain
162
- contact_sid = contact.slug + "@" + domain
163
- 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"])
164
123
  end
165
124
  end
166
125
  end
126
+
127
+ executeCommands(commands)
167
128
  end
168
129
 
169
-
170
-
171
- #Help methods
172
-
173
- def getSocialStreamUserSid
174
- #XMPP DOMAIN
175
- domain = SocialStream::Presence.domain
176
- #SS Username
177
- ss_name = SocialStream::Presence.social_stream_presence_username
178
- return ss_name + "@" + domain
179
- end
180
-
181
-
182
- def openXmppClientForSocialStreamUser
183
- begin
184
- password= SocialStream::Presence.password
185
- client = Jabber::Client.new(Jabber::JID.new(getSocialStreamUserSid))
186
- client.connect
187
- client.auth(password)
188
- return client
189
- rescue Exception => e
190
- case e
191
- when Errno::ECONNREFUSED
192
- puts "Connection to XMPP Server refused"
193
- return nil
194
- else
195
- puts "Unknown exception: #{e.to_s}"
196
- return nil
197
- end
198
- end
199
- end
200
-
201
-
202
- def sendXmppChatMessage(client,dest_sid,body)
203
- msg = Jabber::Message::new(dest_sid, body)
204
- msg.type=:chat
205
- client.send(msg)
206
- end
207
-
208
-
209
- def synchronize_presence_for_slugs(user_slugs)
130
+
131
+ def synchronizePresenceForSlugs(user_slugs)
210
132
  #Check connected users
211
133
  users = User.find_all_by_connected(true)
212
134
 
@@ -227,7 +149,7 @@ module SocialStream
227
149
  end
228
150
 
229
151
 
230
- def reset_presence
152
+ def resetPresence
231
153
  users = User.find_all_by_connected(true)
232
154
 
233
155
  users.each do |user|
@@ -237,17 +159,123 @@ module SocialStream
237
159
  end
238
160
 
239
161
 
240
- def executeEmanagementLocalCommand(order,params)
241
- command = SocialStream::Presence.scripts_path + "/emanagement " + order
162
+
163
+ #Execution commands manage
164
+
165
+ def buildCommand(script,order,params)
166
+ command = SocialStream::Presence.scripts_path + "/" + script + " " + order
242
167
  params.each do |param|
243
168
  command = command + " " + param.split(" ")[0]
244
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)
245
179
  puts "Executing " + command
246
- 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
186
+ return output
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
247
213
  return output
248
214
  end
249
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
+
250
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
+
251
279
  end
252
280
  end
253
281
  end
@@ -7,7 +7,7 @@ namespace :presence do
7
7
  desc "Synchronize user presence"
8
8
  task :connections => :environment do
9
9
  puts "Starting presence:synchronize:connections"
10
- SocialStream::Presence::XmppServerOrder::synchronize_presence
10
+ SocialStream::Presence::XmppServerOrder::synchronizePresence
11
11
  puts "Synchronization complete"
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ namespace :presence do
15
15
  desc "Remove all rosters and populate rosters from Social Stream data."
16
16
  task :rosters => :environment do
17
17
  puts "Starting presence:synchronize:rosters"
18
- SocialStream::Presence::XmppServerOrder::synchronize_rosters
18
+ SocialStream::Presence::XmppServerOrder::synchronizeRosters
19
19
  puts "Rosters Synchronization complete"
20
20
  end
21
21
  end
@@ -22,6 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.add_runtime_dependency('social_stream-base','~> 0.9.18')
23
23
 
24
24
  s.add_runtime_dependency "xmpp4r"
25
+
26
+ s.add_runtime_dependency "net-ssh"
25
27
 
26
28
  s.add_development_dependency "ruby-debug19"
27
29
 
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.17
5
+ version: 0.0.18
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-11-02 00:00:00 +01:00
13
+ date: 2011-11-04 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -36,7 +36,7 @@ dependencies:
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: ruby-debug19
39
+ name: net-ssh
40
40
  prerelease: false
41
41
  requirement: &id003 !ruby/object:Gem::Requirement
42
42
  none: false
@@ -44,8 +44,19 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: "0"
47
- type: :development
47
+ type: :runtime
48
48
  version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: ruby-debug19
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id004
49
60
  description: Social Stream is a Ruby on Rails engine providing your application with social networking features and activity streams.
50
61
  email:
51
62
  - iamchrono@gmail.com