sinatra_debug_console 0.1.0

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.
Files changed (6) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +18 -0
  3. data/Rakefile +19 -0
  4. data/VERSION +1 -0
  5. data/lib/sinatra_debug_console.rb +92 -0
  6. metadata +69 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 jugyo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = sinatra_debug_console
2
+
3
+ Debug console for sinatra
4
+
5
+ http://farm3.static.flickr.com/2659/4187659132_7c3cde58aa_o.png
6
+
7
+ == Notice
8
+
9
+ Rack::Auth::Basic is used to authorization.
10
+
11
+ == Usage
12
+
13
+ require 'sinatra_debug_console'
14
+ Sinatra::DebugConsole.config(USERNAME, PASSWORD)
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 jugyo. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "sinatra_debug_console"
8
+ gem.summary = %Q{Debug console for sinatra}
9
+ gem.description = %Q{Web base debug console for sinatra}
10
+ gem.email = "jugyo.org@gmail.com"
11
+ gem.homepage = "http://github.com/jugyo/sinatra_debug_console"
12
+ gem.authors = ["jugyo"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ task :default => :build
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,92 @@
1
+ get '/debug_console' do
2
+ require_administrative_privileges
3
+ haml <<HAML, :layout => false
4
+ %html
5
+ %head
6
+ %meta{:"http-equiv"=>"Content-Type", :content=>"text/html;charset=UTF-8"}
7
+ %title console
8
+ %script{:type=>"text/javascript", :src=>"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"}
9
+ %body
10
+ #eval_text
11
+ %textarea#text{:rows => 10, :style => 'width: 100%;'}
12
+ #button
13
+ %button{:onclick => 'eval_text()'} eval
14
+ %pre#result{:style => 'color: green; background-color: black; padding: 8px; display: none;'}
15
+ :javascript
16
+ $(document).ready(function() {
17
+ $("#text").focus();
18
+ });
19
+
20
+ function eval_text() {
21
+ $("#result").show();
22
+ $("#result").html('...');
23
+ $("#result").load('/debug_console', {text: $('#text').val()});
24
+ }
25
+ HAML
26
+ end
27
+
28
+ post '/debug_console' do
29
+ require_administrative_privileges
30
+ begin
31
+ eval(params[:text]).inspect
32
+ rescue Exception => e
33
+ ([e.message] + e.backtrace).join("\n")
34
+ end
35
+ end
36
+
37
+ module Sinatra
38
+ module DebugConsole
39
+ class << self
40
+ def config(username, password)
41
+ @username = username
42
+ @password = password
43
+ end
44
+
45
+ def username
46
+ @username
47
+ end
48
+
49
+ def password
50
+ @password
51
+ end
52
+ end
53
+
54
+ module Authorization
55
+
56
+ def auth
57
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
58
+ end
59
+
60
+ def unauthorized!(realm = "sinatra_debug_console")
61
+ header 'WWW-Authenticate' => %(Basic realm="#{realm}")
62
+ throw :halt, [ 401, 'Authorization Required' ]
63
+ end
64
+
65
+ def bad_request!
66
+ throw :halt, [ 400, 'Bad Request' ]
67
+ end
68
+
69
+ def authorized?
70
+ request.env['REMOTE_USER']
71
+ end
72
+
73
+ def authorize(username, password)
74
+ username == DebugConsole.username && password == DebugConsole.password
75
+ end
76
+
77
+ def require_administrative_privileges
78
+ return if authorized?
79
+ unauthorized! unless auth.provided?
80
+ bad_request! unless auth.basic?
81
+ unauthorized! unless authorize(*auth.credentials)
82
+ request.env['REMOTE_USER'] = auth.username
83
+ end
84
+
85
+ def admin?
86
+ authorized?
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ include Sinatra::DebugConsole::Authorization
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra_debug_console
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jugyo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-15 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Web base debug console for sinatra
26
+ email: jugyo.org@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - LICENSE
36
+ - README.rdoc
37
+ - Rakefile
38
+ - VERSION
39
+ - lib/sinatra_debug_console.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/jugyo/sinatra_debug_console
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.5
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Debug console for sinatra
68
+ test_files: []
69
+