waffle-maker 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/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tasks/waffle.rake +9 -0
- data/lib/waffle/maker.rb +53 -0
- data/lib/waffle/maker/formatter.rb +31 -0
- data/lib/waffle/maker/matcher.rb +35 -0
- data/lib/waffle/maker/railtie.rb +9 -0
- data/lib/waffle/maker/route.rb +43 -0
- data/lib/waffle/maker/version.rb +5 -0
- data/lib/waffle/maker/waf.rb +42 -0
- data/waffle-maker.gemspec +28 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4b1b0e46c19776a221e711038296974e903924eb1d95d28263a85d79dff35358
|
4
|
+
data.tar.gz: 04bb2c5facaa8d30e94adc47f6b65f6de3d66162866071aae0224a8a6af92c7b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2878b418573b2038503229d7327270cfcb6edb2358f055d0906a62f68749ccd22fdc26154aa41c649c4ddd5da1cae498dff5614b22bee1fd2db869aedd0ebd09
|
7
|
+
data.tar.gz: 64bf65bb061745b2009a22f4c1c5eadb02b0b33f727ed3b1b282ba635ff941f16e56ace800189f4908a57c9a663988d859b808a4f40c905341edabaa7beb02df
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
waffle-maker (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.0)
|
16
|
+
rspec-support (~> 3.9.0)
|
17
|
+
rspec-expectations (3.9.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 2.0)
|
30
|
+
rake (~> 10.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
waffle-maker!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.0.1
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# WaffleMaker
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/waffle-maker)
|
4
|
+
[](https://coveralls.io/r/chibicco/waffle-maker)
|
5
|
+
[](https://travis-ci.org/chibicco/waffle-maker)
|
6
|
+
|
7
|
+
Find waf logs that match rails routing.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'waffle-maker'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install waffle-maker
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
$ iconv -f cp932 -t utf-8 < alert-201912.txt | bundle exec rake waffle:filter
|
29
|
+
```
|
30
|
+
|
31
|
+
with options
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
$ iconv -f cp932 -t utf-8 < alert-201912.txt | bundle exec rake waffle:filter -f 2 -w 2
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/chibicco/waffle-maker.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "waffle/maker"
|
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
data/lib/waffle/maker.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "waffle/maker/version"
|
2
|
+
require "waffle/maker/route"
|
3
|
+
require "waffle/maker/waf"
|
4
|
+
require "waffle/maker/matcher"
|
5
|
+
require "waffle/maker/railtie" if defined?(::Rails)
|
6
|
+
|
7
|
+
module Waffle
|
8
|
+
module Maker
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class Filter
|
12
|
+
attr_reader :options
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def execute
|
16
|
+
Waffle::Maker::Filter.new(ARGV.dup).execute
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(argv)
|
21
|
+
(@options = default_options).tap do |options|
|
22
|
+
OptionParser.new { |o|
|
23
|
+
o.banner = "Usage: #{$0}"
|
24
|
+
o.on("-f number", "Column number that contains the rails path") { |v| options[:f] << v.to_i }
|
25
|
+
o.on("-w number", "Column number that contains the waf path") { |v| options[:w] << v.to_i }
|
26
|
+
}.parse!(argv)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @override
|
31
|
+
def default_options
|
32
|
+
{f: 2, w: 2}
|
33
|
+
end
|
34
|
+
|
35
|
+
def execute
|
36
|
+
wafs.each do |waf|
|
37
|
+
w = Waffle::Maker::Matcher.new(waf[:path], routes)
|
38
|
+
puts waf[:raw] if w.matche?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def routes
|
45
|
+
@routes ||= Waffle::Maker::Route.new(options[:f]).paths
|
46
|
+
end
|
47
|
+
|
48
|
+
def wafs
|
49
|
+
@wafs ||= Waffle::Maker::Waf.new(options[:w]).all
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Waffle
|
2
|
+
module Maker
|
3
|
+
class Formatter
|
4
|
+
def initialize
|
5
|
+
@buffer = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def result
|
9
|
+
@buffer.join("\n")
|
10
|
+
end
|
11
|
+
|
12
|
+
def section_title(_title)
|
13
|
+
# noop
|
14
|
+
end
|
15
|
+
|
16
|
+
def section(routes)
|
17
|
+
routes.each do |r|
|
18
|
+
@buffer << [r[:name], r[:verb], r[:path], r[:reqs]].join(",")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def header(_routes)
|
23
|
+
# noop
|
24
|
+
end
|
25
|
+
|
26
|
+
def no_routes
|
27
|
+
# noop
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Waffle
|
4
|
+
module Maker
|
5
|
+
class Matcher
|
6
|
+
attr_reader :waf_path, :routes
|
7
|
+
|
8
|
+
def initialize(waf_path, routes)
|
9
|
+
@waf_path = waf_path.to_s.chomp('/')
|
10
|
+
@routes = routes
|
11
|
+
end
|
12
|
+
|
13
|
+
def matche?
|
14
|
+
return true if routes.include?(waf_path)
|
15
|
+
|
16
|
+
routes.any? do |route|
|
17
|
+
-> {
|
18
|
+
params_route_2_regex_route!(route)
|
19
|
+
return false if route.start_with?('/(.*)')
|
20
|
+
/#{route}$/.match?(waf_path)
|
21
|
+
}.call
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# /users/:id/edit/:example
|
28
|
+
# ↓
|
29
|
+
# /users/(.*)/edit/(.*)
|
30
|
+
def params_route_2_regex_route!(route)
|
31
|
+
route.gsub!(/:\w+/, '(.*)')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "waffle/maker/formatter"
|
3
|
+
require 'csv'
|
4
|
+
|
5
|
+
module Waffle
|
6
|
+
module Maker
|
7
|
+
class Route
|
8
|
+
attr_accessor :path_position
|
9
|
+
|
10
|
+
def initialize(path_position)
|
11
|
+
self.path_position = path_position
|
12
|
+
end
|
13
|
+
|
14
|
+
def all
|
15
|
+
defined?(::Rails) ? rails : default
|
16
|
+
end
|
17
|
+
|
18
|
+
def paths
|
19
|
+
all.each.with_object([]) do |v, o|
|
20
|
+
o << v[path_position].gsub(/\(\.:format\)$/, "")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# @override
|
25
|
+
def default
|
26
|
+
[]
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# [
|
32
|
+
# ["home", "GET", "/home(.:format)", "homes#show"],
|
33
|
+
# ["user", "GET", "/user(.:format)", "users#show"],
|
34
|
+
# ...
|
35
|
+
# ]
|
36
|
+
def rails
|
37
|
+
routes = ::Rails.application.routes.routes
|
38
|
+
inspector = ::ActionDispatch::Routing::RoutesInspector.new(routes)
|
39
|
+
CSV.parse(inspector.format(Waffle::Maker::Formatter.new))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "waffle/maker/formatter"
|
3
|
+
require 'csv'
|
4
|
+
|
5
|
+
module Waffle
|
6
|
+
module Maker
|
7
|
+
class Waf
|
8
|
+
attr_accessor :path_position
|
9
|
+
|
10
|
+
def initialize(path_position)
|
11
|
+
self.path_position = path_position
|
12
|
+
end
|
13
|
+
|
14
|
+
# [
|
15
|
+
# { raw: "2019/01/01 01:01:01\t8.8.8.8\t/homes\t攻撃\t○", path: "/hoems" },
|
16
|
+
# { raw: "2019/01/01 01:01:01\t8.8.8.8\t/users\t攻撃\t○", path: "/users" },
|
17
|
+
# ...
|
18
|
+
# ]
|
19
|
+
def all
|
20
|
+
readlines.each.with_object([]) do |line, o|
|
21
|
+
line.chomp.tap do |line|
|
22
|
+
o << {
|
23
|
+
raw: line,
|
24
|
+
path: line.split(/#{parse_symbol}/)[path_position]
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @override
|
31
|
+
def parse_symbol
|
32
|
+
ENV.fetch("IFS", "\t")
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def readlines
|
38
|
+
@readlines ||= $stdin.readlines
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "waffle/maker/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "waffle-maker"
|
8
|
+
spec.version = Waffle::Maker::VERSION
|
9
|
+
spec.authors = ["chibicco"]
|
10
|
+
spec.email = ["chibiccoes@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Find waf logs that match rails routing."
|
13
|
+
spec.description = "Find waf logs that match rails routing."
|
14
|
+
spec.homepage = "http://github.com/chibicco/waffle-maker"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: waffle-maker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- chibicco
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-20 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: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Find waf logs that match rails routing.
|
56
|
+
email:
|
57
|
+
- chibiccoes@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/tasks/waffle.rake
|
72
|
+
- lib/waffle/maker.rb
|
73
|
+
- lib/waffle/maker/formatter.rb
|
74
|
+
- lib/waffle/maker/matcher.rb
|
75
|
+
- lib/waffle/maker/railtie.rb
|
76
|
+
- lib/waffle/maker/route.rb
|
77
|
+
- lib/waffle/maker/version.rb
|
78
|
+
- lib/waffle/maker/waf.rb
|
79
|
+
- waffle-maker.gemspec
|
80
|
+
homepage: http://github.com/chibicco/waffle-maker
|
81
|
+
licenses: []
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.7.6.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Find waf logs that match rails routing.
|
103
|
+
test_files: []
|