sip-capture 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sip/capture/hep3.rb +118 -0
- data/lib/sip/capture/version.rb +5 -0
- data/lib/sip/capture.rb +8 -0
- data/sip-capture.gemspec +40 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f1ce52ec65ab8dd5a45b34f5d0750c9a621d41f
|
4
|
+
data.tar.gz: c3b49a8abd7b189d8b3ad40c195750b96c70b025
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '0866b47fe93414c5cf21c45cc7b008eea982c8d0160b370efda7766c31cb37f6fa38654b0a8b4a9aff1b6be8de6aac1a649070cd33db8f8da54195b896257c5e'
|
7
|
+
data.tar.gz: fe742dfa939c425dbd5bf488f17877974085672ef1aa77837c5a605516f2f7f6cbd95388ad6bb3034d2158dc84e29e40ac2cda700ef648c0c6fcf1b1fc0f148e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sip-capture (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.16)
|
17
|
+
minitest (~> 5.0)
|
18
|
+
rake (~> 10.0)
|
19
|
+
sip-capture!
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 ukolovda
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Sip::Capture
|
2
|
+
|
3
|
+
This gem user in capture-server for FreeSwitch and other SIP servers with HEP3 logging
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'sip-capture'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install sip-capture
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Sip::Capture::Hep3.capture_all('127.0.0.1', 9060) do |item|
|
25
|
+
puts item.inspect
|
26
|
+
# => {"ip_protocol_family":2,
|
27
|
+
# "ip_protocol_id":6,
|
28
|
+
# "protocol_type":1,
|
29
|
+
# "ipv4_source_address":"169.254.0.2",
|
30
|
+
# "protocol_source_port":33620,
|
31
|
+
# "ipv4_destination_address":"169.254.0.2",
|
32
|
+
# "protocol_destination_port":4443,
|
33
|
+
# "timestamp_sec":1534916954,
|
34
|
+
# "timestamp_usec":433421,
|
35
|
+
# "capture_agent_id":114163712,
|
36
|
+
# "payload":"BYE sip:0011@169.254.0.2:5060;transport=udp SIP/2.0\r\nVia: SIP/2.0/WSS df7jal...."}
|
37
|
+
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
44
|
+
|
45
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ukolovda/sip-capture.
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sip/capture"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Sip
|
5
|
+
module Capture
|
6
|
+
|
7
|
+
class Hep3
|
8
|
+
|
9
|
+
SIGNATURE = "HEP3"
|
10
|
+
GENERIC_VENDOR_ID = 0
|
11
|
+
|
12
|
+
def self.capture_all(host, port, &block)
|
13
|
+
h = Hep3.new
|
14
|
+
h.bind(host, port)
|
15
|
+
h.capture_all(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def bind(host, port)
|
19
|
+
@socket = UDPSocket.new
|
20
|
+
@socket.bind(host, port)
|
21
|
+
end
|
22
|
+
|
23
|
+
def process_data(data)
|
24
|
+
if (item = parse(data))
|
25
|
+
yield item if block_given?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def capture_all(&block)
|
30
|
+
@in_loop = true
|
31
|
+
while @in_loop do
|
32
|
+
begin
|
33
|
+
data = @socket.recvfrom_nonblock(65535) #=> ["aaa", ["AF_INET", 33302, "localhost.localdomain", "127.0.0.1"]]
|
34
|
+
process_data data[0], &block
|
35
|
+
rescue IO::WaitReadable
|
36
|
+
IO.select([s1], [], [], 10)
|
37
|
+
retry
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def stop
|
43
|
+
@in_loop = false
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
HEP3_FIELDS = {
|
49
|
+
1 => [:ip_protocol_family, :uint8],
|
50
|
+
2 => [:ip_protocol_id, :uint8],
|
51
|
+
3 => [:ipv4_source_address, :ipv4],
|
52
|
+
4 => [:ipv4_destination_address, :ipv4],
|
53
|
+
5 => [:ipv6_source_address, :ipv6],
|
54
|
+
6 => [:ipv6_destination_address, :ipv6],
|
55
|
+
7 => [:protocol_source_port, :uint16],
|
56
|
+
8 => [:protocol_destination_port, :uint16],
|
57
|
+
9 => [:timestamp_sec, :uint32],
|
58
|
+
10=> [:timestamp_usec, :uint32],
|
59
|
+
11=> [:protocol_type, :uint8],
|
60
|
+
12=> [:capture_agent_id, :uint32],
|
61
|
+
13=> [:keep_alive_timer, :uint16],
|
62
|
+
14=> [:authenticate_key, :str],
|
63
|
+
15=> [:payload, :str]
|
64
|
+
}
|
65
|
+
|
66
|
+
def parse(data)
|
67
|
+
# See https://github.com/sipcapture/HEP
|
68
|
+
if hep3?(data)
|
69
|
+
item = {}
|
70
|
+
length = data[4..5].unpack("S>").first
|
71
|
+
pos = 6
|
72
|
+
while pos < length do
|
73
|
+
vendor_id, type_id, chunk_length = data[pos..pos+5].unpack("S>S>S>")
|
74
|
+
payload = data[pos+6...pos+chunk_length]
|
75
|
+
if vendor_id == GENERIC_VENDOR_ID
|
76
|
+
if (info = HEP3_FIELDS[type_id])
|
77
|
+
name, parse_method = info
|
78
|
+
item[name] = send(:"parse_#{parse_method}", payload)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
pos += chunk_length
|
82
|
+
end
|
83
|
+
item
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def hep3?(data)
|
88
|
+
data[0..3] == SIGNATURE
|
89
|
+
end
|
90
|
+
|
91
|
+
def parse_uint8(payload)
|
92
|
+
payload.unpack("C").first
|
93
|
+
end
|
94
|
+
|
95
|
+
def parse_uint16(payload)
|
96
|
+
payload.unpack("S>").first
|
97
|
+
end
|
98
|
+
|
99
|
+
def parse_uint32(payload)
|
100
|
+
payload.unpack("L>").first
|
101
|
+
end
|
102
|
+
|
103
|
+
def parse_ipv4(payload)
|
104
|
+
payload.unpack("CCCC").join(".")
|
105
|
+
end
|
106
|
+
|
107
|
+
def parse_ipv6(payload)
|
108
|
+
# payload.unpack("CCCCCC").map{}.join(".")
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
|
112
|
+
def parse_str(payload)
|
113
|
+
payload.force_encoding('UTF-8')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
data/lib/sip/capture.rb
ADDED
data/sip-capture.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "sip/capture/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.required_ruby_version = '>= 2.0.0'
|
8
|
+
|
9
|
+
spec.name = "sip-capture"
|
10
|
+
spec.version = Sip::Capture::VERSION
|
11
|
+
spec.authors = ["ukolovda"]
|
12
|
+
spec.email = ["udmitry@mail.ru"]
|
13
|
+
|
14
|
+
spec.summary = %q{SIP capture library.}
|
15
|
+
spec.description = %q{SIP capture library (now process HEP3).}
|
16
|
+
spec.homepage = "https://github.com/ukolovda/sip-capture"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
20
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
|
+
# if spec.respond_to?(:metadata)
|
22
|
+
# spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
23
|
+
# else
|
24
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
+
# "public gem pushes."
|
26
|
+
# end
|
27
|
+
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
end
|
33
|
+
spec.bindir = "exe"
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sip-capture
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ukolovda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: SIP capture library (now process HEP3).
|
56
|
+
email:
|
57
|
+
- udmitry@mail.ru
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/sip/capture.rb
|
72
|
+
- lib/sip/capture/hep3.rb
|
73
|
+
- lib/sip/capture/version.rb
|
74
|
+
- sip-capture.gemspec
|
75
|
+
homepage: https://github.com/ukolovda/sip-capture
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.0.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.6.14
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: SIP capture library.
|
99
|
+
test_files: []
|