-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
89 lines (80 loc) · 2.2 KB
/
main.py
File metadata and controls
89 lines (80 loc) · 2.2 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
82
83
84
85
86
87
88
89
from flask import Flask, request
import json
app = Flask(__name__)
admins = {
"Morgandri1": {
"password": "W!ngnut33",
}
}
@app.route('/')
def example():
with open("data.json", "r") as f:
data = json.load(f)
return data
@app.route("/items/")
def get():
unique_id = request.args.get('UID')
try:
with open("data.json", "r") as f:
data = json.load(f)
return data[unique_id]
except KeyError:
return create(unique_id)
def create(UID):
if UID == None:
return "No UID provided"
with open("data.json", "r") as f:
data = json.load(f)
data[UID] = {"id": UID, "paid": False, "nuke": False}
with open("data.json", "w") as f:
json.dump(data, f)
return data[UID]
@app.route("/update/")
def update():
unique_id = request.args.get('UID')
if unique_id == None:
return "No UID provided"
with open("data.json", "r") as f:
data = json.load(f)
try:
data[unique_id]["paid"] = True
with open("data.json", "w") as f:
json.dump(data, f)
return data[unique_id]
except KeyError:
return create(unique_id)
@app.route("/routes/")
def routes():
return """
Routes: <br>
/items/?UID - Get item by UID <br>
/update/?UID - Update item to 'paid' by UID <br>
/routes/ - Get routes <br>
/nuke/?UID&user&pass - Nuke item by UID <br>
/ - get all item data
"""
@app.route("/nuke/")
def nuke():
user = request.args.get('user')
password = request.args.get('pass')
UID = request.args.get('UID')
try:
if password == admins[user]["password"]:
with open("data.json", "r") as f:
data = json.load(f)
data[UID]["nuke"] = True
with open("data.json", "w") as f:
json.dump(data, f)
return "Nuked"
else:
with open("log.json", "r") as f:
data = json.load(f)
try:
data[user]["attempts"] += 1
except KeyError:
data[user] = {"attempts": 1}
return "Incorrect password"
except KeyError:
return "Invalid user"
if __name__ == '__main__':
app.run(host="0.0.0.0",port=8080)