-
Notifications
You must be signed in to change notification settings - Fork 13
/
server.py
61 lines (51 loc) · 1.58 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
53
54
55
56
57
58
59
60
61
from flask import Flask
import os, hashlib
app = Flask(__name__)
users = {
'username':'password',
}
@app.route("/delete/<username>/<password>/<file>")
def delete(username, password, file):
if login(username, password) is False:
return "Login Failed"
else:
os.remove("files/"+file)
return "Success"
@app.route("/upload/<username>/<password>/<file>/<data>")
def upload(username, password, file, data):
if login(username, password) is False:
return "Login Failed"
else:
if file not in os.listdir("files"):
with open("files/"+file, 'w') as file:
pass
upload = open("files/"+file, 'ab')
data = data.split()
for data in data:
upload.write(chr(int(data)))
upload.close()
return "Success"
@app.route("/download/<username>/<password>/<file>")
def download(username, password, file):
if login(username, password) is False:
return "Login Failed"
else:
with open("files/"+file, 'rb') as file:
return file.read()
@app.route("/list/<username>/<password>")
def list(username, password):
if login(username, password) is False:
return "Login Failed"
else:
return str(os.listdir("files"))
def login(username, password):
if username not in users:
return False
elif hashlib.sha1(users[username]).hexdigest() == password:
return True
else:
return False
if __name__ == "__main__":
if "files" not in os.listdir(os.getcwd()):
os.mkdir("files")
app.run(host='0.0.0.0')