mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 02:41:55 +00:00
Remove all frontend related stuff
This commit is contained in:
parent
3a41423596
commit
7cc5268f9b
19
lib/debug.py
19
lib/debug.py
@ -1,19 +0,0 @@
|
||||
from glob import iglob as glob
|
||||
from itertools import chain
|
||||
|
||||
from tornado.autoreload import watch
|
||||
|
||||
|
||||
# yo dawg, we heard you like generators, so now you can generate generators
|
||||
# with generators
|
||||
def _static_files():
|
||||
return chain.from_iterable(
|
||||
glob(pattern) for pattern in (
|
||||
'static/dist/*.js', 'static/*.css', 'templates/*htm?'
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def watch_static_files():
|
||||
for file in _static_files():
|
||||
watch(file)
|
@ -7,21 +7,14 @@ from tornado.web import Application
|
||||
from tornado.ioloop import IOLoop
|
||||
|
||||
from config import WEB_PORT
|
||||
import debug
|
||||
from handlers import MainHandler, ZMQWebSocketHandler, LoginWebappHandler
|
||||
import ui_modules
|
||||
from handlers import ZMQWebSocketHandler
|
||||
|
||||
if __name__ == '__main__':
|
||||
routes = [
|
||||
(r'/', MainHandler),
|
||||
(r'/ws', ZMQWebSocketHandler),
|
||||
(r'/login', LoginWebappHandler),
|
||||
]
|
||||
application = Application(
|
||||
routes,
|
||||
template_path=r'templates/',
|
||||
static_path=r'static/',
|
||||
ui_modules=ui_modules,
|
||||
autoreload=True
|
||||
)
|
||||
|
||||
@ -32,5 +25,4 @@ if __name__ == '__main__':
|
||||
logging.debug('ZeroMQ version: {}'.format(zmq.zmq_version()))
|
||||
logging.debug('PyZMQ version: {}'.format(zmq.pyzmq_version()))
|
||||
logging.info('Tornado application listening on port {}'.format(WEB_PORT))
|
||||
debug.watch_static_files()
|
||||
IOLoop.instance().start()
|
||||
|
@ -1,3 +1 @@
|
||||
from .main_handler import MainHandler
|
||||
from .zmq_websocket_handler import ZMQWebSocketHandler
|
||||
from .login_webapp_handler import LoginWebappHandler
|
||||
|
@ -1,27 +0,0 @@
|
||||
import json
|
||||
|
||||
from tornado.web import RequestHandler, MissingArgumentError
|
||||
|
||||
# from buttons import fsm
|
||||
from sql_injection_fsm import fsm
|
||||
|
||||
|
||||
class LoginWebappHandler(RequestHandler):
|
||||
anchor_id = 'anchor_login'
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
self.render('login.html', anchor_id=self.anchor_id, form_data=(
|
||||
('email', 'email_input', 'Email address', 'Enter email'),
|
||||
('password', 'password_input', 'Password', 'Password'),
|
||||
))
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
try:
|
||||
message = {
|
||||
'anchor': self.anchor_id,
|
||||
'data': {k: self.get_body_argument(k) for k in ('email', 'password')}
|
||||
}
|
||||
fsm.trigger(self.anchor_id, message=json.dumps(message))
|
||||
except MissingArgumentError:
|
||||
self.write_error(status_code=400, message='Incomplete request')
|
||||
# TODO: return real data if not in a tutorial
|
@ -1,6 +0,0 @@
|
||||
from tornado.web import RequestHandler
|
||||
|
||||
|
||||
class MainHandler(RequestHandler):
|
||||
def get(self, *args, **kwargs):
|
||||
self.render('index.html')
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"presets": ["env"]
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
.tfw-container {
|
||||
min-height: 100%;
|
||||
height: 100%;
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
import * as ace from 'brace';
|
||||
import 'brace/mode/python';
|
||||
import 'brace/theme/monokai';
|
||||
import * as showdown from 'showdown';
|
||||
|
||||
let ws = new WebSocket('ws://' + document.location.host + '/ws');
|
||||
|
||||
let converter = new showdown.Converter();
|
||||
// TODO: don't hardcode anchor id
|
||||
let editor = ace.edit('anchor_webide');
|
||||
editor.setTheme('ace/theme/monokai');
|
||||
editor.getSession().setMode('ace/mode/python');
|
||||
editor.$blockScrolling = Infinity;
|
||||
|
||||
$('#container').on('click', '.anchor', ( function (event) {
|
||||
let anchorName = $(this).attr('id').replace('_event', '');
|
||||
let data = JSON.stringify({
|
||||
'anchor': anchorName,
|
||||
'data': $('#' + anchorName).text()
|
||||
});
|
||||
console.log('Sending: ');
|
||||
console.log(data);
|
||||
ws.send(data);
|
||||
}));
|
||||
|
||||
$('form#anchor_login_event').on('submit', (function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let anchorName = $(this).attr('id').replace('_event', '');
|
||||
$.post(
|
||||
$(this).attr('action'),
|
||||
$(this).serialize(),
|
||||
function (data) {}
|
||||
);
|
||||
}));
|
||||
|
||||
ws.onopen = function () {
|
||||
ws.send(JSON.stringify({
|
||||
'anchor': 'reset',
|
||||
'data': ''
|
||||
}));
|
||||
// init webide
|
||||
ws.send(JSON.stringify({
|
||||
'anchor': 'anchor_webide',
|
||||
'data': ''
|
||||
}));
|
||||
};
|
||||
|
||||
ws.onmessage = function (messageEvent) {
|
||||
let message = JSON.parse(messageEvent.data);
|
||||
console.log('Receiving: ');
|
||||
console.log(message);
|
||||
let $anchor = $('#' + message['anchor']);
|
||||
if (message['anchor'] === 'anchor_webide') {
|
||||
editor.setValue(message['data'], -1);
|
||||
}
|
||||
else {
|
||||
let formatted_message = converter.makeHtml(message['data']);
|
||||
$anchor.html(formatted_message);
|
||||
}
|
||||
};
|
@ -1,4 +0,0 @@
|
||||
#anchor_webide {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"bootstrap": "4.0.0-beta.2",
|
||||
"brace": "^0.11.0",
|
||||
"jquery": "^3.2.1",
|
||||
"popper.js": "^1.12.3",
|
||||
"showdown": "^1.8.5",
|
||||
"webpack": "^3.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-loader": "^7.1.2",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"uglifyjs-webpack-plugin": "^1.1.2"
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
entry: './js/index.js',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: 'bundle.js'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
loader: "babel-loader"
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new webpack.ProvidePlugin({
|
||||
$: 'jquery',
|
||||
jQuery: 'jquery',
|
||||
'window.jQuery': 'jquery',
|
||||
'window.$': 'jquery',
|
||||
}),
|
||||
new UglifyJsPlugin()
|
||||
]
|
||||
};
|
File diff suppressed because it is too large
Load Diff
@ -1,43 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Babylonian Tutorial Proof of Concept</title>
|
||||
|
||||
<link rel="stylesheet" href="{{ static_url('vendor/css/bootstrap.min.css') }}">
|
||||
<link rel="stylesheet" href="{{ static_url('vendor/css/highlight/github.min.css')}}">
|
||||
<link rel="stylesheet" href="{{ static_url('index.css')}}">
|
||||
</head>
|
||||
<body>
|
||||
<div class="jumbotron text-center">
|
||||
<h1>Tutorial framework Demo</h1>
|
||||
</div>
|
||||
<div id="container" class="container-fluid tfw-container">
|
||||
<!--div class="row">
|
||||
{% for aid in ('a', 'b', 'c') %}
|
||||
<div class="col-sm m-3 p-3">
|
||||
<p id="anchor_{{ escape(aid) }}" >
|
||||
Anchor {{ escape(aid).upper() }} content should be inserted here.
|
||||
</p>
|
||||
<button type="button" class="btn btn-outline-primary anchor" id="anchor_{{ escape(aid) }}_event">
|
||||
Fire anchor {{ escape(aid).upper() }}
|
||||
</button>
|
||||
</div>
|
||||
{% end %}
|
||||
</div-->
|
||||
<div class="row">
|
||||
<div class="col-sm col-md col-lg m-3 p-3" id="anchor_login">
|
||||
{% module Login('anchor_login') %}
|
||||
</div>
|
||||
<div class="col-sm-6 col-md-6 col-lg-6 m-3 p-3">
|
||||
{% module WebIDE('anchor_webide') %}
|
||||
</div>
|
||||
<div class="col-sm col-md col-lg m-3 p-3">
|
||||
{% module Logger('anchor_logger') %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="{{ static_url('dist/bundle.js') }}" defer></script>
|
||||
</body>
|
||||
</html>
|
@ -1,14 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Login page</title>
|
||||
|
||||
<link rel="stylesheet" href="{{ static_url('vendor/css/bootstrap.min.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
{% module Login(anchor_id, form_data) %}
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,7 +0,0 @@
|
||||
<h1>Logs</h1>
|
||||
<p id="{{ anchor_id }}">
|
||||
|
||||
</p>
|
||||
<button type="button" class="btn btn-outline-primary anchor" id="{{ anchor_id }}_event">
|
||||
Next
|
||||
</button>
|
@ -1,17 +0,0 @@
|
||||
<h1>Login page</h1>
|
||||
<form id="{{ anchor_id }}_event"
|
||||
action="/login"
|
||||
method="post">
|
||||
{% for type_, id_, label, placeholder in form_data %}
|
||||
<div class="form-group">
|
||||
<label for="{{ id_ }}">{{ label }}</label>
|
||||
<input type="{{ type_ }}"
|
||||
class="form-control"
|
||||
id="{{ id_ }}"
|
||||
name="{{ id_.replace('_input', '') }}"
|
||||
placeholder="{{ placeholder }}">
|
||||
|
||||
</div>
|
||||
{% end %}
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
@ -1,6 +0,0 @@
|
||||
<h1>Source code</h1>
|
||||
<div id="{{ anchor_id }}" class="mt-3 mb-3">
|
||||
</div>
|
||||
<button type="button" class="btn btn-outline-primary anchor" id="{{ anchor_id }}_event">
|
||||
Next
|
||||
</button>
|
@ -1,3 +0,0 @@
|
||||
from .logger import Logger
|
||||
from .login import Login
|
||||
from .webide import WebIDE
|
@ -1,6 +0,0 @@
|
||||
from tornado.web import UIModule
|
||||
|
||||
|
||||
class Logger(UIModule):
|
||||
def render(self, anchor_id, *args, **kwargs):
|
||||
return self.render_string('module-logger.html', anchor_id=anchor_id)
|
@ -1,11 +0,0 @@
|
||||
from tornado.web import UIModule
|
||||
|
||||
|
||||
class Login(UIModule):
|
||||
def render(self, anchor_id, form_data=None):
|
||||
if form_data is None:
|
||||
form_data = (
|
||||
('email', 'email_input', 'Email address', 'Enter email'),
|
||||
('password', 'password_input', 'Password', 'Password'),
|
||||
)
|
||||
return self.render_string('module-login.html', anchor_id=anchor_id, form_data=form_data)
|
@ -1,9 +0,0 @@
|
||||
from tornado.web import UIModule
|
||||
|
||||
|
||||
class WebIDE(UIModule):
|
||||
def render(self, anchor_id, *args, **kwargs):
|
||||
return self.render_string('module-webide.html', anchor_id=anchor_id, **kwargs)
|
||||
|
||||
def css_files(self):
|
||||
return ['module-webide.css']
|
Loading…
Reference in New Issue
Block a user