Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge commit '671f6f70d99bbd1d30ca339f76e778a4bf61e850' as 'Sandbox'
  • Loading branch information
aa9863 committed Nov 9, 2021
2 parents a969e6c + 671f6f7 commit a48dfac
Show file tree
Hide file tree
Showing 53 changed files with 2,011 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sandbox/.gitignore
@@ -0,0 +1,5 @@
*~
package-lock.json
.eslintrc.json
package.json
tsconfig.all.json
11 changes: 11 additions & 0 deletions Sandbox/Development/Dockerfile
@@ -0,0 +1,11 @@
FROM cueh/flask



USER root
ADD REQUIREMENTS.txt /tmp
RUN pip install -r /tmp/REQUIREMENTS.txt

USER flask
WORKDIR /opt
ADD ./opt /opt
1 change: 1 addition & 0 deletions Sandbox/Development/REQUIREMENTS.txt
@@ -0,0 +1 @@
flask-socketio
11 changes: 11 additions & 0 deletions Sandbox/Development/compose-devel.yml
@@ -0,0 +1,11 @@
version: "3.8"
services:
sandbox:
build: .
ports:
- "5000:5000"
volumes:
- ./opt:/opt
environment:
- FLASK_ENV=development

14 changes: 14 additions & 0 deletions Sandbox/Development/docker-compose.yml
@@ -0,0 +1,14 @@
version: "3.8"
services:
sandbox:
build: .
ports:
- "5000:5000"
expose:
- 5000
# deploy:
# restart_policy:
# condition: any
# delay: 5s
# max_attempts: 5
# window: 120s
44 changes: 44 additions & 0 deletions Sandbox/Development/opt/app.py
@@ -0,0 +1,44 @@
"""
Very simple Flask App. For Testing
"""

import sys

import flask
from flask_socketio import SocketIO

import logging
log = logging.getLogger("APP")


app = flask.Flask(__name__)
socketio = SocketIO(app)


@app.route('/', methods=["GET","POST"])
def main():
return flask.render_template('index.html')

@socketio.on("connect")
def connect():
version = sys.version
socketio.send("Python {0}".format(version))

@socketio.on('message')
def handle_message(message):
try:
out = eval(message)
if type(out) == bytes:
socketio.send(out.decode())
else:
socketio.send(out)
except Exception as ex:
socketio.send("{}".format(ex))

@app.route('/debug')
def debug():
return flask.Response(open(__file__).read(), mimetype='text/plain')


if __name__ == "__main__":
socketio.run(app)
1 change: 1 addition & 0 deletions Sandbox/Development/opt/flag.txt
@@ -0,0 +1 @@
CUEH{DEMO FLAG}
21 changes: 21 additions & 0 deletions Sandbox/Development/opt/static/node_modules/xterm/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 201 additions & 0 deletions Sandbox/Development/opt/static/node_modules/xterm/README.md

Large diffs are not rendered by default.

171 changes: 171 additions & 0 deletions Sandbox/Development/opt/static/node_modules/xterm/css/xterm.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions Sandbox/Development/opt/static/term.js
@@ -0,0 +1,107 @@
var term = new Terminal({cursorBlink: true,
cursorStyle: 'underline'});

var thePrompt = ">>> ";

term.open(document.getElementById('terminal'));
//term.write(thePrompt);

var index = 0;
var buffer = "";
var socket = io.connect();

function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
}


socket.on('connect', () => {
//console.log("CONNECTED");
});

// handle the event sent with socket.send()
socket.on('message', data => {
if (typeof(data) == "string"){
var parts = data.split("\n");
for (i=0; i<parts.length; i++){
term.write(parts[i]+"\r\n");
}
}
else{
term.write(data + "\r\n");
}
term.write(thePrompt);
});


term.onData(data => {
//First the lower contoll chars
var ord = data.charCodeAt(0);
//Values lower than 32 are controll.
//Also 127 is Delete
if (ord < 32 || ord ==127) {
//Deal with individual codes
if (ord == 13){ //Newline
socket.send(buffer);
index = 0;
buffer = "";
term.write("\r\n");
//term.write(thePrompt);
}
else if (ord == 27) { //Ascii Controll Chars
//So the next part is the interesting bit
var ctlChar = data.substr(1) //Strip of the first part
if (ctlChar == "[C") {//Right Arrow
//Sanity check
if (index < buffer.length){
index += 1;
term.write(data);
}
else{
term.write("\x07");
}
}else if (ctlChar == "[D") { //leftArrow
if (index > 0){
index -= 1;
term.write(data);
}
else{
//Ring that Bell
term.write("\x07");
}
}
}
else if (ord == 127){ //Deletes
//Decrement
index -= 1;

//Remove the character from the buffer
buffer = buffer.substring(0,index) + buffer.substring(index+1);
//And we can move the text backwards with Ascii Control sequences
term.write("\b\x1b[P");
}
return;
}
else{
//Anything else we stash in the buffer
if (index == buffer.length){
buffer += data;
}
else{
//Strings are immutable
buffer = buffer.substring(0,index) + data + buffer.substring(index+1);
}
index += 1;
term.write(data);
}

});

/* Linefeeds happen (But based on input linefeeds */
/*
term.onLineFeed(data => {
console.log("LINEFEED");
//term.write("\n");
});
*/

0 comments on commit a48dfac

Please sign in to comment.