web-console 2.0.0.beta2 → 2.0.0.beta3
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/MIT-LICENSE +1 -1
- data/README.markdown +304 -19
- data/app/assets/javascripts/web_console/application.js +1 -0
- data/app/assets/javascripts/web_console/console_sessions.js +172 -0
- data/app/assets/stylesheets/web_console/application.css +13 -0
- data/app/assets/stylesheets/web_console/console_sessions.css.erb +6 -0
- data/app/controllers/web_console/application_controller.rb +13 -0
- data/app/controllers/web_console/console_sessions_controller.rb +43 -0
- data/app/helpers/web_console/application_helper.rb +4 -0
- data/app/helpers/web_console/console_session_helper.rb +4 -0
- data/app/models/web_console/console_session.rb +96 -0
- data/app/views/layouts/web_console/application.html.erb +14 -0
- data/app/views/web_console/console_sessions/index.html.erb +15 -0
- data/config/routes.rb +11 -0
- data/lib/action_dispatch/debug_exceptions.rb +69 -69
- data/lib/action_dispatch/exception_wrapper.rb +2 -1
- data/lib/assets/javascripts/web-console.js +1 -0
- data/lib/assets/javascripts/web_console.js +41 -0
- data/lib/web_console.rb +14 -15
- data/lib/web_console/colors.rb +87 -0
- data/lib/web_console/colors/light.rb +24 -0
- data/lib/web_console/colors/monokai.rb +24 -0
- data/lib/web_console/colors/solarized.rb +47 -0
- data/lib/web_console/colors/tango.rb +24 -0
- data/lib/web_console/colors/xterm.rb +24 -0
- data/lib/web_console/engine.rb +95 -0
- data/lib/web_console/exception_extension.rb +10 -11
- data/lib/web_console/repl_session.rb +5 -3
- data/lib/web_console/slave.rb +139 -0
- data/lib/web_console/version.rb +1 -1
- data/lib/web_console/view_helpers.rb +3 -7
- data/test/controllers/web_console/console_sessions_controller_test.rb +95 -0
- data/test/dummy/app/controllers/exception_test_controller.rb +4 -0
- data/test/dummy/app/views/exception_test/xhr.html.erb +1 -0
- data/test/dummy/config/application.rb +37 -1
- data/test/dummy/config/environments/test.rb +2 -0
- data/test/dummy/config/routes.rb +1 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +61814 -0
- data/test/dummy/log/test.log +8621 -3
- data/test/dummy/tmp/cache/assets/development/sprockets/038461854af2e8bccdb29768efd4768f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/0ec396634a5f6808b026257fd107c355 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/127a54171eea8d294e4673599861787d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/17c571144b4e44da39bddb2d2c412414 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/1cb77d8cf661ccbc9de08f347c89b9f1 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/204edd12a29660722d4e0d8de9bd6652 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2b96b037f3dfeccfe27113eb95b06ea1 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2c853768baf811357d81d41bdfd05dcf +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/314d48e543146f617c4d3439a4d8d40d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/34f21019a876722b8c24a6da4f0ef50b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/36341e42f23669574fa1027d0958ff3e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/44117154e909436e7eeaf10cdb18d2b4 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/496864a905d53afd8e176f29500f96a8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/55b7b76605fdffe31d737d4ac1f1ef7b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/5ac98782fe3dfd0a766f75ce1801f0a0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6088d6f344b38303cc8028057d69e0f9 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/676dcf9b2d01b9dc7bd3183d8da88463 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/680381170dc160e358fc28076ea6886c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6ad7acc9a22fe2a67ec24a1fc866c20e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6bdb0d0c602e0e1bc304dc697e2cc6de +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6dc8d7aa69668fce85683aaad6615432 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6e4d5b32cc444226f6597198994ccd5e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/74db0ca5cb8c8c347c9131a3ff516748 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7999e525c88173c1beb785f002effc1d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7a50a9e605754e99783de95715b976b0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/806b0e33a2fe8e1245534345fa27c30a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8aa4c7aabff23c8089d41e9e54193483 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/90396626cba6cbec37e32038e6c54e76 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/976b28910aa72c90a3b30c6e940f51df +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/99e1bd7cbc437505bc8f07bc528c721c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/aaccf2c9ae2add0863c9a49e0042a097 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ae4677d24a79d9411f2fced5011d5807 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b2401118729720034b6f3eda0b4c5025 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/c649837df826fc310cb80f1adafd6b8d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cac185d59612fae451a12df3fc21bb51 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cb0065359d3b5b296f71d673f4b276e9 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cee8c6b09c33d2b276753e959712724e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d1f6e06bc2f112c4ec3a4c3f68351878 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d20d83fd7ffa378b1b2b901786d640f3 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d38c7c3aa1e72b55769ccb3607641ef4 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d6b85d8b0b5c569388b89e56e9f6fed7 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d982412def520c434e2240eae6d29cf2 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/df048a8b0897b9c04acdf59c8f95b18f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/df600f50f002512c95d93bcfbab891ed +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e6d6b8bde546349764be7b44ffcf5807 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/eb25265794d2f7afd1684779d84efdac +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ee8826b12b7d9bfd717df950b58f82ab +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ef9824789c6ed3483590e0564a12e1d1 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/fc7201c6cbef32453aa4175c520c8eae +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/17c571144b4e44da39bddb2d2c412414 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/36341e42f23669574fa1027d0958ff3e +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/55b7b76605fdffe31d737d4ac1f1ef7b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/5ac98782fe3dfd0a766f75ce1801f0a0 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/680381170dc160e358fc28076ea6886c +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/6ad7acc9a22fe2a67ec24a1fc866c20e +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/6e4d5b32cc444226f6597198994ccd5e +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/7a50a9e605754e99783de95715b976b0 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/8aa4c7aabff23c8089d41e9e54193483 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/b2401118729720034b6f3eda0b4c5025 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cb0065359d3b5b296f71d673f4b276e9 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d1f6e06bc2f112c4ec3a4c3f68351878 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d6b85d8b0b5c569388b89e56e9f6fed7 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d982412def520c434e2240eae6d29cf2 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/df048a8b0897b9c04acdf59c8f95b18f +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/e6d6b8bde546349764be7b44ffcf5807 +0 -0
- data/test/models/console_session_test.rb +58 -0
- data/test/web_console/colors_test.rb +58 -0
- data/test/web_console/engine_test.rb +136 -0
- data/test/web_console/slave_test.rb +71 -0
- data/vendor/assets/javascripts/term.js +5726 -0
- metadata +188 -7
- data/lib/web_console/railtie.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: afe33c91afb082074dd982930c4aef140c279c9e
|
|
4
|
+
data.tar.gz: e77676a84dde11dae828446db54974a79fbe3896
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8180671dcf6b9227a3f0c1d1ccf5397f8926734b91a2586bf83f4a2f06b9b1fd7de58f10a13731108493459111c4a522ffde51c14dd668aa2f90255c7e0c6ce1
|
|
7
|
+
data.tar.gz: fbed5ea4aa571865488f344f94b35d05f81b39174f52ddab726f43cbb77274f91aedd1ef72d904a611848082d5f57f920b891614a5610a6755a498a319613eee
|
data/MIT-LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2014 Charlie Somerville, Genadi Samokovarov, Guillermo Iguaran and Ryan Dao
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
4
|
a copy of this software and associated documentation files (the
|
data/README.markdown
CHANGED
|
@@ -8,61 +8,346 @@
|
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
10
|
<p align=center>
|
|
11
|
-
<em>Web Console is
|
|
11
|
+
<em>Web Console is currently in beta for <code>2.0.0</code>. If you're searching for a stable
|
|
12
12
|
version documentation, checkout the links above.</em>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
15
|
Web Console [](https://travis-ci.org/rails/web-console)
|
|
16
16
|
===========
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
_Web Console_ is a set of debugging tools for your Rails application.
|
|
19
19
|
|
|
20
|
+
**A debugging tool in the default error page.**
|
|
21
|
+
|
|
22
|
+
An interactive console is launched automatically in the default Rails error
|
|
23
|
+
page. It makes it easy to inspect the stack trace and execute Ruby code in the stack
|
|
24
|
+
trace's bindings.
|
|
25
|
+
|
|
26
|
+
_(Check out [better_errors] as a great alternative for any Rack application!)_
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
**A debugging tool in your views.**
|
|
31
|
+
|
|
32
|
+
Drop `<%= console %>` anywhere in a view to launch an interactive console session and
|
|
33
|
+
execute code in it.
|
|
34
|
+
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
**A [VT100] compatible terminal.**
|
|
38
|
+
|
|
39
|
+
Running `rails console` is quite handy. Sometimes, though, you can't easily
|
|
40
|
+
access it, or maybe you want to easily share your session with a friend without
|
|
41
|
+
configuring a remote desktop server.
|
|
42
|
+
|
|
43
|
+
_Web Console_ can help you by running `rails console` _(or any other
|
|
44
|
+
commandline app)_, in full featured terminal right in the browser.
|
|
45
|
+
|
|
46
|
+

|
|
20
47
|
|
|
21
48
|
Requirements
|
|
22
49
|
------------
|
|
23
50
|
|
|
24
51
|
_Web Console_ has been tested on the following rubies.
|
|
25
52
|
|
|
53
|
+
* _MRI Ruby_ 2.1.0
|
|
26
54
|
* _MRI Ruby_ 2.0.0
|
|
27
55
|
* _MRI Ruby_ 1.9.3
|
|
28
56
|
|
|
29
|
-
|
|
57
|
+
There is an experimental _JRuby_ 1.7 support. See Installation section for more
|
|
58
|
+
information.
|
|
30
59
|
|
|
31
|
-
|
|
32
|
-
------------
|
|
60
|
+
_Rubunius_ in 1.9 mode may work, but it hasn't been explicitly tested.
|
|
33
61
|
|
|
34
|
-
|
|
62
|
+
_Web Console_ is built explicitly for _Rails 4_. Check out the
|
|
63
|
+
[web-console-rails3] project for a _Rails 3_ compatible build.
|
|
35
64
|
|
|
36
65
|
Installation
|
|
37
66
|
------------
|
|
38
67
|
|
|
39
|
-
|
|
68
|
+
To install it in your current application, add the following to your `Gemfile`.
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
group :development do
|
|
72
|
+
gem 'web-console', '2.0.0.beta2'
|
|
73
|
+
end
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
For _JRuby_ support, you need to add an unreleased version of
|
|
77
|
+
`binding_of_caller`.
|
|
40
78
|
|
|
41
|
-
|
|
79
|
+
```ruby
|
|
80
|
+
group :development do
|
|
81
|
+
gem 'web-console', '2.0.0.beta2'
|
|
82
|
+
gem 'binding_of_caller', github: 'banister/binding_of_caller'
|
|
83
|
+
end
|
|
84
|
+
```
|
|
42
85
|
|
|
86
|
+
After you save the `Gemfile` changes, make sure to run `bundle install` and
|
|
87
|
+
restart your server for the _Web Console_ to kick in.
|
|
43
88
|
|
|
44
|
-
|
|
89
|
+
Configuration
|
|
45
90
|
-------------
|
|
46
91
|
|
|
47
|
-
###
|
|
92
|
+
### config.web_console.automount
|
|
48
93
|
|
|
49
|
-
|
|
94
|
+
If you want to automatically mount `WebConsole::Engine`, you can set this
|
|
95
|
+
option to `true`. The terminal will be mounted at the location pointed by
|
|
96
|
+
`config.web_console.default_mount_path`.
|
|
50
97
|
|
|
51
|
-
|
|
98
|
+
Defaults to `false`.
|
|
52
99
|
|
|
53
|
-
|
|
100
|
+
_(Note that, this option used to default to `true` in the 1.0 days. We no
|
|
101
|
+
longer automatically mount the web terminal at `/console`.)_.
|
|
54
102
|
|
|
55
|
-
|
|
103
|
+
### config.web_console.default_mount_path
|
|
56
104
|
|
|
57
|
-
|
|
105
|
+
By default, the console will be mounted on `/console`.
|
|
106
|
+
|
|
107
|
+
_(This happens only in the development and test environments!)_.
|
|
108
|
+
|
|
109
|
+
Say you want to mount the console to `/debug`, so you can more easily remember
|
|
110
|
+
where to go, when your application needs debugging.
|
|
111
|
+
|
|
112
|
+
```ruby
|
|
113
|
+
class Application < Rails::Application
|
|
114
|
+
config.web_console.default_mount_path = '/debug'
|
|
115
|
+
end
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
> Today we have learned in the agony of war that great power involves great
|
|
119
|
+
> responsibility.
|
|
120
|
+
>
|
|
121
|
+
> -- <cite>Franklin D. Roosevelt</cite>
|
|
122
|
+
|
|
123
|
+
_Web Console_ is a powerful tool. It allows you to execute arbitrary code on
|
|
124
|
+
the server, so you should be very careful, who you give access to it.
|
|
125
|
+
|
|
126
|
+
### config.web_console.whitelisted_ips
|
|
127
|
+
|
|
128
|
+
By default, only requests coming from `127.0.0.1` are allowed.
|
|
129
|
+
|
|
130
|
+
`config.web_console.whitelisted_ips` lets you control which IP's have access to
|
|
131
|
+
the console.
|
|
132
|
+
|
|
133
|
+
Let's say you want to share your console with just that one roommate, you like
|
|
134
|
+
and his/her IP is `192.168.0.100`.
|
|
135
|
+
|
|
136
|
+
```ruby
|
|
137
|
+
class Application < Rails::Application
|
|
138
|
+
config.web_console.whitelisted_ips = %w( 127.0.0.1 192.168.0.100 )
|
|
139
|
+
end
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
From the example, you can guess that `config.web_console.whitelisted_ips`
|
|
143
|
+
accepts an array of ip addresses, provided as strings. An important thing to
|
|
144
|
+
note here is that, we won't push `127.0.0.1` if you manually set the option!
|
|
145
|
+
|
|
146
|
+
Now let's assume you like all of your roommates. Instead of enumerating their
|
|
147
|
+
IP's, you can whitelist the whole private network. Now every time their IP's
|
|
148
|
+
change, you'll have them covered.
|
|
149
|
+
|
|
150
|
+
```ruby
|
|
151
|
+
class Application < Rails::Application
|
|
152
|
+
config.web_console.whitelisted_ips = '192.168.0.0/16'
|
|
153
|
+
end
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
You can see that `config.web_console.whitelisted_ips` accepts plains strings
|
|
157
|
+
too. More than that, they can cover whole networks.
|
|
158
|
+
|
|
159
|
+
Again, note that this network doesn't allow `127.0.0.1`. If you want to access
|
|
160
|
+
the console, you have to do so from it's external IP or add `127.0.0.1` to the
|
|
161
|
+
mix.
|
|
162
|
+
|
|
163
|
+
### config.web_console.command
|
|
164
|
+
|
|
165
|
+
By default, _Web Console_ will run `Rails.root.join('bin/rails console)` to
|
|
166
|
+
spawn you a fresh Rails console. If the relative `bin/rails` doesn't exist,
|
|
167
|
+
`rails console` will be run instead.
|
|
168
|
+
|
|
169
|
+
One of the advantages of being a [VT100] emulator is that _Web Console_ can run
|
|
170
|
+
most of your terminal applications.
|
|
171
|
+
|
|
172
|
+
Let say _(for some reason)_ you can't run SSH on your server machine. You can
|
|
173
|
+
run [`login`][login] instead to let users sign into the host system.
|
|
174
|
+
|
|
175
|
+
```ruby
|
|
176
|
+
class Application < Rails::Application
|
|
177
|
+
# You have to run /bin/login as root. That should worry you and you may work
|
|
178
|
+
# around it by running ssh connecting to the same machine.
|
|
179
|
+
config.web_console.command = 'sudo /bin/login'
|
|
180
|
+
end
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
_Poor man's solution to SSH._ 
|
|
184
|
+
|
|
185
|
+
**If you ever decide to use _Web Console_ that way, use SSL to encrypt the
|
|
186
|
+
traffic, otherwise all the input (including the negotiated username and
|
|
187
|
+
password) can be easily sniffed!**
|
|
188
|
+
|
|
189
|
+
### config.web_console.term
|
|
190
|
+
|
|
191
|
+
By default, the _Web Console_ terminal will report itself as `xterm-color`. You
|
|
192
|
+
can override this option to change it with this option.
|
|
193
|
+
|
|
194
|
+
### config.web_console.timeout
|
|
195
|
+
|
|
196
|
+
You may have noticed that _Web Console_ client sends a lot of requests to the
|
|
197
|
+
server. And by a lot, we really mean, **a lot** _(every few milliseconds)_.
|
|
198
|
+
We do this since we can't reliably predict when the output of your command
|
|
199
|
+
execution will come available, so we poll for it.
|
|
200
|
+
|
|
201
|
+
This option control how much will the server wait on the process output pipe
|
|
202
|
+
for input, before signalling the client to try again.
|
|
203
|
+
|
|
204
|
+
Maybe some day Web Sockets or SSE can be used for more efficient communication.
|
|
205
|
+
Until that day, you can use long-polling. To enable it, use [Puma] as your
|
|
206
|
+
development server and add the following to your configuration.
|
|
207
|
+
|
|
208
|
+
```ruby
|
|
209
|
+
class Application < Rails::Application
|
|
210
|
+
# You have to explicitly enable the concurrency, as in development mode,
|
|
211
|
+
# the falsy config.cache_classes implies no concurrency support.
|
|
212
|
+
#
|
|
213
|
+
# The concurrency is enabled by removing the Rack::Lock middleware, which
|
|
214
|
+
# wraps each request in a mutex, effectively making the request handling
|
|
215
|
+
# synchronous.
|
|
216
|
+
config.allow_concurrency = true
|
|
217
|
+
|
|
218
|
+
# For long-polling, 45 seconds timeout for the development server seems
|
|
219
|
+
# reasonable. You may want to experiment with the value.
|
|
220
|
+
config.web_console.timeout = 45.seconds
|
|
221
|
+
end
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Styling
|
|
225
|
+
-------
|
|
226
|
+
|
|
227
|
+
If you would like to style the terminal a bit different than the default
|
|
228
|
+
appearance, you can do so with the following options.
|
|
229
|
+
|
|
230
|
+
### config.web_console.style.colors
|
|
231
|
+
|
|
232
|
+
_Web Console_ supports up to 256 color themes, though most of the common
|
|
233
|
+
terminal themes are usually 16 colors.
|
|
234
|
+
|
|
235
|
+
The default color theme is a white-on-black theme called `light`. For
|
|
236
|
+
different appearance you may want to experiment with the other included color
|
|
237
|
+
themes.
|
|
238
|
+
|
|
239
|
+
- `monokai` _the default Sublime Text colors_
|
|
240
|
+
- `solarized_dark` _light version of the common solarized colors_
|
|
241
|
+
- `solarized_light` _dark version of the common solarized colors_
|
|
242
|
+
- `tango` _theme based on the tango colors_
|
|
243
|
+
- `xterm` _the standard xterm theme_
|
|
244
|
+
|
|
245
|
+
If you would like to use a custom theme, you may do so with the following
|
|
246
|
+
syntax.
|
|
247
|
+
|
|
248
|
+
```ruby
|
|
249
|
+
class Application < Rails::Application
|
|
250
|
+
# First, you have to define and register your custom color theme. Each color
|
|
251
|
+
# theme is mapped to a name.
|
|
252
|
+
WebConsole::Colors.register_theme(:custom) do |c|
|
|
253
|
+
# The most common color themes are the 16 colors one. They are built from 3
|
|
254
|
+
# parts.
|
|
255
|
+
|
|
256
|
+
# 8 darker colors.
|
|
257
|
+
c.add '#000000'
|
|
258
|
+
c.add '#cd0000'
|
|
259
|
+
c.add '#00cd00'
|
|
260
|
+
c.add '#cdcd00'
|
|
261
|
+
c.add '#0000ee'
|
|
262
|
+
c.add '#cd00cd'
|
|
263
|
+
c.add '#00cdcd'
|
|
264
|
+
c.add '#e5e5e5'
|
|
265
|
+
|
|
266
|
+
# 8 lighter colors.
|
|
267
|
+
c.add '#7f7f7f'
|
|
268
|
+
c.add '#ff0000'
|
|
269
|
+
c.add '#00ff00'
|
|
270
|
+
c.add '#ffff00'
|
|
271
|
+
c.add '#5c5cff'
|
|
272
|
+
c.add '#ff00ff'
|
|
273
|
+
c.add '#00ffff'
|
|
274
|
+
c.add '#ffffff'
|
|
275
|
+
|
|
276
|
+
# Background and foreground colors.
|
|
277
|
+
c.background '#ffffff'
|
|
278
|
+
c.foreground '#000000'
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# Now you have to tell Web Console to actually use it.
|
|
282
|
+
config.web_console.style.colors = :custom
|
|
283
|
+
end
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### config.web_console.style.font
|
|
287
|
+
|
|
288
|
+
You may also change the font, which is following the CSS font property syntax.
|
|
289
|
+
By default it is `large DejaVu Sans Mono, Liberation Mono, monospace`.
|
|
290
|
+
|
|
291
|
+
Shout-out
|
|
292
|
+
---------
|
|
293
|
+
|
|
294
|
+
Great thanks to [Charlie Somerville] for [better_errors]! Most of the exception
|
|
295
|
+
binding code is coming straight out of the [better_errors] project.
|
|
58
296
|
|
|
59
297
|
FAQ
|
|
60
298
|
---
|
|
61
299
|
|
|
62
|
-
###
|
|
300
|
+
### I'm running JRuby and /console doesn't load.
|
|
301
|
+
|
|
302
|
+
**TL;DR** Give it a bit of time, it will load.
|
|
303
|
+
|
|
304
|
+
While spawning processes is relatively cheap on _MRI_, this is not the case in
|
|
305
|
+
_JRuby_. Spawning another process is slow. Spawning another **JRuby** process
|
|
306
|
+
is even slower. Read more about the problem at the _JRuby_ [wiki].
|
|
307
|
+
|
|
308
|
+
### I'm running JRuby and there's no console on the default error page.
|
|
309
|
+
|
|
310
|
+
_JRuby_ support in the default error page requires the latest is experimental
|
|
311
|
+
and requires an unreleased version of `web-console` and `binding_of_caller`.
|
|
312
|
+
|
|
313
|
+
To try it out, put this in your Gemfile.
|
|
314
|
+
|
|
315
|
+
```ruby
|
|
316
|
+
group :development do
|
|
317
|
+
gem 'web-console', github: 'rails/web-console'
|
|
318
|
+
gem 'binding_of_caller', github: 'banister/binding_of_caller'
|
|
319
|
+
end
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
You would also have to run you Rails server in JRuby's interpreted mode. Enable
|
|
323
|
+
it with code snippet below, then start your development Rails server with
|
|
324
|
+
`rails server`, as usual.
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
export JRUBY_OPTS=-J-Djruby.compile.mode=OFF
|
|
328
|
+
|
|
329
|
+
# If you run JRuby 1.7.12 and above, you can use:
|
|
330
|
+
# export JRUBY_OPTS=--dev
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
_(Please, note that we don't guarantee master to be stable and we
|
|
334
|
+
will appreciate any issue reports!)_
|
|
335
|
+
|
|
336
|
+
### Changing the colors is broken.
|
|
337
|
+
|
|
338
|
+
Some of the style sheets may be cached on the file system. Run
|
|
339
|
+
`rake tmp:cache:clear` to clear those up.
|
|
63
340
|
|
|
64
|
-
|
|
341
|
+
### How to view local and instance variables in an interactive console?
|
|
65
342
|
|
|
66
|
-
|
|
343
|
+
The interactive console executes Ruby code. Invoking `instance_variables` and
|
|
344
|
+
`local_variables` will give you what you want.
|
|
67
345
|
|
|
68
|
-
|
|
346
|
+
[Docker]: http://www.docker.io/
|
|
347
|
+
[Puma]: http://puma.io/
|
|
348
|
+
[VT100]: http://en.wikipedia.org/wiki/VT100
|
|
349
|
+
[login]: http://linux.die.net/man/1/login
|
|
350
|
+
[web-console-rails3]: https://github.com/gsamokovarov/web-console-rails3
|
|
351
|
+
[wiki]: https://github.com/jruby/jruby/wiki/Improving-startup-time#avoid-spawning-sub-rubies
|
|
352
|
+
[better_errors]: https://github.com/charliesome/better_errors
|
|
353
|
+
[Charlie Somerville]: https://github.com/charliesome
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//= require_tree .
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
//= require web-console
|
|
2
|
+
|
|
3
|
+
var AJAXTransport = (function(WebConsole) {
|
|
4
|
+
|
|
5
|
+
var inherits = WebConsole.inherits;
|
|
6
|
+
var EventEmitter = WebConsole.EventEmitter;
|
|
7
|
+
|
|
8
|
+
var FORM_MIME_TYPE = 'application/x-www-form-urlencoded; charset=utf-8';
|
|
9
|
+
|
|
10
|
+
var AJAXTransport = function(options) {
|
|
11
|
+
EventEmitter.call(this);
|
|
12
|
+
options || (options = {});
|
|
13
|
+
|
|
14
|
+
this.url = (typeof options.url === 'string') ? {
|
|
15
|
+
input: options.url,
|
|
16
|
+
pendingOutput: options.url,
|
|
17
|
+
configuration: options.url
|
|
18
|
+
} : options.url;
|
|
19
|
+
|
|
20
|
+
this.pendingInput = '';
|
|
21
|
+
|
|
22
|
+
this.initializeEventHandlers();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
inherits(AJAXTransport, EventEmitter);
|
|
26
|
+
|
|
27
|
+
// Initializes the default event handlers.
|
|
28
|
+
AJAXTransport.prototype.initializeEventHandlers = function() {
|
|
29
|
+
this.on('input', this.sendInput);
|
|
30
|
+
this.on('configuration', this.sendConfiguration);
|
|
31
|
+
this.once('initialization', function(cols, rows) {
|
|
32
|
+
this.emit('configuration', cols, rows);
|
|
33
|
+
this.pollForPendingOutput();
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Shorthand for creating XHR requests.
|
|
38
|
+
AJAXTransport.prototype.createRequest = function(method, url, options) {
|
|
39
|
+
options || (options = {});
|
|
40
|
+
|
|
41
|
+
var request = new XMLHttpRequest;
|
|
42
|
+
request.open(method, url);
|
|
43
|
+
|
|
44
|
+
if (typeof options.form === 'object') {
|
|
45
|
+
var content = [], form = options.form;
|
|
46
|
+
|
|
47
|
+
for (var key in form) {
|
|
48
|
+
var value = form[key];
|
|
49
|
+
content.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
request.setRequestHeader('Content-Type', FORM_MIME_TYPE);
|
|
53
|
+
request.data = content.join('&');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return request;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
AJAXTransport.prototype.pollForPendingOutput = function() {
|
|
60
|
+
var request = this.createRequest('GET', this.url.pendingOutput);
|
|
61
|
+
|
|
62
|
+
var self = this;
|
|
63
|
+
request.onreadystatechange = function() {
|
|
64
|
+
if (request.readyState === XMLHttpRequest.DONE) {
|
|
65
|
+
if (request.status === 200) {
|
|
66
|
+
self.emit('pendingOutput', request.responseText);
|
|
67
|
+
self.pollForPendingOutput();
|
|
68
|
+
} else {
|
|
69
|
+
self.emit('disconnect', request);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
request.send(null);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Send the input to the server.
|
|
78
|
+
//
|
|
79
|
+
// Each key press is encoded to an intermediate format, before it is sent to
|
|
80
|
+
// the server.
|
|
81
|
+
//
|
|
82
|
+
// WebConsole#keysPressed is an alias for WebConsole#sendInput.
|
|
83
|
+
AJAXTransport.prototype.sendInput = function(input) {
|
|
84
|
+
input || (input = '');
|
|
85
|
+
|
|
86
|
+
if (this.disconnected) return;
|
|
87
|
+
if (this.sendingInput) return this.pendingInput += input;
|
|
88
|
+
|
|
89
|
+
// Indicate that we are starting to send input.
|
|
90
|
+
this.sendingInput = true;
|
|
91
|
+
|
|
92
|
+
var request = this.createRequest('PUT', this.url.input, {
|
|
93
|
+
form: { input: this.pendingInput + input }
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Clear the pending input.
|
|
97
|
+
this.pendingInput = '';
|
|
98
|
+
|
|
99
|
+
var self = this;
|
|
100
|
+
request.onreadystatechange = function() {
|
|
101
|
+
if (request.readyState === XMLHttpRequest.DONE) {
|
|
102
|
+
self.sendingInput = false;
|
|
103
|
+
if (self.pendingInput) self.sendInput();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
request.send(request.data);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Send the terminal configuration to the server.
|
|
111
|
+
//
|
|
112
|
+
// Right now by configuration, we understand the terminal widht and terminal
|
|
113
|
+
// height.
|
|
114
|
+
//
|
|
115
|
+
// WebConsole#resized is an alias for WebConsole#sendconfiguration.
|
|
116
|
+
AJAXTransport.prototype.sendConfiguration = function(cols, rows) {
|
|
117
|
+
if (this.disconnected) return;
|
|
118
|
+
|
|
119
|
+
var request = this.createRequest('PUT', this.url.configuration, {
|
|
120
|
+
form: { width: cols, height: rows }
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Just send the configuration and don't care about any output.
|
|
124
|
+
request.send(request.data);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return AJAXTransport;
|
|
128
|
+
|
|
129
|
+
}).call(this, WebConsole);
|
|
130
|
+
|
|
131
|
+
window.addEventListener('load', function() {
|
|
132
|
+
var geometry = calculateFitScreenGeometry();
|
|
133
|
+
config.terminal.cols = geometry[0];
|
|
134
|
+
config.terminal.rows = geometry[1];
|
|
135
|
+
|
|
136
|
+
var terminal = window.terminal = new WebConsole.Terminal(config.terminal);
|
|
137
|
+
|
|
138
|
+
terminal.on('data', function(data) {
|
|
139
|
+
transport.emit('input', data);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
var transport = new AJAXTransport(config.transport);
|
|
143
|
+
|
|
144
|
+
transport.on('pendingOutput', function(response) {
|
|
145
|
+
var json = JSON.parse(response);
|
|
146
|
+
if (json.output) terminal.write(json.output);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
transport.on('disconnect', function() {
|
|
150
|
+
terminal.destroy();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
transport.emit('initialization', terminal.cols, terminal.rows);
|
|
154
|
+
|
|
155
|
+
// Utilities
|
|
156
|
+
// ---------
|
|
157
|
+
|
|
158
|
+
function calculateFitScreenGeometry() {
|
|
159
|
+
// Currently, resizing term.js is broken. E.g. opening vi causes it to go
|
|
160
|
+
// back to 80x24 and fail with off-by-one error. Other stuff, like chip8
|
|
161
|
+
// are rendered incorrectly and so on.
|
|
162
|
+
//
|
|
163
|
+
// To work around it, create a temporary terminal, just so we can get the
|
|
164
|
+
// best dimensions for the screen.
|
|
165
|
+
var temporary = new WebConsole.Terminal;
|
|
166
|
+
try {
|
|
167
|
+
return temporary.fitScreen();
|
|
168
|
+
} finally {
|
|
169
|
+
temporary.destroy();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|