Giter VIP home page Giter VIP logo

rack-webconsole's Introduction

rack-webconsole Build Status

Rack-webconsole is a Rack-based interactive console (à la Rails console) in your web application's frontend. That means you can interact with your application's backend from within the browser itself!

To get a clearer idea, you can check out this video showing a live example :)

YouTube video

Rack-webconsole is a Rack middleware designed to be unobtrusive. With Rails 3, for example, you only have to include the gem in your Gemfile and it already works. Without any configuration.

Tested with MRI versions 1.8.7, 1.9.2, ruby-head, and JRuby 1.6.3.

SECURITY NOTE: From version v0.0.5 rack-webconsole uses a token system to protect against cross-site request forgery.

Resources

Install

In your Gemfile:

gem 'rack-webconsole'

Rack-webconsole needs JQuery. If you are using Rails 3, JQuery is loaded by default. In case you don't want to use JQuery in your application, rack-webconsole can inject it for you only when it needs it. To do that you should put this line somewhere in your application (a Rails initializer, or some configuration file):

Rack::Webconsole.inject_jquery = true

You can also change the javascript key_code used to start webconsole:

 # ` = 96 (default), ^ = 94, ç = 231 ... etc.
Rack::Webconsole.key_code = "231"

Usage with Rails 3

If you are using Rails 3, you have no further steps to do. It works! To give it a try, fire up the Rails server and go to any page, press the ` key and the console will show :)

Usage with Sinatra/Padrino

With Sinatra and Padrino you have to tell your application to use the middleware:

require 'sinatra'
require 'rack/webconsole'

class MySinatraApp < Sinatra::Application
  use Rack::Webconsole
  # . . .
end

class SamplePadrino < Padrino::Application
  use Rack::Webconsole
  # . . .
end

NOTE: If you are using Bundler and initializing it from config.ru, you don't have to require 'rack/webconsole' manually, otherwise you have to.

And it works! Fire up the server, go to any page and press the ` key.

Usage with Rails 2

You need to add the following code to an intializer (i.e. config/initializers/webconsole.rb):

require 'rack/webconsole'
ActionController::Dispatcher.middleware.insert_after 1, Rack::Webconsole

Commands

In the console you can issue whatever Ruby commands you want, except multiline commands. Local variables are kept, so you can get a more IRB-esque feeling.

  • reload! resets all local variables
  • request returns the current page request object

Under the hood

Run the test suite by typing:

rake

You can also build the documentation with the following command:

rake docs

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so we don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself we can ignore when we pull)
  • Send us a pull request. Bonus points for topic branches.

Released under the MIT License

Copyright (c) 2011 Codegram.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rack-webconsole's People

Contributors

bryant1410 avatar cannikin avatar cldwalker avatar gucki avatar joliss avatar josepjaume avatar joshbuddy avatar kml avatar madwire avatar mrcasals avatar oriolgual avatar rogerleite avatar stan avatar tobias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rack-webconsole's Issues

UI issues

Hey!

I like really like the idea and so just tested it using an existing rails 3.0.9 project.

However I have the following problems:

  1. The console is always shown. Pressing the ' key does not change anything (wouldnt ^ be a better key anyway?).
  2. The console layer has no scrollbar.

Other than that it seems to be working just fine :)

change key to something different which requires only one key press

I dont really think that using the key is a good idea. At least for me I always have to to two key presses ( and then any other key, like space bar).

I think it should be changed to some other key which is also almost never used but requires only a single keypress. Any ideas? :)

Rack-webconsole messes up send_file

I have a web app that sends a zip file when you visit a url and it was working for a long time before I added rack-webconsole to my Gemfile. Now, visiting the url just gives me a 0-byte zip file and I could consistently reproduce this just by taking rack-webconsole out of the Gemfile.

Another thing to note here is that I added the line outside of the development group because I was planning to use it in production(webconsole)

console not working with rails catch all routes

When you have a route like the following the console does not work because the request if captured by rails before the console middleware gets it.

match ":anything" => "index#routing_error", :constraints => { :anything => /.*/ }

I haven't looked at the source, but I think the order of the middlewares has to be changed.

README video is private

Clicking on the image of the video in the readme takes you to a page with a frowny face where the video would be, with the words "This video is private. Sorry about that."

Rails 4 support?

I'm guessing this works just fine thanks with Rails 4, but it might be helpful to mention that in the README file.

POST to /webconsole is 404'ing

Rails 3.0.7, Ruby 1.9.2

The console pulls up with the ` but trying to run anything POSTS to /webconsole which throws a 404

The middleware does show up in rake middleware

Please advise

Namespaced model is not recognized by console

Just a simple test:
u = Auth::User.new
=> Error: uninitialized constant Rack::Auth::User

My Class:
class Auth::User < ActiveRecord::Base

Nice idea your console, but hmm does not really work for me :(
Any chance of a fix or suppport for namespaces ?
Thanks in advance

Avoid CSRF thanks to generated token

On each request, set a pseudorandom JavaScript token that will be sent in all subsequent AJAX requests.
Make the Repl middleware reject anything without that previously setted token.

Test is failing with Rubinius

$ruby -v
rubinius 1.2.5dev (1.8.7 9b88cd26 yyyy-mm-dd JI) [i686-pc-linux-gnu]

$uname -a
Linux HDU64511 2.6.38-10-generic-pae #46-Ubuntu SMP Tue Jun 28 16:54:49 UTC 2011 i686 i686 i386 GNU/Linux

$rake test

/home/roger/.rvm/rubies/rbx-master/bin/rbx -I"lib:spec" -I"/home/roger/.rvm/gems/rbx-master@global/gems/rake-0.9.2/lib" "/home/roger/.rvm/gems/rbx-master@global/gems/rake-0.9.2/lib/rake/rake_test_loader.rb" "spec/rack/webconsole_spec.rb" "spec/rack/webconsole/sandbox_spec.rb" "spec/rack/webconsole/asset_helpers_spec.rb" "spec/rack/webconsole/assets_spec.rb" "spec/rack/webconsole/repl_spec.rb"
Run options: --seed 37563

Running tests:

...encoding options not supported in 1.8
.encoding options not supported in 1.8
.encoding options not supported in 1.8
...encoding options not supported in 1.8
encoding options not supported in 1.8
encoding options not supported in 1.8
.encoding options not supported in 1.8
encoding options not supported in 1.8
encoding options not supported in 1.8
.encoding options not supported in 1.8
encoding options not supported in 1.8
encoding options not supported in 1.8
.....encoding options not supported in 1.8
encoding options not supported in 1.8
encoding options not supported in 1.8
...F.............

Finished tests in 0.562222s, 56.9170 tests/s, 124.5060 assertions/s.

  1. Failure:
    test_0002_maintains_local_state_in_subsequent_calls_thanks_to_an_evil_global_variable(Rack::Webconsole::Repl::#call) [/home/roger/dev/trivial/rack-webconsole/spec/rack/webconsole/repl_spec.rb:44]:
    --- expected
    +++ actual
    @@ -1 +1 @@
    -"32"
    +"Error: undefined local variable or method `a' on an instance of Rack::Webconsole::Sandbox."

32 tests, 70 assertions, 1 failures, 0 errors, 0 skips
rake aborted!
Command failed with status (1): [/home/roger/.rvm/rubies/rbx-master/bin/rbx...]

Tasks: TOP => test
(See full trace by running task with --trace)

multi line and autocomplete

#19 and #37 requested multi line and autocomplete support and both are closed with some commits, but the documentation page still says no multi line. What is the state of these two features?

Friendly error messages

It seems like exceptions are not being handled at all. Checking my terminal shows me the (e.g. syntax) error and a partial trace, but I should get some kind of feedback in the Webconsole as well. Currently nothing happens.

request.ip whitelist

It's nice to see rack-webconsole can check request.ip and only enable if ip is in a configurable whitelist, say /^127\./

Running this in a Rails 2.3.18 application.

I am doing a simple Rails 2.3.18 application. I've put the gem 'rack-webconsole' in the Gemfile and run the bundle install. I've put the lines..

require 'rack/webconsole'

ActionController::Dispatcher.middleware.insert_after 1, Rack::Webconsole
Rack::Webconsole.inject_jquery = true

..in my application's config/initializers/webconsole.rb. When i run the server and press ` while viewing the page in localhost, the console isnt firing up. Am i doing something wrong here, or does the console not support Rails 2.x.x apps?

Ditch jquery

It would be awesome to remove that ugly jquery dependency and rewrite the whole javascript part in coffee.

Cukes

In order to test rack-webconsole's compatibility with major web frameworks we should add some integration testing.

Is anyone working on it? If not, I could start writing some cukes :)

Console should be accessible not only in development

Hello,

Many people I believe would want to access the console on CI and so and not only on development.
Actually I think a valid case would be that you want the console accessible on most environments but production... as was my case.

Monkey patching this to be accessible outside of development isn't a good solution.
Nor is probably doing unless Rails.env.production?

If anyone feels the same perhaps we can come with a clever solution than changing the IF statement in railtie.rb on line 10.

Cheers!

Console functionality problem

with gem version 0.1.2 on a linux chromium 12.0.742.112.

The console opens up ok (backtic). I can insert chars in the CLI, but the enter key is ignored and the console view is always blank.

Incompatible character encodings error on pages with Unicode characters

With rack-webconsole installed via my Gemfile, whenever I browse to a page in my Rails project that has an ñ character (or an é character), I get the following error page.

Encoding::CompatibilityError in Controller#View

incompatible character encodings: ASCII-8BIT and UTF-8

I'm running the rack-webconsole gem on a Rails 3.1.0.rc5 site, and I'm using the mysql2 gem on a database with encoding: utf8 specified in my database.yml, for what it's worth. The last six lines of my Application Trace are as follows; I can put up more, if need be.

rack-webconsole (0.1.2) lib/rack/webconsole/assets.rb:42:in `gsub!'
rack-webconsole (0.1.2) lib/rack/webconsole/assets.rb:42:in `call'
rack-webconsole (0.1.2) lib/rack/webconsole.rb:63:in `call'
warden (1.0.5) lib/warden/manager.rb:35:in `block in call'
warden (1.0.5) lib/warden/manager.rb:34:in `catch'
warden (1.0.5) lib/warden/manager.rb:34:in `call'

Note that when I disable the rack-webconsole gem from my Gemfile, the error goes away. I also don't get this error on pages without those Unicode characters.

(Also, if I could be doing something wrong… that's entirely possible, too.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.