sniffer 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +2 -0
- data/README.md +58 -24
- data/lib/sniffer.rb +1 -1
- data/lib/sniffer/config.rb +3 -1
- data/lib/sniffer/data.rb +1 -1
- data/lib/sniffer/data_item.rb +7 -0
- data/lib/sniffer/request_policy.rb +33 -0
- data/lib/sniffer/version.rb +1 -1
- metadata +4 -4
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a09ca069eb76f2fc329bf27351cc2499138ca6d
|
4
|
+
data.tar.gz: cb8e52bd4c2ad6ffe509ea85c7a1df80d5d79489
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c34b3b15837f64f6a7c9e45c71fa5f2392854122eb6f462656553a27aa12c875be6146cb0b0aacbe182c229ba2516ea41c8b0431dab33bf16e6f6a88b7f5f9e5
|
7
|
+
data.tar.gz: 0dac7a4e9d90125899d8100d168e5659c37d872b514f57cc94867ac0750b53f5ce2accc2d7527a38d48efa6cd20cf1e91d72b1f8e2c37b6f29fa91232668237f
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -43,30 +43,6 @@ Or install it yourself as:
|
|
43
43
|
|
44
44
|
$ gem install sniffer
|
45
45
|
|
46
|
-
## Configuration
|
47
|
-
|
48
|
-
Sniffer default options:
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
Sniffer.config do |c|
|
52
|
-
c.logger = Logger.new($stdout),
|
53
|
-
c.severity = Logger::Severity::DEBUG,
|
54
|
-
# HTTP options to log
|
55
|
-
c.log = {
|
56
|
-
request_url: true,
|
57
|
-
request_headers: true,
|
58
|
-
request_body: true,
|
59
|
-
request_method: true,
|
60
|
-
response_status: true,
|
61
|
-
response_headers: true,
|
62
|
-
response_body: true,
|
63
|
-
timing: true
|
64
|
-
},
|
65
|
-
c.store = true, # save requests/responses to Sniffer.data
|
66
|
-
c.enabled = false # Sniffer disabled by default
|
67
|
-
end
|
68
|
-
```
|
69
|
-
|
70
46
|
## Usage
|
71
47
|
|
72
48
|
Here's some simple examples to get you started:
|
@@ -143,6 +119,63 @@ D, [2017-10-26T16:47:14.007152 #59511] DEBUG -- : {"port":80,"host":"example.com
|
|
143
119
|
```
|
144
120
|
where `rq_xxx` is request header and `rs_xxx` - response header
|
145
121
|
|
122
|
+
## Configuration
|
123
|
+
|
124
|
+
Sniffer default options:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
Sniffer.config do |c|
|
128
|
+
c.logger = Logger.new($stdout),
|
129
|
+
c.severity = Logger::Severity::DEBUG,
|
130
|
+
# HTTP options to log
|
131
|
+
c.log = {
|
132
|
+
request_url: true,
|
133
|
+
request_headers: true,
|
134
|
+
request_body: true,
|
135
|
+
request_method: true,
|
136
|
+
response_status: true,
|
137
|
+
response_headers: true,
|
138
|
+
response_body: true,
|
139
|
+
timing: true
|
140
|
+
},
|
141
|
+
c.store = true, # save requests/responses to Sniffer.data
|
142
|
+
c.enabled = false # Sniffer disabled by default
|
143
|
+
c.url_whitelist = nil
|
144
|
+
c.url_blacklist = nil
|
145
|
+
end
|
146
|
+
```
|
147
|
+
|
148
|
+
### Whitelist
|
149
|
+
|
150
|
+
You can add specific host url to whitelist as regexp or string. Sniffer will store only requests that matched.
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
Sniffer.config.url_whitelist = /whitelisted.com/
|
154
|
+
|
155
|
+
HTTP.get('http://example.com')
|
156
|
+
Sniffer.data[0].to_h
|
157
|
+
# => {}
|
158
|
+
|
159
|
+
HTTP.get('http://whitelisted.com/')
|
160
|
+
Sniffer.data[0].to_h
|
161
|
+
# => {{:request=>{:host=>"whitelisted.com", ....}}
|
162
|
+
```
|
163
|
+
|
164
|
+
### Blacklist
|
165
|
+
|
166
|
+
You can add specific host url to blacklist as regexp or string. Sniffer will ignore all matched requests.
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
Sniffer.config.url_blacklist = /blacklisted.com/
|
170
|
+
|
171
|
+
HTTP.get('http://blacklisted.com')
|
172
|
+
Sniffer.data[0].to_h
|
173
|
+
# => {}
|
174
|
+
|
175
|
+
HTTP.get('http://example.com')
|
176
|
+
Sniffer.data[0].to_h
|
177
|
+
# => {{:request=>{:host=>"example.com", ...}}
|
178
|
+
```
|
146
179
|
|
147
180
|
## Development
|
148
181
|
|
@@ -160,6 +193,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/aderya
|
|
160
193
|
* [Salahutdinov Dmitry](https://github.com/dsalahutdinov)
|
161
194
|
* [Stanislav Chereshkevich](https://github.com/dissident)
|
162
195
|
* [Anatoliy Kurichev](https://github.com/russo-matrosso)
|
196
|
+
* [Dmitriy Ivliev](https://github.com/moofkit)
|
163
197
|
|
164
198
|
## License
|
165
199
|
|
data/lib/sniffer.rb
CHANGED
data/lib/sniffer/config.rb
CHANGED
data/lib/sniffer/data.rb
CHANGED
data/lib/sniffer/data_item.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'active_attr'
|
4
4
|
require 'json'
|
5
|
+
require_relative 'request_policy'
|
5
6
|
|
6
7
|
module Sniffer
|
7
8
|
# Sniffer data item stores a request info
|
@@ -17,6 +18,7 @@ module Sniffer
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def log
|
21
|
+
return unless allowed_to_sniff?
|
20
22
|
Sniffer.logger.log(Sniffer.config.severity, to_json)
|
21
23
|
end
|
22
24
|
|
@@ -29,6 +31,11 @@ module Sniffer
|
|
29
31
|
to_log.to_json
|
30
32
|
end
|
31
33
|
|
34
|
+
def allowed_to_sniff?
|
35
|
+
return true unless request
|
36
|
+
RequestPolicy.call(request)
|
37
|
+
end
|
38
|
+
|
32
39
|
# Basic object for request and response objects
|
33
40
|
class HttpObject
|
34
41
|
include ActiveAttr::MassAssignment
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sniffer
|
4
|
+
# match request with white and black lists
|
5
|
+
module RequestPolicy
|
6
|
+
class << self
|
7
|
+
def call(request)
|
8
|
+
url = "#{request.host}:#{request.port}"
|
9
|
+
if config.url_whitelist
|
10
|
+
whitelist_url?(url)
|
11
|
+
elsif config.url_blacklist
|
12
|
+
!blacklist_url?(url)
|
13
|
+
else
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def whitelist_url?(url)
|
21
|
+
!url.match(config.url_whitelist).nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def blacklist_url?(url)
|
25
|
+
!url.match(config.url_blacklist).nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
def config
|
29
|
+
Sniffer.config
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/sniffer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sniffer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Deryabin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anyway_config
|
@@ -258,7 +258,6 @@ files:
|
|
258
258
|
- ".gitignore"
|
259
259
|
- ".rspec"
|
260
260
|
- ".rubocop.yml"
|
261
|
-
- ".ruby-version"
|
262
261
|
- ".travis.yml"
|
263
262
|
- CHANGELOG.md
|
264
263
|
- CODE_OF_CONDUCT.md
|
@@ -281,6 +280,7 @@ files:
|
|
281
280
|
- lib/sniffer/config.rb
|
282
281
|
- lib/sniffer/data.rb
|
283
282
|
- lib/sniffer/data_item.rb
|
283
|
+
- lib/sniffer/request_policy.rb
|
284
284
|
- lib/sniffer/version.rb
|
285
285
|
- sniffer.gemspec
|
286
286
|
homepage: http://github.com/aderyabin/sniffer
|
@@ -303,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
303
|
version: '0'
|
304
304
|
requirements: []
|
305
305
|
rubyforge_project:
|
306
|
-
rubygems_version: 2.6.
|
306
|
+
rubygems_version: 2.6.14
|
307
307
|
signing_key:
|
308
308
|
specification_version: 4
|
309
309
|
summary: Analyze HTTP Requests
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.4.2
|