We've got a thing!!

pull/1/head
Matt C 2 years ago
parent 9535fa35a0
commit e9add91e44

@ -0,0 +1,56 @@
import asyncio
import os,subprocess
import threading
from flask import Flask,render_template
app = Flask(__name__)
@app.route("/")
def main():
return render_template("page.html", product="Web Forge", page="Home", content=render_template("console.html"))
@app.route("/run/<what>")
async def run(what):
res = await run_command_shell("/bin/bash -c '" + what + "'")
return res
# Maybe add: https://docs.python.org/3/library/shlex.html#shlex.quote ?
async def run_command_shell(command, grc=False):
"""Run command in subprocess (shell)."""
kill = lambda proc: proc.kill()
# Create subprocess
process = await asyncio.create_subprocess_shell(
command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
# Status
print("Started:", command, "(pid = " + str(process.pid) + ")", flush=True)
kill_timer = threading.Timer(60, kill, [process])
try:
# Wait for the subprocess to finish
kill_timer.start()
stdout, stderr = await process.communicate()
except:
kill_timer.cancel()
# Progress
if process.returncode == 0:
print("Done:", command, "(pid = " + str(process.pid) + ")", flush=True)
# Result
result = stdout.decode().strip()
else:
print("Failed:", command, "(pid = " + str(process.pid) + ")", flush=True)
# Result
result = stderr.decode().strip()
kill_timer.cancel()
if not grc:
# Return stdout
return result
else:
return process.returncode, result

@ -0,0 +1 @@
Flask[async]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -0,0 +1,27 @@
<script>
document.body.addEventListener('keydown', function (e) {
if (e.keyCode === 13) {
// document.getElementById("output").innerHTML += "<br/>" + document.getElementById("thecommand").value;
var inputBox = document.getElementById("thecommand");
var whatDo = inputBox.value;
inputBox.value = "";
// Function to do an Ajax call
$.ajax({
url:"/run/"+whatDo,
type:"GET",
success: function(data) {
document.getElementById("output").innerHTML += "<br/>" + data;
},
});
}
});
</script>
<div class="input-group flex-nowrap">
<span class="input-group-text" id="addon-wrapping">$</span>
<input id="thecommand" type="text" class="form-control" placeholder="" aria-label="Shell" aria-describedby="addon-wrapping">
</div>
<pre>
<code id="output">
</code>
</pre>

@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{product}} - {{page}}</title>
<link href="/static/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
</head>
<body>
<h1>{{product}} - {{page}}</h1>
{{content|safe}}
<script src="/static/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="/static/jquery-3.6.0.min.js"></script>
</body>
</html>
Loading…
Cancel
Save