Skip to content

Commit

Permalink
Merge remote branch 'brynary/master'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/rack/bug.rb
  • Loading branch information
zbelzer committed Nov 23, 2010
2 parents 9b94fd2 + aff9bf6 commit 55deda8
Show file tree
Hide file tree
Showing 66 changed files with 1,364 additions and 799 deletions.
45 changes: 45 additions & 0 deletions History.txt
@@ -0,0 +1,45 @@
== HEAD

* New features

* Can use LoggerPanel on ruby stdlib Logger in non-rails app (Tim Connor)

* Bug fixes

* Fix profile, explain and select in the queries tab, fixes issue #22 (ebertech)

* Minor fixes

* Explicitly require 'digest/sha1' (Jérémy Lecour)
* Eliminate unreachable code in params signature validation (Tim Connor)

* Compatibilty

* Make Redis panel compatible with latest redis-rb gem, without breaking older redis-rb versions (Luke Melia)

* Other

* Refactoring and code cleanup (Tim Connor)
* Testing cleanup - better isolation of Rails vs. non-Rails in tests (Tim Connor)

== 0.3.0 / 2010-05-28

* New features

* Log panel includes log level and timestamp (Tim Connor)
* Sphinx panel (George Chatzigeorgiou)
* Backtraces for Redis panel (Luke Melia & Joey Aghion)

* Minor fixes

* Don't "enable" rack bug if you hit cancel on the bookmarklet prompt (Mischa Fierer)

* Compatibilty

* backtrace filtering now supports more than just Rails (Alex Chaffee)
* compatibility with current rack-test (Luke Melia & Joey Aghion)
* update Sinatra sample app (Tim Conner)

== 0.2.1

* The beginning of recorded history
118 changes: 118 additions & 0 deletions README.md
@@ -0,0 +1,118 @@
Rack::Bug
=========

* Repository: [http://github.com/brynary/rack-bug](http://github.com/brynary/rack-bug)

Description
-----------

Rack::Bug adds a diagnostics toolbar to Rack apps. When enabled, it injects a floating div
allowing exploration of logging, database queries, template rendering times, etc.

Features
--------

* Password-based security
* IP-based security
* Rack::Bug instrumentation/reporting is broken up into panels.
* Panels in default configuration:
* Rails Info
* Timer
* Request Variables
* SQL
* Active Record
* Cache
* Templates
* Log
* Memory
* Other bundled panels:
* Redis
* Sphinx
* The API for adding your own panels is simple and powerful

Rails quick start
---------------------------

script/plugin install git://github.com/brynary/rack-bug.git

In config/environments/development.rb, add:

config.middleware.use "Rack::Bug",
:secret_key => "someverylongandveryhardtoguesspreferablyrandomstring"

Add the bookmarklet to your browser:

open http://RAILS_APP/__rack_bug__/bookmarklet.html

Using with non-Rails Rack apps
------------------------------

Just 'use Rack::Bug' as any other middleware. See the SampleApp in the spec/fixtures folder for an example Sinatra app.

If you wish to use the logger panel define the LOGGER constant that is a ruby Logger or ActiveSupport::BufferedLogger

Configuring custom panels
-------------------------

Specify the set of panels you want, in the order you want them to appear:

require "rack/bug"

ActionController::Dispatcher.middleware.use Rack::Bug,
:secret_key => "someverylongandveryhardtoguesspreferablyrandomstring",
:panel_classes => [
Rack::Bug::TimerPanel,
Rack::Bug::RequestVariablesPanel,
Rack::Bug::RedisPanel,
Rack::Bug::TemplatesPanel,
Rack::Bug::LogPanel,
Rack::Bug::MemoryPanel
]


Running Rack::Bug in staging or production
------------------------------------------

We have have found that Rack::Bug is fast enough to run in production for specific troubleshooting efforts.

### Configuration ####

Add the middleware configuration to an initializer or the appropriate environment files, taking the rest of this section into consideration.

### Security ####

Restrict access to particular IP addresses:

require "ipaddr"

ActionController::Dispatcher.middleware.use "Rack::Bug"
:secret_key => "someverylongandveryhardtoguesspreferablyrandomstring",
:ip_masks => [IPAddr.new("2.2.2.2/0")]

Restrict access using a password:

ActionController::Dispatcher.middleware.use "Rack::Bug",
:secret_key => "someverylongandveryhardtoguesspreferablyrandomstring",
:password => "yourpassword"


Authors
-------

- Maintained by [Bryan Helmkamp](mailto:bryan@brynary.com)
- Contributions from Luke Melia, Joey Aghion, Tim Connor, and more

Thanks
------
Inspiration for Rack::Bug is primarily from the Django debug toolbar. Additional ideas from Rails footnotes, Rack's ShowException middleware, Oink, and Rack::Cache

Thanks to Weplay.com for supporting the development of Rack::Bug

Development
-----------
For development, you'll need to install the following gems: rspec, rack-test, webrat, sinatra

License
-------

See MIT-LICENSE.txt in this directory.
29 changes: 0 additions & 29 deletions README.rdoc

This file was deleted.

9 changes: 6 additions & 3 deletions Rakefile
Expand Up @@ -14,7 +14,10 @@ Spec::Rake::SpecTask.new(:rcov) do |t|
end
end

task :spec => :check_dependencies

desc "Run the specs"
task :default => :spec
task :default => :spec

desc 'Removes trailing whitespace'
task :whitespace do
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
end
8 changes: 6 additions & 2 deletions Thorfile
Expand Up @@ -21,9 +21,13 @@ module GemHelpers
s.test_files = normalize_files(Dir['spec/**/*.rb'] - repo.lib.ignored_files)

s.has_rdoc = true
s.extra_rdoc_files = %w[README.rdoc MIT-LICENSE.txt]
s.extra_rdoc_files = %w[README.md MIT-LICENSE.txt]

s.add_dependency "rack", ">= 1.0"
s.add_development_dependency "webrat"
s.add_development_dependency "rspec"
s.add_development_dependency "sinatra"
s.add_development_dependency "git"
end
end

Expand Down Expand Up @@ -106,4 +110,4 @@ class Release < Thor
def gem
sh "gem push pkg/#{read_gemspec.file_name}"
end
end
end
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

92 changes: 67 additions & 25 deletions lib/rack/bug.rb
@@ -1,28 +1,14 @@
require "ipaddr"
require "digest"
require "rack"
require "digest/sha1"
require "rack/bug/autoloading"

module Rack::Bug
autoload :Options, "rack/bug/options"
autoload :Panel, "rack/bug/panel"
autoload :PanelApp, "rack/bug/panel_app"
autoload :ParamsSignature, "rack/bug/params_signature"
autoload :Render, "rack/bug/render"
autoload :Toolbar, "rack/bug/toolbar"

# Panels
autoload :ActiveRecordPanel, "rack/bug/panels/active_record_panel"
autoload :CachePanel, "rack/bug/panels/cache_panel"
autoload :LogPanel, "rack/bug/panels/log_panel"
autoload :MemoryPanel, "rack/bug/panels/memory_panel"
autoload :RailsInfoPanel, "rack/bug/panels/rails_info_panel"
autoload :RedisPanel, "rack/bug/panels/redis_panel"
autoload :MongoPanel, "rack/bug/panels/mongo_panel"
autoload :RequestVariablesPanel, "rack/bug/panels/request_variables_panel"
autoload :SQLPanel, "rack/bug/panels/sql_panel"
autoload :TemplatesPanel, "rack/bug/panels/templates_panel"
autoload :TimerPanel, "rack/bug/panels/timer_panel"

VERSION = "0.2.2.pre"

class Rack::Bug
include Options

VERSION = "0.3.0"

class SecurityError < StandardError
end

Expand All @@ -38,7 +24,63 @@ def self.enabled?
Thread.current["rack-bug.enabled"] == true
end

def self.new(*args, &block)
Toolbar.new(*args, &block)
def initialize(app, options = {}, &block)
@app = asset_server(app)
initialize_options options
instance_eval(&block) if block_given?

@toolbar = Toolbar.new(RedirectInterceptor.new(@app))
end


def call(env)
env.replace @default_options.merge(env)
@env = env
@original_request = Rack::Request.new(@env)

if toolbar_requested? && ip_authorized? && password_authorized? && toolbar_xhr?
@toolbar.call(env)
else
@app.call(env)
end
end

private

def toolbar_xhr?
!@original_request.xhr? || @original_request.path =~ /^\/__rack_bug__/
end

def asset_server(app)
RackStaticBugAvoider.new(app, Rack::Static.new(app, :urls => ["/__rack_bug__"], :root => public_path))
end

def public_path
::File.expand_path(::File.dirname(__FILE__) + "/bug/public")
end

def toolbar_requested?
@original_request.cookies["rack_bug_enabled"]
end

def ip_authorized?
return true unless options["rack-bug.ip_masks"]

options["rack-bug.ip_masks"].any? do |ip_mask|
ip_mask.include?(IPAddr.new(@original_request.ip))
end
end

def password_authorized?
return true unless options["rack-bug.password"]

expected_sha = Digest::SHA1.hexdigest ["rack_bug", options["rack-bug.password"]].join(":")
actual_sha = @original_request.cookies["rack_bug_password"]

actual_sha == expected_sha
end
<<<<<<< HEAD
=======

>>>>>>> brynary/master
end
25 changes: 25 additions & 0 deletions lib/rack/bug/autoloading.rb
@@ -0,0 +1,25 @@
class Rack::Bug
autoload :FilteredBacktrace, "rack/bug/filtered_backtrace"
autoload :Options, "rack/bug/options"
autoload :Panel, "rack/bug/panel"
autoload :PanelApp, "rack/bug/panel_app"
autoload :ParamsSignature, "rack/bug/params_signature"
autoload :RackStaticBugAvoider, "rack/bug/rack_static_bug_avoider"
autoload :RedirectInterceptor, "rack/bug/redirect_interceptor"
autoload :Render, "rack/bug/render"
autoload :Toolbar, "rack/bug/toolbar"

# Panels
autoload :ActiveRecordPanel, "rack/bug/panels/active_record_panel"
autoload :CachePanel, "rack/bug/panels/cache_panel"
autoload :LogPanel, "rack/bug/panels/log_panel"
autoload :MemoryPanel, "rack/bug/panels/memory_panel"
autoload :RailsInfoPanel, "rack/bug/panels/rails_info_panel"
autoload :RedisPanel, "rack/bug/panels/redis_panel"
autoload :MongoPanel, "rack/bug/panels/mongo_panel"
autoload :RequestVariablesPanel, "rack/bug/panels/request_variables_panel"
autoload :SQLPanel, "rack/bug/panels/sql_panel"
autoload :TemplatesPanel, "rack/bug/panels/templates_panel"
autoload :TimerPanel, "rack/bug/panels/timer_panel"
autoload :SphinxPanel, "rack/bug/panels/sphinx_panel"
end

0 comments on commit 55deda8

Please sign in to comment.