-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmgo3.py
89 lines (76 loc) · 3.42 KB
/
mgo3.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
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, Response, make_response
import os
import sys
sys.path.append(os.path.dirname(__file__))
from CommandProcessor import CommandProcessor
import urllib.parse
from Logger import create_logger
app = Flask(__name__)
logger = create_logger('mgsv')
# Assuming the app directory structure keeps the 'www' folder at the same level as this script
EULA_DIR = os.path.join(os.path.dirname(__file__), 'www', 'tppstmweb', 'eula')
@app.route('/', methods=['POST', 'GET'])
@app.route('/<path:path>', methods=['POST', 'GET'])
def handle_request(path=''):
if request.method == 'POST':
processor = CommandProcessor()
data = request.get_data(as_text=True)
d = urllib.parse.parse_qs(data, True)
client_request = d.get('httpMsg', [''])[0]
logger.debug(f'New client request: {client_request}')
output = processor.process(client_request)
logger.debug(f'Encoded response from processor: {str(output)}')
return Response(output, mimetype='text/plain')
elif request.method == 'GET' and path == 'tppstmweb/eula/eula.var':
file_path = os.path.join(EULA_DIR, 'eula.var')
if os.path.exists(file_path):
with open(file_path, 'r') as file:
file_content = file.read()
response = make_response(file_content)
response.headers['Content-Type'] = 'text/plain; charset=utf-8'
return response
else:
return "File not found", 404
elif request.method == 'GET' and path == 'tppstmweb/coin/coin.var':
file_path = os.path.join(EULA_DIR, 'eula.var')
if os.path.exists(file_path):
with open(file_path, 'r') as file:
file_content = file.read()
response = make_response(file_content)
response.headers['Content-Type'] = 'text/plain; charset=utf-8'
return response
else:
return "File not found", 404
elif request.method == 'GET' and path == 'tppstmweb/gdpr/gdpr.var':
file_path = os.path.join(EULA_DIR, 'eula.var')
if os.path.exists(file_path):
with open(file_path, 'r') as file:
file_content = file.read()
response = make_response(file_content)
response.headers['Content-Type'] = 'text/plain; charset=utf-8'
return response
else:
return "File not found", 404
elif request.method == 'GET' and path == 'tppstmweb/privacy/privacy.var':
file_path = os.path.join(EULA_DIR, 'eula.var')
if os.path.exists(file_path):
with open(file_path, 'r') as file:
file_content = file.read()
response = make_response(file_content)
response.headers['Content-Type'] = 'text/plain; charset=utf-8'
return response
else:
return "File not found", 404
elif request.method == 'GET' and path == 'tppstmweb/privacy_jp/privacyjp.var':
file_path = os.path.join(EULA_DIR, 'eula.var')
if os.path.exists(file_path):
with open(file_path, 'r') as file:
file_content = file.read()
response = make_response(file_content)
response.headers['Content-Type'] = 'text/plain; charset=utf-8'
return response
else:
return "File not found", 404
return Response('This method is not supported.', status=405)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)