Remove throuput control and use the pause/break key to prevent flood.

This commit is contained in:
Florian Mounier
2016-08-08 11:12:22 +02:00
parent 503de38429
commit ac7e9bef8e
6 changed files with 68 additions and 84 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
(function() {
var $, State, Terminal, cancel, cols, openTs, quit, rows, s,
var $, State, Terminal, cancel, cols, cutMessage, openTs, quit, rows, s,
slice = [].slice,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
@@ -9,10 +9,12 @@
openTs = (new Date()).getTime();
cutMessage = '\r\nCutting...... 8< ...... 8< ...... ' + '\r\nYou can release when there is no more output.' + '\r\nCutting...... 8< ...... 8< ......' + '\r\nCutting...... 8< ...... 8< ......';
$ = document.querySelectorAll.bind(document);
document.addEventListener('DOMContentLoaded', function() {
var ctl, lastData, queue, root_path, send, t_queue, term, treat, ws, wsUrl;
var ctl, root_path, send, term, ws, wsUrl;
term = null;
send = function(data) {
return ws.send('S' + data);
@@ -47,11 +49,8 @@
ws.addEventListener('error', function() {
return console.log("WebSocket error", arguments);
});
lastData = '';
t_queue = null;
queue = '';
ws.addEventListener('message', function(e) {
var ref;
var letter, ref;
if (e.data[0] === 'R') {
ref = e.data.slice(1).split(','), cols = ref[0], rows = ref[1];
term.resize(cols, rows, true);
@@ -61,27 +60,17 @@
console.error('Garbage message');
return;
}
if (t_queue) {
clearTimeout(t_queue);
}
queue += e.data.slice(1);
if (term.stop) {
queue = queue.slice(-10 * 1024);
}
if (queue.length > term.buffSize) {
return treat();
if (term.stop == null) {
return term.write(e.data.slice(1));
} else {
return t_queue = setTimeout(treat, 1);
if (term.stop < cutMessage.length) {
letter = cutMessage[term.stop++];
} else {
letter = '.';
}
return term.write(letter);
}
});
treat = function() {
term.write(queue);
if (term.stop) {
term.stop = false;
term.body.classList.remove('stopped');
}
return queue = '';
};
ws.addEventListener('close', function() {
console.log("WebSocket closed", arguments);
setTimeout(function() {
@@ -185,12 +174,11 @@
this.termName = 'xterm';
this.cursorBlink = true;
this.cursorState = 0;
this.stop = false;
this.lastcc = 0;
this.resetVars();
this.focus();
this.startBlink();
addEventListener('keydown', this.keyDown.bind(this));
addEventListener('keyup', this.keyUp.bind(this));
addEventListener('keypress', this.keyPress.bind(this));
addEventListener('focus', this.focus.bind(this));
addEventListener('blur', this.blur.bind(this));
@@ -1380,11 +1368,31 @@
return this.write(data + "\r\n");
};
Terminal.prototype.keyUp = function(ev) {
if (ev.keyCode === 19) {
if (!this.stop) {
return;
}
this.body.classList.remove('stopped');
this.stop = null;
return this.out('\x03\n');
}
};
Terminal.prototype.keyDown = function(ev) {
var id, key, ref, t;
var key, ref;
if (ev.keyCode > 15 && ev.keyCode < 19) {
return true;
}
if (ev.keyCode === 19) {
if (this.stop) {
return;
}
this.body.classList.add('stopped');
this.stop = 0;
this.out('\x03');
return false;
}
if ((ev.shiftKey || ev.ctrlKey) && ev.keyCode === 45) {
return true;
}
@@ -1550,23 +1558,6 @@
default:
if (ev.ctrlKey) {
if (ev.keyCode >= 65 && ev.keyCode <= 90) {
if (ev.keyCode === 67) {
t = (new Date()).getTime();
if ((t - this.lastcc) < 500 && !this.stop) {
id = setTimeout(function() {});
while (id--) {
if (id !== this.t_bell && id !== this.t_queue && id !== this.t_blink) {
clearTimeout(id);
}
}
this.body.classList.add('stopped');
this.stop = true;
return this.send(' \x7f');
} else if (this.stop) {
return true;
}
this.lastcc = t;
}
key = String.fromCharCode(ev.keyCode - 64);
} else if (ev.keyCode === 32) {
key = String.fromCharCode(0);

File diff suppressed because one or more lines are too long

View File

@@ -140,7 +140,6 @@ class Terminal(object):
# butterfly is executed
self.callee = self.callee or utils.User()
def shell(self):
try:
os.chdir(self.path or self.callee.dir)
@@ -191,7 +190,8 @@ class Terminal(object):
# User has been auth with ssl or is the same user as server
# or login is explicitly turned off
if (
not tornado.options.options.unsecure and not (
not tornado.options.options.unsecure and
tornado.options.options.login and not (
self.socket.local and
self.caller == self.callee and
server == self.callee

View File

@@ -18,6 +18,10 @@
cols = rows = null
quit = false
openTs = (new Date()).getTime()
cutMessage = '\r\nCutting...... 8< ...... 8< ...... ' +
'\r\nYou can release when there is no more output.' +
'\r\nCutting...... 8< ...... 8< ......' +
'\r\nCutting...... 8< ...... 8< ......'
$ = document.querySelectorAll.bind(document)
@@ -54,10 +58,6 @@ document.addEventListener 'DOMContentLoaded', ->
ws.addEventListener 'error', ->
console.log "WebSocket error", arguments
lastData = ''
t_queue = null
queue = ''
ws.addEventListener 'message', (e) ->
if e.data[0] is 'R'
[cols, rows] = e.data.slice(1).split(',')
@@ -68,22 +68,14 @@ document.addEventListener 'DOMContentLoaded', ->
console.error 'Garbage message'
return
clearTimeout t_queue if t_queue
queue += e.data.slice(1)
if term.stop
queue = queue.slice -10 * 1024
if queue.length > term.buffSize
treat()
unless term.stop?
term.write e.data.slice(1)
else
t_queue = setTimeout treat, 1
treat = ->
term.write queue
if term.stop
term.stop = false
term.body.classList.remove 'stopped'
queue = ''
if term.stop < cutMessage.length
letter = cutMessage[term.stop++]
else
letter = '.'
term.write letter
ws.addEventListener 'close', ->
console.log "WebSocket closed", arguments
@@ -102,7 +94,6 @@ document.addEventListener 'DOMContentLoaded', ->
if not quit
'This will exit the terminal session'
window.bench = (n=100000000) ->
rnd = ''
while rnd.length < n

View File

@@ -80,14 +80,14 @@ class Terminal
@termName = 'xterm'
@cursorBlink = true
@cursorState = 0
@stop = false
@lastcc = 0
@resetVars()
@focus()
@startBlink()
addEventListener 'keydown', @keyDown.bind(@)
addEventListener 'keyup', @keyUp.bind(@)
addEventListener 'keypress', @keyPress.bind(@)
addEventListener 'focus', @focus.bind(@)
addEventListener 'blur', @blur.bind(@)
@@ -1258,12 +1258,26 @@ class Terminal
writeln: (data) ->
@write "#{data}\r\n"
keyUp: (ev) ->
if ev.keyCode is 19 # Pause break
return unless @stop
@body.classList.remove 'stopped'
@stop = null
@out '\x03\n'
keyDown: (ev) ->
# Key Resources:
# https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
# Don't handle modifiers alone
return true if ev.keyCode > 15 and ev.keyCode < 19
if ev.keyCode is 19 # Pause break
return if @stop
@body.classList.add 'stopped'
@stop = 0
@out '\x03'
return false
# Handle shift insert and ctrl insert
# copy/paste usefull for typematrix keyboard
return true if (ev.shiftKey or ev.ctrlKey) and ev.keyCode is 45
@@ -1446,21 +1460,9 @@ class Terminal
# a-z and space
if ev.ctrlKey
if ev.keyCode >= 65 and ev.keyCode <= 90
if ev.keyCode is 67
t = (new Date()).getTime()
if (t - @lastcc) < 500 and not @stop
id = (setTimeout ->)
(clearTimeout id if id not in [
@t_bell, @t_queue, @t_blink]) while id--
@body.classList.add 'stopped'
@stop = true
return @send ' \x7f'
else if @stop
return true
@lastcc = t
key = String.fromCharCode(ev.keyCode - 64)
else if ev.keyCode is 32
else if ev.keyCode is 32
# NUL
key = String.fromCharCode(0)
else if ev.keyCode >= 51 and ev.keyCode <= 55