web-console-compat 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.markdown +110 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +5 -0
- data/Rakefile +27 -0
- data/lib/web-console-compat.rb +1 -0
- data/lib/web-console.rb +1 -0
- data/lib/web_console.rb +28 -0
- data/lib/web_console/context.rb +43 -0
- data/lib/web_console/errors.rb +7 -0
- data/lib/web_console/evaluator.rb +33 -0
- data/lib/web_console/exception_mapper.rb +33 -0
- data/lib/web_console/extensions.rb +44 -0
- data/lib/web_console/integration.rb +31 -0
- data/lib/web_console/integration/cruby.rb +23 -0
- data/lib/web_console/integration/rubinius.rb +39 -0
- data/lib/web_console/locales/en.yml +15 -0
- data/lib/web_console/middleware.rb +140 -0
- data/lib/web_console/railtie.rb +71 -0
- data/lib/web_console/request.rb +50 -0
- data/lib/web_console/response.rb +23 -0
- data/lib/web_console/session.rb +76 -0
- data/lib/web_console/tasks/extensions.rake +60 -0
- data/lib/web_console/tasks/templates.rake +54 -0
- data/lib/web_console/template.rb +23 -0
- data/lib/web_console/templates/_inner_console_markup.html.erb +8 -0
- data/lib/web_console/templates/_markup.html.erb +5 -0
- data/lib/web_console/templates/_prompt_box_markup.html.erb +2 -0
- data/lib/web_console/templates/console.js.erb +922 -0
- data/lib/web_console/templates/error_page.js.erb +70 -0
- data/lib/web_console/templates/index.html.erb +8 -0
- data/lib/web_console/templates/layouts/inlined_string.erb +1 -0
- data/lib/web_console/templates/layouts/javascript.erb +5 -0
- data/lib/web_console/templates/main.js.erb +1 -0
- data/lib/web_console/templates/style.css.erb +33 -0
- data/lib/web_console/testing/erb_precompiler.rb +25 -0
- data/lib/web_console/testing/fake_middleware.rb +39 -0
- data/lib/web_console/testing/helper.rb +9 -0
- data/lib/web_console/version.rb +3 -0
- data/lib/web_console/view.rb +50 -0
- data/lib/web_console/whiny_request.rb +31 -0
- data/lib/web_console/whitelist.rb +44 -0
- metadata +147 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
// Try intercept traces links in Rails 4.2.
|
2
|
+
var traceFrames = document.getElementsByClassName('trace-frames');
|
3
|
+
var selectedFrame, currentSource = document.getElementById('frame-source-0');
|
4
|
+
|
5
|
+
// Add click listeners for all stack frames
|
6
|
+
for (var i = 0; i < traceFrames.length; i++) {
|
7
|
+
traceFrames[i].addEventListener('click', function(e) {
|
8
|
+
e.preventDefault();
|
9
|
+
var target = e.target;
|
10
|
+
var frameId = target.dataset.frameId;
|
11
|
+
|
12
|
+
// Change the binding of the console.
|
13
|
+
changeBinding(frameId, function() {
|
14
|
+
if (selectedFrame) {
|
15
|
+
selectedFrame.className = selectedFrame.className.replace("selected", "");
|
16
|
+
}
|
17
|
+
|
18
|
+
target.className += " selected";
|
19
|
+
selectedFrame = target;
|
20
|
+
});
|
21
|
+
|
22
|
+
// Change the extracted source code
|
23
|
+
changeSourceExtract(frameId);
|
24
|
+
});
|
25
|
+
}
|
26
|
+
|
27
|
+
function changeBinding(frameId, callback) {
|
28
|
+
REPLConsole.currentSession.switchBindingTo(frameId, callback);
|
29
|
+
}
|
30
|
+
|
31
|
+
function changeSourceExtract(frameId) {
|
32
|
+
var el = document.getElementById('frame-source-' + frameId);
|
33
|
+
if (currentSource && el) {
|
34
|
+
currentSource.className += " hidden";
|
35
|
+
el.className = el.className.replace(" hidden", "");
|
36
|
+
currentSource = el;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
// Push the error page body upwards the size of the console.
|
41
|
+
//
|
42
|
+
// While, I wouldn't like to do that on every custom page (so I don't screw
|
43
|
+
// user's layouts), I think a lot of developers want to see all of the content
|
44
|
+
// on the default Rails error page.
|
45
|
+
//
|
46
|
+
// Since it's quite special as is now, being a bit more special in the name of
|
47
|
+
// better user experience, won't hurt.
|
48
|
+
document.addEventListener('DOMContentLoaded', function() {
|
49
|
+
var consoleElement = document.getElementById('console');
|
50
|
+
var resizerElement = consoleElement.getElementsByClassName('resizer')[0];
|
51
|
+
var containerElement = document.getElementById('container');
|
52
|
+
|
53
|
+
function setContainerElementBottomMargin(pixels) {
|
54
|
+
containerElement.style.marginBottom = pixels + 'px';
|
55
|
+
}
|
56
|
+
|
57
|
+
var currentConsoleElementHeight = consoleElement.offsetHeight;
|
58
|
+
setContainerElementBottomMargin(currentConsoleElementHeight);
|
59
|
+
|
60
|
+
resizerElement.addEventListener('mousedown', function(event) {
|
61
|
+
function recordConsoleElementHeight(event) {
|
62
|
+
resizerElement.removeEventListener('mouseup', recordConsoleElementHeight);
|
63
|
+
|
64
|
+
var currentConsoleElementHeight = consoleElement.offsetHeight;
|
65
|
+
setContainerElementBottomMargin(currentConsoleElementHeight);
|
66
|
+
}
|
67
|
+
|
68
|
+
resizerElement.addEventListener('mouseup', recordConsoleElementHeight);
|
69
|
+
});
|
70
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
"<%= j yield %>"
|
@@ -0,0 +1 @@
|
|
1
|
+
REPLConsole.installInto('console');
|
@@ -0,0 +1,33 @@
|
|
1
|
+
.console .pos-absolute { position: absolute; }
|
2
|
+
.console .pos-fixed { position: fixed; }
|
3
|
+
.console .pos-right { right: 0; }
|
4
|
+
.console .border-box { box-sizing: border-box; }
|
5
|
+
.console .layer { width: 100%; height: 100%; }
|
6
|
+
.console .layer.console-outer { z-index: 1; }
|
7
|
+
.console .layer.resizer { z-index: 2; }
|
8
|
+
.console { position: fixed; left: 0; bottom: 0; width: 100%; height: 148px; padding: 0; margin: 0; background: none repeat scroll 0% 0% #333; z-index: 9999; }
|
9
|
+
.console .console-outer { overflow: auto; padding-top: 4px; }
|
10
|
+
.console .console-inner { font-family: monospace; font-size: 11px; width: 100%; height: 100%; overflow: none; background: #333; }
|
11
|
+
.console .console-prompt-box { color: #FFF; }
|
12
|
+
.console .console-message { color: #1AD027; margin: 0; border: 0; white-space: pre-wrap; background-color: #333; padding: 0; }
|
13
|
+
.console .console-message.error-message { color: #fc9; }
|
14
|
+
.console .console-message.auto-complete { word-break: break-all; }
|
15
|
+
.console .console-message.auto-complete .keyword { margin-right: 11px; }
|
16
|
+
.console .console-message.auto-complete .keyword.selected { background: #FFF; color: #000; }
|
17
|
+
.console .console-message.auto-complete .hidden { display: none; }
|
18
|
+
.console .console-message.auto-complete .trimmed { display: none; }
|
19
|
+
.console .console-hint { color: #096; }
|
20
|
+
.console .console-focus .console-cursor { background: #FEFEFE; color: #333; font-weight: bold; }
|
21
|
+
.console .resizer { background: #333; width: 100%; height: 4px; cursor: ns-resize; }
|
22
|
+
.console .console-actions { padding-right: 3px; }
|
23
|
+
.console .console-actions .button { float: left; }
|
24
|
+
.console .button { cursor: pointer; border-radius: 1px; font-family: monospace; font-size: 13px; width: 14px; height: 14px; line-height: 14px; text-align: center; color: #ccc; }
|
25
|
+
.console .button:hover { background: #666; color: #fff; }
|
26
|
+
.console .button.close-button:hover { background: #966; }
|
27
|
+
.console .clipboard { height: 0px; padding: 0px; margin: 0px; width: 0px; margin-left: -1000px; }
|
28
|
+
.console .console-prompt-label { display: inline; color: #FFF; background: none repeat scroll 0% 0% #333; border: 0; padding: 0; }
|
29
|
+
.console .console-prompt-display { display: inline; color: #FFF; background: none repeat scroll 0% 0% #333; border: 0; padding: 0; }
|
30
|
+
.console.full-screen { height: 100%; }
|
31
|
+
.console.full-screen .console-outer { padding-top: 3px; }
|
32
|
+
.console.full-screen .resizer { display: none; }
|
33
|
+
.console.full-screen .close-button { display: none; }
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'web_console/testing/helper'
|
2
|
+
require 'web_console/testing/fake_middleware'
|
3
|
+
|
4
|
+
module WebConsole
|
5
|
+
module Testing
|
6
|
+
# This class is to pre-compile 'templates/*.erb'.
|
7
|
+
class ERBPrecompiler
|
8
|
+
def initialize(path)
|
9
|
+
@erb = ERB.new(File.read(path))
|
10
|
+
@view = FakeMiddleware.new(
|
11
|
+
view_path: Helper.gem_root.join('lib/web_console/templates'),
|
12
|
+
).view
|
13
|
+
end
|
14
|
+
|
15
|
+
def build
|
16
|
+
@erb.result(binding)
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(name, *args, &block)
|
20
|
+
return super unless @view.respond_to?(name)
|
21
|
+
@view.send(name, *args, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'web_console'
|
3
|
+
require 'web_console/testing/helper'
|
4
|
+
Mime = { web_console_v2: 'fake' }
|
5
|
+
|
6
|
+
module WebConsole
|
7
|
+
module Testing
|
8
|
+
class FakeMiddleware
|
9
|
+
I18n.load_path.concat(Dir[Helper.gem_root.join('lib/web_console/locales/*.yml')])
|
10
|
+
|
11
|
+
DEFAULT_HEADERS = { "Content-Type" => "application/javascript" }
|
12
|
+
|
13
|
+
def initialize(opts)
|
14
|
+
@headers = opts.fetch(:headers, DEFAULT_HEADERS)
|
15
|
+
@req_path_regex = opts[:req_path_regex]
|
16
|
+
@view_path = opts[:view_path]
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
[ 200, @headers, [ render(req_path(env)) ] ]
|
21
|
+
end
|
22
|
+
|
23
|
+
def view
|
24
|
+
@view = View.new(@view_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# extract target path from REQUEST_PATH
|
30
|
+
def req_path(env)
|
31
|
+
env["REQUEST_PATH"].match(@req_path_regex)[1]
|
32
|
+
end
|
33
|
+
|
34
|
+
def render(template)
|
35
|
+
view.render(template: template, layout: nil)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module WebConsole
|
2
|
+
class View < ActionView::Base
|
3
|
+
# Execute a block only on error pages.
|
4
|
+
#
|
5
|
+
# The error pages are special, because they are the only pages that
|
6
|
+
# currently require multiple bindings. We get those from exceptions.
|
7
|
+
def only_on_error_page(*args)
|
8
|
+
yield if Thread.current[:__web_console_exception].present?
|
9
|
+
end
|
10
|
+
|
11
|
+
# Render JavaScript inside a script tag and a closure.
|
12
|
+
#
|
13
|
+
# This one lets write JavaScript that will automatically get wrapped in a
|
14
|
+
# script tag and enclosed in a closure, so you don't have to worry for
|
15
|
+
# leaking globals, unless you explicitly want to.
|
16
|
+
def render_javascript(template)
|
17
|
+
assign(template: template)
|
18
|
+
render(template: template, layout: 'layouts/javascript')
|
19
|
+
end
|
20
|
+
|
21
|
+
# Render inlined string to be used inside of JavaScript code.
|
22
|
+
#
|
23
|
+
# The inlined string is returned as an actual JavaScript string. You
|
24
|
+
# don't need to wrap the result yourself.
|
25
|
+
def render_inlined_string(template)
|
26
|
+
render(template: template, layout: 'layouts/inlined_string')
|
27
|
+
end
|
28
|
+
|
29
|
+
# Custom ActionView::Base#render wrapper which silences all the log
|
30
|
+
# printings.
|
31
|
+
#
|
32
|
+
# Helps to keep the Rails logs clean during errors.
|
33
|
+
def render(*)
|
34
|
+
if logger = WebConsole.logger and logger.respond_to?(:silence)
|
35
|
+
WebConsole.logger.silence { super }
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Override method for ActionView::Helpers::TranslationHelper#t.
|
42
|
+
#
|
43
|
+
# This method escapes the original return value for JavaScript, since the
|
44
|
+
# method returns a HTML tag with some attributes when the key is not found,
|
45
|
+
# so it could cause a syntax error if we use the value in the string literals.
|
46
|
+
def t(key, options = {})
|
47
|
+
j super
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module WebConsole
|
2
|
+
# Noisy wrapper around +Request+.
|
3
|
+
#
|
4
|
+
# If any calls to +from_whitelisted_ip?+ and +acceptable_content_type?+
|
5
|
+
# return false, an info log message will be displayed in users' logs.
|
6
|
+
class WhinyRequest < SimpleDelegator
|
7
|
+
def from_whitelisted_ip?
|
8
|
+
whine_unless request.from_whitelisted_ip? do
|
9
|
+
"Cannot render console from #{request.strict_remote_ip}! " \
|
10
|
+
"Allowed networks: #{request.whitelisted_ips}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def whine_unless(condition)
|
17
|
+
unless condition
|
18
|
+
logger.info { yield }
|
19
|
+
end
|
20
|
+
condition
|
21
|
+
end
|
22
|
+
|
23
|
+
def logger
|
24
|
+
env['action_dispatch.logger'] || WebConsole.logger
|
25
|
+
end
|
26
|
+
|
27
|
+
def request
|
28
|
+
__getobj__
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
|
3
|
+
module WebConsole
|
4
|
+
# Whitelist of allowed networks that can access Web Console.
|
5
|
+
#
|
6
|
+
# Networks are represented by standard IPAddr and can be either IPv4 or IPv6
|
7
|
+
# networks.
|
8
|
+
class Whitelist
|
9
|
+
# IPv4 and IPv6 localhost should be always whitelisted.
|
10
|
+
ALWAYS_WHITELISTED_NETWORKS = %w( 127.0.0.0/8 ::1 )
|
11
|
+
|
12
|
+
def initialize(networks = nil)
|
13
|
+
@networks = normalize_networks(networks).map(&method(:coerce_network_to_ipaddr)).uniq
|
14
|
+
end
|
15
|
+
|
16
|
+
def include?(network)
|
17
|
+
@networks.any? { |whitelist| whitelist.include?(network.to_s) }
|
18
|
+
rescue IPAddr::InvalidAddressError
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
@networks.map(&method(:human_readable_ipaddr)).join(', ')
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def normalize_networks(networks)
|
29
|
+
Array(networks).concat(ALWAYS_WHITELISTED_NETWORKS)
|
30
|
+
end
|
31
|
+
|
32
|
+
def coerce_network_to_ipaddr(network)
|
33
|
+
if network.is_a?(IPAddr)
|
34
|
+
network
|
35
|
+
else
|
36
|
+
IPAddr.new(network)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def human_readable_ipaddr(ipaddr)
|
41
|
+
ipaddr.to_range.to_s.split('..').uniq.join('/')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: web-console-compat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charlie Somerville
|
8
|
+
- Genadi Samokovarov
|
9
|
+
- Guillermo Iguaran
|
10
|
+
- Ryan Dao
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: railties
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "<"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activemodel
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '5.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "<"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '5.0'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: actionview
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '5.0'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "<"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '5.0'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: debug_inspector
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
description:
|
73
|
+
email:
|
74
|
+
- charlie@charliesomerville.com
|
75
|
+
- gsamokovarov@gmail.com
|
76
|
+
- guilleiguaran@gmail.com
|
77
|
+
- daoduyducduong@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- CHANGELOG.markdown
|
83
|
+
- MIT-LICENSE
|
84
|
+
- README.markdown
|
85
|
+
- Rakefile
|
86
|
+
- lib/web-console-compat.rb
|
87
|
+
- lib/web-console.rb
|
88
|
+
- lib/web_console.rb
|
89
|
+
- lib/web_console/context.rb
|
90
|
+
- lib/web_console/errors.rb
|
91
|
+
- lib/web_console/evaluator.rb
|
92
|
+
- lib/web_console/exception_mapper.rb
|
93
|
+
- lib/web_console/extensions.rb
|
94
|
+
- lib/web_console/integration.rb
|
95
|
+
- lib/web_console/integration/cruby.rb
|
96
|
+
- lib/web_console/integration/rubinius.rb
|
97
|
+
- lib/web_console/locales/en.yml
|
98
|
+
- lib/web_console/middleware.rb
|
99
|
+
- lib/web_console/railtie.rb
|
100
|
+
- lib/web_console/request.rb
|
101
|
+
- lib/web_console/response.rb
|
102
|
+
- lib/web_console/session.rb
|
103
|
+
- lib/web_console/tasks/extensions.rake
|
104
|
+
- lib/web_console/tasks/templates.rake
|
105
|
+
- lib/web_console/template.rb
|
106
|
+
- lib/web_console/templates/_inner_console_markup.html.erb
|
107
|
+
- lib/web_console/templates/_markup.html.erb
|
108
|
+
- lib/web_console/templates/_prompt_box_markup.html.erb
|
109
|
+
- lib/web_console/templates/console.js.erb
|
110
|
+
- lib/web_console/templates/error_page.js.erb
|
111
|
+
- lib/web_console/templates/index.html.erb
|
112
|
+
- lib/web_console/templates/layouts/inlined_string.erb
|
113
|
+
- lib/web_console/templates/layouts/javascript.erb
|
114
|
+
- lib/web_console/templates/main.js.erb
|
115
|
+
- lib/web_console/templates/style.css.erb
|
116
|
+
- lib/web_console/testing/erb_precompiler.rb
|
117
|
+
- lib/web_console/testing/fake_middleware.rb
|
118
|
+
- lib/web_console/testing/helper.rb
|
119
|
+
- lib/web_console/version.rb
|
120
|
+
- lib/web_console/view.rb
|
121
|
+
- lib/web_console/whiny_request.rb
|
122
|
+
- lib/web_console/whitelist.rb
|
123
|
+
homepage: https://github.com/rails/web-console
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: 1.9.3
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.6.11
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: A debugging tool for your Ruby on Rails applications.
|
147
|
+
test_files: []
|