forked from SereneWindCoding/SSRSpeedN-Mod
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
241 lines (202 loc) · 5.85 KB
/
main.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
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
#coding:utf-8
import time
import sys
import os
import logging, colorlog
from config import config
from ssrspeed.shell import cli as cli_cfg
from ssrspeed.utils import check_platform, RequirementsCheck
from ssrspeed.core import SSRSpeedCore
if (not os.path.exists("./logs/")):
os.mkdir("./logs/")
if (not os.path.exists("./results/")):
os.mkdir("./results/")
loggerList = []
loggerSub = logging.getLogger("Sub")
logger = logging.getLogger(__name__)
loggerList.append(loggerSub)
loggerList.append(logger)
formatter = logging.Formatter("[%(asctime)s][%(levelname)s][%(thread)d][%(filename)s:%(lineno)d]%(message)s")
fileHandler = logging.FileHandler("./logs/" + time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + ".log",encoding="utf-8")
fileHandler.setFormatter(formatter)
consoleHandler = colorlog.ConsoleHandler()
consoleHandler.setFormatter(formatter)
VERSION = config["VERSION"]
if (__name__ == "__main__"):
pfInfo = check_platform()
if (pfInfo == "Unknown"):
logger.critical("Your system does not supported.Please contact developer.")
sys.exit(1)
DEBUG = False
CONFIG_LOAD_MODE = 0 #0 for import result,1 for guiconfig,2 for subscription url
CONFIG_FILENAME = ""
CONFIG_URL = ""
IMPORT_FILENAME = ""
FILTER_KEYWORD = []
FILTER_GROUP_KRYWORD = []
FILTER_REMARK_KEYWORD = []
EXCLUDE_KEYWORD = []
EXCLUDE_GROUP_KEYWORD = []
EXCLUDE_REMARK_KEWORD = []
TEST_METHOD = ""
TEST_MODE = ""
#PROXY_TYPE = "SSR"
#SPLIT_CNT = 0
SORT_METHOD = ""
SKIP_COMFIRMATION = True
RESULT_IMAGE_COLOR = "origin"
options,args = cli_cfg.init(VERSION)
if (options.paolu):
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
try:
os.remove(os.path.join(root, name))
except:
pass
for name in dirs:
try:
os.remove(os.path.join(root, name))
except:
pass
sys.exit(0)
# input("Press ENTER to conitnue or Crtl+C to exit.")
if (options.debug):
DEBUG = options.debug
for item in loggerList:
item.setLevel(logging.DEBUG)
item.addHandler(fileHandler)
item.addHandler(consoleHandler)
else:
for item in loggerList:
item.setLevel(logging.INFO)
item.addHandler(fileHandler)
item.addHandler(consoleHandler)
logger.info("SSRSpeed {}, Web Api Version {}".format(config["VERSION"], config["WEB_API_VERSION"]))
if (logger.level == logging.DEBUG):
logger.debug("Program running in debug mode")
if not options.skip_requirements_check:
rc = RequirementsCheck()
rc.check()
else:
logger.warn("Requirements check skipped.")
'''
if (options.proxy_type):
if (options.proxy_type.lower() == "ss"):
PROXY_TYPE = "SS"
elif (options.proxy_type.lower() == "ssr"):
PROXY_TYPE = "SSR"
elif (options.proxy_type.lower() == "ssr-cs"):
PROXY_TYPE = "SSR-C#"
elif (options.proxy_type.lower() == "v2ray"):
PROXY_TYPE = "V2RAY"
else:
logger.warn("Unknown proxy type {} ,using default ssr.".format(options.proxy_type))
'''
#print(options.test_method)
if options.test_method == "speedtestnet":
TEST_METHOD = "SPEED_TEST_NET"
else:
TEST_METHOD = "FAST"
if (options.test_mode == "pingonly"):
TEST_MODE = "TCP_PING"
elif(options.test_mode == "all"):
TEST_MODE = "ALL"
elif (options.test_mode == "wps"):
TEST_MODE = "WEB_PAGE_SIMULATION"
else:
logger.critical("Invalid test mode : %s" % options.test_mode)
sys.exit(1)
if (options.confirmation):
SKIP_COMFIRMATION = options.confirmation
if (options.result_color):
RESULT_IMAGE_COLOR = options.result_color
if (options.import_file):
CONFIG_LOAD_MODE = 0
elif (options.guiConfig):
CONFIG_LOAD_MODE = 1
CONFIG_FILENAME = options.guiConfig
elif(options.url):
CONFIG_LOAD_MODE = 2
CONFIG_URL = options.url
else:
logger.error("No config input,exiting...")
sys.exit(1)
if (options.filter):
FILTER_KEYWORD = options.filter
if (options.group):
FILTER_GROUP_KRYWORD = options.group
if (options.remarks):
FILTER_REMARK_KEYWORD = options.remarks
if (options.efliter):
EXCLUDE_KEYWORD = options.efliter
# print (EXCLUDE_KEYWORD)
if (options.egfilter):
EXCLUDE_GROUP_KEYWORD = options.egfilter
if (options.erfilter):
EXCLUDE_REMARK_KEWORD = options.erfilter
logger.debug(
"\nFilter keyword : %s\nFilter group : %s\nFilter remark : %s\nExclude keyword : %s\nExclude group : %s\nExclude remark : %s" % (
str(FILTER_KEYWORD),str(FILTER_GROUP_KRYWORD),str(FILTER_REMARK_KEYWORD),str(EXCLUDE_KEYWORD),str(EXCLUDE_GROUP_KEYWORD),str(EXCLUDE_REMARK_KEWORD)
)
)
'''
if (int(options.split_count) > 0):
SPLIT_CNT = int(options.split_count)
'''
if (options.sort_method):
sm = options.sort_method
# print(sm)
if (sm == "speed"):
SORT_METHOD = "SPEED"
elif(sm == "rspeed"):
SORT_METHOD = "REVERSE_SPEED"
elif(sm == "ping"):
SORT_METHOD = "PING"
elif(sm == "rping"):
SORT_METHOD = "REVERSE_PING"
else:
logger.error("Sort method %s not support." % sm)
sc = SSRSpeedCore()
if (options.import_file and CONFIG_LOAD_MODE == 0):
IMPORT_FILENAME = options.import_file
sc.colors = RESULT_IMAGE_COLOR
sc.sortMethod = SORT_METHOD if SORT_METHOD else ""
sc.import_and_export(IMPORT_FILENAME)
sys.exit(0)
configs = []
if (CONFIG_LOAD_MODE == 1):
sc.console_setup(
TEST_MODE,
TEST_METHOD,
RESULT_IMAGE_COLOR,
SORT_METHOD,
cfg_filename = CONFIG_FILENAME
)
# sc.consoleReadFileConfigs(CONFIG_FILENAME)
else:
sc.console_setup(
TEST_MODE,
TEST_METHOD,
RESULT_IMAGE_COLOR,
SORT_METHOD,
url = CONFIG_URL
)
# sc.consoleReadSubscription(CONFIG_URL)
if options.group_override:
sc.set_group(options.group_override)
sc.filter_nodes(
FILTER_KEYWORD,
FILTER_GROUP_KRYWORD,
FILTER_REMARK_KEYWORD,
EXCLUDE_KEYWORD,
EXCLUDE_GROUP_KEYWORD,
EXCLUDE_REMARK_KEWORD
)
sc.clean_result()
if not SKIP_COMFIRMATION:
ans = input("Before the test please confirm the nodes,Ctrl-C to exit. (Y/N)")
if ans.upper() == "Y":
pass
else:
sys.exit(0)
sc.start_test(options.use_ssr_cs)