mistiq 0.0.82 → 0.0.83
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 +8 -8
- data/lib/mistiq.rb +2 -1
- data/lib/mistiq/init.rb +57 -0
- data/lib/mistiq/middleware.rb +37 -0
- metadata +3 -4
- data/bin/rails/init.rb +0 -51
- data/lib/mistiq/link_redactor.rb +0 -29
- data/lib/mistiq/railtie.rb +0 -7
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
NTVjNmY2YmZlMjNjMjlkZTRjMjlhODdlZmVkYTMzZTVhNzg1MmU2OQ==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
MjMzNjQ2MGYwNjM2MWM3Yzk3YjM1NGEyMTE2ODk3MTAzZThiODhjYg==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
YTFmMDJmN2Y5MDE4ODMwZjI1ZTZiMDNlMWQ1NDAzNTM3ZDc2MzFkNjU2NDZi
|
|
10
|
+
ZjEyYTdhMzg3YzA2MDY4NDRjNDI5OWVjNmU3OTMxMzUwMzZiMjFjNGIzYTVh
|
|
11
|
+
NDA0Y2JhYWNjYjI3ZDAxMzc0ZTMzZDNhZjQ2ZjExY2VmMzk4ZjM=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
YTYxNDlmYTQzNTM3ZjlhZWNkOTc5YWFjYzVjYTRlZDAxYTA3ZWMyOTcwNTI4
|
|
14
|
+
ODEzYzBiMTQ3YWUxZDIxMjY2OTFhZTQ2OGEwOTUwNjA1ODVlMDFlNWRmOGQ0
|
|
15
|
+
YWJmYmVmM2I3ZjFhODliZGQ4NDk5NTIzMWVmMmJjODg3Y2VlOWE=
|
data/lib/mistiq.rb
CHANGED
data/lib/mistiq/init.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module Mistiq
|
|
2
|
+
class Railtie < Rails::Railtie
|
|
3
|
+
initializer "mistiq.configure_rails_initialization" do |app|
|
|
4
|
+
Rails.application.config.after_initialize do
|
|
5
|
+
LINK_REGEX_HASH = Hash.new
|
|
6
|
+
|
|
7
|
+
#pre-load routes
|
|
8
|
+
Rails.application.reload_routes!
|
|
9
|
+
|
|
10
|
+
#get routes
|
|
11
|
+
routes = Rails.application.routes.routes
|
|
12
|
+
|
|
13
|
+
routes.each {
|
|
14
|
+
|r|
|
|
15
|
+
controller = r.defaults[:controller]
|
|
16
|
+
action = r.defaults[:action]
|
|
17
|
+
|
|
18
|
+
route = r.path.spec.to_s
|
|
19
|
+
|
|
20
|
+
#removes (.:format)
|
|
21
|
+
if route.match("(.:format)")
|
|
22
|
+
pattern = route.sub("(.:format)","")
|
|
23
|
+
else
|
|
24
|
+
pattern = route
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
#if there are any parameters in
|
|
28
|
+
#the route use regex to ignore them
|
|
29
|
+
if pattern.match(/(:.*\/)/)
|
|
30
|
+
pattern.gsub!(/(:.*\/)/,".*/")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#if there is a parameter at the end
|
|
34
|
+
if pattern.match(/(:.*)/)
|
|
35
|
+
pattern.gsub!(/(:.*)/,"[^\/\"]*")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if action == "destroy"
|
|
39
|
+
destroy_regex = "data-method=(\"|')delete(\"|')";
|
|
40
|
+
pattern = "<a.*#{destroy_regex}.*href=(\"|')#{pattern}(\"|').*>.*<\/a>"
|
|
41
|
+
#also check if destroy_regex occurs after the href attribute
|
|
42
|
+
pattern = pattern+"@@@<a.*href=(\"|')#{pattern}(\"|').*#{destroy_regex}.*>.*<\/a>"
|
|
43
|
+
else
|
|
44
|
+
pattern = "<a.*href=(\"|')#{pattern}(\"|').*>.*<\/a>"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
#espace / characters
|
|
48
|
+
pattern.gsub!(/\//,"\\/")
|
|
49
|
+
|
|
50
|
+
LINK_REGEX_HASH["#{controller}##{action}"] = pattern
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
puts "Link REGEX hash has been computed"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Mistiq
|
|
2
|
+
class Railtie < Rails::Railtie
|
|
3
|
+
initializer "mistiq.configure_rails_initialization" do |app|
|
|
4
|
+
app.config.middleware.use Middleware
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class Middleware
|
|
9
|
+
def initialize(app)
|
|
10
|
+
@app = app
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call(env)
|
|
14
|
+
status, headers, response = @app.call(env)
|
|
15
|
+
|
|
16
|
+
#if the current file is an HTML document
|
|
17
|
+
if headers != nil && headers["Content-Type"] != nil && (headers["Content-Type"].include? "text/html")
|
|
18
|
+
regex = ENV['REGEX'].split("@@@")
|
|
19
|
+
body = response.body
|
|
20
|
+
|
|
21
|
+
regex.each {
|
|
22
|
+
|r|
|
|
23
|
+
temp = body.gsub(/#{r}/,"Redacted")
|
|
24
|
+
if temp != nil
|
|
25
|
+
body = temp
|
|
26
|
+
end
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#rebuild response
|
|
30
|
+
response = Rack::Response.new(body,status,headers)
|
|
31
|
+
response.finish
|
|
32
|
+
else
|
|
33
|
+
[status, headers, response]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mistiq
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.83
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Papancea
|
|
@@ -19,10 +19,9 @@ files:
|
|
|
19
19
|
- Rakefile
|
|
20
20
|
- lib/mistiq.rb
|
|
21
21
|
- lib/mistiq/base.rb
|
|
22
|
-
- lib/mistiq/
|
|
23
|
-
- lib/mistiq/
|
|
22
|
+
- lib/mistiq/middleware.rb
|
|
23
|
+
- lib/mistiq/init.rb
|
|
24
24
|
- bin/mistiq
|
|
25
|
-
- bin/rails/init.rb
|
|
26
25
|
- test/test_mistiq.rb
|
|
27
26
|
homepage:
|
|
28
27
|
licenses: []
|
data/bin/rails/init.rb
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
Rails.application.config.after_initialize do
|
|
2
|
-
LINK_REGEX_HASH = Hash.new
|
|
3
|
-
|
|
4
|
-
#pre-load routes
|
|
5
|
-
Rails.application.reload_routes!
|
|
6
|
-
|
|
7
|
-
#get routes
|
|
8
|
-
routes = Rails.application.routes.routes
|
|
9
|
-
|
|
10
|
-
routes.each {
|
|
11
|
-
|r|
|
|
12
|
-
controller = r.defaults[:controller]
|
|
13
|
-
action = r.defaults[:action]
|
|
14
|
-
|
|
15
|
-
route = r.path.spec.to_s
|
|
16
|
-
|
|
17
|
-
#removes (.:format)
|
|
18
|
-
if route.match("(.:format)")
|
|
19
|
-
pattern = route.sub("(.:format)","")
|
|
20
|
-
else
|
|
21
|
-
pattern = route
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
#if there are any parameters in
|
|
25
|
-
#the route use regex to ignore them
|
|
26
|
-
if pattern.match(/(:.*\/)/)
|
|
27
|
-
pattern.gsub!(/(:.*\/)/,".*/")
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
#if there is a parameter at the end
|
|
31
|
-
if pattern.match(/(:.*)/)
|
|
32
|
-
pattern.gsub!(/(:.*)/,"[^\/\"]*")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
if action == "destroy"
|
|
36
|
-
destroy_regex = "data-method=(\"|')delete(\"|')";
|
|
37
|
-
pattern = "<a.*#{destroy_regex}.*href=(\"|')#{pattern}(\"|').*>.*<\/a>"
|
|
38
|
-
#also check if destroy_regex occurs after the href attribute
|
|
39
|
-
pattern = pattern+"@@@<a.*href=(\"|')#{pattern}(\"|').*#{destroy_regex}.*>.*<\/a>"
|
|
40
|
-
else
|
|
41
|
-
pattern = "<a.*href=(\"|')#{pattern}(\"|').*>.*<\/a>"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
#espace / characters
|
|
45
|
-
pattern.gsub!(/\//,"\\/")
|
|
46
|
-
|
|
47
|
-
LINK_REGEX_HASH["#{controller}##{action}"] = pattern
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
puts "Link REGEX hash has been computed"
|
|
51
|
-
end
|
data/lib/mistiq/link_redactor.rb
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
class LinkRedactor
|
|
2
|
-
def initialize(app)
|
|
3
|
-
@app = app
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
def call(env)
|
|
7
|
-
status, headers, response = @app.call(env)
|
|
8
|
-
|
|
9
|
-
#if the current file is an HTML document
|
|
10
|
-
if headers != nil && headers["Content-Type"] != nil && (headers["Content-Type"].include? "text/html")
|
|
11
|
-
regex = ENV['REGEX'].split("@@@")
|
|
12
|
-
body = response.body
|
|
13
|
-
|
|
14
|
-
regex.each {
|
|
15
|
-
|r|
|
|
16
|
-
temp = body.gsub(/#{r}/,"Redacted")
|
|
17
|
-
if temp != nil
|
|
18
|
-
body = temp
|
|
19
|
-
end
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
#rebuild response
|
|
23
|
-
response = Rack::Response.new(body,status,headers)
|
|
24
|
-
response.finish
|
|
25
|
-
else
|
|
26
|
-
[status, headers, response]
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|