This repository was archived by the owner on Nov 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (53 loc) · 1.9 KB
/
main.py
File metadata and controls
80 lines (53 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# coding: utf-8
import json
from flask import *
import user
import process
import _thread as thread
pc = process.ProcessesController()
print("ProcessController got")
app = Flask("main")
print("Flask object registed")
app.add_template_global(len)
app.config['SECRET_KEY'] = 'secretkey'
@app.route("/")
def login():
return render_template("login.html")
@app.route("/login", methods=['POST'])
def loginapi():
if user.login((request.form).get("u"), (request.form).get("p")):
return redirect("/internal")
else:
return "<script>alert('Account or password does not exist');history.go(-1);</script>"
@app.route("/internal")
def internal():
return render_template("list.html", processes=[i[0] for i in pc.get_processes()])
@app.route("/internal/<int:process_id>")
def process_info(process_id: int):
return render_template("process_info.html", process=pc.get_processes()[process_id], pid=process_id, process_name=pc.get_processes()[process_id][0])
@app.route("/internal/create")
def create_process():
return render_template("create.html")
@app.route("/internal/terminal_page/<int:pid>")
def terminal_page(pid):
return render_template("terminal.html", pid=pid)
@app.route("/internal/debug/crash")
def close_app():
exit(0)
@app.route("/internal/terminal_ajax/<int:pid>/flush")
def get_term_flush(pid: int):
return pc.read_flush(pid).decode()
@app.route("/internal/terminal_ajax/<int:pid>/read")
def get_term_stdout(pid: int):
return pc.read_stdout(pid).decode()
@app.route("/internal/terminal_ajax/<int:process_id>/write", methods=['POST'])
def terminal_input(process_id: int):
input_data = (request.form).get("s")
pc.put_stdin(int(process_id), input_data.encode())
return "ok"
with open("./processes.json", "r", encoding="utf-8") as f:
data = json.load(f)
for k in data:
v = data[k]
pc.create_process(k, v, shell=True)
app.run(threaded=True)