social_stream-presence 0.8.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/chat_persistence.js +25 -26
- data/app/assets/javascripts/chat_window_manager.js +1 -1
- data/app/controllers/xmpp_controller.rb +3 -3
- data/ejabberd/conf/ssconfig_example.cfg +4 -3
- data/ejabberd/ejabberd_files.zip +0 -0
- data/ejabberd/ejabberd_scripts/authentication_script +22 -12
- data/ejabberd/ejabberd_scripts/development_scripts/show_config.sh +9 -10
- data/ejabberd/ejabberd_scripts/emanagement +275 -178
- data/ejabberd/ejabberd_scripts/manageWebDomains +170 -0
- data/ejabberd/ejabberd_scripts/rest_api_client_script +75 -32
- data/ejabberd/ejabberd_scripts/synchronize_presence_script +81 -34
- data/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
- data/ejabberd/mod_sspresence/mod_sspresence.erl +27 -23
- data/lib/generators/social_stream/presence/templates/initializer.rb +1 -1
- data/lib/social_stream/presence/version.rb +1 -1
- data/lib/social_stream/presence/xmpp_server_order.rb +104 -40
- data/lib/tasks/presence/multidomain.rake +45 -0
- data/lib/tasks/presence/synchronize.rake +18 -4
- metadata +6 -26
- data/ejabberd/ejabberd_scripts/reset_connection_script +0 -300
- data/ejabberd/ejabberd_scripts/set_script_header.sh +0 -112
@@ -32,54 +32,53 @@ module SocialStream
|
|
32
32
|
executeEmanagementCommand("removeBuddyFromRoster",[userSid,buddySid])
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
def synchronizePresence
|
35
|
+
|
36
|
+
# Presence synchronization
|
37
|
+
def synchronizePresence(webDomain)
|
38
38
|
if isEjabberdNodeUp
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
if (webDomain=="all")
|
40
|
+
output = executeEmanagementCommand("getConnectedJids",[])
|
41
|
+
else
|
42
|
+
output = executeEmanagementCommand("getConnectedJidsByDomain",[webDomain])
|
43
|
+
end
|
44
|
+
user_jids = output.split("\n")
|
45
|
+
synchronizePresenceForJids(user_jids)
|
42
46
|
else
|
43
47
|
resetPresence
|
44
48
|
return "Xmpp Server Down: Reset Connected Users"
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
def synchronizePresenceForJids(user_jids)
|
53
|
+
domains = getDomainsFromJids(user_jids)
|
54
|
+
domains.each do |domain|
|
55
|
+
user_slugs = getSlugsFromJids(user_jids,domain)
|
56
|
+
synchronizePresenceForSlugs(user_slugs,domain)
|
57
|
+
end
|
51
58
|
end
|
52
|
-
|
53
|
-
|
54
|
-
def synchronizeRosters
|
55
|
-
commands = []
|
56
|
-
|
57
|
-
#"Remove all rosters"
|
58
|
-
commands << buildCommand("emanagement","removeAllRosters",[])
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
users.each do |user|
|
66
|
-
checkedUsers << user.slug
|
67
|
-
contacts = user.contact_actors(:type=>:user)
|
68
|
-
contacts.each do |contact|
|
69
|
-
unless checkedUsers.include?(contact.slug)
|
70
|
-
domain = SocialStream::Presence.domain
|
71
|
-
user_sid = user.slug + "@" + domain
|
72
|
-
contact_sid = contact.slug + "@" + domain
|
73
|
-
commands << buildCommand("emanagement","setBidireccionalBuddys",[user_sid,contact_sid,user.name,contact.name,site_name,site_name])
|
60
|
+
def getSlugsFromJids(user_jids,domain)
|
61
|
+
user_slugs = []
|
62
|
+
user_jids.each do |user_jid|
|
63
|
+
if(user_jid.split("@")[1]==domain)
|
64
|
+
user_slugs << user_jid.split("@")[0]
|
74
65
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
executeCommands(commands)
|
66
|
+
end
|
67
|
+
return user_slugs
|
79
68
|
end
|
80
69
|
|
81
|
-
|
82
|
-
|
70
|
+
def getDomainsFromJids(user_jids)
|
71
|
+
domains = []
|
72
|
+
user_jids.each do |user_jid|
|
73
|
+
domain=user_jid.split("@")[1]
|
74
|
+
if !domains.include?(domain)
|
75
|
+
domains << domain
|
76
|
+
end
|
77
|
+
end
|
78
|
+
return domains
|
79
|
+
end
|
80
|
+
|
81
|
+
def synchronizePresenceForSlugs(user_slugs,domain)
|
83
82
|
|
84
83
|
#Check connected users
|
85
84
|
users = User.find_all_by_connected(true)
|
@@ -101,6 +100,7 @@ module SocialStream
|
|
101
100
|
end
|
102
101
|
|
103
102
|
|
103
|
+
#Reset presence for all domains
|
104
104
|
def resetPresence
|
105
105
|
users = User.find_all_by_connected(true)
|
106
106
|
|
@@ -111,6 +111,40 @@ module SocialStream
|
|
111
111
|
end
|
112
112
|
|
113
113
|
|
114
|
+
|
115
|
+
# Rosters synchronization
|
116
|
+
def removeAllRosters(webDomain)
|
117
|
+
executeEmanagementCommand("removeAllRostersByDomain",[webDomain])
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
def synchronizeRosters(webDomain)
|
122
|
+
commands = []
|
123
|
+
|
124
|
+
#"Remove all rosters"
|
125
|
+
commands << buildCommand("emanagement","removeAllRostersByDomain",[webDomain])
|
126
|
+
|
127
|
+
#"Populate rosters"
|
128
|
+
users = User.all
|
129
|
+
checkedUsers = []
|
130
|
+
site_name = I18n.t('site.name').delete(' ')
|
131
|
+
|
132
|
+
users.each do |user|
|
133
|
+
checkedUsers << user.slug
|
134
|
+
contacts = user.contact_actors(:type=>:user)
|
135
|
+
contacts.each do |contact|
|
136
|
+
unless checkedUsers.include?(contact.slug)
|
137
|
+
user_sid = user.slug + "@" + webDomain
|
138
|
+
contact_sid = contact.slug + "@" + webDomain
|
139
|
+
commands << buildCommand("emanagement","setBidireccionalBuddys",[user_sid,contact_sid,user.name,contact.name,site_name,site_name])
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
executeCommands(commands)
|
145
|
+
end
|
146
|
+
|
147
|
+
|
114
148
|
#Installation methods
|
115
149
|
|
116
150
|
def copyFolderToXmppServer(oPath,dPath)
|
@@ -183,8 +217,8 @@ module SocialStream
|
|
183
217
|
autoconf.push("scripts_path=" + SocialStream::Presence.scripts_path)
|
184
218
|
autoconf.push("ejabberd_password=" + SocialStream::Presence.xmpp_server_password)
|
185
219
|
autoconf.push("secure_rest_api=" + SocialStream::Presence.secure_rest_api.to_s)
|
186
|
-
autoconf.push("server_domain=" + SocialStream::Presence.domain)
|
187
220
|
autoconf.push("cookie_name=" + Rails.application.config.session_options[:key])
|
221
|
+
autoconf.push("web_domains=[" + SocialStream::Presence.config.domain + "]")
|
188
222
|
|
189
223
|
#Param options
|
190
224
|
if options
|
@@ -337,7 +371,7 @@ module SocialStream
|
|
337
371
|
output=""
|
338
372
|
commands.each do |command|
|
339
373
|
response = %x[#{command}]
|
340
|
-
output = output + "\n"
|
374
|
+
output = output + response + "\n";
|
341
375
|
end
|
342
376
|
return output
|
343
377
|
end
|
@@ -354,7 +388,7 @@ module SocialStream
|
|
354
388
|
commands.each do |command|
|
355
389
|
response = session.exec!(command)
|
356
390
|
if response != nil
|
357
|
-
output = output + "\n"
|
391
|
+
output = output + response + "\n";
|
358
392
|
end
|
359
393
|
end
|
360
394
|
end
|
@@ -506,10 +540,40 @@ module SocialStream
|
|
506
540
|
return hash
|
507
541
|
end
|
508
542
|
|
543
|
+
|
544
|
+
|
545
|
+
#Multidomain tasks
|
546
|
+
def addWebDomain(domain,url)
|
547
|
+
commands = []
|
548
|
+
if url
|
549
|
+
commands << buildCommand("manageWebDomains","add",[domain,url])
|
550
|
+
else
|
551
|
+
commands << buildCommand("manageWebDomains","add",[domain])
|
552
|
+
end
|
553
|
+
return executeCommands(commands)
|
554
|
+
end
|
555
|
+
|
556
|
+
def removeWebDomain(domain)
|
557
|
+
commands = []
|
558
|
+
commands << buildCommand("manageWebDomains","remove",[domain])
|
559
|
+
return executeCommands(commands)
|
560
|
+
end
|
561
|
+
|
562
|
+
def updateWebDomain(domain,url)
|
563
|
+
commands = []
|
564
|
+
if url
|
565
|
+
commands << buildCommand("manageWebDomains","update",[domain,url])
|
566
|
+
else
|
567
|
+
commands << buildCommand("manageWebDomains","update",[domain])
|
568
|
+
end
|
569
|
+
return executeCommands(commands)
|
570
|
+
end
|
571
|
+
|
572
|
+
|
509
573
|
#Xmpp client manage methods
|
510
574
|
|
511
575
|
def getSocialStreamUserSid
|
512
|
-
#
|
576
|
+
#WEB DOMAIN
|
513
577
|
domain = SocialStream::Presence.domain
|
514
578
|
#SS Username
|
515
579
|
ss_name = SocialStream::Presence.social_stream_presence_username
|
@@ -0,0 +1,45 @@
|
|
1
|
+
namespace :presence do
|
2
|
+
desc 'Add web domains to Xmpp Server'
|
3
|
+
task :multidomain => [ 'presence:multidomain:add', 'presence:multidomain:remove' ,
|
4
|
+
'presence:multidomain:update']
|
5
|
+
|
6
|
+
namespace :multidomain do
|
7
|
+
|
8
|
+
desc "Add new web domain to XMPP Server"
|
9
|
+
task :add, [:domain, :url] => :environment do |t, args|
|
10
|
+
puts "Starting presence:multidomain:add"
|
11
|
+
unless args[:domain]
|
12
|
+
puts "Please specify a web domain"
|
13
|
+
puts "Syntax: rake presence:multidomain:add[domain,[url]]"
|
14
|
+
return
|
15
|
+
end
|
16
|
+
response = SocialStream::Presence::XmppServerOrder::addWebDomain(args[:domain],args[:url])
|
17
|
+
puts response
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Remove web domain from the XMPP Server"
|
21
|
+
task :remove, [:domain] => :environment do |t, args|
|
22
|
+
puts "Starting presence:multidomain:remove"
|
23
|
+
unless args[:domain]
|
24
|
+
puts "Please specify a web domain"
|
25
|
+
puts "Syntax: rake presence:multidomain:remove[domain]"
|
26
|
+
return
|
27
|
+
end
|
28
|
+
response = SocialStream::Presence::XmppServerOrder::removeWebDomain(args[:domain])
|
29
|
+
puts response
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Update web domain of XMPP Server"
|
33
|
+
task :update, [:domain, :url] => :environment do |t, args|
|
34
|
+
puts "Starting presence:multidomain:update"
|
35
|
+
unless args[:domain]
|
36
|
+
puts "Please specify a web domain"
|
37
|
+
puts "Syntax: rake presence:multidomain:update[domain,[url]]"
|
38
|
+
return
|
39
|
+
end
|
40
|
+
response = SocialStream::Presence::XmppServerOrder::updateWebDomain(args[:domain],args[:url])
|
41
|
+
puts response
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -5,17 +5,31 @@ namespace :presence do
|
|
5
5
|
namespace :synchronize do
|
6
6
|
|
7
7
|
desc "Synchronize user presence"
|
8
|
-
task :connections => :environment do
|
8
|
+
task :connections, [:domain] => :environment do |t, args|
|
9
9
|
puts "Starting presence:synchronize:connections"
|
10
|
-
|
10
|
+
unless args[:domain]
|
11
|
+
puts "No web domain specified"
|
12
|
+
domain = SocialStream::Presence.domain
|
13
|
+
puts "Executing rake presence:synchronize:connections[" + domain + "]"
|
14
|
+
else
|
15
|
+
domain = args[:domain]
|
16
|
+
end
|
17
|
+
SocialStream::Presence::XmppServerOrder::synchronizePresence(domain)
|
11
18
|
puts "Synchronization complete"
|
12
19
|
end
|
13
20
|
|
14
21
|
desc "Synchronize Xmpp Server database with Social Stream Rails Application database"
|
15
22
|
desc "Remove all rosters and populate rosters from Social Stream data."
|
16
|
-
task :rosters => :environment do
|
23
|
+
task :rosters, [:domain] => :environment do |t, args|
|
17
24
|
puts "Starting presence:synchronize:rosters"
|
18
|
-
|
25
|
+
unless args[:domain]
|
26
|
+
puts "No web domain specified"
|
27
|
+
domain = SocialStream::Presence.domain
|
28
|
+
puts "Executing rake presence:synchronize:rosters[" + domain + "]"
|
29
|
+
else
|
30
|
+
domain = args[:domain]
|
31
|
+
end
|
32
|
+
SocialStream::Presence::XmppServerOrder::synchronizeRosters(domain)
|
19
33
|
puts "Rosters Synchronization complete"
|
20
34
|
end
|
21
35
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_stream-presence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 8
|
8
|
-
- 0
|
9
|
-
version: 0.8.0
|
4
|
+
prerelease:
|
5
|
+
version: 0.8.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Aldo Gordillo
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2012-02-
|
13
|
+
date: 2012-02-27 00:00:00 +01:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,10 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ~>
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
- 16
|
31
|
-
- 2
|
32
24
|
version: 0.16.2
|
33
25
|
type: :runtime
|
34
26
|
version_requirements: *id001
|
@@ -40,8 +32,6 @@ dependencies:
|
|
40
32
|
requirements:
|
41
33
|
- - ">="
|
42
34
|
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 0
|
45
35
|
version: "0"
|
46
36
|
type: :runtime
|
47
37
|
version_requirements: *id002
|
@@ -53,8 +43,6 @@ dependencies:
|
|
53
43
|
requirements:
|
54
44
|
- - ">="
|
55
45
|
- !ruby/object:Gem::Version
|
56
|
-
segments:
|
57
|
-
- 0
|
58
46
|
version: "0"
|
59
47
|
type: :runtime
|
60
48
|
version_requirements: *id003
|
@@ -66,8 +54,6 @@ dependencies:
|
|
66
54
|
requirements:
|
67
55
|
- - ">="
|
68
56
|
- !ruby/object:Gem::Version
|
69
|
-
segments:
|
70
|
-
- 0
|
71
57
|
version: "0"
|
72
58
|
type: :runtime
|
73
59
|
version_requirements: *id004
|
@@ -79,8 +65,6 @@ dependencies:
|
|
79
65
|
requirements:
|
80
66
|
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
segments:
|
83
|
-
- 0
|
84
68
|
version: "0"
|
85
69
|
type: :development
|
86
70
|
version_requirements: *id005
|
@@ -157,9 +141,8 @@ files:
|
|
157
141
|
- ejabberd/ejabberd_scripts/development_scripts/start_ejabberd.sh
|
158
142
|
- ejabberd/ejabberd_scripts/development_scripts/stop_ejabberd.sh
|
159
143
|
- ejabberd/ejabberd_scripts/emanagement
|
160
|
-
- ejabberd/ejabberd_scripts/
|
144
|
+
- ejabberd/ejabberd_scripts/manageWebDomains
|
161
145
|
- ejabberd/ejabberd_scripts/rest_api_client_script
|
162
|
-
- ejabberd/ejabberd_scripts/set_script_header.sh
|
163
146
|
- ejabberd/ejabberd_scripts/synchronize_presence_script
|
164
147
|
- ejabberd/installer.sh
|
165
148
|
- ejabberd/mod_admin_extra/mod_admin_extra.beam
|
@@ -181,6 +164,7 @@ files:
|
|
181
164
|
- lib/social_stream/presence/xmpp_server_order.rb
|
182
165
|
- lib/social_stream/views/settings/presence.rb
|
183
166
|
- lib/tasks/presence/installer.rake
|
167
|
+
- lib/tasks/presence/multidomain.rake
|
184
168
|
- lib/tasks/presence/synchronize.rake
|
185
169
|
- social_stream-presence.gemspec
|
186
170
|
- spec/demo/.gitignore
|
@@ -254,21 +238,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
238
|
requirements:
|
255
239
|
- - ">="
|
256
240
|
- !ruby/object:Gem::Version
|
257
|
-
segments:
|
258
|
-
- 0
|
259
241
|
version: "0"
|
260
242
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
261
243
|
none: false
|
262
244
|
requirements:
|
263
245
|
- - ">="
|
264
246
|
- !ruby/object:Gem::Version
|
265
|
-
segments:
|
266
|
-
- 0
|
267
247
|
version: "0"
|
268
248
|
requirements: []
|
269
249
|
|
270
250
|
rubyforge_project: social_stream-presence
|
271
|
-
rubygems_version: 1.
|
251
|
+
rubygems_version: 1.6.1
|
272
252
|
signing_key:
|
273
253
|
specification_version: 3
|
274
254
|
summary: Presence capabilities for Social Stream, the core for building social network websites
|
@@ -1,300 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#Rest Api Client Script
|
3
|
-
#Version: 13-12-2011
|
4
|
-
#@author Aldo
|
5
|
-
|
6
|
-
|
7
|
-
require 'logger'
|
8
|
-
require 'rest_client'
|
9
|
-
|
10
|
-
|
11
|
-
path = "/var/log/ejabberd/scripts.log"
|
12
|
-
file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)
|
13
|
-
file.sync = true
|
14
|
-
$logger = Logger.new(file)
|
15
|
-
$logger.level = Logger::DEBUG
|
16
|
-
|
17
|
-
def getOption(option)
|
18
|
-
File.open('/etc/ejabberd/ssconfig.cfg', 'r') do |f1|
|
19
|
-
while line = f1.gets
|
20
|
-
line = line.gsub(/\n/,'')
|
21
|
-
if line.match(/^#/)
|
22
|
-
#Comments
|
23
|
-
elsif line.match(/^#{option}/)
|
24
|
-
return line.gsub(/#{option}/,'')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
return "Undefined"
|
29
|
-
end
|
30
|
-
|
31
|
-
#Constants
|
32
|
-
$secure_rest_api = getOption("secure_rest_api=")
|
33
|
-
$pass = getOption("ejabberd_password=")
|
34
|
-
$scripts_path = getOption("scripts_path=")
|
35
|
-
$script_title = "Reset Connection Script"
|
36
|
-
|
37
|
-
|
38
|
-
def log(title,text)
|
39
|
-
$logger.info title + ": " + text
|
40
|
-
end
|
41
|
-
|
42
|
-
def getMethodName
|
43
|
-
caller[0] =~ /`(.*?)'/
|
44
|
-
$1
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
#####################
|
49
|
-
##### Example #####
|
50
|
-
#####################
|
51
|
-
#def myHook(param1,param2)
|
52
|
-
# log(getMethodName,"(My message: #{param1},#{param2})")
|
53
|
-
# url = "http://" + getOption("web_domain=") + "/xmpp/hookRoute"
|
54
|
-
|
55
|
-
# params = {}
|
56
|
-
# encrypted_params = {}
|
57
|
-
# #Add params to sent in clear
|
58
|
-
# params[:param1_in_server]=param1
|
59
|
-
# #Add params to sent cipher
|
60
|
-
# encrypted_params[:param2_in_server]=param2
|
61
|
-
|
62
|
-
# return [getMethodName,generic_api_call(url,params,encrypted_params)]
|
63
|
-
#end
|
64
|
-
|
65
|
-
def setConnection(username)
|
66
|
-
log($script_title,"#{getMethodName}(#{username})")
|
67
|
-
url = "http://" + getOption("web_domain=") + "/xmpp/setConnection"
|
68
|
-
|
69
|
-
params = {}
|
70
|
-
encrypted_params = {}
|
71
|
-
encrypted_params[:name]=username
|
72
|
-
|
73
|
-
return [getMethodName,generic_api_call(url,params,encrypted_params)]
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
def unsetConnection(username)
|
78
|
-
log($script_title,"#{getMethodName}(#{username})")
|
79
|
-
url = "http://" + getOption("web_domain=") + "/xmpp/unsetConnection"
|
80
|
-
|
81
|
-
params = {}
|
82
|
-
encrypted_params = {}
|
83
|
-
encrypted_params[:name]=username
|
84
|
-
|
85
|
-
return [getMethodName,generic_api_call(url,params,encrypted_params)]
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
def setPresence(username,status)
|
90
|
-
log($script_title,"#{getMethodName}(#{username},#{status})")
|
91
|
-
url = "http://" + getOption("web_domain=") + "/xmpp/setPresence"
|
92
|
-
|
93
|
-
params = {}
|
94
|
-
encrypted_params = {}
|
95
|
-
encrypted_params[:name]=username
|
96
|
-
encrypted_params[:status]=status
|
97
|
-
|
98
|
-
return [getMethodName,generic_api_call(url,params,encrypted_params)]
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
def unsetPresence(username)
|
103
|
-
log($script_title,"#{getMethodName}(#{username})")
|
104
|
-
url = "http://" + getOption("web_domain=") + "/xmpp/unsetPresence"
|
105
|
-
|
106
|
-
params = {}
|
107
|
-
encrypted_params = {}
|
108
|
-
encrypted_params[:name]=username
|
109
|
-
|
110
|
-
return [getMethodName,generic_api_call(url,params,encrypted_params)]
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
def resetConnection()
|
115
|
-
log($script_title,"Call #{getMethodName}()")
|
116
|
-
url = "http://" + getOption("web_domain=") + "/xmpp/resetConnection"
|
117
|
-
|
118
|
-
params = {}
|
119
|
-
encrypted_params = {}
|
120
|
-
|
121
|
-
return [getMethodName,generic_api_call(url,params,encrypted_params)]
|
122
|
-
end
|
123
|
-
|
124
|
-
|
125
|
-
def synchronize()
|
126
|
-
log($script_title,"Call #{getMethodName}()")
|
127
|
-
url = "http://" + getOption("web_domain=") + "/xmpp/synchronizePresence"
|
128
|
-
|
129
|
-
|
130
|
-
#Get connected users using Emanagement
|
131
|
-
users = []
|
132
|
-
command = $scripts_path + "/emanagement getConnectedUsers"
|
133
|
-
output = %x[#{command}]
|
134
|
-
sessions = output.split("\n")
|
135
|
-
|
136
|
-
sessions.each do |session|
|
137
|
-
users << session.split("@")[0]
|
138
|
-
end
|
139
|
-
#Finish
|
140
|
-
|
141
|
-
|
142
|
-
#In this cases users always will be sent in clear (not cipher)
|
143
|
-
#(Too much data to cipher)
|
144
|
-
#Anyway, we must to build the hash to pass the authentication
|
145
|
-
params = {}
|
146
|
-
encrypted_params = {}
|
147
|
-
params[:name]=users.join(",")
|
148
|
-
|
149
|
-
return [getMethodName,generic_api_call(url,params,encrypted_params)]
|
150
|
-
end
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
#Params must include the password and all the parameters to be sent in clear.
|
155
|
-
#Anyway, If "secure_rest_api" is disable, encrypted_params will be send in clear.
|
156
|
-
def generic_api_call(url,params,encrypted_params)
|
157
|
-
|
158
|
-
begin
|
159
|
-
unless params
|
160
|
-
params = {}
|
161
|
-
end
|
162
|
-
|
163
|
-
unless encrypted_params
|
164
|
-
encrypted_params = {}
|
165
|
-
end
|
166
|
-
|
167
|
-
params[:password]=$pass
|
168
|
-
|
169
|
-
response=sendHttpRequest(url,params,encrypted_params)
|
170
|
-
puts response.body
|
171
|
-
|
172
|
-
if response.body.include?("Ok")
|
173
|
-
return true
|
174
|
-
else
|
175
|
-
return false
|
176
|
-
end
|
177
|
-
|
178
|
-
rescue => e
|
179
|
-
log($script_title,"#{e.class.name}: #{e.message}")
|
180
|
-
puts("#{e.class.name}: #{e.message}")
|
181
|
-
return false
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
|
186
|
-
#Send HTTP Request to Social Stream Presence API
|
187
|
-
def sendHttpRequest(url,params,encrypted_params)
|
188
|
-
|
189
|
-
unless params[:password]
|
190
|
-
return "params[:password] required in sendHttpRequest";
|
191
|
-
end
|
192
|
-
|
193
|
-
|
194
|
-
if $secure_rest_api == "true"
|
195
|
-
#Require libraries
|
196
|
-
require 'openssl'
|
197
|
-
|
198
|
-
xmpp_private_key_path = $scripts_path + "/rsa_keys/xmpp_rsa_key_private.pem";
|
199
|
-
web_public_key_path = $scripts_path + "/rsa_keys/web_rsa_key_public.pem";
|
200
|
-
xmpp_private_key = OpenSSL::PKey::RSA.new(File.read(xmpp_private_key_path))
|
201
|
-
web_public_key = OpenSSL::PKey::RSA.new(File.read(web_public_key_path))
|
202
|
-
|
203
|
-
request_params = {};
|
204
|
-
|
205
|
-
#Copy non encypted params
|
206
|
-
params.each do |key,value|
|
207
|
-
unless key.to_s == "password"
|
208
|
-
request_params[key] = value
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
#Include encrypted params
|
213
|
-
if encrypted_params and encrypted_params.empty? == false
|
214
|
-
request_params[:encrypted_params] = web_public_key.public_encrypt(encrypted_params.to_s)
|
215
|
-
end
|
216
|
-
|
217
|
-
#Generating stamp
|
218
|
-
#1 Get constant password
|
219
|
-
password = params[:password];
|
220
|
-
#2 Generating timestamp
|
221
|
-
timestamp = Time.now.utc.to_s
|
222
|
-
#3 Calculating Hash
|
223
|
-
hash = calculateHash(request_params)
|
224
|
-
|
225
|
-
#Add cipher stamp to the request
|
226
|
-
request_params[:password] = xmpp_private_key.private_encrypt(password+"#####"+timestamp+"#####"+hash)
|
227
|
-
|
228
|
-
#Replace previous params
|
229
|
-
params = request_params
|
230
|
-
else
|
231
|
-
#Non secure mode: send encrypted params in clear
|
232
|
-
if encrypted_params
|
233
|
-
encrypted_params.each do |key,value|
|
234
|
-
params[key] = value
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
response = RestClient.get url, :params => params
|
240
|
-
return response
|
241
|
-
end
|
242
|
-
|
243
|
-
|
244
|
-
def calculateHash(request_params)
|
245
|
-
require 'digest/md5'
|
246
|
-
|
247
|
-
unless request_params
|
248
|
-
request_params = {};
|
249
|
-
end
|
250
|
-
|
251
|
-
hash = "";
|
252
|
-
request_params.each do |key,value|
|
253
|
-
hash = hash + key.to_s + value.to_s
|
254
|
-
end
|
255
|
-
return Digest::MD5.hexdigest(hash)
|
256
|
-
end
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
def invokeApiCall(method,args)
|
262
|
-
length = args.length;
|
263
|
-
case length
|
264
|
-
when 0
|
265
|
-
return send(method)
|
266
|
-
when 1
|
267
|
-
return send(method,args[0])
|
268
|
-
when 2
|
269
|
-
return send(method,args[0],args[1])
|
270
|
-
when 3
|
271
|
-
return send(method,args[0],args[1],args[2])
|
272
|
-
when 4
|
273
|
-
return send(method,args[0],args[1],args[2],args[3])
|
274
|
-
else
|
275
|
-
return send(method,args)
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
|
280
|
-
#Main Program
|
281
|
-
|
282
|
-
begin
|
283
|
-
|
284
|
-
args = []
|
285
|
-
method = "resetConnection";
|
286
|
-
|
287
|
-
if (response = invokeApiCall(method, args) and response[1])
|
288
|
-
puts $script_title + ": #{response[0]} [OK]"
|
289
|
-
log( $script_title , "#{response[0]} [OK]" )
|
290
|
-
else
|
291
|
-
puts $script_title + ": #{response[0]} [FAIL]"
|
292
|
-
log( $script_title , "#{response[0]} [FAIL]" )
|
293
|
-
end
|
294
|
-
|
295
|
-
rescue => e
|
296
|
-
log($script_title,"#{e.class.name}: #{e.message}")
|
297
|
-
puts("#{e.class.name}: #{e.message}")
|
298
|
-
exit 1
|
299
|
-
end
|
300
|
-
|