-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (31 loc) · 1.21 KB
/
app.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
from flask import Flask, request
from flask_cors import CORS
import os
import datetime
import json
import random
app = Flask(__name__)
CORS(app) # Enable CORS on all routes
RECORD_FOLDER = "records"
@app.route('/accept', methods=['POST'])
def accept_cookies():
# Get the current timestamp
timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
# Generate a unique filename based on the timestamp and remote address
rand_id = random.randrange(100_000) # doesn't have to be that big due to remote addr and timestamp
filename = f"{timestamp}_{request.remote_addr}_{rand_id}.txt"
# Create a new text file to store the request information
request_info = {
"Timestamp": timestamp,
"Remote Address": request.remote_addr,
"Request Headers": dict(request.headers),
"Cookies": request.cookies,
"Request Data": request.data.decode('utf-8'),
"Query Parameters": request.args.to_dict()
}
# Create a new JSON file to store the request information
with open(os.path.join(RECORD_FOLDER, filename), 'w') as file:
json.dump(request_info, file)
return json.dumps({'accepted': True}), 200
if __name__ == '__main__':
app.run()