abalone 0.2.1 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/abalone.rb +29 -2
- data/public/index.html +9 -0
- data/public/js/abalone.js +17 -5
- data/views/index.erb +12 -0
- 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: ea051e4cf4c221ad17b102a504eff7a40452ad1e
|
4
|
+
data.tar.gz: dba07d3f25fb3529a7bdf645587b7096fe5e6803
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6342b905e0315d42a301fc0367d67c6a2a4481821669befb4f3044adf20def7cb804093f6aef0a1135f4d602137fb73e9b1f674cd48c49a67ea29f090cab24f8
|
7
|
+
data.tar.gz: 13f2c302b13da357add6286a605f2cbb56ba2853ea82afc7fbafea698c987059bde51756410353e720ef766e47411d73164c91b50870e45da5f8ae6baded641e
|
data/README.md
CHANGED
@@ -42,6 +42,11 @@ can set several options:
|
|
42
42
|
* The path of a file to log to.
|
43
43
|
* Default value: Log only to `STDERR`. If you pass `-l` at the command line
|
44
44
|
with no filename, it will log to `/var/log/abalone`.
|
45
|
+
* `:timeout`
|
46
|
+
* Maximum number of seconds a session can last. The shell will be killed at the
|
47
|
+
end of that time. For example, set it to 300 for shells that last for up to
|
48
|
+
five minutes.
|
49
|
+
* Default value: unset.
|
45
50
|
* One of [`:command`](#configuring-a-custom-command) or [`:ssh`](#configuring-ssh), exclusive.
|
46
51
|
* The login method to use. Abalone can use `login`, SSH, or a custom command
|
47
52
|
to start a shell. See configuration instructions below.
|
data/lib/abalone.rb
CHANGED
@@ -14,6 +14,13 @@ class Abalone < Sinatra::Base
|
|
14
14
|
|
15
15
|
before {
|
16
16
|
env["rack.logger"] = settings.logger if settings.logger
|
17
|
+
|
18
|
+
trap('INT') do
|
19
|
+
# this forces all the spawned children to terminate as well
|
20
|
+
puts "Caught SIGINT. Terminating active sessions (#{Process.pid}) now."
|
21
|
+
exit!
|
22
|
+
end
|
23
|
+
|
17
24
|
}
|
18
25
|
|
19
26
|
get '/?:user?' do
|
@@ -59,7 +66,7 @@ class Abalone < Sinatra::Base
|
|
59
66
|
data = (carry + output[0..last_low]).pack('C*').force_encoding('UTF-8') # repack into a string up until the last low bit
|
60
67
|
carry = output[trailing..-1] # save the any remaining high bits and partial chars for next go-round
|
61
68
|
|
62
|
-
ws.send(data)
|
69
|
+
ws.send({'data' => data}.to_json)
|
63
70
|
|
64
71
|
rescue IO::WaitReadable
|
65
72
|
IO.select([reader])
|
@@ -69,12 +76,32 @@ class Abalone < Sinatra::Base
|
|
69
76
|
warn('Terminal has exited!')
|
70
77
|
ws.close_connection
|
71
78
|
|
79
|
+
@timer.terminate
|
80
|
+
@timer.join rescue nil
|
72
81
|
Thread.exit
|
73
82
|
end
|
83
|
+
|
74
84
|
sleep(0.05)
|
75
85
|
end
|
76
86
|
end
|
77
87
|
|
88
|
+
if settings.respond_to? :timeout
|
89
|
+
@timer = Thread.new do
|
90
|
+
expiration = Time.now + settings.timeout
|
91
|
+
loop do
|
92
|
+
remaining = expiration - Time.now
|
93
|
+
stop_term if remaining < 0
|
94
|
+
|
95
|
+
time = {
|
96
|
+
'event' => 'time',
|
97
|
+
'data' => Time.at(remaining).utc.strftime("%H:%M:%S"),
|
98
|
+
}
|
99
|
+
ws.send(time.to_json)
|
100
|
+
sleep 1
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
78
105
|
end
|
79
106
|
|
80
107
|
ws.onclose do
|
@@ -120,7 +147,7 @@ class Abalone < Sinatra::Base
|
|
120
147
|
|
121
148
|
helpers do
|
122
149
|
def stop_term()
|
123
|
-
Process.kill('
|
150
|
+
Process.kill('HUP', @pid) rescue nil
|
124
151
|
@term.join rescue nil
|
125
152
|
end
|
126
153
|
|
data/public/index.html
CHANGED
@@ -12,6 +12,14 @@
|
|
12
12
|
width: 100%;
|
13
13
|
margin: 0px;
|
14
14
|
}
|
15
|
+
#timer {
|
16
|
+
position: absolute;
|
17
|
+
z-index: 1000;
|
18
|
+
top: 15px;
|
19
|
+
right: 15px;
|
20
|
+
opacity: 0.5;
|
21
|
+
display: none;
|
22
|
+
}
|
15
23
|
#overlay {
|
16
24
|
position: absolute;
|
17
25
|
z-index: 1000;
|
@@ -37,6 +45,7 @@
|
|
37
45
|
</head>
|
38
46
|
|
39
47
|
<body onload="connect();">
|
48
|
+
<div id="timer"></div>
|
40
49
|
<div id="overlay"><input type="button" onclick="javascript:connect();" value="reconnect" /></div>
|
41
50
|
<div id="terminal"></div>
|
42
51
|
</body>
|
data/public/js/abalone.js
CHANGED
@@ -60,12 +60,24 @@ function disconnected() {
|
|
60
60
|
document.getElementById("overlay").style.display = "block";
|
61
61
|
}
|
62
62
|
|
63
|
-
function messageHandler(
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
function messageHandler(message) {
|
64
|
+
var message = JSON.parse(message);
|
65
|
+
var event = message['event'];
|
66
|
+
var data = message['data'];
|
67
|
+
|
68
|
+
switch(event) {
|
69
|
+
case 'time':
|
70
|
+
document.getElementById("timer").style.display = "block";
|
71
|
+
document.getElementById("timer").innerHTML = data;
|
72
|
+
break;
|
73
|
+
|
74
|
+
default:
|
75
|
+
if (!term) {
|
76
|
+
buf += data;
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
term.io.writeUTF16(data);
|
67
80
|
}
|
68
|
-
term.io.writeUTF16(data);
|
69
81
|
}
|
70
82
|
|
71
83
|
/* borrowed from https://github.com/krishnasrinivas/wetty */
|
data/views/index.erb
CHANGED
@@ -12,6 +12,17 @@
|
|
12
12
|
width: 100%;
|
13
13
|
margin: 0px;
|
14
14
|
}
|
15
|
+
#timer {
|
16
|
+
position: absolute;
|
17
|
+
z-index: 1000;
|
18
|
+
top: 15px;
|
19
|
+
right: 15px;
|
20
|
+
opacity: 0.25;
|
21
|
+
font-size: 3em;
|
22
|
+
font-weight: bolder;
|
23
|
+
color: red;
|
24
|
+
display: none;
|
25
|
+
}
|
15
26
|
#overlay {
|
16
27
|
position: absolute;
|
17
28
|
z-index: 1000;
|
@@ -37,6 +48,7 @@
|
|
37
48
|
</head>
|
38
49
|
|
39
50
|
<body <% if @autoconnect %>onload="connect(<%= @requestUsername %>);"<% end %>>
|
51
|
+
<div id="timer"></div>
|
40
52
|
<div id="overlay"><input type="button" onclick="javascript:connect(<%= @requestUsername %>);" value="Start Session" /></div>
|
41
53
|
<div id="terminal"></div>
|
42
54
|
</body>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abalone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Ford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|