Skip to content

Commit

Permalink
Fix bugs from remarks fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bafflingbug committed Nov 25, 2017
1 parent 19d5bac commit 2329458
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,42 @@
- 主服务器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)
}
```
### SSR服务器订阅地址
**http(s)://[main-server]/?token=[user-token]**
此处user-token为未加密的明文
示例:*http://example.com/?token=password*
### 运行流程
Expand Down
17 changes: 15 additions & 2 deletions python/config.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 12 additions & 7 deletions python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
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)
except:
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)
Expand All @@ -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')
Expand Down
16 changes: 8 additions & 8 deletions python/ssrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ 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()
b64 = base64.urlsafe_b64encode((main_part + '/?' + param_str).encode()).decode().rstrip('=')
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()
Expand Down

0 comments on commit 2329458

Please sign in to comment.