forked from rfresh2/ZenithProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
275 lines (247 loc) · 8.51 KB
/
Copy pathsetup.py
File metadata and controls
275 lines (247 loc) · 8.51 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import http.client
import json
import os
import platform
import re
import subprocess
system = platform.system()
if os.path.exists("launch_config.json"):
while True:
print("launch_config.json already exists, overwrite and continue anyway? (y/n)")
i1 = input("> ").lower()
if i1 == "n":
print("Setup complete!")
print("Run './launch.sh' (Unix) or '.\\launch.bat` (Windows) to start ZenithProxy!")
exit(0)
elif i1 == "y":
break
else:
print("Invalid input. Enter y or n")
def validate_linux_cpu_flags():
x86_64_v3_flags = ["avx", "avx2", "bmi1", "bmi2", "fma", "sse4_1", "sse4_2", "ssse3"]
try:
output = subprocess.check_output(['cat', '/proc/cpuinfo'], stderr=subprocess.STDOUT, text=True)
flags = []
for line in output.splitlines():
if line.startswith("flags"):
flags = line.split(": ")[1].split(" ")
break
for flag in x86_64_v3_flags:
if flag not in flags:
print("Unsupported CPU for linux release channel. "
+ "\nFlag not found: " + flag)
return False
return True
except Exception as e:
print("Error checking CPU flags.")
return False
def validate_linux_glibc_version():
try:
output = subprocess.check_output(['ldd', '--version'], stderr=subprocess.STDOUT, text=True)
# ldd (Ubuntu GLIBC 2.35-0ubuntu3.4) 2.35
# get the version from the last word of the first line
version = output.splitlines()[0].split(" ")[-1]
version = version.split(".")
if int(version[0]) != 2:
print("Unsupported OS for linux release channel. "
+ "\nglibc version too low: " + ".".join(version))
return False
if int(version[1]) < 31:
print("Unsupported OS for linux release channel. "
+ "\nglibc version too low: " + ".".join(version))
return False
return True
except Exception as e:
print("Error checking GLIBC version.")
return False
def validate_linux_system():
return system == "Linux" and validate_linux_cpu_flags() and validate_linux_glibc_version()
if validate_linux_system(): # otherwise we will always select java
while True:
print("Select a ZenithProxy platform: (1/2)")
print("1. java")
print("2. linux")
i1 = input("> ")
if i1 == "1":
release_channel = "java"
break
elif i1 == "2":
release_channel = "linux"
break
else:
print("Invalid input. Enter 1 or 2")
else:
print("Auto-selecting the java release channel based on current system")
release_channel = "java"
while True:
print("Select a Minecraft version: (1/2)")
print("1. 1.20.1")
print("2. 1.20.4")
i1 = input("> ")
if i1 == "1":
minecraft_version = "1.20.1"
break
elif i1 == "2":
minecraft_version = "1.20.4"
break
else:
print("Invalid input. Enter 1 or 2")
launch_config = {
"auto_update": True,
"auto_update_launcher": True,
"release_channel": release_channel + "." + minecraft_version,
"version": "0.0.0",
"local_version": "0.0.0",
"repo_owner": "rfresh2",
"repo_name": "ZenithProxy"
}
with open("launch_config.json", "w") as f:
f.write(json.dumps(launch_config, indent=2))
print("launch_config written successfully")
if os.path.exists("config.json"):
while True:
print("config.json already exists, overwrite and continue anyway? (y/n)")
i1 = input("> ").lower()
if i1 == "n":
print("Setup complete!")
print("Run './launch.sh' (Unix) or '.\\launch.bat` (Windows) to start ZenithProxy!")
exit(0)
elif i1 == "y":
break
else:
print("Invalid input. Enter y or n")
while True:
print("Select authentication method: (1/2)")
print("1. Device Code (Recommended)")
print("2. Username and Password")
i1 = input("> ")
if i1 == "1":
auth_method = "device_code"
break
elif i1 == "2":
auth_method = "msa"
break
else:
print("Invalid input. Enter 1 or 2")
if auth_method == "msa":
while True:
print("Enter your Microsoft account email/username:")
username = input("> ")
if "@" in username:
break
while True:
print("Enter your Microsoft account password:")
password = input("> ")
if len(password) > 0:
break
while True:
print("Input port the proxy will listen on (e.g. 25565):")
port = input("> ")
try:
port = int(port)
if port < 1 or port > 65535:
raise ValueError
break
except ValueError:
print("Invalid port number. Must be between 1 and 65535")
while True:
print("Input the IP address players should connect to. This can be a domain name or an IP address.")
print("If you are unsure, leave this blank and the proxy will use the IP address of the machine it is running on.")
print("If you are using a domain name, make sure you have DNS records set up (see README.md)")
ip = input("> ")
if ip == "":
connection = http.client.HTTPSConnection("api.ipify.org")
connection.request("GET", "/")
response = connection.getresponse()
if response.status == 200:
ip = response.read().decode()
break
else:
print("Failed to get IP address:", response.status, response.reason)
else:
break
while True:
print("Enable Discord bot? (y/n)")
i2 = input("> ")
if i2 == "y":
discord_bot = True
break
elif i2 == "n":
discord_bot = False
break
else:
print("Invalid input. Enter y or n")
if discord_bot:
while True:
print("See README.md for instructions on how to set up a Discord bot")
print("Enter your Discord bot token:")
discord_bot_token = input("> ")
if len(discord_bot_token) > 50:
break
else:
print("Invalid token")
while True:
print("Enter the channel ID the proxy will be managed in:")
discord_channel_id = input("> ")
try:
discord_channel_id = int(discord_channel_id)
if discord_channel_id < 1000000000 or discord_channel_id > 9999999999999999999:
raise ValueError
break
except ValueError:
print("Invalid ID")
while True:
print("Enter the role ID of the role that will be able to manage the proxy's whitelist:")
discord_admin_role_id = input("> ")
try:
discord_admin_role_id = int(discord_admin_role_id)
if discord_admin_role_id < 1000000000 or discord_admin_role_id > 9999999999999999999:
raise ValueError
break
except ValueError:
print("Invalid ID")
while True:
print("Enter the channel ID the proxy will relay chat messages to:")
discord_chat_relay_channel = input("> ")
try:
discord_chat_relay_channel = int(discord_chat_relay_channel)
if discord_chat_relay_channel < 1000000000 or discord_chat_relay_channel > 9999999999999999999:
raise ValueError
if discord_chat_relay_channel == discord_channel_id:
print("Chat relay channel cannot be the same as the management channel")
continue
break
except ValueError:
print("Invalid ID")
# Write config.json
config = {}
if auth_method == "msa":
config["authentication"] = {
"accountType": "msa",
"email": username,
"password": password
}
ipPattern = re.compile(r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$")
proxyAddress = ip + ":" + str(port) if ipPattern.match(ip) else ip
config["server"] = {
"bind": {
"port": port,
},
"proxyIP": proxyAddress
}
if discord_bot:
config["discord"] = {
"enable": True,
"token": discord_bot_token,
"channelId": discord_channel_id,
"accountOwnerRoleId": discord_admin_role_id,
"chatRelay": {
"enable": True,
"channelId": discord_chat_relay_channel
}
}
with open("config.json", "w") as f:
f.write(json.dumps(config, indent=2))
print("config.json written successfully!")
print("Setup complete!")
print("Run './launch.sh' (Unix) or '.\\launch.bat` (Windows) to start ZenithProxy!")