forked from Jrohy/multi-v2ray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_json.py
More file actions
125 lines (107 loc) · 4.36 KB
/
read_json.py
File metadata and controls
125 lines (107 loc) · 4.36 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import urllib.request
def read_sin_user(part_json, multi_user_conf, index_dict):
conf_path=""
conf_host=""
conf_Dyp=""
conf_stream_security=""
conf_stream_header=""
tls_domain=""
global conf_ip
global conf_inboundDetour
if "streamSettings" not in part_json:
return
#节点组别分组
if index_dict["inboundOrDetour"] == 1:
number = ord(index_dict['group'])
number += 1
index_dict['group'] = chr(number)
conf_settings = part_json["settings"]
conf_stream = part_json["streamSettings"]
conf_stream_kcp_settings = conf_stream["kcpSettings"]
conf_stream_network = conf_stream["network"]
conf_stream_security = conf_stream["security"]
if "detour" in conf_settings:
dyp_AId=""
dynamic_port_tag = conf_settings["detour"]["to"]
for detour_list in conf_inboundDetour:
if "tag" in detour_list and detour_list["tag"] == dynamic_port_tag:
dyp_AId = detour_list["settings"]["default"]["alterId"]
break
conf_Dyp="开启,alterId为 %s" % dyp_AId
else:
conf_Dyp="关闭"
if conf_stream["httpSettings"] != None:
conf_path = conf_stream["httpSettings"]["path"]
if conf_stream["wsSettings"] != None:
conf_host = conf_stream["wsSettings"]["headers"]["Host"]
conf_path = conf_stream["wsSettings"]["path"]
if conf_stream["tcpSettings"] != None:
conf_host = conf_stream["tcpSettings"]["header"]["request"]["headers"]["Host"]
if (conf_stream_security == "tls"):
with open('/usr/local/v2ray.fun/my_domain', 'r') as domain_file:
content = domain_file.read()
tls_domain = str(content)
if conf_stream_network == "kcp" :
if "header" in conf_stream_kcp_settings:
conf_stream_header = conf_stream_kcp_settings["header"]["type"]
else:
conf_stream_header = "none"
protocol = part_json["protocol"]
if protocol == "vmess":
clients=conf_settings["clients"]
elif protocol == "socks":
clients=conf_settings["accounts"]
for index,client in enumerate(clients):
index_dict['clientIndex']=index
email = ""
if "email" in client and client["email"] != None:
email = client["email"]
copy_index_dict = index_dict.copy()
sinUserConf={}
sinUserConf['protocol']=protocol
sinUserConf['port']=part_json["port"]
sinUserConf['add']=(tls_domain if tls_domain != "" else conf_ip)
sinUserConf['id']= (client["id"] if protocol == "vmess" else client["pass"])
sinUserConf['email']=(email if protocol == "vmess" else client["user"])
sinUserConf['tls']=conf_stream_security
if protocol == "vmess":
sinUserConf['v']="2"
sinUserConf['aid']=client["alterId"]
sinUserConf['type']=conf_stream_header
sinUserConf['net']=conf_stream_network
sinUserConf['path']=conf_path
sinUserConf['host']=conf_host
sinUserConf['dyp']=conf_Dyp
sinUserConf['indexDict']=copy_index_dict
multi_user_conf.append(sinUserConf)
with open('/etc/v2ray/config.json', 'r') as json_file:
config = json.load(json_file)
#读取配置文件大框架
conf_inbound=config["inbound"]
conf_outbound=config["outbound"]
conf_inboundDetour=config["inboundDetour"]
conf_outboundDetour=config["outboundDetour"]
conf_dns=config["dns"]
conf_routing=config["routing"]
conf_stats = "开启" if "stats" in config else "关闭"
if conf_stats == "开启":
for detour_list in conf_inboundDetour:
if "protocol" in detour_list and detour_list["protocol"] == "dokodemo-door":
conf_door_port = detour_list["port"]
#获取本机IP地址
my_ip = urllib.request.urlopen('http://api.ipify.org').read()
conf_ip = bytes.decode(my_ip)
multiUserConf=[]
#indexDict存储节点在json的索引,和节点代表的组别
#读取inbound节点
index_dict={"inboundOrDetour":0, "detourIndex":0, "clientIndex":0, "group":"A"}
read_sin_user(conf_inbound, multiUserConf, index_dict)
#读取inboundDetour节点
index_dict['inboundOrDetour']=1
if conf_inboundDetour != None:
for index,detour_list in enumerate(conf_inboundDetour):
index_dict['detourIndex']=index
read_sin_user(detour_list, multiUserConf, index_dict)