diff --git a/README.md b/README.md index e38f07e..9748b2a 100644 --- a/README.md +++ b/README.md @@ -33,21 +33,34 @@ - 主服务器config.json ``` { - "group": "PowerByBafflingBUG", //SSR GROUP - "token": "password", //服务器间token,用于防止恶意的post数据(弱验证) - "user-token": "696d29e0940a4957748fe3fc9efd22a3" //用户获取ssr链接时候的token,此处填写值为原始密钥经过[两次]md5加密以后的值(32位/小写/强验证) + "group": "PowerByBafflingBUG", //SSR GROUP + "token": "password", //服务器间token,用于防止恶意的post数据(弱验证) + "user-token": "696d29e0940a4957748fe3fc9efd22a3" //用户获取ssr链接时候的token,此处填写值为原始密钥经过[两次]md5加密以后的值(32位/小写/强验证) } ``` - SSR服务器config.json ``` { - "ss-config-file": ["ss_config1","ss_config2"], //SS服务器的配置文件路径 - "ssr-config-file": ["ssr_config1","ssr_config2"], //SSR服务器的配置文件路径 - "main-server": "ssr.example.com", //主服务器的域名/IP - "host": "0.0.0.0", //当前服务器的外网IP - "token": "password", //服务器间token,需与主服务器一致 - "ssl": false //主服务器是否使用SSL(https) + "ss-config-file": [ //SS服务器配置文件(多个) + { //第一个SS服务器 + "config-file": "ss_config1", //配置文件地址 + "remarks": "ss备注1" //服务器备注(客户端备注位置) + },{ //第二个SS服务器 + "config-file": "ss_config2", + "remarks": "ss备注2" + } + ], + "ssr-config-file": [ //SSR服务器配置文件(多个/同SS) + { + "config-file": "ssr_config1", + "remarks": "ssr备注1" + } + ], + "main-server": "example.com", //主服务器的域名/IP + "host": "0.0.0.0", //当前服务器的外网IP + "token": "password", //服务器间token,需与主服务器一致 + "ssl": false //主服务器是否使用SSL(https) } ``` @@ -55,6 +68,7 @@ **http(s)://[main-server]/?token=[user-token]** 此处user-token为未加密的明文 + 示例:*http://example.com/?token=password* ### 运行流程 diff --git a/python/config.json b/python/config.json index a47c72f..220e2d5 100644 --- a/python/config.json +++ b/python/config.json @@ -1,6 +1,19 @@ { - "ss-config-file": ["ss_config1","ss_config2"], - "ssr-config-file": ["ssr_config1","ssr_config2"], + "ss-config-file": [ + { + "config-file": "ss_config1", + "remarks": "ss备注1" + },{ + "config-file": "ss_config2", + "remarks": "ss备注2" + } + ], + "ssr-config-file": [ + { + "config-file": "ssr_config1", + "remarks": "ssr备注1" + } + ], "main-server": "ssr.example.com", "host": "0.0.0.0", "token": "password", diff --git a/python/main.py b/python/main.py index aa44a90..2a7e43e 100644 --- a/python/main.py +++ b/python/main.py @@ -2,10 +2,14 @@ import os from network import * from ssrs import * +import sys if __name__ == "__main__": + reload(sys) + sys.setdefaultencoding('utf-8') update = False dir_path = os.path.dirname(os.path.realpath(__file__)) + MD5_file = None try: MD5_file = open(dir_path + '/MD5.json', 'r') fileMD5 = json.load(MD5_file) @@ -13,7 +17,8 @@ fileMD5 = {} update = True finally: - MD5_file.close() + if MD5_file: + MD5_file.close() update = new_config(dir_path + '/config.json', fileMD5, update) config_file = open(dir_path + '/config.json', 'r') config = json.load(config_file) @@ -24,12 +29,12 @@ update = True fileMD5['group'] = group ssr_url = '' - for ss_config_file_name in config['ss-config-file']: - update = new_config(ss_config_file_name, fileMD5, update) - ssr_url += ss2URL(ss_config_file_name, config, group) - for ssr_config_file_name in config['ssr-config-file']: - update = new_config(ssr_config_file_name, fileMD5, update) - ssr_url += ssr2URL(ssr_config_file_name, config, group) + for ss_config in config['ss-config-file']: + update = new_config(ss_config['config-file'], fileMD5, update) + ssr_url += ss2URL(ss_config, config, group) + for ssr_config in config['ssr-config-file']: + update = new_config(ssr_config['config-file'], fileMD5, update) + ssr_url += ssr2URL(ssr_config, config, group) if update: print(ssr_url) MD5_file = open(dir_path + '/MD5.json', 'w') diff --git a/python/ssrs.py b/python/ssrs.py index 576b814..0663e42 100644 --- a/python/ssrs.py +++ b/python/ssrs.py @@ -13,14 +13,14 @@ def new_config(file, fileMD5, update): return True -def ssr2URL(file, config, group): - ssr_config_file = open(file) +def ssr2URL(ssr, config, group): + ssr_config_file = open(ssr['config-file'], 'r') ssr_config = json.load(ssr_config_file) param_str = "obfsparam=" + base64.urlsafe_b64encode(ssr_config['obfs_param'].encode() if not ssr_config['obfs_param'] is None else ''.encode()).decode().rstrip('=') if 'protocol_param' in ssr_config.keys() and (not ssr_config['protocol_param'] == ""): param_str += '&protoparam=' + base64.urlsafe_b64encode(ssr_config['protocol_param'].encode()).decode().rstrip('=') - if 'remarks' in ssr_config.keys() and (not ssr_config['remarks'] == ""): - param_str += '&remarks=' + base64.urlsafe_b64encode(ssr_config['remarks'].encode()).decode().rstrip('=') + if 'remarks' in ssr.keys() and (not ssr['remarks'] == ""): + param_str += '&remarks=' + base64.urlsafe_b64encode(ssr['remarks'].encode()).decode().rstrip('=') param_str += '&group=' + base64.urlsafe_b64encode(group.encode()).decode().rstrip('=') main_part = config["host"] + ':' + str(ssr_config['server_port']) + ':' + ssr_config['protocol'] + ':' + ssr_config['method'] + ':' + ssr_config['obfs'] + ':' + base64.urlsafe_b64encode(ssr_config['password'].encode()).decode().rstrip('=') ssr_config_file.close() @@ -28,12 +28,12 @@ def ssr2URL(file, config, group): return 'ssr://' + b64 + '\n' -def ss2URL(file, config, group): - ss_config_file = open(file) +def ss2URL(ss, config, group): + ss_config_file = open(ss['config-file'], 'r') ss_config = json.load(ss_config_file) param_str = "obfsparam=" + '' - if 'remarks' in ss_config.keys() and (not ss_config['remarks'] == ""): - param_str += '&remarks=' + base64.urlsafe_b64encode(ss_config['remarks'].encode()).decode().rstrip('=') + if 'remarks' in ss.keys() and (not ss['remarks'] == ""): + param_str += '&remarks=' + base64.urlsafe_b64encode(ss['remarks'].encode()).decode().rstrip('=') param_str += '&group=' + base64.urlsafe_b64encode(group.encode()).decode().rstrip('=') main_part = config["host"] + ':' + str(ss_config['server_port']) + ':' + 'origin' + ':' + ss_config['method'] + ':' + 'plain' + ':' + base64.urlsafe_b64encode(ss_config['password'].encode()).decode().rstrip('=') ss_config_file.close()