lrd_rack_bug 0.3.1 → 0.3.1.1
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.
- data/lib/rack/bug/autoloading.rb +1 -0
- data/lib/rack/bug/logger.rb +47 -0
- data/lib/rack/bug/options.rb +9 -7
- data/lib/rack/bug/panels/speedtracer_panel.rb +11 -13
- data/lib/rack/bug.rb +19 -3
- data/lrd_rack_bug.gemspec +1 -1
- metadata +4 -2
data/lib/rack/bug/autoloading.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class Rack::Bug
|
2
2
|
autoload :FilteredBacktrace, "rack/bug/filtered_backtrace"
|
3
3
|
autoload :Options, "rack/bug/options"
|
4
|
+
autoload :Logger, "rack/bug/logger"
|
4
5
|
autoload :Panel, "rack/bug/panel"
|
5
6
|
autoload :PanelApp, "rack/bug/panel_app"
|
6
7
|
autoload :ParamsSignature, "rack/bug/params_signature"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Rack::Bug
|
2
|
+
class Logger
|
3
|
+
def initialize(level, path)
|
4
|
+
@level = level
|
5
|
+
@log_path = path
|
6
|
+
@logfile = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_accessor :level
|
10
|
+
|
11
|
+
DEBUG = 0
|
12
|
+
INFO = 1
|
13
|
+
WARN = 2
|
14
|
+
ERROR = 3
|
15
|
+
FATAL = 4
|
16
|
+
UNKNOWN = 5
|
17
|
+
|
18
|
+
def log(severity, message)
|
19
|
+
if defined? Rails and not Rails.logger.nil?
|
20
|
+
Rails.logger.add(severity, "[Rack::Bug]: " + message)
|
21
|
+
end
|
22
|
+
|
23
|
+
if severity >= @level
|
24
|
+
logfile.puts(message)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def logfile
|
29
|
+
@logfile ||= File::open(path, "a+")
|
30
|
+
rescue
|
31
|
+
$stderr
|
32
|
+
end
|
33
|
+
|
34
|
+
def debug; log(DEBUG, yield) if @level >= DEBUG; end
|
35
|
+
def info; log(INFO, yield) if @level >= INFO; end
|
36
|
+
def warn; log(WARN, yield) if @level >= WARN; end
|
37
|
+
def error; log(ERROR, yield) if @level >= ERROR; end
|
38
|
+
def fatal; log(FATAL, yield) if @level >= FATAL; end
|
39
|
+
def unknown; log(UNKNOWN, yield) if @level >= UNKNOWN; end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Logging
|
43
|
+
def logger(env)
|
44
|
+
env["rack-bug.logger"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/rack/bug/options.rb
CHANGED
@@ -64,13 +64,15 @@ class Rack::Bug
|
|
64
64
|
|
65
65
|
def initialize_options(options={})
|
66
66
|
@default_options = {
|
67
|
-
'rack-bug.ip_masks'
|
68
|
-
'rack-bug.password'
|
69
|
-
'rack-bug.verbose'
|
70
|
-
'rack-bug.secret_key'
|
71
|
-
'rack-bug.intercept_redirects'
|
72
|
-
'rack-bug.panels'
|
73
|
-
'rack-bug.
|
67
|
+
'rack-bug.ip_masks' => [IPAddr.new("127.0.0.1")],
|
68
|
+
'rack-bug.password' => nil,
|
69
|
+
'rack-bug.verbose' => nil,
|
70
|
+
'rack-bug.secret_key' => nil,
|
71
|
+
'rack-bug.intercept_redirects' => false,
|
72
|
+
'rack-bug.panels' => [],
|
73
|
+
'rack-bug.log_level' => Logger::DEBUG,
|
74
|
+
'rack-bug.log_path' => "log/rack_bug.log",
|
75
|
+
'rack-bug.panel_classes' => [
|
74
76
|
RailsInfoPanel,
|
75
77
|
TimerPanel,
|
76
78
|
RequestVariablesPanel,
|
@@ -49,19 +49,17 @@ class Rack::Bug
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def make_database
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
# return {}
|
64
|
-
# end
|
52
|
+
require 'rack/bug/panels/speedtracer_panel/database'
|
53
|
+
return Database.new("speedtracer")
|
54
|
+
rescue Object => ex
|
55
|
+
msg = "Speedtracer issue while loading SQLite DB:" + [ex.class, ex.message, ex.backtrace[0..4]].inspect
|
56
|
+
if Rails.logger
|
57
|
+
Rails.logger.debug msg
|
58
|
+
else
|
59
|
+
puts msg
|
60
|
+
end
|
61
|
+
|
62
|
+
return {}
|
65
63
|
end
|
66
64
|
|
67
65
|
end
|
data/lib/rack/bug.rb
CHANGED
@@ -3,6 +3,7 @@ require "digest"
|
|
3
3
|
require "rack"
|
4
4
|
require "digest/sha1"
|
5
5
|
require "rack/bug/autoloading"
|
6
|
+
require 'rack/bug/logger'
|
6
7
|
|
7
8
|
class Rack::Bug
|
8
9
|
include Options
|
@@ -29,14 +30,16 @@ class Rack::Bug
|
|
29
30
|
@app = asset_server(app)
|
30
31
|
instance_eval(&block) if block_given?
|
31
32
|
|
33
|
+
@logger = Logger.new(read_option(:log_level), read_option(:log_path))
|
32
34
|
@toolbar = Toolbar.new(RedirectInterceptor.new(@app))
|
33
35
|
end
|
34
|
-
|
36
|
+
attr_reader :logger
|
35
37
|
|
36
38
|
def call(env)
|
37
39
|
env.replace @default_options.merge(env)
|
38
40
|
@env = env
|
39
41
|
@original_request = Rack::Request.new(@env)
|
42
|
+
env['rack-bug.logger'] = @logger
|
40
43
|
|
41
44
|
if toolbar_requested? && ip_authorized? && password_authorized? && toolbar_xhr?
|
42
45
|
@toolbar.call(env)
|
@@ -81,17 +84,30 @@ private
|
|
81
84
|
def ip_authorized?
|
82
85
|
return true unless options["rack-bug.ip_masks"]
|
83
86
|
|
84
|
-
|
85
|
-
|
87
|
+
logger.debug{ "Checking #{@original_request.ip} against ip_masks" }
|
88
|
+
ip = IPAddr.new(@original_request.ip)
|
89
|
+
|
90
|
+
mask = options["rack-bug.ip_masks"].find do |ip_mask|
|
91
|
+
ip_mask.include?(ip)
|
92
|
+
end
|
93
|
+
if mask
|
94
|
+
logger.debug{ "Matched #{mask}" }
|
95
|
+
return true
|
96
|
+
else
|
97
|
+
logger.debug{ "Matched no masks" }
|
98
|
+
return false
|
86
99
|
end
|
87
100
|
end
|
88
101
|
|
89
102
|
def password_authorized?
|
90
103
|
return true unless options["rack-bug.password"]
|
91
104
|
|
105
|
+
logger.debug{"Checking password"}
|
106
|
+
|
92
107
|
expected_sha = Digest::SHA1.hexdigest ["rack_bug", options["rack-bug.password"]].join(":")
|
93
108
|
actual_sha = @original_request.cookies["rack_bug_password"]
|
94
109
|
|
110
|
+
logger.debug{"Password result: #{actual_sha == expected_sha}"}
|
95
111
|
actual_sha == expected_sha
|
96
112
|
end
|
97
113
|
end
|
data/lrd_rack_bug.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{lrd_rack_bug}
|
5
|
-
s.version = "0.3.1"
|
5
|
+
s.version = "0.3.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Bryan Helmkamp", "Evan Dorn", "Judson Lester"]
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lrd_rack_bug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 81
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
9
|
- 1
|
10
|
-
|
10
|
+
- 1
|
11
|
+
version: 0.3.1.1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Bryan Helmkamp
|
@@ -79,6 +80,7 @@ files:
|
|
79
80
|
- lib/rack/bug/views/error.html.erb
|
80
81
|
- lib/rack/bug/options.rb
|
81
82
|
- lib/rack/bug/panel.rb
|
83
|
+
- lib/rack/bug/logger.rb
|
82
84
|
- lib/rack/bug/filtered_backtrace.rb
|
83
85
|
- lib/rack/bug/panels/request_variables_panel.rb
|
84
86
|
- lib/rack/bug/panels/redis_panel.rb
|