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.
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ####################################
4
+ #WebDomain script
5
+ #Add or remove web domains server by ejabberd
6
+ #@author Aldo Gordillo < agordillos@gmail.com >
7
+ #@version 1.0 - 27-2-2012
8
+ ####################################
9
+
10
+
11
+ require 'logger'
12
+
13
+ path = "/var/log/ejabberd/scripts.log"
14
+ file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)
15
+ file.sync = true
16
+ $logger = Logger.new(file)
17
+ $logger.level = Logger::DEBUG
18
+ def log(text)
19
+ $logger.info "SetWebDomain Script: " + text
20
+ end
21
+
22
+ $debug = true
23
+
24
+ #Config files
25
+ if($debug)
26
+ $ssconfig = '/etc/ejabberd/test/ssconfig.cfg'
27
+ $ejabberd = '/etc/ejabberd/test/ejabberd.cfg'
28
+ else
29
+ $ssconfig = '/etc/ejabberd/ssconfig.cfg'
30
+ $ejabberd = '/etc/ejabberd/ejabberd.cfg'
31
+ end
32
+
33
+ $domain_not_exists = "Domain don't exists"
34
+ $domain_exists = "Domain already exists"
35
+ $done = "Done"
36
+
37
+ def getOptionFromSSConfig(option)
38
+ File.open($ssconfig, 'r') do |f1|
39
+ while line = f1.gets
40
+ line = line.gsub(/\n/,'')
41
+ if line.match(/^#/)
42
+ #Comments
43
+ elsif line.match(/^#{option}/)
44
+ return line.gsub(/#{option}/,'')
45
+ end
46
+ end
47
+ end
48
+ return "Undefined"
49
+ end
50
+
51
+ def getWebDomains()
52
+ begin
53
+ web_domains = getOptionFromSSConfig("web_domains=");
54
+ #web_domains=["domain1","domain2"]
55
+ return getElementsFromStringArray(web_domains);
56
+ rescue Exception=>e
57
+ return [""]
58
+ end
59
+ end
60
+
61
+ def getElementsFromStringArray(stringArray)
62
+ stringArray=stringArray[1,stringArray.length-2]
63
+ return stringArray.split(",")
64
+ end
65
+
66
+ def getSSConfigStringFromDomainsArray(domainsArray)
67
+ return "[" + domainsArray.join(",") + "]"
68
+ end
69
+
70
+ def getEjabberdStringFromDomainsArray(domainsArray)
71
+ newDomains=[]
72
+ domainsArray.each do |domain|
73
+ newDomains << "\"" + domain + "\""
74
+ end
75
+ return "{hosts, [" + newDomains.join(" , ") + "]}."
76
+ end
77
+
78
+
79
+ #Write the domains array content in the corresponding configuration files
80
+ def writeDomains(domains)
81
+ #SSconfig
82
+ ssconfigText = File.read($ssconfig)
83
+ newssconfig = ssconfigText.gsub(/web_domains=.*/, "web_domains=" + getSSConfigStringFromDomainsArray(domains))
84
+ File.open($ssconfig, "w") { |file| file.puts newssconfig }
85
+
86
+ #Ejabberd
87
+ ejabbberdText = File.read($ejabberd)
88
+ newEjabberdconfig = ejabbberdText.gsub(/^{hosts, .*/, getEjabberdStringFromDomainsArray(domains))
89
+ File.open($ejabberd, "w") { |file| file.puts newEjabberdconfig }
90
+
91
+ return $done
92
+ end
93
+
94
+
95
+ def addDomain(domain,url)
96
+ if(url)
97
+ log("Add domain:" + domain + " with url:" + url)
98
+ else
99
+ log("Add domain:" + domain)
100
+ end
101
+ domains = getWebDomains();
102
+ if !domains.include?(domain)
103
+ domains << domain;
104
+ if((url)&&(url!=domain))
105
+ addDomainUrl(domain,url)
106
+ end
107
+ return writeDomains(domains)
108
+ else
109
+ return $domain_exists
110
+ end
111
+ end
112
+
113
+ def removeDomain(domain)
114
+ log("Remove domain:" + domain)
115
+ domains = getWebDomains();
116
+ if domains.include?(domain)
117
+ domains.delete(domain)
118
+ removeDomainUrl(domain)
119
+ return writeDomains(domains)
120
+ else
121
+ return $domain_not_exists
122
+ end
123
+ end
124
+
125
+ def updateDomain(domain,url)
126
+ removeDomain(domain)
127
+ return addDomain(domain,url)
128
+ end
129
+
130
+ def addDomainUrl(domain,url)
131
+ if (getOptionFromSSConfig(domain+"=")=="Undefined")
132
+ ssconfigText = File.read($ssconfig)
133
+ newssconfig = ssconfigText + "\n" + domain + "=" + url + "\n"
134
+ File.open($ssconfig, "w") { |file| file.puts newssconfig }
135
+ end
136
+ end
137
+
138
+ def removeDomainUrl(domain)
139
+ if (getOptionFromSSConfig(domain+"=")!="Undefined")
140
+ ssconfigText = File.read($ssconfig)
141
+ newssconfig = ssconfigText.gsub(/#{domain}=.*/, "")
142
+ File.open($ssconfig, "w") { |file| file.puts newssconfig }
143
+ end
144
+ end
145
+
146
+
147
+ #Main Thread
148
+
149
+ begin
150
+ if (ARGV[0])
151
+ if ((ARGV[0]=="add")&&(ARGV[1]))
152
+ puts addDomain(ARGV[1],ARGV[2])
153
+ exit 0
154
+ elsif ((ARGV[0]=="remove")&&(ARGV[1]))
155
+ puts removeDomain(ARGV[1])
156
+ exit 0
157
+ elsif ((ARGV[0]=="update")&&(ARGV[1]))
158
+ puts updateDomain(ARGV[1],ARGV[2])
159
+ exit 0
160
+ elsif (ARGV[0]=="view")
161
+ puts getWebDomains()
162
+ exit 0
163
+ end
164
+ end
165
+ puts("Syntax error: ./manageWebDomains add/remove/update/view domain [url]")
166
+ exit 1
167
+ rescue => e
168
+ puts("#{e.class.name}: #{e.message}")
169
+ exit 1
170
+ end
@@ -1,13 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
- #Rest Api Client Script
3
- #Version: 13-12-2011
4
- #@author Aldo
2
+ ####################################
3
+ # Rest Api Client Script
4
+ #Generate and send requests to Social Stream presence API
5
+ #@author Aldo Gordillo < agordillos@gmail.com >
6
+ #@version 2.0 - 24-2-2012
7
+ ####################################
5
8
 
6
9
 
7
10
  require 'logger'
8
11
  require 'rest_client'
9
12
 
10
-
11
13
  path = "/var/log/ejabberd/scripts.log"
12
14
  file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)
13
15
  file.sync = true
@@ -50,7 +52,7 @@ end
50
52
  #####################
51
53
  #def myHook(param1,param2)
52
54
  # log(getMethodName,"(My message: #{param1},#{param2})")
53
- # url = "http://" + getOption("web_domain=") + "/xmpp/hookRoute"
55
+ # url = "http://" + getWebDomainUrlFromDomain(domain) + "/xmpp/hookRoute"
54
56
 
55
57
  # params = {}
56
58
  # encrypted_params = {}
@@ -62,58 +64,59 @@ end
62
64
  # return [getMethodName,generic_api_call(url,params,encrypted_params)]
63
65
  #end
64
66
 
65
- def setConnection(username)
66
- log($script_title,"#{getMethodName}(#{username})")
67
- url = "http://" + getOption("web_domain=") + "/xmpp/setConnection"
67
+ def setConnection(userJid)
68
+ log($script_title,"#{getMethodName}(#{userJid})")
69
+ url = "http://" + getWebDomainUrlFromDomain(getDomainFromJid(userJid)) + "/xmpp/setConnection"
68
70
 
69
71
  params = {}
70
72
  encrypted_params = {}
71
- encrypted_params[:name]=username
73
+ encrypted_params[:name]=getUsernameFromJid(userJid)
72
74
 
73
75
  return [getMethodName,generic_api_call(url,params,encrypted_params)]
74
76
  end
75
77
 
76
78
 
77
- def unsetConnection(username)
78
- log($script_title,"#{getMethodName}(#{username})")
79
- url = "http://" + getOption("web_domain=") + "/xmpp/unsetConnection"
79
+ def unsetConnection(userJid)
80
+ log($script_title,"#{getMethodName}(#{userJid})")
81
+ url = "http://" + getWebDomainUrlFromDomain(getDomainFromJid(userJid)) + "/xmpp/unsetConnection"
80
82
 
81
83
  params = {}
82
84
  encrypted_params = {}
83
- encrypted_params[:name]=username
85
+ encrypted_params[:name]=getUsernameFromJid(userJid)
84
86
 
85
87
  return [getMethodName,generic_api_call(url,params,encrypted_params)]
86
88
  end
87
89
 
88
90
 
89
- def setPresence(username,status)
90
- log($script_title,"#{getMethodName}(#{username},#{status})")
91
- url = "http://" + getOption("web_domain=") + "/xmpp/setPresence"
91
+ def setPresence(userJid,status)
92
+ log($script_title,"#{getMethodName}(#{userJid},#{status})")
93
+ url = "http://" + getWebDomainUrlFromDomain(getDomainFromJid(userJid)) + "/xmpp/setPresence"
92
94
 
93
95
  params = {}
94
96
  encrypted_params = {}
95
- encrypted_params[:name]=username
97
+ encrypted_params[:name]=getUsernameFromJid(userJid)
96
98
  encrypted_params[:status]=status
97
99
 
98
100
  return [getMethodName,generic_api_call(url,params,encrypted_params)]
99
101
  end
100
102
 
101
103
 
102
- def unsetPresence(username)
103
- log($script_title,"#{getMethodName}(#{username})")
104
- url = "http://" + getOption("web_domain=") + "/xmpp/unsetPresence"
104
+ def unsetPresence(userJid)
105
+ log($script_title,"#{getMethodName}(#{userJid})")
106
+ url = "http://" + getWebDomainUrlFromDomain(getDomainFromJid(userJid)) + "/xmpp/unsetPresence"
105
107
 
106
108
  params = {}
107
109
  encrypted_params = {}
108
- encrypted_params[:name]=username
110
+ encrypted_params[:name]=getUsernameFromJid(userJid)
109
111
 
110
112
  return [getMethodName,generic_api_call(url,params,encrypted_params)]
111
113
  end
112
114
 
113
115
 
116
+ #Reset all domains connections
114
117
  def resetConnection()
115
118
  log($script_title,"Call #{getMethodName}()")
116
- url = "http://" + getOption("web_domain=") + "/xmpp/resetConnection"
119
+ url = "http://" + getWebDomainUrlFromDomain("all") + "/xmpp/resetConnection"
117
120
 
118
121
  params = {}
119
122
  encrypted_params = {}
@@ -122,29 +125,31 @@ def resetConnection()
122
125
  end
123
126
 
124
127
 
125
- def synchronize()
126
- log($script_title,"Call #{getMethodName}()")
127
- url = "http://" + getOption("web_domain=") + "/xmpp/synchronizePresence"
128
-
129
-
128
+ def synchronize(domain)
129
+ log($script_title,"Call #{getMethodName}(#{domain})")
130
+ url = "http://" + getWebDomainUrlFromDomain(domain) + "/xmpp/synchronizePresence"
131
+
130
132
  #Get connected users using Emanagement
131
- users = []
132
- command = $scripts_path + "/emanagement getConnectedUsers"
133
+ jids = []
134
+ if domain=="all"
135
+ command = $scripts_path + "/emanagement getConnectedJids"
136
+ else
137
+ command = $scripts_path + "/emanagement getConnectedJidsByDomain " + domain
138
+ end
133
139
  output = %x[#{command}]
134
140
  sessions = output.split("\n")
135
141
 
136
142
  sessions.each do |session|
137
- users << session.split("@")[0]
143
+ jids << session.split("/")[0]
138
144
  end
139
145
  #Finish
140
146
 
141
-
142
147
  #In this cases users always will be sent in clear (not cipher)
143
148
  #(Too much data to cipher)
144
149
  #Anyway, we must to build the hash to pass the authentication
145
150
  params = {}
146
151
  encrypted_params = {}
147
- params[:name]=users.join(",")
152
+ params[:name]=jids.join(",")
148
153
 
149
154
  return [getMethodName,generic_api_call(url,params,encrypted_params)]
150
155
  end
@@ -277,6 +282,44 @@ def invokeApiCall(method,args)
277
282
  end
278
283
 
279
284
 
285
+ def getUsernameFromJid(jid)
286
+ return jid.split("@")[0];
287
+ end
288
+
289
+ def getDomainFromJid(jid)
290
+ return jid.split("@")[1];
291
+ end
292
+
293
+ def getWebDomainUrlFromDomain(domain)
294
+
295
+ if domain=="all"
296
+ return getWebDomainUrlFromDomain(getWebDomains()[0])
297
+ end
298
+
299
+ web_domain = getOption(domain + "=");
300
+ if (web_domain != "Undefined")
301
+ return web_domain
302
+ else
303
+ return domain
304
+ end
305
+ end
306
+
307
+ def getWebDomains()
308
+ begin
309
+ web_domains = getOption("web_domains=");
310
+ #web_domains=["domain1","domain2"]
311
+ return getElementsFromStringArray(web_domains);
312
+ rescue Exception=>e
313
+ return [""]
314
+ end
315
+ end
316
+
317
+ def getElementsFromStringArray(stringArray)
318
+ stringArray=stringArray[1,stringArray.length-2]
319
+ return stringArray.split(",")
320
+ end
321
+
322
+
280
323
  #Main Program
281
324
 
282
325
  begin
@@ -1,13 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
- #Rest Api Client Script
3
- #Version: 13-12-2011
4
- #@author Aldo
2
+ ####################################
3
+ # Rest Api Client Script
4
+ #Generate and send requests to Social Stream presence API
5
+ #@author Aldo Gordillo < agordillos@gmail.com >
6
+ #@version 2.0 - 24-2-2012
7
+ ####################################
5
8
 
6
9
 
7
10
  require 'logger'
8
11
  require 'rest_client'
9
12
 
10
-
11
13
  path = "/var/log/ejabberd/scripts.log"
12
14
  file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)
13
15
  file.sync = true
@@ -32,7 +34,7 @@ end
32
34
  $secure_rest_api = getOption("secure_rest_api=")
33
35
  $pass = getOption("ejabberd_password=")
34
36
  $scripts_path = getOption("scripts_path=")
35
- $script_title = "Synchronize Presence Script"
37
+ $script_title = "Rest Api Client"
36
38
 
37
39
 
38
40
  def log(title,text)
@@ -50,7 +52,7 @@ end
50
52
  #####################
51
53
  #def myHook(param1,param2)
52
54
  # log(getMethodName,"(My message: #{param1},#{param2})")
53
- # url = "http://" + getOption("web_domain=") + "/xmpp/hookRoute"
55
+ # url = "http://" + getWebDomainUrlFromDomain(domain) + "/xmpp/hookRoute"
54
56
 
55
57
  # params = {}
56
58
  # encrypted_params = {}
@@ -62,58 +64,59 @@ end
62
64
  # return [getMethodName,generic_api_call(url,params,encrypted_params)]
63
65
  #end
64
66
 
65
- def setConnection(username)
66
- log($script_title,"#{getMethodName}(#{username})")
67
- url = "http://" + getOption("web_domain=") + "/xmpp/setConnection"
67
+ def setConnection(userJid)
68
+ log($script_title,"#{getMethodName}(#{userJid})")
69
+ url = "http://" + getWebDomainUrlFromDomain(getDomainFromJid(userJid)) + "/xmpp/setConnection"
68
70
 
69
71
  params = {}
70
72
  encrypted_params = {}
71
- encrypted_params[:name]=username
73
+ encrypted_params[:name]=getUsernameFromJid(userJid)
72
74
 
73
75
  return [getMethodName,generic_api_call(url,params,encrypted_params)]
74
76
  end
75
77
 
76
78
 
77
- def unsetConnection(username)
78
- log($script_title,"#{getMethodName}(#{username})")
79
- url = "http://" + getOption("web_domain=") + "/xmpp/unsetConnection"
79
+ def unsetConnection(userJid)
80
+ log($script_title,"#{getMethodName}(#{userJid})")
81
+ url = "http://" + getWebDomainUrlFromDomain(getDomainFromJid(userJid)) + "/xmpp/unsetConnection"
80
82
 
81
83
  params = {}
82
84
  encrypted_params = {}
83
- encrypted_params[:name]=username
85
+ encrypted_params[:name]=getUsernameFromJid(userJid)
84
86
 
85
87
  return [getMethodName,generic_api_call(url,params,encrypted_params)]
86
88
  end
87
89
 
88
90
 
89
- def setPresence(username,status)
90
- log($script_title,"#{getMethodName}(#{username},#{status})")
91
- url = "http://" + getOption("web_domain=") + "/xmpp/setPresence"
91
+ def setPresence(userJid,status)
92
+ log($script_title,"#{getMethodName}(#{userJid},#{status})")
93
+ url = "http://" + getWebDomainUrlFromDomain(getDomainFromJid(userJid)) + "/xmpp/setPresence"
92
94
 
93
95
  params = {}
94
96
  encrypted_params = {}
95
- encrypted_params[:name]=username
97
+ encrypted_params[:name]=getUsernameFromJid(userJid)
96
98
  encrypted_params[:status]=status
97
99
 
98
100
  return [getMethodName,generic_api_call(url,params,encrypted_params)]
99
101
  end
100
102
 
101
103
 
102
- def unsetPresence(username)
103
- log($script_title,"#{getMethodName}(#{username})")
104
- url = "http://" + getOption("web_domain=") + "/xmpp/unsetPresence"
104
+ def unsetPresence(userJid)
105
+ log($script_title,"#{getMethodName}(#{userJid})")
106
+ url = "http://" + getWebDomainUrlFromDomain(getDomainFromJid(userJid)) + "/xmpp/unsetPresence"
105
107
 
106
108
  params = {}
107
109
  encrypted_params = {}
108
- encrypted_params[:name]=username
110
+ encrypted_params[:name]=getUsernameFromJid(userJid)
109
111
 
110
112
  return [getMethodName,generic_api_call(url,params,encrypted_params)]
111
113
  end
112
114
 
113
115
 
116
+ #Reset all domains connections
114
117
  def resetConnection()
115
118
  log($script_title,"Call #{getMethodName}()")
116
- url = "http://" + getOption("web_domain=") + "/xmpp/resetConnection"
119
+ url = "http://" + getWebDomainUrlFromDomain("all") + "/xmpp/resetConnection"
117
120
 
118
121
  params = {}
119
122
  encrypted_params = {}
@@ -122,29 +125,31 @@ def resetConnection()
122
125
  end
123
126
 
124
127
 
125
- def synchronize()
126
- log($script_title,"Call #{getMethodName}()")
127
- url = "http://" + getOption("web_domain=") + "/xmpp/synchronizePresence"
128
-
129
-
128
+ def synchronize(domain)
129
+ log($script_title,"Call #{getMethodName}(#{domain})")
130
+ url = "http://" + getWebDomainUrlFromDomain(domain) + "/xmpp/synchronizePresence"
131
+
130
132
  #Get connected users using Emanagement
131
- users = []
132
- command = $scripts_path + "/emanagement getConnectedUsers"
133
+ jids = []
134
+ if domain=="all"
135
+ command = $scripts_path + "/emanagement getConnectedJids"
136
+ else
137
+ command = $scripts_path + "/emanagement getConnectedJidsByDomain " + domain
138
+ end
133
139
  output = %x[#{command}]
134
140
  sessions = output.split("\n")
135
141
 
136
142
  sessions.each do |session|
137
- users << session.split("@")[0]
143
+ jids << session.split("/")[0]
138
144
  end
139
145
  #Finish
140
146
 
141
-
142
147
  #In this cases users always will be sent in clear (not cipher)
143
148
  #(Too much data to cipher)
144
149
  #Anyway, we must to build the hash to pass the authentication
145
150
  params = {}
146
151
  encrypted_params = {}
147
- params[:name]=users.join(",")
152
+ params[:name]=jids.join(",")
148
153
 
149
154
  return [getMethodName,generic_api_call(url,params,encrypted_params)]
150
155
  end
@@ -277,11 +282,53 @@ def invokeApiCall(method,args)
277
282
  end
278
283
 
279
284
 
285
+ def getUsernameFromJid(jid)
286
+ return jid.split("@")[0];
287
+ end
288
+
289
+ def getDomainFromJid(jid)
290
+ return jid.split("@")[1];
291
+ end
292
+
293
+ def getWebDomainUrlFromDomain(domain)
294
+
295
+ if domain=="all"
296
+ return getWebDomainUrlFromDomain(getWebDomains()[0])
297
+ end
298
+
299
+ web_domain = getOption(domain + "=");
300
+ if (web_domain != "Undefined")
301
+ return web_domain
302
+ else
303
+ return domain
304
+ end
305
+ end
306
+
307
+ def getWebDomains()
308
+ begin
309
+ web_domains = getOption("web_domains=");
310
+ #web_domains=["domain1","domain2"]
311
+ return getElementsFromStringArray(web_domains);
312
+ rescue Exception=>e
313
+ return [""]
314
+ end
315
+ end
316
+
317
+ def getElementsFromStringArray(stringArray)
318
+ stringArray=stringArray[1,stringArray.length-2]
319
+ return stringArray.split(",")
320
+ end
321
+
322
+
280
323
  #Main Program
281
324
 
282
325
  begin
326
+ if !ARGV[0]
327
+ puts("Syntax Error: ./synchronize_presence_script domain")
328
+ exit 1
329
+ end
283
330
 
284
- args = []
331
+ args = ARGV[0]
285
332
  method = "synchronize"
286
333
 
287
334
  if (response = invokeApiCall(method, args) and response[1])
@@ -1,9 +1,10 @@
1
1
  %%%-------------------------------------------------------------------
2
2
  %%% File : mod_sspresence.erl
3
- %%% Author : Aldo
4
- %%% Contact: < social-stream@dit.upm.es >
3
+ %%% Author : Aldo Gordillo
4
+ %%% Contact : < social-stream@dit.upm.es >
5
5
  %%% Purpose : Process events and hooks for Social Stream Presence: http://social-stream.dit.upm.es/
6
6
  %%% Created : 1 Oct 2011
7
+ %%% Version : 2.0
7
8
  %%%
8
9
  %%%
9
10
  %%% http://social-stream.dit.upm.es/
@@ -50,42 +51,46 @@ stop(Host) ->
50
51
 
51
52
 
52
53
  on_register_connection(_SID, _JID, _Info) ->
53
- {_A,User,_B,_C,_D,_E,_F} = _JID,
54
- ?INFO_MSG("mod_sspresence: on_register_connection (~p)", [User]),
54
+ {_A,User,Domain,_C,_D,_E,_F} = _JID,
55
+ UserJid = string:join([User, Domain ], "@"),
56
+ ?INFO_MSG("mod_sspresence: on_register_connection (~p)", [UserJid]),
55
57
  Rest_api_script_path = string:concat(getOptionValue("scripts_path="), "/rest_api_client_script "),
56
- os:cmd(string:join([Rest_api_script_path, "setConnection", User ], " ")),
58
+ os:cmd(string:join([Rest_api_script_path, "setConnection", UserJid ], " ")),
57
59
  ok.
58
60
 
59
61
  on_remove_connection(_SID, _JID, _SessionInfo) ->
60
- {_A,User,_B,_C,_D,_E,_F} = _JID,
61
- ?INFO_MSG("mod_sspresence: on_remove_connection (~p)", [User]),
62
- Connected = isConnected(User),
62
+ {_A,User,Domain,_C,_D,_E,_F} = _JID,
63
+ UserJid = string:join([User, Domain ], "@"),
64
+ ?INFO_MSG("mod_sspresence: on_remove_connection (~p)", [UserJid]),
65
+ Connected = isConnected(UserJid),
63
66
  case Connected of
64
67
  true -> ok;
65
68
  _ -> Rest_api_script_path = string:concat(getOptionValue("scripts_path="), "/rest_api_client_script "),
66
- os:cmd(string:join([Rest_api_script_path, "unsetConnection", User ], " "))
69
+ os:cmd(string:join([Rest_api_script_path, "unsetConnection", UserJid ], " "))
67
70
  end,
68
71
  ok.
69
72
 
70
- on_presence(User, _Server, _Resource, Packet) ->
71
- ?INFO_MSG("mod_sspresence: on_presence (~p)", [User]),
73
+ on_presence(User, Server, _Resource, Packet) ->
74
+ UserJid = string:join([User, Server ], "@"),
75
+ ?INFO_MSG("mod_sspresence: on_presence (~p)", [UserJid]),
72
76
  {_xmlelement, Type, _Attr, Subel} = Packet,
73
77
 
74
78
  case Type of
75
79
  "presence" -> Status = getStatusFromSubel(Subel),
76
80
  Rest_api_script_path = string:concat(getOptionValue("scripts_path="), "/rest_api_client_script "),
77
- ?INFO_MSG("mod_sspresence: set_presence_script call with user (~p) and status (~p)", [User,Status]),
78
- os:cmd(string:join([Rest_api_script_path, "setPresence", User , Status], " "));
81
+ ?INFO_MSG("mod_sspresence: set_presence_script call with userJid (~p) and status (~p)", [UserJid,Status]),
82
+ os:cmd(string:join([Rest_api_script_path, "setPresence", UserJid , Status], " "));
79
83
  _ -> ok
80
84
  end,
81
85
  ok.
82
86
 
83
- on_unset_presence(User, _Server, _Resource, _Status) ->
84
- ?INFO_MSG("mod_sspresence: on_unset_presence (~p)", [User]),
87
+ on_unset_presence(User, Server, _Resource, _Status) ->
88
+ UserJid = string:join([User, Server ], "@"),
89
+ ?INFO_MSG("mod_sspresence: on_unset_presence (~p)", [UserJid]),
85
90
  _Rest_api_script_path = string:concat(getOptionValue("scripts_path="), "/rest_api_client_script "),
86
91
  %% Wait for on_remove_connection
87
- %% ?INFO_MSG("mod_sspresence: unset_presence_script call with user (~p)", [User]),
88
- %%os:cmd(string:join([_Rest_api_script_path, "unsetPresence", User , Status], " ")),
92
+ %% ?INFO_MSG("mod_sspresence: unset_presence_script call with userJid (~p)", [UserJid]),
93
+ %%os:cmd(string:join([_Rest_api_script_path, "unsetPresence", UserJid], " ")),
89
94
  ok.
90
95
 
91
96
  on_packet_send(_From, _To, {xmlelement, Type, _Attr, _Subel} = _Packet) ->
@@ -158,9 +163,9 @@ parser(In,Option) ->
158
163
 
159
164
 
160
165
  %%Check if a user is connected (any active session with Ejabberd server)
161
- isConnected(User) ->
166
+ isConnected(UserJid) ->
162
167
 
163
- Command = string:concat("ejabberdctl connected-users | grep ", User),
168
+ Command = string:concat("ejabberdctl connected-users | grep ", UserJid),
164
169
  Output = os:cmd(Command),
165
170
 
166
171
  case Output of
@@ -169,11 +174,10 @@ case Output of
169
174
 
170
175
  catch lists:foreach(
171
176
  fun(S) ->
172
- [Slug|_R] = string:tokens(S, "@"),
173
- %User.slug connected = Slug
177
+ [Jid|_R] = string:tokens(S, "/"),
174
178
 
175
- case Slug of
176
- User -> throw(true);
179
+ case Jid of
180
+ UserJid -> throw(true);
177
181
  _ -> false
178
182
  end
179
183
 
@@ -1,5 +1,5 @@
1
1
  SocialStream::Presence.setup do |config|
2
- #Configures XMPP Server Domain
2
+ #Configures Web Server Domain served by XMPP Server
3
3
  config.domain = "localhost"
4
4
  #Configures Bosh Service Path
5
5
  #config.bosh_service = "http://xmpp-proxy/http-bind"