ass 0.0.20 → 0.0.21
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/ass.yml +2 -1
- data/lib/ass.rb +46 -24
- metadata +19 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.21
|
data/ass.yml
CHANGED
data/lib/ass.rb
CHANGED
@@ -20,6 +20,7 @@ require 'will_paginate'
|
|
20
20
|
require 'will_paginate/sequel' # or data_mapper/sequel
|
21
21
|
require 'uri'
|
22
22
|
require 'sinatra/reloader' if development?
|
23
|
+
require 'sinatra/synchrony'
|
23
24
|
|
24
25
|
############################################################
|
25
26
|
## Initilization Setup
|
@@ -47,13 +48,17 @@ env = ENV['SINATRA_ENV'] || "development"
|
|
47
48
|
config = YAML.load_file("#{Dir.pwd}/ass.yml")
|
48
49
|
$timer = "#{config['timer']}".to_i
|
49
50
|
$cron = config['cron'] || 'cron'
|
50
|
-
$port = config['port'] || 4567
|
51
|
+
$port = "#{config['port']}".to_i || 4567
|
51
52
|
$mode = config['mode'] || env
|
52
53
|
$VERSION = File.open("#{ROOTDIR}/VERSION", "rb").read
|
53
54
|
$apps = config['apps'] || []
|
54
55
|
$log = config['log'] || 'off'
|
55
56
|
$user = config['user'] || 'admin'
|
56
57
|
$pass = config['pass'] || 'pass'
|
58
|
+
$flood = "#{config['flood']}".to_i || 1 # default 1 minute
|
59
|
+
|
60
|
+
$client_ip = '127.0.0.1'
|
61
|
+
$last_access = 0
|
57
62
|
|
58
63
|
############################################################
|
59
64
|
## Certificate Key Setup
|
@@ -112,9 +117,8 @@ end
|
|
112
117
|
## Sequel Database Setup
|
113
118
|
############################################################
|
114
119
|
|
115
|
-
unless File.exist?("#{Dir.pwd}/ass-#{$
|
116
|
-
$DB = Sequel.connect("sqlite://#{Dir.pwd}/ass-#{$
|
117
|
-
|
120
|
+
unless File.exist?("#{Dir.pwd}/ass-#{$mode}.db") then
|
121
|
+
$DB = Sequel.connect("sqlite://#{Dir.pwd}/ass-#{$mode}.db")
|
118
122
|
$DB.create_table :tokens do
|
119
123
|
primary_key :id
|
120
124
|
String :app, :unique => false, :null => false
|
@@ -122,34 +126,26 @@ unless File.exist?("#{Dir.pwd}/ass-#{$model}.db") then
|
|
122
126
|
Time :created_at
|
123
127
|
index [:app, :token]
|
124
128
|
end
|
125
|
-
|
126
129
|
$DB.create_table :pushes do
|
127
130
|
primary_key :id
|
128
|
-
String :pid, :unique =>
|
131
|
+
String :pid, :unique => false, :null => false, :size => 100
|
129
132
|
String :app, :unique => false, :null => false, :size => 30
|
130
133
|
String :message, :unique => false, :null => false, :size => 107
|
131
134
|
Time :created_at
|
132
135
|
index [:pid, :app, :message]
|
133
136
|
end
|
134
137
|
else
|
135
|
-
$DB = Sequel.connect("sqlite://#{Dir.pwd}/ass-#{$
|
138
|
+
$DB = Sequel.connect("sqlite://#{Dir.pwd}/ass-#{$mode}.db")
|
136
139
|
end
|
137
140
|
|
138
141
|
WillPaginate.per_page = 10
|
139
142
|
|
140
|
-
# Token = $DB[:tokens]
|
141
|
-
# Push = $DB[:pushes]
|
142
|
-
|
143
143
|
class Token < Sequel::Model
|
144
144
|
Sequel.extension :pagination
|
145
|
-
|
146
|
-
# here is your code
|
147
145
|
end
|
148
146
|
|
149
147
|
class Push < Sequel::Model
|
150
148
|
Sequel.extension :pagination
|
151
|
-
|
152
|
-
# here is your code
|
153
149
|
end
|
154
150
|
|
155
151
|
############################################################
|
@@ -169,6 +165,9 @@ end
|
|
169
165
|
############################################################
|
170
166
|
|
171
167
|
class App < Sinatra::Base
|
168
|
+
|
169
|
+
register Sinatra::Synchrony
|
170
|
+
|
172
171
|
use Rack::MobileDetect
|
173
172
|
|
174
173
|
set :root, File.expand_path('../../', __FILE__)
|
@@ -177,14 +176,33 @@ class App < Sinatra::Base
|
|
177
176
|
set :views, File.dirname(__FILE__) + '/../views'
|
178
177
|
|
179
178
|
helpers do
|
180
|
-
|
179
|
+
|
180
|
+
def checkFlood?(req)
|
181
|
+
if $client_ip != "#{req.ip}" then
|
182
|
+
$client_ip = "#{req.ip}"
|
183
|
+
return false
|
184
|
+
else
|
185
|
+
if $last_access == 0 then
|
186
|
+
return false
|
187
|
+
else
|
188
|
+
return isFlood?
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def isFlood?
|
194
|
+
result = (Time.now - $last_access) < $flood * 60
|
195
|
+
$last_access = Time.now
|
196
|
+
return result
|
197
|
+
end
|
198
|
+
|
181
199
|
def iOS?
|
182
|
-
|
200
|
+
result = case request.env['X_MOBILE_DEVICE']
|
183
201
|
when /iPhone|iPod|iPad/ then
|
184
202
|
true
|
185
203
|
else false
|
186
204
|
end
|
187
|
-
return
|
205
|
+
return result
|
188
206
|
end
|
189
207
|
|
190
208
|
def authorized?
|
@@ -198,7 +216,6 @@ class App < Sinatra::Base
|
|
198
216
|
throw(:halt, [401, "Oops... we need your login name & password\n"])
|
199
217
|
end
|
200
218
|
end
|
201
|
-
|
202
219
|
end
|
203
220
|
|
204
221
|
configure :production, :development do
|
@@ -273,13 +290,14 @@ class App < Sinatra::Base
|
|
273
290
|
|
274
291
|
## register token api
|
275
292
|
get "/v1/apps/#{app}/:token" do
|
276
|
-
if (("#{params[:token]}".length == 64) and iOS? ) then
|
293
|
+
if (("#{params[:token]}".length == 64) and iOS? and checkFlood?(request) ) then
|
277
294
|
puts "[#{params[:token]}] was added to '#{app}'" if "#{$mode}".strip == 'development'
|
278
295
|
o = Token.first(:app => app, :token => params[:token])
|
279
296
|
unless o
|
280
297
|
Token.insert(
|
281
298
|
:app => app,
|
282
|
-
:token => params[:token]
|
299
|
+
:token => params[:token],
|
300
|
+
:created_at => Time.now
|
283
301
|
)
|
284
302
|
end
|
285
303
|
end
|
@@ -304,6 +322,9 @@ class App < Sinatra::Base
|
|
304
322
|
@exist = Push.first(:pid => "#{pid}", :app => "#{app}")
|
305
323
|
|
306
324
|
unless @exist
|
325
|
+
|
326
|
+
Push.insert(:pid => pid, :message => message, :created_at => Time.now, :app => "#{app}" )
|
327
|
+
|
307
328
|
openSSLContext = $certkey["#{app}"]
|
308
329
|
# Connect to port 2195 on the server.
|
309
330
|
sock = nil
|
@@ -315,8 +336,7 @@ class App < Sinatra::Base
|
|
315
336
|
# do our SSL handshaking
|
316
337
|
sslSocket = OpenSSL::SSL::SSLSocket.new(sock, openSSLContext)
|
317
338
|
sslSocket.connect
|
318
|
-
|
319
|
-
Push.insert(:pid => pid, :message => message, :created_at => Time.now, :app => "#{app}" )
|
339
|
+
|
320
340
|
# write our packet to the stream
|
321
341
|
@tokens.each do |o|
|
322
342
|
tokenText = o[:token]
|
@@ -349,6 +369,9 @@ class App < Sinatra::Base
|
|
349
369
|
@exist = Push.first(:pid => "#{pid}", :app => "#{app}")
|
350
370
|
|
351
371
|
unless @exist
|
372
|
+
|
373
|
+
Push.insert(:pid => pid, :message => message, :created_at => Time.now, :app => "#{app}" )
|
374
|
+
|
352
375
|
openSSLContext = $certkey["#{app}"]
|
353
376
|
# Connect to port 2195 on the server.
|
354
377
|
sock = nil
|
@@ -360,8 +383,7 @@ class App < Sinatra::Base
|
|
360
383
|
# do our SSL handshaking
|
361
384
|
sslSocket = OpenSSL::SSL::SSLSocket.new(sock, openSSLContext)
|
362
385
|
sslSocket.connect
|
363
|
-
|
364
|
-
Push.insert(:pid => pid, :message => message, :created_at => Time.now, :app => "#{app}" )
|
386
|
+
|
365
387
|
# write our packet to the stream
|
366
388
|
@tokens.each do |o|
|
367
389
|
tokenText = o[:token]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.21
|
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: 2013-
|
12
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|
@@ -203,6 +203,22 @@ dependencies:
|
|
203
203
|
- - ! '>='
|
204
204
|
- !ruby/object:Gem::Version
|
205
205
|
version: '0'
|
206
|
+
- !ruby/object:Gem::Dependency
|
207
|
+
name: sinatra-synchrony
|
208
|
+
requirement: !ruby/object:Gem::Requirement
|
209
|
+
none: false
|
210
|
+
requirements:
|
211
|
+
- - ~>
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: 0.4.1
|
214
|
+
type: :runtime
|
215
|
+
prerelease: false
|
216
|
+
version_requirements: !ruby/object:Gem::Requirement
|
217
|
+
none: false
|
218
|
+
requirements:
|
219
|
+
- - ~>
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: 0.4.1
|
206
222
|
- !ruby/object:Gem::Dependency
|
207
223
|
name: shoulda
|
208
224
|
requirement: !ruby/object:Gem::Requirement
|
@@ -474,7 +490,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
474
490
|
version: '0'
|
475
491
|
segments:
|
476
492
|
- 0
|
477
|
-
hash: -
|
493
|
+
hash: -3291505526784258788
|
478
494
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
479
495
|
none: false
|
480
496
|
requirements:
|