-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
50 lines (42 loc) · 1.46 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
from flask import Flask, request, render_template, Response
import os
from functools import wraps
# Load configuration
from config import USERNAME, PASSWORD
app = Flask(__name__)
def check_auth(username, password):
"""Check if a username/password combination is valid."""
return username == USERNAME and password == PASSWORD
def authenticate():
"""Sends a 401 response to enable basic auth"""
return Response(
'Could not verify your access level for that URL.\n'
'You have to login with proper credentials', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'})
def requires_auth(f):
"""Decorator to prompt for user authentication"""
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated
@app.route('/')
@requires_auth
def index():
return render_template('upload.html')
@app.route('/upload', methods=['POST'])
@requires_auth
def upload_file():
if 'file' not in request.files:
return 'No file part'
file = request.files['file']
if file.filename == '':
return 'No selected file'
if file:
filename = file.filename
file.save(os.path.join('/home/alex/byteheist/ex', filename))
return 'Good job, we stole their rent money'
if __name__ == '__main__':
app.run(ssl_context='adhoc', host='0.0.0.0', port=443)