Repository navigation
Expand file tree
/
Copy pathserver.py
More file actions
108 lines (88 loc) · 3.46 KB
/
Copy pathserver.py
File metadata and controls
108 lines (88 loc) · 3.46 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
import subprocess
import http.server
import socketserver
import ssl
import threading
from http import HTTPStatus
from flask import Flask, request, send_file
HOSTS_PATH = "/etc/hosts"
DOMAIN = "lic.cryptolive.one"
DOMAIN2 = "lic.bitmaster.cc"
IP_ADDRESS = ""
PORT_HTTP = 80
PORT_HTTPS = 443
CERTS_PATH = "./certs"
KEY_FILE = os.path.join(CERTS_PATH, "key.pem")
CERT_FILE = os.path.join(CERTS_PATH, "cert.pem")
app = Flask(__name__)
@app.before_request
def log_request():
if request.method == 'POST':
print(f"Received POST request to {request.url}")
print("Headers:", dict(request.headers))
try:
if request.is_json:
print("Body:", request.get_json())
elif request.form:
print("Form data:", request.form.to_dict())
elif request.data:
print("Raw data:", request.data.decode('utf-8'))
except Exception as e:
print(f"Error parsing request body: {e}")
@app.route('/lic', methods=['POST'])
def handle_lic():
print("Received POST /lic request")
file_path = os.path.join(os.getcwd(), "lic.cr")
if not os.path.exists(file_path):
print("File not found:", file_path)
return "File not found", HTTPStatus.NOT_FOUND
if request.form:
print("Form data:", request.form.to_dict())
return send_file(file_path, as_attachment=True)
@app.route('/')
def index():
return "Welcome to the license server!"
# Ensure certificates exist
def generate_certificates():
if not os.path.exists(CERTS_PATH):
os.makedirs(CERTS_PATH)
if not os.path.exists(KEY_FILE) or not os.path.exists(CERT_FILE):
subprocess.run([
"openssl", "req", "-x509", "-newkey", "rsa:2048", "-keyout", KEY_FILE,
"-out", CERT_FILE, "-days", "365", "-nodes", "-subj", "/CN=localhost"
], check=True)
def update_hosts():
try:
with open(HOSTS_PATH, "r+") as hosts_file:
lines = hosts_file.readlines()
hosts_file.seek(0)
hosts_file.truncate()
# Remove existing domain entries
lines = [line for line in lines if DOMAIN not in line and DOMAIN2 not in line]
# Append new domain mappings
lines.append(f"{IP_ADDRESS} {DOMAIN}\n")
lines.append(f"{IP_ADDRESS} {DOMAIN2}\n")
hosts_file.writelines(lines)
print(f"Successfully mapped {DOMAIN} to {IP_ADDRESS} in {HOSTS_PATH}")
print(f"Successfully mapped {DOMAIN2} to {IP_ADDRESS} in {HOSTS_PATH}")
except Exception as e:
print(f"Error updating hosts file: {e}")
def run_http_server():
handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT_HTTP), handler) as httpd:
print(f"HTTP server running on port {PORT_HTTP}")
httpd.serve_forever()
def run_https_server():
generate_certificates()
handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", PORT_HTTPS), handler)
httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=KEY_FILE, certfile=CERT_FILE, server_side=True)
print(f"HTTPS server running on port {PORT_HTTPS}")
httpd.serve_forever()
if __name__ == "__main__":
update_hosts()
generate_certificates()
threading.Thread(target=run_http_server, daemon=True).start()
threading.Thread(target=run_https_server, daemon=True).start()
app.run(host="0.0.0.0", port=5454)