Skip to content
Permalink
Browse files
Squashed 'Sandbox/' content from commit f80dfd3
git-subtree-dir: Sandbox
git-subtree-split: f80dfd3ede9465c5e401514e0d14df5f7e86e18a
  • Loading branch information
aa9863 committed Oct 25, 2021
0 parents commit 2e7e595d8b421e63ead51ef17174328074bb1992
Show file tree
Hide file tree
Showing 53 changed files with 2,011 additions and 0 deletions.
@@ -0,0 +1,5 @@
*~
package-lock.json
.eslintrc.json
package.json
tsconfig.all.json
@@ -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
@@ -0,0 +1 @@
flask-socketio
@@ -0,0 +1,11 @@
version: "3.8"
services:
sandbox:
build: .
ports:
- "5000:5000"
volumes:
- ./opt:/opt
environment:
- FLASK_ENV=development

@@ -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
@@ -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)
@@ -0,0 +1 @@
CUEH{DEMO FLAG}

Some generated files are not rendered by default. Learn more.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -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 2e7e595

Please sign in to comment.