-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.py
More file actions
318 lines (285 loc) · 12.5 KB
/
Core.py
File metadata and controls
318 lines (285 loc) · 12.5 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import os
import sqlite3
from print_color import print
import requests
import time
import Generator
import json
class Core:
def __init__(self, db: sqlite3.Connection, cursor: sqlite3.Cursor):
self.db = db
self.cursor = cursor
self.value = ''
def main(self):
os.system("clear")
print(r""" _ ____ ____
/ \ | _ \/ ___|
/ _ \ | |_) \___ \
/ ___ \| _ < ___) |
/_/ \_\_| \_\____/
""", color="green")
print("""**********************
1. Add Server
2. Edit Server
3. Server List
4. Get Config
5. Delete Server
6. Exit
**********************
""", color="blue")
self.value = input("Enter A Number : ")
def check_data(self, txt: str):
while True:
data = input(txt)
if data.isspace() or data.strip() == "":
continue
else:
return data
def add_server(self):
os.system("clear")
print("\n* Add Server *", color="blue")
server_url = self.check_data("\nEnter Your URL Server [Menu = 0]:")
if server_url == "0":
return self.main()
username = self.check_data("\nEnter Your UserName Server [Menu = 0]:")
if username == "0":
return self.main()
password = self.check_data("\nEnter Your Password Server [Menu = 0]:")
if password == "0":
return self.main()
name = self.check_data("\nEnter Your Name Server [Menu = 0]:")
if name == "0":
return self.main()
domain = self.check_data("\nEnter Your Domain Server [Menu = 0]:")
if domain == "0":
return self.main()
try:
self.cursor.execute("INSERT INTO Server(Name, URL, UserName, Password, Address) VALUES(?,?,?,?,?)",
(name, server_url, username, password, domain))
self.db.commit()
print(f"Server added \n", tag="Success", tag_color="green", color="green")
input("Input Enter Key To Continue :")
return self.main()
except Exception as e:
print(e.args[0], color="magenta", tag="Error", tag_color="red")
def edit_server(self):
os.system("clear")
print("\n* Edit Server *", color="blue")
name = input("Please Enter Name Server [Main = 0]:")
self.cursor.execute("SELECT * FROM Server WHERE Name = ?", (name,))
server = self.cursor.fetchone()
if name == "0":
return self.main()
if server is None:
print("Server is not defined", tag="Error", tag_color="red", color="magenta")
return self.main()
print(f"""
Server Found Info :
*********
1. Name : {server[1]}
2. URL : {server[2]}
3. UserName : {server[3]}
4. Password : {server[4]}
5. Domain : {server[5]}
""", color="white")
key = input("Enter Key For Edit Field [Main = 0]:")
if key == "0":
return self.main()
while True:
value = ""
if value == "0":
print(f"""
Server Found Info :
*********
1. Name : {server[1]}
2. URL : {server[2]}
3. UserName : {server[3]}
4. Password : {server[4]}
5. Domain : {server[5]}
""", color="white")
key = input("Enter Key For Edit Field [Main = 0]:")
if key == "0":
return self.main()
if key == "1":
value = input("Enter New Name [Main = 0]:")
if value == "0" or value.isspace() or value.strip() == "":
continue
try:
self.cursor.execute("UPDATE Server SET Name = ? WHERE Name = ?", (value, name))
self.db.commit()
print(f"Edit server success \n", tag="Success", tag_color="green", color="green")
value = "0"
except Exception as e:
print(e.args[0], color="magenta", tag="Error", tag_color="red")
if key == "2":
value = input("Enter New URL [Main = 0]:")
if value == "0" or value.isspace() or value.strip() == "":
continue
try:
self.cursor.execute("UPDATE Server SET URL = ? WHERE Name = ?", (value, name))
self.db.commit()
print(f"Edit server success \n", tag="Success", tag_color="green", color="green")
value = "0"
except Exception as e:
print(e.args[0], color="magenta", tag="Error", tag_color="red")
if key == "3":
value = input("Enter New UserName [Main = 0]:")
if value == "0" or value.isspace() or value.strip() == "":
continue
try:
self.cursor.execute("UPDATE Server SET UserName = ? WHERE Name = ?", (value, name))
self.db.commit()
print(f"Edit server success \n", tag="Success", tag_color="green", color="green")
value = "0"
except Exception as e:
print(e.args[0], color="magenta", tag="Error", tag_color="red")
if key == "4":
value = input("Enter New Password [Main = 0]:")
if value == "0" or value.isspace() or value.strip() == "":
continue
try:
self.cursor.execute("UPDATE Server SET Password = ? WHERE Name = ?", (value, name))
self.db.commit()
print(f"Edit server success \n", tag="Success", tag_color="green", color="green")
value = "0"
except Exception as e:
print(e.args[0], color="magenta", tag="Error", tag_color="red")
if key == "5":
value = input("Enter New Domain [Main = 0]:")
if value == "0" or value.isspace() or value.strip() == "":
continue
try:
self.cursor.execute("UPDATE Server SET Domain = ? WHERE Name = ?", (value, name))
self.db.commit()
print(f"Edit server success \n", tag="Success", tag_color="green", color="green")
value = "0"
except Exception as e:
print(e.args[0], color="magenta", tag="Error", tag_color="red")
def get_server_list(self):
data = self.cursor.execute("SELECT * FROM Server")
servers = data.fetchall()
counter = 1
os.system("clear")
print("\n* Server List *\n", color="blue")
for server in servers:
print(f"{counter}. {server[1]}")
counter += 1
input("Input Enter Key To Continue :")
return self.main()
def delete_server(self):
print("\n* Delete Server *", color="blue")
os.system("clear")
name = input("Please Enter Name Server [Main = 0]:")
if name == "0":
return self.main()
self.cursor.execute("SELECT * FROM Server WHERE Name = ?", (name,))
server = self.cursor.fetchone()
if server is None:
print("Server is not defined", tag="Error", tag_color="red", color="magenta")
input("Input Enter To Back Main :")
return self.main()
try:
self.cursor.execute(f"DELETE Server WHERE Id = '{server[0]}'")
self.db.commit()
print(f"delete server success \n", tag="Success", tag_color="green", color="green")
input("Input Enter To Back Main :")
return self.main()
except Exception as e:
print(e.args[0], color="magenta", tag="Error", tag_color="red")
input("Input Enter To Back Main :")
return self.main()
def get_config(self):
step = 0
while True:
if step == 0:
os.system("clear")
print("\n* Get Config Server *", color="blue")
name = input("Please Enter Name Server [Main = 0]:")
if name == "0":
return self.main()
self.cursor.execute("SELECT * FROM Server WHERE Name = ?", (name,))
global server
server = self.cursor.fetchone()
if server is None:
print("Server is not defined", tag="Error", tag_color="red", color="magenta")
return
else :step =1
if step == 1:
global inboundId
inboundId = input("Enter Inbound Id Your Server [Main = 0]:")
if not inboundId.isdigit() : continue
if inboundId=="0":
return self.main()
else: step = 2
if step == 2:
global uuid
uuid = input("Enter Your Config UUID [Main = 0]:")
if uuid=="0":
return self.main()
else: step = 3
if step == 3:
global ConfigName
ConfigName = input("Enter Your Config Name Config [Main = 0]:")
if ConfigName=="0":
return self.main()
else: step = 4
if step == 4:
try:
response = None
try:
response = requests.post(f"{server[2]}/login",data={"username": f"{server[3]}", "password": f"{server[4]}"})
except:
response = requests.post(f"{server[2]}/login",data={"username": f"{server[3]}", "password": f"{server[4]}"})
responseLogon = json.loads(response.text)
if responseLogon['success'] == False:
print(f"can not login server. details : {response.text}\n",tag_color="red",tag="Error" ,color="magenta" )
input("Input Enter To Back Main :")
return self.main()
session = ""
if len(response.headers.get("Set-Cookie").split("; ") )>= 6:
session = response.headers.get("Set-Cookie").split("; ")[4]
session =session.split(", ")[1]
else:
session = response.headers.get("Set-Cookie").split("; ")[0]
origin = server[2].split("/")
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': f'{origin[0]}://{origin[2]}',
'Connection': 'keep-alive',
'Referer': f'{server[2]}/panel/inbounds',
'Cookie': f'lang=en-US; {session}'
}
try:
response = requests.request("POST", f"{server[2]}/panel/inbound/list", headers=headers)
except:
response = requests.request("POST", f"{server[2]}/panel/inbound/list", headers=headers)
responseLogon = json.loads(response.text)
if responseLogon['success'] == True:
for inbound in responseLogon['obj']:
if inbound['id'] == int(inboundId):
try:
config = Generator.GetConfig(inbound,uuid,ConfigName,inbound['port'],inbound['protocol'],server[3])
print("create config success fully",tag="success",tag_color="green",color="magenta")
print(f"Config : {config} \n")
input("Input Enter To Back Main :")
return self.main()
except:
print(f"There was a problem while creating the configuration.\n",tag_color="red",tag="Error" ,color="magenta" )
input("Input Enter To Back Main :")
return self.main()
print(f"can not read data as server. details : {response.text}\n",tag_color="red",tag="Error" ,color="magenta" )
input("Input Enter To Back Main :")
return self.main()
else:
print(f"can not read data as server. details : {response.text}\n",tag_color="red",tag="Error" ,color="magenta" )
input("Input Enter To Back Main :")
return self.main()
except:
print(f"error in Login or Get Data:\n",tag_color="red",tag="Error" ,color="magenta" )
input("Input Enter To Back Main :")
return self.main()