opensaz 0.1.0
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.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/lib/opensaz/builder.rb +45 -0
- data/lib/opensaz/extractor.rb +40 -0
- data/lib/opensaz/general_info.rb +45 -0
- data/lib/opensaz/http_miscel.rb +50 -0
- data/lib/opensaz/http_request.rb +48 -0
- data/lib/opensaz/http_response.rb +16 -0
- data/lib/opensaz/package.rb +31 -0
- data/lib/opensaz/version.rb +3 -0
- data/lib/opensaz.rb +29 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bbc175174d131d8b538a15e4f92252233897af72
|
4
|
+
data.tar.gz: 62dff9ccc64e2be22e98c55b2eaf83c48ef91e00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a9cbe05c2d8256aa1b0183485979b736dbd93fd968cd26a8e447b33bd59e11b8169537cf671cc1eb3d016169427752ea92858276cc70623ebead17f2ca91d3a
|
7
|
+
data.tar.gz: c8819d81bcdaed910e030e276727e92d34d0f6286c7cc068727dd018aec0b1683f69ae10c00455d8c416ce2dbd9fcf1d37afe00830a1e600ec4e5b65f5ebabda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 TODO: Write your name
|
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,43 @@
|
|
1
|
+
# Opensaz
|
2
|
+
|
3
|
+
This is my first serious repo.!
|
4
|
+
|
5
|
+
It's a Ruby Gem.
|
6
|
+
|
7
|
+
It's used to read .saz file(generated by Fiddler, consist of HTTP requests and responses).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'opensaz'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install opensaz
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
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.
|
32
|
+
|
33
|
+
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).
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/opensaz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
38
|
+
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
43
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Opensaz
|
2
|
+
class Builder
|
3
|
+
|
4
|
+
attr_reader :raw_files, :packages
|
5
|
+
|
6
|
+
def initialize(saz_path)
|
7
|
+
@saz_path = saz_path
|
8
|
+
@dest = nil
|
9
|
+
|
10
|
+
@raw_files = get_raw_files
|
11
|
+
@packages = get_packages
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# ============================
|
17
|
+
# return a list of hash, e.g.:
|
18
|
+
# [{
|
19
|
+
# :id=>"2",
|
20
|
+
# :c=>"raw/1_c.txt",
|
21
|
+
# :s=>"raw/1_s.txt",
|
22
|
+
# :m=>"raw/1_m.xml"
|
23
|
+
# }, ...]
|
24
|
+
def get_raw_files
|
25
|
+
@dest ||= Extractor.new(@saz_path).unzip
|
26
|
+
index_file = File.join(@dest, "_index.htm")
|
27
|
+
raise "no such file: #{index_file}" unless File.exist?(index_file)
|
28
|
+
GeneralInfo.new(File.read(index_file)).to_a
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_packages
|
32
|
+
pkgs = []
|
33
|
+
@raw_files.each do |x|
|
34
|
+
ahash = {
|
35
|
+
dest: @dest,
|
36
|
+
c: x[:c],
|
37
|
+
s: x[:s],
|
38
|
+
m: x[:m]
|
39
|
+
}
|
40
|
+
pkgs.push(Package.new(x[:id], ahash))
|
41
|
+
end
|
42
|
+
pkgs
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'zip'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module Opensaz
|
5
|
+
class Extractor
|
6
|
+
def initialize(saz_path)
|
7
|
+
# saz_path should be absolute path
|
8
|
+
raise "no such file: #{saz_path}" unless File.exist?(saz_path)
|
9
|
+
@saz = saz_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def unzip
|
13
|
+
Extractor.unzip(@saz, destination)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def destination
|
19
|
+
File.join(Dir.pwd, filename)
|
20
|
+
end
|
21
|
+
|
22
|
+
def filename
|
23
|
+
File.basename(@saz, ".*") + "_" + SecureRandom.hex
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.unzip(file, destination)
|
27
|
+
begin
|
28
|
+
Zip::File.open(file) do |zip_file|
|
29
|
+
zip_file.each do |f|
|
30
|
+
fpath = File.join(destination, f.name)
|
31
|
+
zip_file.extract(f, fpath) unless File.exist?(fpath)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
rescue Zip::Error => e
|
35
|
+
raise e.message
|
36
|
+
end
|
37
|
+
destination
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Opensaz
|
4
|
+
class GeneralInfo
|
5
|
+
def initialize(content)
|
6
|
+
@page = Nokogiri::HTML(content)
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_a
|
10
|
+
keys = [:id, :c, :s, :m]
|
11
|
+
ary = []
|
12
|
+
@page.css('tbody tr').each do |x|
|
13
|
+
values = get_tbody_tr(x)
|
14
|
+
tmp = (0...keys.size).map{ |i| [keys[i], values[i]] }.to_h
|
15
|
+
ary.push(tmp)
|
16
|
+
end
|
17
|
+
ary
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def get_tbody_tr(tr_node)
|
23
|
+
tds = tr_node.css('td')
|
24
|
+
[tds[1].text] + seperate_c_s_m(tds[0])
|
25
|
+
end
|
26
|
+
|
27
|
+
def seperate_c_s_m(a_node)
|
28
|
+
a_node.css('a').map{|a| folder_platform_compatible(a["href"]) }
|
29
|
+
end
|
30
|
+
|
31
|
+
# ============================
|
32
|
+
# "raw\\1_c.txt" is too windows specific
|
33
|
+
# from
|
34
|
+
# windows specific
|
35
|
+
# too
|
36
|
+
# platform compatible
|
37
|
+
def folder_platform_compatible(win_path)
|
38
|
+
res = ""
|
39
|
+
win_path.split("\\").each do |f|
|
40
|
+
res = File.join(res, f)
|
41
|
+
end
|
42
|
+
res[1..-1]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Opensaz
|
4
|
+
class HTTPMiscel
|
5
|
+
def initialize(xml_str)
|
6
|
+
@xml = Nokogiri::XML(xml_str)
|
7
|
+
end
|
8
|
+
|
9
|
+
def timers
|
10
|
+
timers_hash = {}
|
11
|
+
@xml.xpath("/Session/SessionTimers").each do |node|
|
12
|
+
timers_hash = {
|
13
|
+
client_connected: node.attribute("ClientConnected").text,
|
14
|
+
client_begin_request: node.attribute("ClientBeginRequest").text,
|
15
|
+
got_request_headers: node.attribute("GotRequestHeaders").text,
|
16
|
+
client_done_request: node.attribute("ClientDoneRequest").text,
|
17
|
+
gateway_time: node.attribute("GatewayTime").text,
|
18
|
+
dns_time: node.attribute("DNSTime").text,
|
19
|
+
tcp_connect_time: node.attribute("TCPConnectTime").text,
|
20
|
+
https_handshake_time: node.attribute("HTTPSHandshakeTime").text,
|
21
|
+
server_connected: node.attribute("ServerConnected").text,
|
22
|
+
fiddler_begin_request: node.attribute("FiddlerBeginRequest").text,
|
23
|
+
server_got_request: node.attribute("ServerGotRequest").text,
|
24
|
+
server_begin_response: node.attribute("ServerBeginResponse").text,
|
25
|
+
got_response_headers: node.attribute("GotResponseHeaders").text,
|
26
|
+
server_done_response: node.attribute("ServerDoneResponse").text,
|
27
|
+
client_begin_response: node.attribute("ClientBeginResponse").text,
|
28
|
+
client_done_response: node.attribute("ClientDoneResponse").text
|
29
|
+
}
|
30
|
+
end
|
31
|
+
timers_hash
|
32
|
+
end
|
33
|
+
|
34
|
+
def flags
|
35
|
+
flags_hash = {}
|
36
|
+
@xml.xpath("/Session/SessionFlags/SessionFlag").each do |node|
|
37
|
+
flags_hash.store(symbolize_it(node.attribute("N").text), node.attribute("V").text)
|
38
|
+
end
|
39
|
+
flags_hash
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def symbolize_it(str)
|
45
|
+
# make it lower case
|
46
|
+
# sub '-'' with '_'
|
47
|
+
str.downcase.gsub('-', '_').to_sym
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Opensaz
|
2
|
+
class HTTPRequest
|
3
|
+
|
4
|
+
CRLF = "\r\n"
|
5
|
+
SEPERATOR = ": "
|
6
|
+
|
7
|
+
def initialize(content)
|
8
|
+
raise "request_str couldn't be nil" if content == nil
|
9
|
+
@content = content
|
10
|
+
end
|
11
|
+
|
12
|
+
def headers
|
13
|
+
first_line = headers_str.split(CRLF)[0]
|
14
|
+
following_lines = headers_str.split(CRLF)[1..-1]
|
15
|
+
get_request_line(first_line).merge(get_headers(following_lines))
|
16
|
+
end
|
17
|
+
|
18
|
+
def body
|
19
|
+
@content.split(CRLF * 2)[1]
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def headers_str
|
25
|
+
@content.split(CRLF * 2)[0]
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_request_line(str)
|
29
|
+
# turn first line of headers into hash
|
30
|
+
a = str.split(" ")
|
31
|
+
{method: a[0], path: a[1], version: a[2]}
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_headers(lines)
|
35
|
+
# turn following lines of headers into hash
|
36
|
+
lines.map do |x|
|
37
|
+
a = x.split(SEPERATOR)
|
38
|
+
[symbolize_it(a[0]), a[1]]
|
39
|
+
end.to_h
|
40
|
+
end
|
41
|
+
|
42
|
+
def symbolize_it(str)
|
43
|
+
# make it lower case
|
44
|
+
# sub '-'' with '_'
|
45
|
+
str.downcase.gsub('-', '_').to_sym
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Opensaz
|
2
|
+
class HTTPResponse < HTTPRequest
|
3
|
+
def headers
|
4
|
+
first_line = headers_str.split(CRLF)[0]
|
5
|
+
following_lines = headers_str.split(CRLF)[1..-1]
|
6
|
+
get_status_line(first_line).merge(get_headers(following_lines))
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def get_status_line(str)
|
12
|
+
a = str.split(" ")
|
13
|
+
{version: a[0], code: a[1], status: a[2]}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Opensaz
|
2
|
+
class Package
|
3
|
+
attr_reader :id, :request, :response, :miscel
|
4
|
+
def initialize(id, ahash)
|
5
|
+
@id = id
|
6
|
+
|
7
|
+
requestf = File.join(ahash[:dest], ahash[:c])
|
8
|
+
responsef = File.join(ahash[:dest], ahash[:s])
|
9
|
+
|
10
|
+
check_files(requestf, responsef)
|
11
|
+
|
12
|
+
@request = HTTPRequest.new(str_in_file(requestf))
|
13
|
+
@response = HTTPResponse.new(str_in_file(responsef))
|
14
|
+
# @miscel = HTTPMiscel.new(File.read(files[2]))
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def check_files(*files)
|
20
|
+
files.each{|x| raise "No such file: #{x}" unless File.exist?(x) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def str_in_file(file)
|
24
|
+
# "b" is important. It won't change line endings.
|
25
|
+
f = File.open(file, "rb")
|
26
|
+
content = f.read
|
27
|
+
f.close
|
28
|
+
return content
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/opensaz.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative "opensaz/builder"
|
2
|
+
require_relative "opensaz/extractor"
|
3
|
+
require_relative "opensaz/general_info"
|
4
|
+
require_relative "opensaz/http_request"
|
5
|
+
require_relative "opensaz/http_response"
|
6
|
+
require_relative "opensaz/http_miscel"
|
7
|
+
require_relative "opensaz/package"
|
8
|
+
require_relative "opensaz/version"
|
9
|
+
|
10
|
+
#a = Opensaz.read(saz_path)
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
#a.basic_info[:destination]
|
15
|
+
#a.basic_info[:number_of_requests]
|
16
|
+
#a.basic_info[:hosts]
|
17
|
+
#a.packages.each{|x| puts x.duration}
|
18
|
+
#a.packages.each{|x| puts x.start_time}
|
19
|
+
#a.packages.each{|x| puts x.comments}
|
20
|
+
#a.packages.each{|x| puts x.request[:host]}
|
21
|
+
#a.packages.each{|x| puts x.response[:version]}
|
22
|
+
|
23
|
+
module Opensaz
|
24
|
+
|
25
|
+
def self.read(saz_path)
|
26
|
+
Builder.new(saz_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opensaz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cong Yang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-09 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubyzip
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: a handy tool to read from .saz file(package captured by Fiddler).
|
84
|
+
email:
|
85
|
+
- ''
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- LICENSE.txt
|
91
|
+
- README.md
|
92
|
+
- lib/opensaz.rb
|
93
|
+
- lib/opensaz/builder.rb
|
94
|
+
- lib/opensaz/extractor.rb
|
95
|
+
- lib/opensaz/general_info.rb
|
96
|
+
- lib/opensaz/http_miscel.rb
|
97
|
+
- lib/opensaz/http_request.rb
|
98
|
+
- lib/opensaz/http_response.rb
|
99
|
+
- lib/opensaz/package.rb
|
100
|
+
- lib/opensaz/version.rb
|
101
|
+
homepage: ''
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.6.7
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: a handy tool to read from .saz file.
|
125
|
+
test_files: []
|