Add server option for enabling very unsafe html escapes and change them to DCS

This commit is contained in:
Florian Mounier
2015-04-08 11:25:43 +02:00
parent 16a1dae39c
commit c2bde7b3b6
12 changed files with 176 additions and 110 deletions

2
bin/hr
View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
print('\x1b]99;<hr />\x07')
print('\x1bP;HTML|<hr />\x1bP')

View File

@@ -6,7 +6,7 @@ import os
import mimetypes
import base64
import io
print('\x1b]99;')
print('\x1bP;HTML|')
out = ''
@@ -28,4 +28,4 @@ for f in os.listdir(os.getcwd()):
print(out)
print('\x07')
print('\x1bP')

View File

@@ -8,6 +8,6 @@ calendar = LocaleHTMLCalendar(locale=locale.getlocale())
calendar_table = calendar.formatmonth(now.year, now.month)
calendar_table = calendar_table.replace('border="0"', 'border="1"')
print('\x1b]99;')
print('\x1bP;HTML|')
print(calendar_table)
print('\x07')
print('\x1bP')

View File

@@ -40,6 +40,9 @@ tornado.options.define("cmd",
help="Command to run instead of shell, f.i.: 'ls -l'")
tornado.options.define("unsecure", default=False,
help="Don't use ssl not recommended")
tornado.options.define("allow_html_escapes", default=False,
help="Allow use of HTML escapes. "
"Really unsafe as it is now.")
tornado.options.define("login", default=True,
help="Use login screen at start")
tornado.options.define("ssl_version", default=None,

View File

@@ -1,6 +1,6 @@
(function() {
var Selection, alt, cancel, copy, ctrl, first, next_leaf, previous_leaf, selection, set_alarm, virtual_input,
__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; };
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; };
set_alarm = function(notification) {
var alarm;
@@ -48,14 +48,14 @@
});
document.addEventListener('copy', copy = function(e) {
var data, end, line, sel, _i, _len, _ref;
var data, end, j, len1, line, ref, sel;
butterfly.bell("copied");
e.clipboardData.clearData();
sel = getSelection().toString().replace(/\u00A0/g, ' ').replace(/\u2007/g, ' ');
data = '';
_ref = sel.split('\n');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
ref = sel.split('\n');
for (j = 0, len1 = ref.length; j < len1; j++) {
line = ref[j];
if (line.slice(-1) === '\u23CE') {
end = '';
line = line.slice(0, -1);
@@ -127,7 +127,7 @@
}
Selection.prototype.reset = function() {
var fake_range, _ref, _results;
var fake_range, ref, results;
this.selection = getSelection();
fake_range = document.createRange();
fake_range.setStart(this.selection.anchorNode, this.selection.anchorOffset);
@@ -141,18 +141,18 @@
offset: this.selection.focusOffset
};
if (fake_range.collapsed) {
_ref = [this.end, this.start], this.start = _ref[0], this.end = _ref[1];
ref = [this.end, this.start], this.start = ref[0], this.end = ref[1];
}
this.start_line = this.start.node;
while (!this.start_line.classList || __indexOf.call(this.start_line.classList, 'line') < 0) {
while (!this.start_line.classList || indexOf.call(this.start_line.classList, 'line') < 0) {
this.start_line = this.start_line.parentNode;
}
this.end_line = this.end.node;
_results = [];
while (!this.end_line.classList || __indexOf.call(this.end_line.classList, 'line') < 0) {
_results.push(this.end_line = this.end_line.parentNode);
results = [];
while (!this.end_line.classList || indexOf.call(this.end_line.classList, 'line') < 0) {
results.push(this.end_line = this.end_line.parentNode);
}
return _results;
return results;
};
Selection.prototype.clear = function() {
@@ -302,8 +302,8 @@
})();
document.addEventListener('keydown', function(e) {
var _ref, _ref1;
if (_ref = e.keyCode, __indexOf.call([16, 17, 18, 19], _ref) >= 0) {
var ref, ref1;
if (ref = e.keyCode, indexOf.call([16, 17, 18, 19], ref) >= 0) {
return true;
}
if (e.shiftKey && e.keyCode === 13 && !selection && !getSelection().isCollapsed) {
@@ -313,7 +313,7 @@
}
if (selection) {
selection.reset();
if (!e.ctrlKey && e.shiftKey && (37 <= (_ref1 = e.keyCode) && _ref1 <= 40)) {
if (!e.ctrlKey && e.shiftKey && (37 <= (ref1 = e.keyCode) && ref1 <= 40)) {
return true;
}
if (e.shiftKey && e.ctrlKey) {
@@ -348,8 +348,8 @@
});
document.addEventListener('keyup', function(e) {
var _ref, _ref1;
if (_ref = e.keyCode, __indexOf.call([16, 17, 18, 19], _ref) >= 0) {
var ref, ref1;
if (ref = e.keyCode, indexOf.call([16, 17, 18, 19], ref) >= 0) {
return true;
}
if (selection) {
@@ -359,7 +359,7 @@
selection = null;
return cancel(e);
}
if (_ref1 = e.keyCode, __indexOf.call([37, 38, 39, 40], _ref1) < 0) {
if (ref1 = e.keyCode, indexOf.call([37, 38, 39, 40], ref1) < 0) {
selection.destroy();
selection = null;
return true;

File diff suppressed because one or more lines are too long

View File

@@ -133,12 +133,12 @@ html, body {
width: 100%;
height: 100%;
transform: rotate(-45deg);
opacity: 0.2;
opacity: .2;
font-weight: 900; }
.terminal.copied {
transform: scale(1.05); }
.terminal.pasted {
transform: scale(0.95); }
transform: scale(.95); }
/* *-* coding: utf-8 *-* */
/* This file is part of butterfly */

View File

@@ -1,7 +1,7 @@
(function() {
var $, State, Terminal, cancel, cols, open_ts, 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; };
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; };
cols = rows = null;
@@ -18,7 +18,7 @@
};
ctl = function() {
var args, params, type;
type = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
type = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
params = args.join(',');
if (type === 'Resize') {
return ws.send('R' + params);
@@ -73,7 +73,7 @@
}
t0 = (new Date()).getTime();
term.write(rnd);
return console.log("" + n + " chars in " + ((new Date()).getTime() - t0) + " ms");
return console.log(n + " chars in " + ((new Date()).getTime() - t0) + " ms");
};
cbench = function(n) {
var rnd, t0;
@@ -87,7 +87,7 @@
}
t0 = (new Date()).getTime();
term.write(rnd);
return console.log("" + n + " chars + colors in " + ((new Date()).getTime() - t0) + " ms");
return console.log(n + " chars + colors in " + ((new Date()).getTime() - t0) + " ms");
};
term.ws = ws;
return window.butterfly = term;
@@ -117,11 +117,11 @@
};
Terminal = (function() {
function Terminal(parent, out, ctl) {
function Terminal(parent1, out1, ctl1) {
var div, i, term_size;
this.parent = parent;
this.out = out;
this.ctl = ctl != null ? ctl : function() {};
this.parent = parent1;
this.out = out1;
this.ctl = ctl1 != null ? ctl1 : function() {};
this.context = this.parent.ownerDocument.defaultView;
this.document = this.parent.ownerDocument;
this.body = this.document.getElementsByTagName('body')[0];
@@ -622,7 +622,7 @@
};
Terminal.prototype.write = function(data) {
var ch, cs, i, j, l, pt, valid, _ref;
var ch, content, cs, html, i, j, l, line, pt, ref, ref1, type, valid;
this.refreshStart = this.y;
this.refreshEnd = this.y;
if (this.ybase !== this.ydisp) {
@@ -673,7 +673,7 @@
break;
default:
if (ch >= " ") {
if ((_ref = this.charset) != null ? _ref[ch] : void 0) {
if ((ref = this.charset) != null ? ref[ch] : void 0) {
ch = this.charset[ch];
}
if (this.x >= this.cols) {
@@ -1043,6 +1043,45 @@
}
switch (this.prefix) {
case "":
pt = this.currentParam;
if (pt[0] !== ';') {
console.error("Unknown DECUDK: " + pt);
break;
}
pt = pt.slice(1);
ref1 = pt.split('|', 2), type = ref1[0], content = ref1[1];
if (!content) {
console.error("No type for inline DECUDK: " + pt);
break;
}
switch (type) {
case "HTML":
if (document.getElementsByTagName('body')[0].getAttribute('data-allow-html') !== 'yes') {
console.log("HTML escapes are disabled");
break;
}
html = "<div class=\"inline-html\">" + content + "</div>";
this.lines[this.y + this.ybase][this.x] = [this.curAttr, html];
line = 0;
while (line < this.get_html_height_in_lines(html) - 1) {
this.y++;
if (this.y > this.scrollBottom) {
this.y--;
this.scroll();
}
line++;
}
break;
case "PROMPT":
this.send(content);
break;
case "TEXT":
l += content.length;
data = data.slice(0, i + 1) + content + data.slice(i + 1);
break;
default:
console.error("Unknown type " + type + " for DECUDK");
}
break;
case "$q":
pt = this.currentParam;
@@ -1104,18 +1143,18 @@
};
Terminal.prototype.writeln = function(data) {
return this.write("" + data + "\r\n");
return this.write(data + "\r\n");
};
Terminal.prototype.keyDown = function(ev) {
var id, key, t, _ref;
var id, key, ref, t;
if (ev.keyCode > 15 && ev.keyCode < 19) {
return true;
}
if ((ev.shiftKey || ev.ctrlKey) && ev.keyCode === 45) {
return true;
}
if ((ev.shiftKey && ev.ctrlKey) && ((_ref = ev.keyCode) === 67 || _ref === 86)) {
if ((ev.shiftKey && ev.ctrlKey) && ((ref = ev.keyCode) === 67 || ref === 86)) {
return true;
}
if (ev.altKey && ev.keyCode === 90 && !this.skipNextKey) {
@@ -1290,7 +1329,7 @@
key = String.fromCharCode(29);
}
}
} else if ((ev.altKey && __indexOf.call(navigator.platform, 'Mac') < 0) || (ev.metaKey && __indexOf.call(navigator.platform, 'Mac') >= 0)) {
} else if ((ev.altKey && indexOf.call(navigator.platform, 'Mac') < 0) || (ev.metaKey && indexOf.call(navigator.platform, 'Mac') >= 0)) {
if (ev.keyCode >= 65 && ev.keyCode <= 90) {
key = "\x1b" + String.fromCharCode(ev.keyCode + 32);
} else if (ev.keyCode === 192) {
@@ -1476,7 +1515,7 @@
};
Terminal.prototype.setupStops = function(i) {
var _results;
var results;
if (i != null) {
if (!this.tabs[i]) {
i = this.prevStop(i);
@@ -1485,12 +1524,12 @@
this.tabs = {};
i = 0;
}
_results = [];
results = [];
while (i < this.cols) {
this.tabs[i] = true;
_results.push(i += 8);
results.push(i += 8);
}
return _results;
return results;
};
Terminal.prototype.prevStop = function(x) {
@@ -1696,34 +1735,34 @@
};
Terminal.prototype.eraseInDisplay = function(params) {
var j, _results, _results1, _results2;
var j, results, results1, results2;
switch (params[0]) {
case 0:
this.eraseRight(this.x, this.y);
j = this.y + 1;
_results = [];
results = [];
while (j < this.rows) {
this.eraseLine(j);
_results.push(j++);
results.push(j++);
}
return _results;
return results;
break;
case 1:
this.eraseLeft(this.x, this.y);
j = this.y;
_results1 = [];
results1 = [];
while (j--) {
_results1.push(this.eraseLine(j));
results1.push(this.eraseLine(j));
}
return _results1;
return results1;
break;
case 2:
j = this.rows;
_results2 = [];
results2 = [];
while (j--) {
_results2.push(this.eraseLine(j));
results2.push(this.eraseLine(j));
}
return _results2;
return results2;
}
};
@@ -1834,7 +1873,7 @@
};
Terminal.prototype.insertChars = function(params) {
var ch, j, param, row, _results;
var ch, j, param, results, row;
param = params[0];
if (param < 1) {
param = 1;
@@ -1842,12 +1881,12 @@
row = this.y + this.ybase;
j = this.x;
ch = [this.eraseAttr(), " "];
_results = [];
results = [];
while (param-- && j < this.cols) {
this.lines[row].splice(j++, 0, ch);
_results.push(this.lines[row].pop());
results.push(this.lines[row].pop());
}
return _results;
return results;
};
Terminal.prototype.cursorNextLine = function(params) {
@@ -1920,23 +1959,23 @@
};
Terminal.prototype.deleteChars = function(params) {
var ch, param, row, _results;
var ch, param, results, row;
param = params[0];
if (param < 1) {
param = 1;
}
row = this.y + this.ybase;
ch = [this.eraseAttr(), " "];
_results = [];
results = [];
while (param--) {
this.lines[row].splice(this.x, 1);
_results.push(this.lines[row].push(ch));
results.push(this.lines[row].push(ch));
}
return _results;
return results;
};
Terminal.prototype.eraseChars = function(params) {
var ch, j, param, row, _results;
var ch, j, param, results, row;
param = params[0];
if (param < 1) {
param = 1;
@@ -1944,11 +1983,11 @@
row = this.y + this.ybase;
j = this.x;
ch = [this.eraseAttr(), " "];
_results = [];
results = [];
while (param-- && j < this.cols) {
_results.push(this.lines[row][j++] = ch);
results.push(this.lines[row][j++] = ch);
}
return _results;
return results;
};
Terminal.prototype.charPosAbsolute = function(params) {
@@ -2199,13 +2238,13 @@
};
Terminal.prototype.cursorForwardTab = function(params) {
var param, _results;
var param, results;
param = params[0] || 1;
_results = [];
results = [];
while (param--) {
_results.push(this.x = this.nextStop());
results.push(this.x = this.nextStop());
}
return _results;
return results;
};
Terminal.prototype.scrollUp = function(params) {
@@ -2235,25 +2274,25 @@
Terminal.prototype.resetTitleModes = function(params) {};
Terminal.prototype.cursorBackwardTab = function(params) {
var param, _results;
var param, results;
param = params[0] || 1;
_results = [];
results = [];
while (param--) {
_results.push(this.x = this.prevStop());
results.push(this.x = this.prevStop());
}
return _results;
return results;
};
Terminal.prototype.repeatPrecedingCharacter = function(params) {
var ch, line, param, _results;
var ch, line, param, results;
param = params[0] || 1;
line = this.lines[this.ybase + this.y];
ch = line[this.x - 1] || [this.defAttr, " "];
_results = [];
results = [];
while (param--) {
_results.push(line[this.x++] = ch);
results.push(line[this.x++] = ch);
}
return _results;
return results;
};
Terminal.prototype.tabClear = function(params) {

File diff suppressed because one or more lines are too long

View File

@@ -13,7 +13,7 @@
<link href="/style.css" rel="stylesheet">
</head>
<body spellcheck="false">
<body spellcheck="false" data-allow-html="{{ 'yes' if options.allow_html_escapes else 'no' }}">
<main id="wrapper"> </main>
<script src="{{ static_url('main.%sjs' % (
'' if options.unminified else 'min.')) }}"></script>

View File

@@ -787,30 +787,11 @@ class Terminal
i++ if ch is "\x1b"
@params.push @currentParam
switch @params[0]
when 0, 1 , 2
when 0, 1, 2
if @params[1]
@title = @params[1] + " - ƸӜƷ butterfly"
@handleTitle @title
# Disabling this for now as we need a good script
# striper to avoid malicious script injection
# when 99
# # Custom escape to produce raw html
# html = "<div class=\"inline-html\">" + @params[1] + "</div>"
# @lines[@y + @ybase][@x] = [
# @curAttr
# html
# ]
# line = 0
# while line < @get_html_height_in_lines(html) - 1
# @y++
# if @y > @scrollBottom
# @y--
# @scroll()
# line++
# @updateRange @y
# reset colors
@params = []
@currentParam = 0
@@ -1035,7 +1016,49 @@ class Terminal
switch @prefix
# User-Defined Keys (DECUDK).
when ""
break
# Disabling this for now as we need a good script
# striper to avoid malicious script injection
pt = @currentParam
unless pt[0] is ';'
console.error "Unknown DECUDK: #{pt}"
break
pt = pt.slice(1)
[type, content] = pt.split('|', 2)
unless content
console.error "No type for inline DECUDK: #{pt}"
break
switch type
when "HTML"
unless document.getElementsByTagName('body')[0]
.getAttribute('data-allow-html') is 'yes'
console.log "HTML escapes are disabled"
break
html = "<div class=\"inline-html\">" + content + "</div>"
@lines[@y + @ybase][@x] = [
@curAttr
html
]
line = 0
while line < @get_html_height_in_lines(html) - 1
@y++
if @y > @scrollBottom
@y--
@scroll()
line++
when "PROMPT"
@send content
when "TEXT"
l += content.length
data = data.slice(0, i + 1) + content + data.slice(i + 1)
else
console.error "Unknown type #{type} for DECUDK"
# Request Status String (DECRQSS).
# test: echo -e '\eP$q"p\e\\'

View File

@@ -13,13 +13,13 @@
},
"homepage": "https://github.com/paradoxxxzero/butterfly",
"devDependencies": {
"coffeelint": "^1.8.1",
"coffeelint": "^1.9.3",
"grunt": "^0.4.5",
"grunt-coffeelint": "0.0.13",
"grunt-contrib-coffee": "^0.12.0",
"grunt-contrib-cssmin": "^0.11.0",
"grunt-contrib-uglify": "^0.7.0",
"grunt-contrib-coffee": "^0.13.0",
"grunt-contrib-cssmin": "^0.12.2",
"grunt-contrib-uglify": "^0.9.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-sass": "^0.17.0"
"grunt-sass": "^0.18.1"
}
}