social_stream-presence 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -25,7 +25,7 @@ def getOption(option)
25
25
  return "Undefined"
26
26
  end
27
27
 
28
- $url = getOption("reset_connection_api=")
28
+ $url = "http://" + getOption("web_domain=") + "/xmpp/resetConnection"
29
29
  $pass = getOption("ejabberd_password=")
30
30
 
31
31
 
@@ -25,7 +25,7 @@ def getOption(option)
25
25
  return "Undefined"
26
26
  end
27
27
 
28
- $url = getOption("set_connection_api=")
28
+ $url = "http://" + getOption("web_domain=") + "/xmpp/setConnection"
29
29
  $pass = getOption("ejabberd_password=")
30
30
 
31
31
 
@@ -25,7 +25,7 @@ def getOption(option)
25
25
  return "Undefined"
26
26
  end
27
27
 
28
- $url = getOption("set_presence_api=")
28
+ $url = "http://" + getOption("web_domain=") + "/xmpp/setPresence"
29
29
  $pass = getOption("ejabberd_password=")
30
30
 
31
31
 
@@ -0,0 +1,112 @@
1
+ #!/bin/bash
2
+ #Script header edition
3
+ #@author Aldo
4
+
5
+ #Constants
6
+ installer_file_path=$(readlink -f $0)
7
+ installer_folder_path=`dirname "$installer_file_path"`
8
+
9
+
10
+ #Functions
11
+
12
+
13
+ msg () {
14
+ echo "#################################"
15
+ echo $1
16
+ }
17
+
18
+
19
+ #Main Program
20
+
21
+ msg "Starting set scripts header"
22
+
23
+ echo "Installer path:" $installer_file_path
24
+
25
+
26
+ #Look for params
27
+
28
+ msg "Detecting ruby enviroment"
29
+
30
+ if [ $1 ]
31
+ then {
32
+ echo "Ruby enviromet specified by param"
33
+ ruby_env=$1
34
+ } else {
35
+ ruby_env=`which ruby`
36
+ }
37
+ fi
38
+
39
+ echo "Ruby enviroment:" $ruby_env
40
+
41
+
42
+ msg "Writing scripts header"
43
+ echo ""
44
+ for file in `ls $installer_folder_path/` ; do
45
+
46
+
47
+ if [ ! -f $installer_folder_path/$file ];
48
+ then
49
+ continue
50
+ fi
51
+
52
+ if [[ $file =~ .sh$ ]]
53
+ then
54
+ continue
55
+ fi
56
+
57
+ if [ $installer_folder_path/$file == $installer_file_path ];
58
+ then
59
+ continue
60
+ fi
61
+
62
+
63
+ printf $file"\n"
64
+
65
+ #Create temporal file
66
+ temporal_path=$installer_folder_path/$file"_temp"
67
+
68
+ if [ -f $temporal_path ];
69
+ then
70
+ echo "File $temporal_path exists."
71
+ rm $temporal_path
72
+ fi
73
+
74
+ touch $temporal_path
75
+
76
+ #Read file
77
+ file_path=$installer_folder_path/$file
78
+
79
+ SAVEIFS=$IFS
80
+ IFS=$(echo -en "\n\b")
81
+
82
+ while read line
83
+ do
84
+ #Look for Pattern !/usr/bin/env ruby
85
+ if [[ $line =~ ^#!/usr/bin/env ]]
86
+ then
87
+ scriptheader="#!/usr/bin/env"
88
+ line="${scriptheader} ${ruby_env}"
89
+ fi
90
+ echo $line >> $temporal_path
91
+ done < $file_path
92
+
93
+ IFS=$SAVEIFS
94
+
95
+ #Replace original file
96
+ cp $temporal_path $file_path
97
+
98
+ #Remove temporal file
99
+ rm $temporal_path
100
+
101
+ done
102
+
103
+
104
+ msg "Complete"
105
+ exit 0
106
+
107
+
108
+
109
+
110
+
111
+
112
+
@@ -25,8 +25,9 @@ def getOption(option)
25
25
  return "Undefined"
26
26
  end
27
27
 
28
- $url = getOption("synchronize_presence_api=")
28
+ $url = "http://" + getOption("web_domain=") + "/xmpp/synchronizePresence"
29
29
  $pass = getOption("ejabberd_password=")
30
+ $scripts_path = getOption("scripts_path=")
30
31
 
31
32
 
32
33
  def log(text)
@@ -37,7 +38,8 @@ def synchronize()
37
38
  log("Start Synchronize")
38
39
 
39
40
  users = []
40
- output = %x[ejabberdctl connected-users]
41
+ command = $scripts_path + "/emanagement getConnectedUsers"
42
+ output = %x[#{command}]
41
43
  sessions = output.split("\n")
42
44
 
43
45
  sessions.each do |session|
@@ -25,7 +25,7 @@ def getOption(option)
25
25
  return "Undefined"
26
26
  end
27
27
 
28
- $url = getOption("unset_connection_api=")
28
+ $url = "http://" + getOption("web_domain=") + "/xmpp/unsetConnection"
29
29
  $pass = getOption("ejabberd_password=")
30
30
 
31
31
 
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ #Unset Presence Script
3
+ #@author Aldo
4
+
5
+ require 'logger'
6
+ require 'rest_client'
7
+
8
+ path = "/var/log/ejabberd/scripts.log"
9
+ file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)
10
+ file.sync = true
11
+ $logger = Logger.new(file)
12
+ $logger.level = Logger::DEBUG
13
+
14
+ def getOption(option)
15
+ File.open('/etc/ejabberd/ssconfig.cfg', 'r') do |f1|
16
+ while line = f1.gets
17
+ line = line.gsub(/\n/,'')
18
+ if line.match(/^#/)
19
+ #Comments
20
+ elsif line.match(/^#{option}/)
21
+ return line.gsub(/#{option}/,'')
22
+ end
23
+ end
24
+ end
25
+ return "Undefined"
26
+ end
27
+
28
+ $url = "http://" + getOption("web_domain=") + "/xmpp/unsetPresence"
29
+ $pass = getOption("ejabberd_password=")
30
+
31
+
32
+ def log(text)
33
+ $logger.info "Unset Presence Script: " + text
34
+ end
35
+
36
+ def unsetPresence(username)
37
+ log("unsetPresence(#{username})")
38
+ RestClient.post($url, :name => username, :password => $pass)
39
+ return true
40
+
41
+ rescue RestClient::Exception
42
+ log("RestClient::Exception with unsetPresence(#{username})")
43
+ end
44
+
45
+
46
+ unsetPresence(ARGV[0])
47
+
48
+
@@ -0,0 +1,267 @@
1
+ #!/bin/bash
2
+
3
+ #Social Stream Presence Ejabberd files installer
4
+ #@author Aldo
5
+
6
+ #Call example:
7
+ #./installer.sh ejabberd_module_path="/ejabberd_module_path/" scripts_path="/scripts_path/" [key1=value1,key2=value2]
8
+
9
+ #Constants
10
+ config_files_path="/etc/ejabberd/"
11
+ logs_path="/var/log/ejabberd/"
12
+ installer_file_path=$(readlink -f $0)
13
+ installer_folder_path=`dirname "$installer_file_path"`
14
+
15
+
16
+
17
+ #Functions
18
+
19
+ help () {
20
+ echo "Syntax error: ./installer [onlyconf=true] ejabberd_module_path=mpath scripts_path=spath [key1=value1,key2=value2,...]"
21
+ }
22
+
23
+
24
+ msg () {
25
+ echo "#################################"
26
+ echo $1
27
+ }
28
+
29
+
30
+ applyOption () {
31
+ if [ ! $1 ] || [ ! $2 ]
32
+ then
33
+ return 1
34
+ fi
35
+ #key $1
36
+ #value $2
37
+ #string ssconfig $3
38
+ echo "Enable option " $1"="$2
39
+
40
+ SEPARATOR=$(echo -en "\n\b")
41
+ match=$1"="
42
+
43
+ if [[ $ssconfig == *$match* ]]
44
+ then {
45
+ #Modify existing options
46
+ repl=$1"="$2"="
47
+
48
+ if [ $2 == "remove" ]
49
+ then
50
+ repl="removedVar=true="
51
+ fi
52
+
53
+ ssconfig=${ssconfig/$match/$repl}
54
+ } else {
55
+ #Add new options
56
+ if [ ! $2 == "remove" ]
57
+ then
58
+ ssconfig="${ssconfig}${SEPARATOR}${1}=${2}="
59
+ fi
60
+ }
61
+ fi
62
+
63
+ return 0
64
+ }
65
+
66
+
67
+ restoreFile () {
68
+ IFS=$(echo -en "\n\b")
69
+ cat /dev/null > $conffile
70
+ for word in $ssconfigrestore; do
71
+ echo $word >> $conffile
72
+ done
73
+ return 0
74
+ }
75
+
76
+
77
+ updateSSConfig () {
78
+
79
+ if [ $1 ] && [ ${#1} -gt 2 ]
80
+ then {
81
+
82
+ if [ ${1:0:1} != "[" ] || [ ${1:${#1}-1:${#1}} != "]" ]
83
+ then
84
+ echo "Malformed options"
85
+ help
86
+ exit 1
87
+ fi
88
+
89
+ msg "Processing options"
90
+ options=${1:1:${#1}-2}
91
+ options=(${options//","/ })
92
+
93
+
94
+ #Read config file
95
+ ssconfig=""
96
+ conffile=$config_files_path/ssconfig.cfg
97
+
98
+ SAVEIFS=$IFS
99
+ IFS=$(echo -en "\n\b")
100
+
101
+ while read line
102
+ do
103
+ ssconfig="${ssconfig}${line}${IFS}"
104
+ done < $conffile
105
+
106
+ IFS=$SAVEIFS
107
+
108
+ ssconfigrestore=$ssconfig;
109
+
110
+ #Modify ssconfig to apply options
111
+ for option in ${options[@]}; do
112
+ option=(${option//"="/ })
113
+ key=${option[0]}
114
+ value=${option[1]}
115
+ applyOption $key $value
116
+ done
117
+
118
+
119
+ #Write (ssconfig) to file
120
+ cat /dev/null > $conffile
121
+ IFS=$(echo -en "\n\b")
122
+ for word in $ssconfig; do
123
+
124
+ if [[ $word =~ [#] ]] || [ -z $word ]
125
+ then {
126
+ echo $word >> $conffile
127
+ } else {
128
+ IFS=$SAVEIFS
129
+ arr=(${word//"="/ })
130
+ if [ ${#arr[@]} -lt 2 ]
131
+ then
132
+ echo "ssconfig.cfg error in line:" $word
133
+ restoreFile
134
+ exit 1
135
+ fi
136
+ word="${arr[0]}=${arr[1]}"
137
+ if [ ! $word == "removedVar=true" ]
138
+ then
139
+ echo $word >> $conffile
140
+ fi
141
+ }
142
+ fi
143
+ done
144
+ }
145
+ fi
146
+
147
+ }
148
+
149
+
150
+ #Main Program
151
+
152
+
153
+ #Look for only configuration mode
154
+ arr=(${1//"="/ })
155
+ if [ ${#arr} -ge 2 ] && [ ${arr[0]} == "onlyconf" ] && [ ${arr[1]} == "true" ]
156
+ then {
157
+ msg "Updating ssconfig"
158
+ updateSSConfig $2
159
+ exit 0
160
+ }
161
+ fi
162
+
163
+
164
+
165
+ #Installer mode
166
+ msg "Start installer"
167
+
168
+ if [ $# -lt 2 ]
169
+ then
170
+ help
171
+ exit 1
172
+ fi
173
+
174
+
175
+ msg "Reading parameters..."
176
+
177
+ arr=(${1//"="/ })
178
+
179
+ if [ ${arr[0]} == "ejabberd_module_path" ]
180
+ then {
181
+ ejabberd_module_path=${arr[1]}
182
+ } else {
183
+ help
184
+ exit 1
185
+ }
186
+ fi
187
+
188
+ arr=(${2//"="/ })
189
+
190
+ if [ ${arr[0]} == "scripts_path" ]
191
+ then {
192
+ scripts_path=${arr[1]}
193
+ } else {
194
+ help
195
+ exit 1
196
+ }
197
+ fi
198
+
199
+
200
+ echo "Installer path:" $installer_file_path
201
+ echo "Ejabberd module path:" $ejabberd_module_path
202
+ echo "scripts_path:" $scripts_path
203
+ echo "config_files_path:" $config_files_path
204
+ echo "logs_path:" $logs_path
205
+
206
+
207
+ paths=($ejabberd_module_path $scripts_path $config_files_path $logs_path )
208
+
209
+ msg "Creating directories"
210
+
211
+ for path in ${paths[@]}; do
212
+ mkdir -p $path
213
+ done
214
+
215
+
216
+ msg "Copying Ejabberd modules"
217
+ cp $installer_folder_path/mod_admin_extra/mod_admin_extra.beam $ejabberd_module_path
218
+ cp $installer_folder_path/mod_sspresence/mod_sspresence.beam $ejabberd_module_path
219
+
220
+ msg "Copying scripts"
221
+ cp -r $installer_folder_path/ejabberd_scripts/* $scripts_path
222
+
223
+
224
+ msg "Checking and copying configuration files"
225
+
226
+ if [ -e $config_files_path/ssconfig.cfg ]
227
+ then {
228
+ echo "Find ssconfig.cfg: updating ssconfig_example.cfg"
229
+ cp $installer_folder_path/conf/ssconfig_example.cfg $config_files_path/ssconfig_example.cfg
230
+ } else {
231
+ echo "ssconfig not exists"
232
+ cp $installer_folder_path/conf/ssconfig_example.cfg $config_files_path/ssconfig.cfg
233
+ }
234
+ fi
235
+
236
+ cp $installer_folder_path/conf/ejabberd_example.cfg $config_files_path/ejabberd_example.cfg
237
+ echo "Updating ejabberd_example.cfg"
238
+
239
+ msg "Check and copying log files"
240
+ if [ ! -e $logs_path/scripts.log ]
241
+ then {
242
+ echo "Creating scripts.log"
243
+ touch $logs_path/scripts.log
244
+ }
245
+ fi
246
+
247
+ if [ ! -e $logs_path/auth.log ]
248
+ then {
249
+ echo "Creating auth.log"
250
+ touch $logs_path/auth.log
251
+ }
252
+ fi
253
+
254
+
255
+ #Processing options
256
+ updateSSConfig $3
257
+
258
+
259
+ msg "Complete"
260
+ exit 0
261
+
262
+
263
+
264
+
265
+
266
+
267
+