social_stream-presence 0.0.10 → 0.0.12
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.
- data/app/controllers/xmpp_controller.rb +37 -65
- data/ejabberd/ejabberd_scripts/authentication_script +6 -2
- data/ejabberd/ejabberd_scripts/emanagement +18 -14
- data/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
- data/lib/generators/social_stream/presence/templates/initializer.rb +10 -6
- data/lib/social_stream-presence.rb +8 -5
- data/lib/social_stream/presence/models/buddy_manager.rb +13 -44
- data/lib/social_stream/presence/version.rb +1 -1
- data/lib/social_stream/presence/xmpp_server_order.rb +181 -0
- data/lib/tasks/presence/synchronize.rake +5 -112
- metadata +3 -2
@@ -1,9 +1,3 @@
|
|
1
|
-
require 'xmpp4r'
|
2
|
-
require 'xmpp4r/muc'
|
3
|
-
require 'xmpp4r/roster'
|
4
|
-
require 'xmpp4r/client'
|
5
|
-
require 'xmpp4r/message'
|
6
|
-
|
7
1
|
class XmppController < ApplicationController
|
8
2
|
|
9
3
|
#Mapping XMPP Standar Status to Social Stream Chat Status
|
@@ -19,42 +13,6 @@ class XmppController < ApplicationController
|
|
19
13
|
|
20
14
|
|
21
15
|
#API METHODS
|
22
|
-
|
23
|
-
def resetConnection
|
24
|
-
unless authorization
|
25
|
-
render :text => "Authorization error"
|
26
|
-
return
|
27
|
-
end
|
28
|
-
|
29
|
-
users = User.find_all_by_connected(true)
|
30
|
-
|
31
|
-
users.each do |user|
|
32
|
-
user.connected = false
|
33
|
-
user.save!
|
34
|
-
end
|
35
|
-
|
36
|
-
render :text => "Ok"
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
def unsetConecction
|
41
|
-
unless authorization
|
42
|
-
render :text => "Authorization error"
|
43
|
-
return
|
44
|
-
end
|
45
|
-
|
46
|
-
user = User.find_by_slug(params[:name])
|
47
|
-
|
48
|
-
if user && user.connected
|
49
|
-
user.connected = false
|
50
|
-
user.save!
|
51
|
-
render :text => "Ok"
|
52
|
-
return
|
53
|
-
end
|
54
|
-
|
55
|
-
render :text => "User not connected"
|
56
|
-
end
|
57
|
-
|
58
16
|
|
59
17
|
def setConnection
|
60
18
|
unless authorization
|
@@ -76,34 +34,22 @@ class XmppController < ApplicationController
|
|
76
34
|
end
|
77
35
|
|
78
36
|
|
79
|
-
def
|
37
|
+
def unsetConecction
|
80
38
|
unless authorization
|
81
39
|
render :text => "Authorization error"
|
82
40
|
return
|
83
41
|
end
|
84
|
-
|
85
|
-
#Actual connected users
|
86
|
-
user_slugs = params[:name]
|
87
42
|
|
88
|
-
|
89
|
-
users = User.find_all_by_connected(true)
|
90
|
-
|
91
|
-
users.each do |user|
|
92
|
-
if user_slugs.include?(user.slug) == false
|
93
|
-
user.connected = false
|
94
|
-
user.save!
|
95
|
-
end
|
96
|
-
end
|
43
|
+
user = User.find_by_slug(params[:name])
|
97
44
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
45
|
+
if user && user.connected
|
46
|
+
user.connected = false
|
47
|
+
user.save!
|
48
|
+
render :text => "Ok"
|
49
|
+
return
|
104
50
|
end
|
105
51
|
|
106
|
-
render :text => "
|
52
|
+
render :text => "User not connected"
|
107
53
|
end
|
108
54
|
|
109
55
|
|
@@ -146,6 +92,34 @@ class XmppController < ApplicationController
|
|
146
92
|
|
147
93
|
render :text => "User not connected"
|
148
94
|
end
|
95
|
+
|
96
|
+
|
97
|
+
def resetConnection
|
98
|
+
unless authorization
|
99
|
+
render :text => "Authorization error"
|
100
|
+
return
|
101
|
+
end
|
102
|
+
|
103
|
+
SocialStream::Presence::XmppServerOrder::reset_presence
|
104
|
+
|
105
|
+
render :text => "Ok"
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def synchronizePresence
|
110
|
+
unless authorization
|
111
|
+
render :text => "Authorization error"
|
112
|
+
return
|
113
|
+
end
|
114
|
+
|
115
|
+
#Actual connected users
|
116
|
+
user_slugs = params[:name]
|
117
|
+
|
118
|
+
SocialStream::Presence::XmppServerOrder::synchronize_presence_for_slugs(user_slugs)
|
119
|
+
|
120
|
+
render :text => "ok"
|
121
|
+
end
|
122
|
+
|
149
123
|
|
150
124
|
def authorization
|
151
125
|
return params[:password] == SocialStream::Presence.xmpp_server_password
|
@@ -160,8 +134,7 @@ class XmppController < ApplicationController
|
|
160
134
|
render :partial => 'xmpp/chat_off'
|
161
135
|
end
|
162
136
|
end
|
163
|
-
|
164
|
-
|
137
|
+
|
165
138
|
|
166
139
|
|
167
140
|
|
@@ -176,7 +149,6 @@ class XmppController < ApplicationController
|
|
176
149
|
end
|
177
150
|
|
178
151
|
|
179
|
-
|
180
152
|
private
|
181
153
|
|
182
154
|
def setStatus(user,status)
|
@@ -45,8 +45,12 @@ def auth(username, password)
|
|
45
45
|
#end
|
46
46
|
|
47
47
|
#Social Stream password
|
48
|
-
if username == $sslogin
|
49
|
-
|
48
|
+
if username == $sslogin
|
49
|
+
if password == $sspass
|
50
|
+
return true
|
51
|
+
else
|
52
|
+
return false
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
52
56
|
begin
|
@@ -39,7 +39,7 @@ PARAMS_FOR_COMMANDS = {
|
|
39
39
|
'addBuddyToRoster' => 5,
|
40
40
|
'removeRoster' => 1,
|
41
41
|
'getBuddysFromRoster' => 1,
|
42
|
-
'setBidireccionalBuddys' =>
|
42
|
+
'setBidireccionalBuddys' => 6,
|
43
43
|
'help' => 0,
|
44
44
|
'getUserResource' => 1,
|
45
45
|
'sendMessageToUser' => 3,
|
@@ -52,10 +52,10 @@ PARAMS_FOR_COMMANDS = {
|
|
52
52
|
SYNTAX_FOR_COMMANDS = {
|
53
53
|
'getRoster' => "getRoster username",
|
54
54
|
'removeBuddyFromRoster' => "removeBuddyFromRoster username buddy",
|
55
|
-
'addBuddyToRoster' => "addBuddyToRoster
|
55
|
+
'addBuddyToRoster' => "addBuddyToRoster userSid buddySid buddyNick buddyGroup subscription_type",
|
56
56
|
'removeRoster' => "removeRoster username",
|
57
57
|
'getBuddysFromRoster' => "getBuddysFromRoster roster",
|
58
|
-
'setBidireccionalBuddys' => "setBidireccionalBuddys
|
58
|
+
'setBidireccionalBuddys' => "setBidireccionalBuddys userASid userBSid userANick userBNick groupForA groupForB",
|
59
59
|
'getUserResource' => "getUserResource username",
|
60
60
|
'sendMessageToUser' => "sendMessageToUser from_name to_name msg",
|
61
61
|
'sendPresence' => 'sendPresence username show',
|
@@ -88,11 +88,6 @@ def removeBuddyFromRoster(username,buddy)
|
|
88
88
|
%x[#{command}];
|
89
89
|
end
|
90
90
|
|
91
|
-
def addBuddyToRoster(username,buddy,buddyNick,buddyGroup,subscription_type)
|
92
|
-
command = "ejabberdctl add-rosteritem " + username + " " + $domain + " " + buddy + " " + $domain + " \\'" + buddyNick + "\\' " + buddyGroup + " " + subscription_type
|
93
|
-
%x[#{command}];
|
94
|
-
end
|
95
|
-
|
96
91
|
def removeRoster(username)
|
97
92
|
user_roster = getRoster(username);
|
98
93
|
user_buddys = getBuddysFromRoster(user_roster);
|
@@ -117,15 +112,22 @@ def getBuddysFromRoster(roster)
|
|
117
112
|
buddys
|
118
113
|
end
|
119
114
|
|
120
|
-
def setBidireccionalBuddys(
|
121
|
-
|
122
|
-
addBuddyToRoster(
|
123
|
-
addBuddyToRoster(usernameB,usernameA,nickA,"SocialStream","both")
|
124
|
-
#sendPresence(usernameA,"chat")
|
125
|
-
#sendPresence(usernameB,"chat")
|
115
|
+
def setBidireccionalBuddys(userASid,userBSid,userANick,userBNick,groupForA,groupForB)
|
116
|
+
addBuddyToRoster(userASid,userBSid,userBNick,groupForB,"both")
|
117
|
+
addBuddyToRoster(userBSid,userASid,userANick,groupForA,"both")
|
126
118
|
return "Done"
|
127
119
|
end
|
128
120
|
|
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
|
127
|
+
puts command
|
128
|
+
%x[#{command}];
|
129
|
+
end
|
130
|
+
|
129
131
|
def sendStanzaUserMessage(username,msg)
|
130
132
|
resource = getUserResource(username);
|
131
133
|
stanza = "\\<\\'message\\'\\>\\<\\'body\\'\\>\\'" + msg + "\\'\\<\\'/body\\'\\>\\<\\'/message\\'\\>"
|
@@ -226,6 +228,8 @@ begin
|
|
226
228
|
puts send(ARGV[0],ARGV[1],ARGV[2],ARGV[3],ARGV[4])
|
227
229
|
when 6
|
228
230
|
puts send(ARGV[0],ARGV[1],ARGV[2],ARGV[3],ARGV[4],ARGV[5])
|
231
|
+
when 7
|
232
|
+
puts send(ARGV[0],ARGV[1],ARGV[2],ARGV[3],ARGV[4],ARGV[5],ARGV[6])
|
229
233
|
else
|
230
234
|
puts send(ARGV[0],ARGV)
|
231
235
|
end
|
Binary file
|
@@ -3,16 +3,20 @@ 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 Social Stream Rails App Password
|
7
|
-
config.password = "password"
|
8
6
|
#Configures XMPP Server Password
|
9
7
|
config.xmpp_server_password = "password"
|
10
|
-
#Username of the Social Stream Admin sid
|
11
|
-
config.social_stream_presence_username = "social_stream-presence"
|
12
|
-
#Scripts path, only to execute local ejabberd commands
|
13
|
-
config.scripts_path = "/scripts_path"
|
14
8
|
#Remote or local mode
|
15
9
|
config.remote_xmpp_server = false
|
16
10
|
#False to disable Social Stream Presence
|
17
11
|
#config.enable = false
|
12
|
+
|
13
|
+
#Parameters for remote mode
|
14
|
+
#Username of the the Social Stream Admin sid
|
15
|
+
config.social_stream_presence_username = "social_stream-presence"
|
16
|
+
#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"
|
18
22
|
end
|
@@ -3,20 +3,23 @@ require 'social_stream-base'
|
|
3
3
|
module SocialStream
|
4
4
|
module Presence
|
5
5
|
|
6
|
-
autoload :
|
6
|
+
autoload :XmppServerOrder, 'social_stream/presence/xmpp_server_order'
|
7
7
|
|
8
8
|
module Models
|
9
9
|
autoload :BuddyManager, 'social_stream/presence/models/buddy_manager'
|
10
10
|
end
|
11
11
|
|
12
|
-
mattr_accessor :domain
|
13
12
|
mattr_accessor :bosh_service
|
14
|
-
mattr_accessor :password
|
15
13
|
mattr_accessor :xmpp_server_password
|
16
14
|
mattr_accessor :remote_xmpp_server
|
17
|
-
mattr_accessor :scripts_path
|
18
|
-
mattr_accessor :social_stream_presence_username
|
19
15
|
mattr_accessor :enable
|
16
|
+
|
17
|
+
mattr_accessor :domain
|
18
|
+
mattr_accessor :social_stream_presence_username
|
19
|
+
mattr_accessor :password
|
20
|
+
|
21
|
+
mattr_accessor :scripts_path
|
22
|
+
|
20
23
|
@@enable = true
|
21
24
|
@@remote_xmpp_server = false
|
22
25
|
|
@@ -1,9 +1,3 @@
|
|
1
|
-
require 'xmpp4r'
|
2
|
-
require 'xmpp4r/muc'
|
3
|
-
require 'xmpp4r/roster'
|
4
|
-
require 'xmpp4r/client'
|
5
|
-
require 'xmpp4r/message'
|
6
|
-
|
7
1
|
module SocialStream
|
8
2
|
module Presence
|
9
3
|
module Models
|
@@ -25,51 +19,26 @@ module SocialStream
|
|
25
19
|
unless self.receiver.subject_type == "User" and self.sender.subject_type == "User"
|
26
20
|
return
|
27
21
|
end
|
28
|
-
|
22
|
+
|
29
23
|
#XMPP DOMAIN
|
30
24
|
domain = SocialStream::Presence.domain
|
31
|
-
#PASSWORD
|
32
|
-
password= SocialStream::Presence.password
|
33
|
-
#SS Username
|
34
|
-
ss_name = SocialStream::Presence.social_stream_presence_username
|
35
|
-
ss_sid = ss_name + "@" + domain
|
36
|
-
|
37
25
|
user_sid = self.sender.slug + "@" + domain
|
38
26
|
user_name = self.sender.name
|
39
27
|
buddy_sid = self.receiver.slug + "@" + domain
|
40
28
|
buddy_name = self.receiver.name
|
41
29
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
sType = "from"
|
55
|
-
#AddItemToRoster[UserSID,BuddySID,BuddyName,Subscription_type]
|
56
|
-
msg = Jabber::Message::new(ss_sid, "AddItemToRoster&" + user_sid + "&" + buddy_sid + "&" + buddy_name + "&" + sType)
|
57
|
-
else
|
58
|
-
return
|
59
|
-
end
|
60
|
-
|
61
|
-
msg.type=:chat
|
62
|
-
client.send(msg)
|
63
|
-
client.close()
|
64
|
-
|
65
|
-
rescue Exception => e
|
66
|
-
case e
|
67
|
-
when Errno::ECONNREFUSED
|
68
|
-
puts "Connection to XMPP Server refused"
|
69
|
-
else
|
70
|
-
puts "Unknown exception: #{e.to_s}"
|
71
|
-
end
|
72
|
-
end
|
30
|
+
#Check if is a positive and replied tie
|
31
|
+
if self.bidirectional?
|
32
|
+
#Execute setRosterForBidirectionalTie(userASid,userBSid,userANick,userBNick,groupForA,groupForB)
|
33
|
+
SocialStream::Presence::XmppServerOrder::setRosterForBidirectionalTie(user_sid,buddy_sid,user_name,buddy_name,"SocialStream","SocialStream")
|
34
|
+
elsif self.positive?
|
35
|
+
#Case: Possitive tie unidirectional
|
36
|
+
#Execute addBuddyToRoster(userSID,buddySID,buddyNick,buddyGroup,subscription_type)
|
37
|
+
subscription_type = "to"
|
38
|
+
SocialStream::Presence::XmppServerOrder::addBuddyToRoster(user_sid,buddy_sid,buddy_name,"SocialStream",subscription_type)
|
39
|
+
else
|
40
|
+
return
|
41
|
+
end
|
73
42
|
|
74
43
|
end
|
75
44
|
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'xmpp4r'
|
2
|
+
require 'xmpp4r/muc'
|
3
|
+
require 'xmpp4r/roster'
|
4
|
+
require 'xmpp4r/client'
|
5
|
+
require 'xmpp4r/message'
|
6
|
+
|
7
|
+
module SocialStream
|
8
|
+
module Presence
|
9
|
+
class XmppServerOrder
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
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
|
21
|
+
end
|
22
|
+
|
23
|
+
def addBuddyToRoster(userSID,buddySID,buddyNick,buddyGroup,subscription_type)
|
24
|
+
if SocialStream::Presence.remote_xmpp_server
|
25
|
+
puts "Not implemented addBuddyToRoster(userSID,buddySID,buddyNick,buddyGroup,subscription_type) for remote_xmpp_server"
|
26
|
+
return
|
27
|
+
else
|
28
|
+
#SocialStream::Presence.remote_xmpp_server=false
|
29
|
+
executeEmanagementLocalCommand("addBuddyToRoster",[userSID,buddySID,buddyNick,buddyGroup,subscription_type])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def synchronize_presence
|
34
|
+
if SocialStream::Presence.remote_xmpp_server
|
35
|
+
|
36
|
+
begin
|
37
|
+
client = openXmppClientForSocialStreamUser
|
38
|
+
if client
|
39
|
+
sendXmppChatMessage(client,getSocialStreamUserSid,"Synchronize")
|
40
|
+
client.close()
|
41
|
+
return "Ok"
|
42
|
+
else
|
43
|
+
reset_presence
|
44
|
+
return "Reset Connected Users"
|
45
|
+
end
|
46
|
+
rescue
|
47
|
+
puts "Error in SocialStream::Presence::XmppServerOrder::synchronize_presence"
|
48
|
+
end
|
49
|
+
|
50
|
+
else
|
51
|
+
#SocialStream::Presence.remote_xmpp_server=false
|
52
|
+
|
53
|
+
#Get connected users locally
|
54
|
+
users = []
|
55
|
+
output = %x[ejabberdctl connected-users]
|
56
|
+
sessions = output.split("\n")
|
57
|
+
|
58
|
+
sessions.each do |session|
|
59
|
+
users << session.split("@")[0]
|
60
|
+
puts session.split("@")[0]
|
61
|
+
end
|
62
|
+
|
63
|
+
synchronize_presence_for_slugs(users)
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def remove_all_rosters
|
70
|
+
if SocialStream::Presence.remote_xmpp_server
|
71
|
+
puts "Not implemented SocialStream::Presence::XmppServerOrder::remove_all_rosters for remote_xmpp_server"
|
72
|
+
return
|
73
|
+
else
|
74
|
+
#SocialStream::Presence.remote_xmpp_server=false
|
75
|
+
executeEmanagementLocalCommand("removeAllRosters",[])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def synchronize_rosters
|
80
|
+
puts "Removing all rosters"
|
81
|
+
remove_all_rosters
|
82
|
+
puts "Rosters removed"
|
83
|
+
|
84
|
+
puts "Populate rosters"
|
85
|
+
users = User.all
|
86
|
+
checkedUsers = []
|
87
|
+
|
88
|
+
users.each do |user|
|
89
|
+
checkedUsers << user.slug
|
90
|
+
contacts = user.contact_actors(:type=>:user)
|
91
|
+
contacts.each do |contact|
|
92
|
+
unless checkedUsers.include?(contact.slug)
|
93
|
+
domain = SocialStream::Presence.domain
|
94
|
+
user_sid = user.slug + "@" + domain
|
95
|
+
contact_sid = contact.slug + "@" + domain
|
96
|
+
setRosterForBidirectionalTie(user_sid,contact_sid,user.name,contact.name,"SocialStream","SocialStream")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
#Help methods
|
104
|
+
|
105
|
+
def getSocialStreamUserSid
|
106
|
+
#XMPP DOMAIN
|
107
|
+
domain = SocialStream::Presence.domain
|
108
|
+
#SS Username
|
109
|
+
ss_name = SocialStream::Presence.social_stream_presence_username
|
110
|
+
return ss_name + "@" + domain
|
111
|
+
end
|
112
|
+
|
113
|
+
def openXmppClientForSocialStreamUser
|
114
|
+
begin
|
115
|
+
password= SocialStream::Presence.password
|
116
|
+
client = Jabber::Client.new(Jabber::JID.new(getSocialStreamUserSid))
|
117
|
+
client.connect
|
118
|
+
client.auth(password)
|
119
|
+
return client
|
120
|
+
rescue Exception => e
|
121
|
+
case e
|
122
|
+
when Errno::ECONNREFUSED
|
123
|
+
puts "Connection to XMPP Server refused"
|
124
|
+
return nil
|
125
|
+
else
|
126
|
+
puts "Unknown exception: #{e.to_s}"
|
127
|
+
return nil
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def sendXmppChatMessage(client,dest_sid,body)
|
133
|
+
msg = Jabber::Message::new(dest_sid, body)
|
134
|
+
msg.type=:chat
|
135
|
+
client.send(msg)
|
136
|
+
end
|
137
|
+
|
138
|
+
def synchronize_presence_for_slugs(user_slugs)
|
139
|
+
#Check connected users
|
140
|
+
users = User.find_all_by_connected(true)
|
141
|
+
|
142
|
+
users.each do |user|
|
143
|
+
if user_slugs.include?(user.slug) == false
|
144
|
+
user.connected = false
|
145
|
+
user.save!
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
user_slugs.each do |user_slug|
|
150
|
+
u = User.find_by_slug(user_slug)
|
151
|
+
if (u != nil && u.connected == false)
|
152
|
+
u.connected = true
|
153
|
+
u.save!
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def reset_presence
|
159
|
+
users = User.find_all_by_connected(true)
|
160
|
+
|
161
|
+
users.each do |user|
|
162
|
+
user.connected = false
|
163
|
+
user.save!
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def executeEmanagementLocalCommand(order,params)
|
168
|
+
command = SocialStream::Presence.scripts_path + "/emanagement " + order
|
169
|
+
params.each do |param|
|
170
|
+
command = command + " " + param.split(" ")[0]
|
171
|
+
end
|
172
|
+
puts "Executing " + command
|
173
|
+
system command
|
174
|
+
puts "Ok"
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -4,126 +4,19 @@ namespace :presence do
|
|
4
4
|
|
5
5
|
namespace :synchronize do
|
6
6
|
|
7
|
-
desc "Synchronize user presence
|
7
|
+
desc "Synchronize user presence"
|
8
8
|
task :connections => :environment do
|
9
9
|
puts "Starting presence:synchronize:connections"
|
10
|
-
|
11
|
-
|
12
|
-
#XMPP DOMAIN
|
13
|
-
domain = SocialStream::Presence.domain
|
14
|
-
#PASSWORD
|
15
|
-
password= SocialStream::Presence.password
|
16
|
-
#SS Username
|
17
|
-
ss_name = SocialStream::Presence.social_stream_presence_username
|
18
|
-
|
19
|
-
ss_sid = ss_name + "@" + domain
|
20
|
-
client = Jabber::Client.new(Jabber::JID.new(ss_sid))
|
21
|
-
client.connect
|
22
|
-
client.auth(password)
|
23
|
-
|
24
|
-
msg = Jabber::Message::new(ss_sid, "Synchronize")
|
25
|
-
msg.type=:chat
|
26
|
-
client.send(msg)
|
27
|
-
client.close()
|
28
|
-
|
29
|
-
rescue Exception => e
|
30
|
-
case e
|
31
|
-
when Errno::ECONNREFUSED
|
32
|
-
desc "Reset connected users when XMMP Server Down"
|
33
|
-
puts "Connection to XMPP Server refused: Reset Connected Users"
|
34
|
-
users = User.find_all_by_connected(true)
|
35
|
-
users.each do |user|
|
36
|
-
user.connected = false
|
37
|
-
user.save!
|
38
|
-
end
|
39
|
-
else
|
40
|
-
puts "Unknown exception: #{e.to_s}"
|
41
|
-
return
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
puts "Synchronization complete"
|
10
|
+
SocialStream::Presence::XmppServerOrder::synchronize_presence
|
11
|
+
puts "Synchronization complete"
|
46
12
|
end
|
47
13
|
|
48
14
|
desc "Synchronize Xmpp Server database with Social Stream Rails Application database"
|
49
15
|
desc "Remove all rosters and populate rosters from Social Stream data."
|
50
16
|
task :rosters => :environment do
|
51
17
|
puts "Starting presence:synchronize:rosters"
|
52
|
-
|
53
|
-
|
54
|
-
if SocialStream::Presence.remote_xmpp_server
|
55
|
-
|
56
|
-
#XMPP DOMAIN
|
57
|
-
domain = SocialStream::Presence.domain
|
58
|
-
#PASSWORD
|
59
|
-
password= SocialStream::Presence.password
|
60
|
-
#SS Username
|
61
|
-
ss_name = SocialStream::Presence.social_stream_presence_username
|
62
|
-
ss_sid = ss_name + "@" + domain
|
63
|
-
|
64
|
-
puts "Connecting to Xmpp Server"
|
65
|
-
client = Jabber::Client.new(Jabber::JID.new(ss_sid))
|
66
|
-
client.connect
|
67
|
-
puts "Authentication..."
|
68
|
-
client.auth(password)
|
69
|
-
puts "Connected to Xmpp Server"
|
70
|
-
|
71
|
-
puts "Remove all rosters"
|
72
|
-
msg = Jabber::Message::new(ss_sid, "SynchronizeRosters")
|
73
|
-
msg.type=:chat
|
74
|
-
client.send(msg)
|
75
|
-
|
76
|
-
|
77
|
-
puts "Populate rosters"
|
78
|
-
users = User.all
|
79
|
-
checkedUsers = []
|
80
|
-
|
81
|
-
users.each do |user|
|
82
|
-
checkedUsers << user.slug
|
83
|
-
contacts = user.contact_actors(:type=>:user)
|
84
|
-
contacts.each do |contact|
|
85
|
-
unless checkedUsers.include?(contact.slug)
|
86
|
-
user_sid = user.slug + "@" + domain
|
87
|
-
buddy_sid = contact.slug + "@" + domain
|
88
|
-
msg = Jabber::Message::new(ss_sid, "SetRosterForBidirectionalTie&" + user_sid + "&" + buddy_sid + "&" + user.name + "&" + contact.name)
|
89
|
-
msg.type=:chat
|
90
|
-
client.send(msg)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
puts "Synchronization complete"
|
96
|
-
puts "Closing connection"
|
97
|
-
client.close()
|
98
|
-
puts "Connection closing"
|
99
|
-
|
100
|
-
else
|
101
|
-
#SocialStream::Presence.remote_xmpp_server=false
|
102
|
-
|
103
|
-
puts "Removing all rosters"
|
104
|
-
system SocialStream::Presence.scripts_path + "/emanagement removeAllRosters"
|
105
|
-
puts "Rosters removed"
|
106
|
-
|
107
|
-
puts "Populate rosters"
|
108
|
-
users = User.all
|
109
|
-
checkedUsers = []
|
110
|
-
|
111
|
-
users.each do |user|
|
112
|
-
checkedUsers << user.slug
|
113
|
-
contacts = user.contact_actors(:type=>:user)
|
114
|
-
contacts.each do |contact|
|
115
|
-
unless checkedUsers.include?(contact.slug)
|
116
|
-
user_nick = user.name.split(" ")[0]
|
117
|
-
buddy_nick = contact.name.split(" ")[0]
|
118
|
-
command = SocialStream::Presence.scripts_path + "/emanagement setBidireccionalBuddys " + user.slug + " " + contact.slug + " " + user_nick + " " + buddy_nick
|
119
|
-
puts command
|
120
|
-
system command
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
18
|
+
SocialStream::Presence::XmppServerOrder::synchronize_rosters
|
19
|
+
puts "Rosters Synchronization complete"
|
127
20
|
end
|
128
21
|
end
|
129
22
|
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.12
|
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-26 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/social_stream/presence/engine.rb
|
117
117
|
- lib/social_stream/presence/models/buddy_manager.rb
|
118
118
|
- lib/social_stream/presence/version.rb
|
119
|
+
- lib/social_stream/presence/xmpp_server_order.rb
|
119
120
|
- lib/tasks/presence/synchronize.rake
|
120
121
|
- social_stream-presence.gemspec
|
121
122
|
- spec/demo/.gitignore
|