spns 0.2.11 → 0.2.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/VERSION +1 -1
- data/lib/spns.rb +38 -18
- data/spns.yml +0 -5
- metadata +5 -6
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.12
|
data/lib/spns.rb
CHANGED
@@ -40,7 +40,6 @@ $timer = "#{config['timer']}".to_i
|
|
40
40
|
$cron = config['cron'] || 'cron'
|
41
41
|
$port = config['port'] || 4567
|
42
42
|
$mode = config['mode'] || env
|
43
|
-
$certificate = config["#{$mode}"][0]['certificate'] || 'ck.pem'
|
44
43
|
ROOTDIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
45
44
|
VERSION = File.open("#{ROOTDIR}/VERSION", "rb").read
|
46
45
|
$apps = config['apps'] || []
|
@@ -49,8 +48,25 @@ $apps = config['apps'] || []
|
|
49
48
|
## Certificate Key Setup
|
50
49
|
############################################################
|
51
50
|
|
52
|
-
|
53
|
-
|
51
|
+
$certkey = {}
|
52
|
+
def check_cert
|
53
|
+
$apps.each { |app|
|
54
|
+
unless File.exist?("#{Dir.pwd}/#{app}_#{$mode}.pem") then
|
55
|
+
puts "Please provide #{app}_#{$mode}.pem under '#{Dir.pwd}/' directory"
|
56
|
+
return false;
|
57
|
+
else
|
58
|
+
certfile = File.read("#{Dir.pwd}/#{app}_#{$mode}.pem")
|
59
|
+
openSSLContext = OpenSSL::SSL::SSLContext.new
|
60
|
+
openSSLContext.cert = OpenSSL::X509::Certificate.new(certfile)
|
61
|
+
openSSLContext.key = OpenSSL::PKey::RSA.new(certfile)
|
62
|
+
$certkey["#{app}"] = openSSLContext
|
63
|
+
end
|
64
|
+
}
|
65
|
+
return true
|
66
|
+
end
|
67
|
+
|
68
|
+
unless check_cert then
|
69
|
+
puts "1: please provide certificate key pem file under current directory, name should be: appid_dev.pem for development and appid_prod.pem for production"
|
54
70
|
puts "2: edit your spns.yml under current directory"
|
55
71
|
puts "3: run spns"
|
56
72
|
puts "4: iOS Client: in AppDelegate file, didRegisterForRemoteNotificationsWithDeviceToken method should access url below:"
|
@@ -64,43 +80,37 @@ else
|
|
64
80
|
puts "Simple Push Notification Server is Running (#{VERSION}) ..."
|
65
81
|
puts "Mode: #{$mode}"
|
66
82
|
puts "Port: #{$port}"
|
67
|
-
puts "Certificate File: '#{Dir.pwd}/#{$certificate}'"
|
68
83
|
puts "Cron Job: '#{Dir.pwd}/#{$cron}' script is running every #{$timer} #{($timer == 1) ? 'minute' : 'minutes'} " unless "#{$timer}".squeeze.strip == "0"
|
69
84
|
puts "*"*80
|
70
85
|
end
|
71
86
|
|
72
|
-
$cert = File.read("#{Dir.pwd}/#{$certificate}")
|
73
|
-
$openSSLContext = OpenSSL::SSL::SSLContext.new
|
74
|
-
$openSSLContext.cert = OpenSSL::X509::Certificate.new($cert)
|
75
|
-
$openSSLContext.key = OpenSSL::PKey::RSA.new($cert)
|
76
|
-
|
77
87
|
############################################################
|
78
88
|
## Sequel Database Setup
|
79
89
|
############################################################
|
80
90
|
|
81
|
-
DB
|
91
|
+
$DB;
|
82
92
|
|
83
93
|
unless File.exist?("#{Dir.pwd}/push.db") then
|
84
|
-
DB = Sequel.connect("sqlite://#{Dir.pwd}/push.db")
|
94
|
+
$DB = Sequel.connect("sqlite://#{Dir.pwd}/push.db")
|
85
95
|
|
86
|
-
DB.create_table :tokens do
|
96
|
+
$DB.create_table :tokens do
|
87
97
|
primary_key :id
|
88
98
|
String :app, :unique => true, :null => false
|
89
99
|
String :token, :unique => true, :null => false, :size => 100
|
90
100
|
index [:app, :token]
|
91
101
|
end
|
92
102
|
|
93
|
-
DB.create_table :pushes do
|
103
|
+
$DB.create_table :pushes do
|
94
104
|
primary_key :id
|
95
105
|
String :pid, :unique => true, :null => false, :size => 100
|
96
106
|
index :pid
|
97
107
|
end
|
98
108
|
else
|
99
|
-
DB = Sequel.connect("sqlite://#{Dir.pwd}/push.db")
|
109
|
+
$DB = Sequel.connect("sqlite://#{Dir.pwd}/push.db")
|
100
110
|
end
|
101
111
|
|
102
|
-
Token = DB[:tokens]
|
103
|
-
Push = DB[:pushes]
|
112
|
+
Token = $DB[:tokens]
|
113
|
+
Push = $DB[:pushes]
|
104
114
|
|
105
115
|
############################################################
|
106
116
|
## Timer Job Setup
|
@@ -143,6 +153,14 @@ end
|
|
143
153
|
class App < Sinatra::Base
|
144
154
|
|
145
155
|
set :port, "#{$port}".to_i
|
156
|
+
|
157
|
+
if $mode == 'development' then
|
158
|
+
set :show_exceptions, true
|
159
|
+
set :dump_errors, true
|
160
|
+
else
|
161
|
+
set :show_exceptions, false
|
162
|
+
set :dump_errors, false
|
163
|
+
end
|
146
164
|
|
147
165
|
get '/' do
|
148
166
|
puts "Simple Push Notification Server"
|
@@ -168,7 +186,9 @@ class App < Sinatra::Base
|
|
168
186
|
|
169
187
|
@push = Token.where(:app => app)
|
170
188
|
@exist = Push.first(:pid => pid)
|
171
|
-
|
189
|
+
|
190
|
+
openSSLContext = $certkey["#{app}"]
|
191
|
+
|
172
192
|
unless @exist
|
173
193
|
# Connect to port 2195 on the server.
|
174
194
|
sock = nil
|
@@ -178,7 +198,7 @@ class App < Sinatra::Base
|
|
178
198
|
sock = TCPSocket.new('gateway.sandbox.push.apple.com', 2195)
|
179
199
|
end
|
180
200
|
# do our SSL handshaking
|
181
|
-
sslSocket = OpenSSL::SSL::SSLSocket.new(sock,
|
201
|
+
sslSocket = OpenSSL::SSL::SSLSocket.new(sock, openSSLContext)
|
182
202
|
sslSocket.connect
|
183
203
|
#Push.create( :pid => pid )
|
184
204
|
Push.insert(:pid => pid)
|
data/spns.yml
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|
@@ -266,8 +266,7 @@ files:
|
|
266
266
|
- cron
|
267
267
|
- lib/spns.rb
|
268
268
|
- spns.yml
|
269
|
-
-
|
270
|
-
YmluL3NwbnM=
|
269
|
+
- bin/spns
|
271
270
|
homepage: http://github.com/eiffelqiu/spns
|
272
271
|
licenses:
|
273
272
|
- MIT
|
@@ -283,7 +282,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
283
282
|
version: '0'
|
284
283
|
segments:
|
285
284
|
- 0
|
286
|
-
hash:
|
285
|
+
hash: 2341524814472371474
|
287
286
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
288
287
|
none: false
|
289
288
|
requirements:
|
@@ -292,7 +291,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
292
291
|
version: '0'
|
293
292
|
requirements: []
|
294
293
|
rubyforge_project: spns
|
295
|
-
rubygems_version: 1.8.
|
294
|
+
rubygems_version: 1.8.24
|
296
295
|
signing_key:
|
297
296
|
specification_version: 3
|
298
297
|
summary: Simple Push Notification Server
|