rack_web_console 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +6 -1
- data/lib/rack-console-view.erb +4 -1
- data/lib/rack_console/version.rb +1 -1
- data/lib/rack_web_console.rb +8 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dfaeac9ee45c324241bea12915d58f6bbd5be2e
|
4
|
+
data.tar.gz: 2bd64bc6b3e89fc89610a7c570136237b300888b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85a986e233d90c6723b59b35a8d5fa310ec6db0820b25b61c8b1dd4a85e069e53a3074817fa517fe27fd800ab08439228213a2fa301dc9d9acf02d60b0fd9269
|
7
|
+
data.tar.gz: 422c7aa741fbae714a64ba95ca3530f86d98ec4a321519241897269a1155f2b315fb243140bbc3b8fc422babd27f51e71c7901df360aa3afd90566101316d7f0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Rack Web Console
|
1
|
+
# Rack Web Console [](https://travis-ci.org/rosenfeld/rack_web_console)
|
2
2
|
|
3
3
|
Rack Web Console is a simple Rack app class that allows one to run arbitrary Ruby code on a given
|
4
4
|
binding, which may be useful in development mode to test some code in a given context. This is
|
@@ -96,6 +96,11 @@ Thread.current[:rack_console_capture_all] = true
|
|
96
96
|
Thread.start{ puts 'now it should be displayed in the browser' }.join
|
97
97
|
```
|
98
98
|
|
99
|
+
### Shortcuts from inside the textarea
|
100
|
+
|
101
|
+
- Ctrl+Enter: Run code
|
102
|
+
- Esc, Esc: Clear output
|
103
|
+
|
99
104
|
## Development
|
100
105
|
|
101
106
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec`
|
data/lib/rack-console-view.erb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
<div id="results"></div>
|
22
22
|
|
23
23
|
<script>
|
24
|
+
;(function(){
|
24
25
|
var run_path = '', lastEscTime = 0,
|
25
26
|
results = $el('results'), runScriptButton = $el('run-script'),
|
26
27
|
clearResultsButton = $el('clear-results'), script = $el('script'), request
|
@@ -46,7 +47,8 @@
|
|
46
47
|
div.innerHTML = this.responseText
|
47
48
|
results.appendChild(div)
|
48
49
|
}
|
49
|
-
request.send('script=' + encodeURIComponent(script.value)
|
50
|
+
request.send('script=' + encodeURIComponent(script.value) + '&token=' +
|
51
|
+
encodeURIComponent('<%= token %>'))
|
50
52
|
}
|
51
53
|
function onKeyDown(ev) {
|
52
54
|
if (ev.ctrlKey && ev.keyCode == 13) runScript() // Ctrl + Enter
|
@@ -55,6 +57,7 @@
|
|
55
57
|
lastEscTime = new Date().getTime()
|
56
58
|
}
|
57
59
|
}
|
60
|
+
})();
|
58
61
|
</script>
|
59
62
|
</body>
|
60
63
|
</html>
|
data/lib/rack_console/version.rb
CHANGED
data/lib/rack_web_console.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'cgi'
|
3
|
+
require 'securerandom'
|
3
4
|
require_relative 'rack_console/version'
|
4
5
|
require_relative 'rack_console/cookie_script_storage'
|
5
6
|
require_relative 'rack_console/output_capture'
|
@@ -7,8 +8,9 @@ require_relative 'rack_console/output_capture'
|
|
7
8
|
class RackConsole
|
8
9
|
VIEW_TEMPLATE = ::File.join __dir__, 'rack-console-view.erb'
|
9
10
|
|
10
|
-
def initialize(_binding = binding, storage: ->(env){ CookieScriptStorage.new env })
|
11
|
+
def initialize(_binding = binding, storage: ->(env){ CookieScriptStorage.new env }, token: nil)
|
11
12
|
@storage, @binding = storage, _binding
|
13
|
+
@@token ||= token || SecureRandom.base64(32)
|
12
14
|
end
|
13
15
|
|
14
16
|
def call(env)
|
@@ -20,8 +22,10 @@ class RackConsole
|
|
20
22
|
|
21
23
|
|
22
24
|
def process_script(env)
|
23
|
-
|
24
|
-
|
25
|
+
params = CGI.parse env['rack.input'].read
|
26
|
+
token = params['token']&.first.to_s
|
27
|
+
return [403, {}, []] unless same_origin?(env) && token == @@token
|
28
|
+
script = params['script'].first
|
25
29
|
@_storage&.script=(script)
|
26
30
|
result = []
|
27
31
|
(oc = OutputCapture.new).capture do
|
@@ -52,6 +56,7 @@ class RackConsole
|
|
52
56
|
|
53
57
|
def view_response(env)
|
54
58
|
script = (s = @_storage&.script) ? ::ERB::Util.h(s) : ''
|
59
|
+
token = @@token
|
55
60
|
::ERB.new(::File.read view_template).result binding
|
56
61
|
end
|
57
62
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_web_console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Rosenfeld Rosas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|