web-console-2.2.1/ 0000755 0000764 0000764 00000000000 12560702257 012773 5 ustar pravi pravi web-console-2.2.1/CHANGELOG.markdown 0000644 0000764 0000764 00000005320 12560702257 016026 0 ustar pravi pravi # CHANGELOG ## master (unreleased) ## 2.2.1 * [#150](https://github.com/rails/web-console/pull/150) Change config.development_only default until 4.2.4 is released. ## 2.2.0 * [#140](https://github.com/rails/web-console/pull/140) Add the ability to close the console on each page ([@sh19910711]) * [#135](https://github.com/rails/web-console/pull/135) Run the console only in development mode and raise warning in tests ([@frenesim]) * [#134](https://github.com/rails/web-conscle/pull/134) Force development only web console by default ([@gsamokovarov]) * [#123](https://github.com/rails/web-console/pull/123) Replace deprecated `alias_method_chain` with `alias_method` ([@jonatack]) ## 2.1.3 * Fix remote code execution vulnerability in Web Console. CVE-2015-3224. ## 2.1.2 * [#115](https://github.com/rails/web-console/pull/115) Show proper binding when raising an error in a template ([@gsamokovarov]) * [#114](https://github.com/rails/web-console/pull/114) Fix templates non rendering, because of missing template suffix ([@gsamokovarov]) ## 2.1.1 * [#112](https://github.com/rails/web-console/pull/112) Always allow application/x-www-form-urlencoded content type ([@gsamokovarov]) ## 2.1.0 * [#109](https://github.com/rails/web-console/pull/109) Revamp unavailable session response message ([@gsamokovarov]) * [#107](https://github.com/rails/web-console/pull/107) Fix pasting regression for all browsers ([@parterburn]) * [#105](https://github.com/rails/web-console/pull/105) Lock scroll bottom on console window resize ([@noahpatterson]) * [#104](https://github.com/rails/web-console/pull/104) Always whitelist localhost and inform users why no console is displayed ([@gsamokovarov]) * [#100](https://github.com/rails/web-console/pull/100) Accept text/plain as acceptable content type for Puma ([@gsamokovarov]) * [#98](https://github.com/rails/web-console/pull/98) Add arbitrary big z-index to the console ([@bglbruno]) * [#88](https://github.com/rails/web-console/pull/88) Spelling fixes ([@jeffnv]) * [#86](https://github.com/rails/web-console/pull/86) Disable autofocus when initializing the console ([@ryandao]) * [#84](https://github.com/rails/web-console/pull/84) Allow Rails 5 as dependency in gemspec ([@jonatack]) * [#69](https://github.com/rails/web-console/pull/69) Introduce middleware for request dispatch and console rendering ([@gsamokovarov]) [@jonatack]: https://github.com/jonatack [@ryandao]: https://github.com/ryandao [@jeffnv]: https://github.com/jeffnv [@gsamokovarov]: https://github.com/gsamokovarov [@bglbruno]: https://github.com/bglbruno [@noahpatterson]: https://github.com/noahpatterson [@parterburn]: https://github.com/parterburn [@sh19910711]: https://github.com/sh19910711 [@frenesim]: https://github.com/frenesim web-console-2.2.1/metadata.yml 0000644 0000764 0000764 00000010662 12560702257 015303 0 ustar pravi pravi --- !ruby/object:Gem::Specification name: web-console version: !ruby/object:Gem::Version version: 2.2.1 platform: ruby authors: - Charlie Somerville - Genadi Samokovarov - Guillermo Iguaran - Ryan Dao autorequire: bindir: bin cert_chain: [] date: 2015-07-10 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: railties requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '4.0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '4.0' - !ruby/object:Gem::Dependency name: activemodel requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '4.0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '4.0' - !ruby/object:Gem::Dependency name: sprockets-rails requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '2.0' - - "<" - !ruby/object:Gem::Version version: '4.0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '2.0' - - "<" - !ruby/object:Gem::Version version: '4.0' - !ruby/object:Gem::Dependency name: binding_of_caller requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 0.7.2 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 0.7.2 - !ruby/object:Gem::Dependency name: actionmailer requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '4.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '4.0' - !ruby/object:Gem::Dependency name: activerecord requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '4.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '4.0' description: email: - charlie@charliesomerville.com - gsamokovarov@gmail.com - guilleiguaran@gmail.com - daoduyducduong@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - CHANGELOG.markdown - MIT-LICENSE - README.markdown - Rakefile - lib/web-console.rb - lib/web_console.rb - lib/web_console/errors.rb - lib/web_console/evaluator.rb - lib/web_console/extensions.rb - lib/web_console/helper.rb - lib/web_console/integration.rb - lib/web_console/integration/cruby.rb - lib/web_console/integration/jruby.rb - lib/web_console/integration/rubinius.rb - lib/web_console/middleware.rb - lib/web_console/railtie.rb - lib/web_console/request.rb - lib/web_console/session.rb - lib/web_console/template.rb - lib/web_console/templates/_inner_console_markup.html.erb - lib/web_console/templates/_markup.html.erb - lib/web_console/templates/_prompt_box_markup.html.erb - lib/web_console/templates/console.js.erb - lib/web_console/templates/error_page.js.erb - lib/web_console/templates/index.html.erb - lib/web_console/templates/layouts/inlined_string.erb - lib/web_console/templates/layouts/javascript.erb - lib/web_console/templates/main.js.erb - lib/web_console/templates/style.css.erb - lib/web_console/tracer.rb - lib/web_console/version.rb - lib/web_console/whiny_request.rb - lib/web_console/whitelist.rb homepage: https://github.com/rails/web-console licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.4.5 signing_key: specification_version: 4 summary: A debugging tool for your Ruby on Rails applications. test_files: [] web-console-2.2.1/README.markdown 0000644 0000764 0000764 00000014551 12560702257 015502 0 ustar pravi pravi
Documentation for: v2.0.0 v2.1.0 v2.1.1 v2.1.2 v2.1.3
# Web Console [](https://travis-ci.org/rails/web-console) _Web Console_ is a debugging tool for your Ruby on Rails applications. - [Installation](#installation) - [Runtime](#runtime) - [CRuby](#cruby) - [JRuby](#jruby) - [Rubinius](#rubinius) - [Configuration](#configuration) - [Usage](#usage) - [FAQ](#faq) - [Credits](#credits) ## Installation _Web Console_ is meant to work as a Rails plugin. To install it in your current application, add the following to your `Gemfile`. ```ruby group :development do gem 'web-console', '~> 2.0' end ``` After you save the `Gemfile` changes, make sure to run `bundle install` and restart your server for the _Web Console_ to kick in. ## Runtime _Web Console_ uses [John Mair]'s [binding_of_caller] to spawn a console in a specific binding. This comes at the price of limited Ruby runtime support. ### CRuby CRuby 1.9.2 and below is **not** supported. ### JRuby JRuby needs to run in interpreted mode. You can enable it by: ```bash export JRUBY_OPTS=-J-Djruby.compile.mode=OFF # If you run JRuby 1.7.12 and above, you can use: export JRUBY_OPTS=--dev ``` An unstable version of [binding_of_caller] is needed as the latest stable one won't compile on _JRuby_. To install it, put the following in your application `Gemfile`: ```ruby group :development do gem 'binding_of_caller', '0.7.3.pre1' end ``` Only _JRuby_ 1.7, is supported (no JRuby 9K support at the moment). ### Rubinius Internal errors like `ZeroDevisionError` aren't caught. ## Usage The web console allows you to create an interactive Ruby session in your browser. Those sessions are launched automatically in case on an error, but they can also be launched manually in in any page. For example, calling `console` in a view will display a console in the current page in the context of the view binding. ```html <% console %> ``` Calling `console` in a controller will result in a console in the context of the controller action: ```ruby class PostsController < ApplicationController def new console @post = Post.new end end ``` Only one `console` invocation is allowed per request. If you happen to have multiple ones, a `WebConsole::DoubleRenderError` is raised. ## Configuration _Web Console_ allows you to execute arbitrary code on the server, so you should be very careful, who you give access to. ### config.web_console.whitelisted_ips By default, only requests coming from IPv4 and IPv6 localhosts are allowed. `config.web_console.whitelisted_ips` lets you control which IP's have access to the console. You can whitelist single IP's or whole networks. Say you want to share your console with `192.168.0.100`. You can do this: ```ruby class Application < Rails::Application config.web_console.whitelisted_ips = '192.168.0.100' end ``` If you want to whitelist the whole private network, you can do: ```ruby Rails.application.configure do config.web_console.whitelisted_ips = '192.168.0.0/16' end ``` Take a note that IPv4 and IPv6 localhosts are always allowed. This wasn't the case in 2.0. ### config.web_console.whiny_requests When a console cannot be shown for a given IP address or content type, a messages like the following is printed in the server logs: > Cannot render console from 192.168.1.133! Allowed networks: > 127.0.0.0/127.255.255.255, ::1 If you don't wanna see this message anymore, set this option to `false`: ```ruby Rails.application.configure do config.web_console.whiny_requests = false end ``` ### config.web_console.template_paths If you wanna style the console yourself, you can place `style.css` at a directory pointed by `config.web_console.template_paths`: ```ruby Rails.application.configure do config.web_console.template_paths = 'app/views/web_console' end ``` You may wanna check the [templates] folder at the source tree for the files you may override. ## FAQ ### Where did /console go? The remote terminal emulator was extracted in its own gem that is no longer bundled with _Web Console_. If you miss this feature, check out [rvt]. ### Why I constantly get unavailable session errors? All of _Web Console_ sessions are stored in memory. If you happen to run on a multi-process server (like Unicorn) you may get unavailable session errors while the server is still running. This is because a request may hit a different worker (process) that doesn't have the desired session in memory. To avoid that, if you use such servers in development, configure them so they server requests only out of one process. ### How to inspect local and instance variables? The interactive console executes Ruby code. Invoking `instance_variables` and `local_variables` will give you what you want. ### Why does console only appear on error pages but not when I call it? This can be happening if you are using `Rack::Deflater`. Be sure that `WebConsole::Middleware` is used after `Rack::Deflater`. The easiest way to do this is to insert `Rack::Deflater` as early as possible ```ruby Rails.application.configure do config.middleware.insert(0, Rack::Deflater) end ``` ### Why I'm getting an undefined method `web_console`? Make sure you configuration lives in `config/environments/development.rb`. ## Credits * Shoutout to [Charlie Somerville] for [better_errors] and [this] code. * Kudos to [John Mair] for [binding_of_caller]. * Thanks to [Charles Oliver Nutter] for all the _JRuby_ feedback. * Hugs and kisses to all of our [contributors]. [better_errors]: https://github.com/charliesome/better_errors [binding_of_caller]: https://github.com/banister/binding_of_caller [Charlie Somerville]: https://github.com/charliesome [John Mair]: https://github.com/banister [Charles Oliver Nutter]: https://github.com/headius [templates]: https://github.com/rails/web-console/tree/master/lib/web_console/templates [this]: https://github.com/rails/web-console/blob/master/lib/web_console/integration/cruby.rb#L20-L32 [rvt]: https://github.com/gsamokovarov/rvt [contributors]: https://github.com/rails/web-console/graphs/contributors web-console-2.2.1/lib/ 0000755 0000764 0000764 00000000000 12560702257 013541 5 ustar pravi pravi web-console-2.2.1/lib/web_console.rb 0000644 0000764 0000764 00000001125 12560702257 016364 0 ustar pravi pravi require 'binding_of_caller' require 'active_support/lazy_load_hooks' require 'active_support/logger' require 'web_console/integration' require 'web_console/railtie' require 'web_console/errors' require 'web_console/helper' require 'web_console/evaluator' require 'web_console/session' require 'web_console/template' require 'web_console/middleware' require 'web_console/whitelist' require 'web_console/request' require 'web_console/whiny_request' module WebConsole mattr_accessor :logger @@logger = ActiveSupport::Logger.new($stderr) ActiveSupport.run_load_hooks(:web_console, self) end web-console-2.2.1/lib/web-console.rb 0000644 0000764 0000764 00000000026 12560702257 016301 0 ustar pravi pravi require 'web_console' web-console-2.2.1/lib/web_console/ 0000755 0000764 0000764 00000000000 12560702257 016040 5 ustar pravi pravi web-console-2.2.1/lib/web_console/whitelist.rb 0000644 0000764 0000764 00000002042 12560702257 020377 0 ustar pravi pravi require 'ipaddr' module WebConsole # Whitelist of allowed networks that can access Web Console. # # Networks are represented by standard IPAddr and can be either IPv4 or IPv6 # networks. class Whitelist # IPv4 and IPv6 localhost should be always whitelisted. ALWAYS_WHITELISTED_NETWORKS = %w( 127.0.0.0/8 ::1 ) def initialize(networks = nil) @networks = normalize_networks(networks).map(&method(:coerce_network_to_ipaddr)).uniq end def include?(network) @networks.any? { |whitelist| whitelist.include?(network.to_s) } end def to_s @networks.map(&method(:human_readable_ipaddr)).join(', ') end private def normalize_networks(networks) Array(networks).concat(ALWAYS_WHITELISTED_NETWORKS) end def coerce_network_to_ipaddr(network) if network.is_a?(IPAddr) network else IPAddr.new(network) end end def human_readable_ipaddr(ipaddr) ipaddr.to_range.to_s.split('..').uniq.join('/') end end end web-console-2.2.1/lib/web_console/whiny_request.rb 0000644 0000764 0000764 00000001752 12560702257 021300 0 ustar pravi pravi module WebConsole # Noisy wrapper around +Request+. # # If any calls to +from_whitelisted_ip?+ and +acceptable_content_type?+ # return false, an info log message will be displayed in users' logs. class WhinyRequest < SimpleDelegator def from_whitelited_ip? whine_unless request.from_whitelited_ip? do "Cannot render console from #{request.remote_ip}! " \ "Allowed networks: #{request.whitelisted_ips}" end end def acceptable_content_type? whine_unless request.acceptable_content_type? do "Cannot render console with content type #{request.content_type}" \ "Allowed content types: #{request.acceptable_content_types}" end end private def whine_unless(condition) unless condition logger.info { yield } end condition end def logger env['action_dispatch.logger'] || WebConsole.logger end def request __getobj__ end end end web-console-2.2.1/lib/web_console/errors.rb 0000644 0000764 0000764 00000000341 12560702257 017677 0 ustar pravi pravi module WebConsole # The base class for every Web Console related error. Error = Class.new(StandardError) # Raised when there is an attempt to render a console more than once. DoubleRenderError = Class.new(Error) end web-console-2.2.1/lib/web_console/extensions.rb 0000644 0000764 0000764 00000001517 12560702257 020570 0 ustar pravi pravi ActionDispatch::DebugExceptions.class_eval do def render_exception_with_web_console(env, exception) render_exception_without_web_console(env, exception).tap do error = ActionDispatch::ExceptionWrapper.new(env, exception).exception # Get the original exception if ExceptionWrapper decides to follow it. env['web_console.exception'] = error # ActionView::Template::Error bypass ExceptionWrapper original # exception following. The backtrace in the view is generated from # reaching out to original_exception in the view. if error.is_a?(ActionView::Template::Error) env['web_console.exception'] = error.original_exception end end end alias_method :render_exception_without_web_console, :render_exception alias_method :render_exception, :render_exception_with_web_console end web-console-2.2.1/lib/web_console/evaluator.rb 0000644 0000764 0000764 00000001706 12560702257 020373 0 ustar pravi pravi module WebConsole # Simple Ruby code evaluator. # # This class wraps a +Binding+ object and evaluates code inside of it. The # difference of a regular +Binding+ eval is that +Evaluator+ will always # return a string and will format exception output. class Evaluator # Cleanses exceptions raised inside #eval. cattr_reader :cleaner @@cleaner = ActiveSupport::BacktraceCleaner.new @@cleaner.add_silencer { |line| line.start_with?(File.expand_path('..', __FILE__)) } def initialize(binding = TOPLEVEL_BINDING) @binding = binding end def eval(input) "=> #{@binding.eval(input).inspect}\n" rescue Exception => exc format_exception(exc) end private def format_exception(exc) backtrace = cleaner.clean(Array(exc.backtrace) - caller) format = "#{exc.class.name}: #{exc}\n" format << backtrace.map { |trace| "\tfrom #{trace}\n" }.join format end end end web-console-2.2.1/lib/web_console/railtie.rb 0000644 0000764 0000764 00000004661 12560702257 020025 0 ustar pravi pravi require 'rails/railtie' module WebConsole class Railtie < ::Rails::Railtie config.web_console = ActiveSupport::OrderedOptions.new config.web_console.whitelisted_ips = %w( 127.0.0.1 ::1 ) # See rails/web-console#150 and rails/rails#20319. Revert when Ruby on # Rails 4.2.4 is released. config.web_console.development_only = false initializer 'web_console.initialize' do require 'web_console/extensions' ActiveSupport.on_load(:action_view) do ActionView::Base.send(:include, Helper) end ActiveSupport.on_load(:action_controller) do ActionController::Base.send(:include, Helper) end end initializer 'web_console.development_only' do unless (config.web_console.development_only == false) || Rails.env.development? abort <<-END.strip_heredoc Web Console is activated in the #{Rails.env} environment, which is usually a mistake. To ensure it's only activated in development mode, move it to the development group of your Gemfile: gem 'web-console', group: :development If you still want to run it the #{Rails.env} environment (and know what you are doing), put this in your Rails application configuration: config.web_console.development_only = false END end end initializer 'web_console.insert_middleware' do |app| app.middleware.insert_before ActionDispatch::DebugExceptions, Middleware end initializer 'web_console.template_paths' do if template_paths = config.web_console.template_paths Template.template_paths.unshift(*Array(template_paths)) end end initializer 'web_console.whitelisted_ips' do if whitelisted_ips = config.web_console.whitelisted_ips Request.whitelisted_ips = Whitelist.new(whitelisted_ips) end end initializer 'web_console.whiny_requests' do if config.web_console.key?(:whiny_requests) Middleware.whiny_requests = config.web_console.whiny_requests end end # Leave this undocumented so we treat such content type misses as bugs, # while still being able to help the affected users in the meantime. initializer 'web_console.acceptable_content_types' do if acceptable_content_types = config.web_console.acceptable_content_types Request.acceptable_content_types.concat(Array(acceptable_content_types)) end end end end web-console-2.2.1/lib/web_console/tracer.rb 0000644 0000764 0000764 00000000317 12560702257 017646 0 ustar pravi pravi module WebConsole class BindingTracer def initialize(exception) @bindings = exception.bindings @backtrace = exception.backtrace end def binding_for_trace(trace) end end end web-console-2.2.1/lib/web_console/request.rb 0000644 0000764 0000764 00000003465 12560702257 020065 0 ustar pravi pravi module WebConsole # Web Console tailored request object. class Request < ActionDispatch::Request # While most of the servers will return blank content type if none given, # Puma will return text/plain. cattr_accessor :acceptable_content_types @@acceptable_content_types = [Mime::HTML, Mime::TEXT, Mime::URL_ENCODED_FORM] # Configurable set of whitelisted networks. cattr_accessor :whitelisted_ips @@whitelisted_ips = Whitelist.new # Define a vendor MIME type. We can call it using Mime::WEB_CONSOLE_V2 constant. Mime::Type.register 'application/vnd.web-console.v2', :web_console_v2 # Returns whether a request came from a whitelisted IP. # # For a request to hit Web Console features, it needs to come from a white # listed IP. def from_whitelited_ip? whitelisted_ips.include?(strict_remote_ip) end # Determines the remote IP using our much stricter whitelist. def strict_remote_ip GetSecureIp.new(env, whitelisted_ips).to_s end # Returns whether the request is from an acceptable content type. # # We can render a console for HTML and TEXT by default. If a client didn't # specified any content type and the server returned it as blank, we'll # render it as well. def acceptable_content_type? content_type.blank? || content_type.in?(acceptable_content_types) end # Returns whether the request is acceptable. def acceptable? xhr? && accepts.any? { |mime| Mime::WEB_CONSOLE_V2 == mime } end class GetSecureIp < ActionDispatch::RemoteIp::GetIp def initialize(env, proxies) @env = env @check_ip = true @proxies = proxies end def filter_proxies(ips) ips.reject do |ip| @proxies.include?(ip) end end end end end web-console-2.2.1/lib/web_console/template.rb 0000644 0000764 0000764 00000003335 12560702257 020204 0 ustar pravi pravi module WebConsole # A facade that handles template rendering and composition. # # It introduces template helpers to ease the inclusion of scripts only on # Rails error pages. class Template class Context < ActionView::Base # Execute a block only on error pages. # # The error pages are special, because they are the only pages that # currently require multiple bindings. We get those from exceptions. def only_on_error_page(*args) yield if @env['web_console.exception'].present? end # Render JavaScript inside a script tag and a closure. # # This one lets write JavaScript that will automatically get wrapped in a # script tag and enclosed in a closure, so you don't have to worry for # leaking globals, unless you explicitly want to. def render_javascript(template) render(template: template, layout: 'layouts/javascript') end # Render inlined string to be used inside of JavaScript code. # # The inlined string is returned as an actual JavaScript string. You # don't need to wrap the result yourself. def render_inlined_string(template) render(template: template, layout: 'layouts/inlined_string') end end # Lets you customize the default templates folder location. cattr_accessor :template_paths @@template_paths = [ File.expand_path('../templates', __FILE__) ] def initialize(env, session) @env = env @session = session end # Render a template (inferred from +template_paths+) as a plain string. def render(template) context = Context.new(template_paths, instance_values) context.render(template: template, layout: false) end end end web-console-2.2.1/lib/web_console/version.rb 0000644 0000764 0000764 00000000052 12560702257 020047 0 ustar pravi pravi module WebConsole VERSION = '2.2.1' end web-console-2.2.1/lib/web_console/integration/ 0000755 0000764 0000764 00000000000 12560702257 020363 5 ustar pravi pravi web-console-2.2.1/lib/web_console/integration/cruby.rb 0000644 0000764 0000764 00000002711 12560702257 022035 0 ustar pravi pravi class Exception begin # We share the same exception binding extraction mechanism as better_errors, # so try to use it if it is already available. It also solves problems like # charliesome/better_errors#272, caused by an infinite recursion. require 'better_errors' # The bindings in which the exception originated in. def bindings @bindings || __better_errors_bindings_stack end rescue LoadError # The bindings in which the exception originated in. def bindings @bindings || [] end # CRuby calls #set_backtrace every time it raises an exception. Overriding # it to assign the #bindings. def set_backtrace_with_binding_of_caller(*args) # Thanks to @charliesome who wrote this bit for better_errors. unless Thread.current[:__web_console_exception_lock] Thread.current[:__web_console_exception_lock] = true begin # Raising an exception here will cause all of the rubies to go into a # stack overflow. Some rubies may even segfault. See # https://bugs.ruby-lang.org/issues/10164 for details. @bindings = binding.callers.drop(1) ensure Thread.current[:__web_console_exception_lock] = false end end set_backtrace_without_binding_of_caller(*args) end alias_method :set_backtrace_without_binding_of_caller, :set_backtrace alias_method :set_backtrace, :set_backtrace_with_binding_of_caller end end web-console-2.2.1/lib/web_console/integration/rubinius.rb 0000644 0000764 0000764 00000003620 12560702257 022551 0 ustar pravi pravi module WebConsole module Rubinius # Filters internal Rubinius locations. # # There are a couple of reasons why we wanna filter out the locations. # # * ::Kernel.raise, is implemented in Ruby for Rubinius. We don't wanna # have the frame for it to align with the CRuby and JRuby implementations. # # * For internal methods location variables can be nil. We can't create a # bindings for them. # # * Bindings from the current file are considered internal and ignored. # # We do that all that so we can align the bindings with the backtraces # entries. class InternalLocationFilter def initialize(locations) @locations = locations end def filter @locations.reject do |location| location.file.start_with?('kernel/delta/kernel.rb') || location.file == __FILE__ || location.variables.nil? end end end # Gets the current bindings for all available Ruby frames. # # Filters the internal Rubinius and WebConsole frames. def self.current_bindings locations = ::Rubinius::VM.backtrace(1, true) InternalLocationFilter.new(locations).filter.map do |location| Binding.setup( location.variables, location.variables.method, location.constant_scope, location.variables.self, location ) end end end end ::Exception.class_eval do def bindings @bindings || [] end end ::Rubinius.singleton_class.class_eval do def raise_exception_with_current_bindings(exc) if exc.bindings.empty? exc.instance_variable_set(:@bindings, WebConsole::Rubinius.current_bindings) end raise_exception_without_current_bindings(exc) end alias_method :raise_exception_without_current_bindings, :raise_exception alias_method :raise_exception, :raise_exception_with_current_bindings end web-console-2.2.1/lib/web_console/integration/jruby.rb 0000644 0000764 0000764 00000006351 12560702257 022050 0 ustar pravi pravi require 'English' require 'active_support/core_ext/string/strip' java_import org.jruby.RubyInstanceConfig module WebConsole module JRuby class << self # Returns whether JRuby is ran in interpreted mode. def interpreted_mode? compile_mode = ::JRuby.runtime.instance_config.compile_mode interpreted_mode = RubyInstanceConfig::CompileMode::OFF compile_mode == interpreted_mode end # A proc to be used in Kernel#set_trace_func. # # It sets Exception#bindings for an error with all the bindings the # current ThreadContext contains. def set_exception_bindings_trace_func proc do |event, file, line, id, binding, classname| case event when 'raise' if $ERROR_INFO.bindings.empty? # binding_of_caller will generate an improperly built binding at # caller[1]. Every call to a non existent method, constant or a # local variable will result in a Java NullPointerException. # # The binding that Kernel#set_trace_func is giving us is properly # built, so we can use in place of the broken one. bindings = ::Kernel.binding.callers.drop(2).unshift(binding) $ERROR_INFO.instance_variable_set(:@bindings, bindings) end end end end end # A fake binding for JRuby in non interpreted mode. # # It won't actually evaluate any code, rather it will tell the user how to # enable interpreted mode. class FakeJRubyBinding TURN_ON_INTERPRETED_MODE_TEXT = <<-END.strip_heredoc JRuby needs to run in interpreted mode for introspection support. To turn on interpreted mode, put -J-Djruby.compile.mode=OFF in the JRUBY_OPTS environment variable. END def TURN_ON_INTERPRETED_MODE_TEXT.inspect self end TURN_ON_INTERPRETED_MODE_TEXT.freeze def eval(*) TURN_ON_INTERPRETED_MODE_TEXT end end # A fake array of FakeJRubyBinding objects. # # It is used in Exception#bindings to make sure that when users switch # bindings on the UI, they get a FakeJRubyBinding notifying them what to do # if they want introspection. class FakeJRubyBindingsArray < Array def [](*) FakeJRubyBinding.new end # For Kernel#Array and other implicit conversion API. JRuby expects it to # return an object that is_a? an Array. This is the reasoning of # FakeJRubyBindingsArray being a subclass of Array. def to_ary self end end end end if WebConsole::JRuby.interpreted_mode? ::Exception.class_eval do def bindings @bindings || [] end end # Kernel#set_trace_func will complain about not being able to capture all the # events without the JRuby --debug flag. silence_warnings do set_trace_func WebConsole::JRuby.set_exception_bindings_trace_func end else ::Exception.class_eval do def bindings WebConsole::JRuby::FakeJRubyBindingsArray.new end end ::Binding.class_eval do def of_caller(*) WebConsole::JRuby::FakeJRubyBinding.new end def callers WebConsole::JRuby::FakeJRubyBindingsArray.new end end end web-console-2.2.1/lib/web_console/integration.rb 0000644 0000764 0000764 00000000272 12560702257 020711 0 ustar pravi pravi case RUBY_ENGINE when 'rbx' require 'web_console/integration/rubinius' when 'jruby' require 'web_console/integration/jruby' when 'ruby' require 'web_console/integration/cruby' end web-console-2.2.1/lib/web_console/session.rb 0000644 0000764 0000764 00000003204 12560702257 020047 0 ustar pravi pravi module WebConsole # A session lets you persist wrap an +Evaluator+ instance in memory # associated with multiple bindings. # # Each newly created session is persisted into memory and you can find it # later its +id+. # # A session may be associated with multiple bindings. This is used by the # error pages only, as currently, this is the only client that needs to do # that. class Session cattr_reader :inmemory_storage @@inmemory_storage = {} class << self # Finds a persisted session in memory by its id. # # Returns a persisted session if found in memory. # Raises NotFound error unless found in memory. def find(id) inmemory_storage[id] end # Create a Session from an exception. def from_exception(exc) new(exc.bindings) end # Create a Session from a single binding. def from_binding(binding) new(binding) end end # An unique identifier for every REPL. attr_reader :id def initialize(bindings) @id = SecureRandom.hex(16) @bindings = Array(bindings) @evaluator = Evaluator.new(@bindings[0]) store_into_memory end # Evaluate +input+ on the current Evaluator associated binding. # # Returns a string of the Evaluator output. def eval(input) @evaluator.eval(input) end # Switches the current binding to the one at specified +index+. # # Returns nothing. def switch_binding_to(index) @evaluator = Evaluator.new(@bindings[index.to_i]) end private def store_into_memory inmemory_storage[id] = self end end end web-console-2.2.1/lib/web_console/helper.rb 0000644 0000764 0000764 00000001362 12560702257 017646 0 ustar pravi pravi module WebConsole module Helper # Communicates with the middleware to render a console in a +binding+. # # If +bidning+ isn't explicitly given, Binding#of_caller will be used to # get the binding of the previous frame. E.g. the one that invoked # +console+. # # Raises DoubleRenderError if a double +console+ invocation per request is # detected. def console(binding = nil) raise DoubleRenderError if request.env['web_console.binding'] request.env['web_console.binding'] = binding || ::Kernel.binding.of_caller(1) # Make sure nothing is rendered from the view helper. Otherwise # you're gonna see unexpected #