-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
72 lines (58 loc) · 2.46 KB
/
app.py
File metadata and controls
72 lines (58 loc) · 2.46 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
from datetime import datetime, timedelta
from flask import Flask, request, render_template, redirect, make_response
from utils.nc import get_response_for
from utils.other import log, get_user_by_token, get_token_for_user
app = Flask(__name__)
target_host = {
"hostname" : "localhost",
"port": "80"
}
@app.route("/", methods=["GET", "POST"])
def root():
token = request.cookies.get("token")
if not token:
return redirect("login")
u_name, cl = "test", "class"
if request.method == "POST":
req = request.form["req"]
port = req.split('\n')[1][5:].strip().split(":")[1]
res = get_response_for(port,req)
target_host_updated = {
"hostname" : "localhost",
"port": req.split('\n')[1][5:].strip().split(":")[1]
}
target_host.update(target_host_updated)
log(cl, u_name, req, res["raw"])
return render_template("http.html", data={**target_host,
**res,
"req": req,
"user": u_name,
"cl": cl})
return render_template("http.html", data={**target_host,
"req" : "",
"raw": "",
"r_line": "",
"header": "",
"body": "",
"user": u_name,
"cl": cl})
@app.route("/login", methods=["GET", "POST"])
def login():
token = request.cookies.get("token")
if get_user_by_token(token):
return redirect("/")
if request.method == "POST":
username = request.form["username"]
password = request.form["password"]
if username and password:
token = get_token_for_user(username, password)
if token:
res = make_response(redirect("/"))
res.set_cookie(
"token",
token,
expires=datetime.now() + timedelta(weeks=1))
return res
return app.send_static_file("login.html")
if __name__ == "__main__":
app.run(debug=True)