forked from bigbigbigboss/v2ray.fun-2
-
Notifications
You must be signed in to change notification settings - Fork 3
/
writejson.py
executable file
·139 lines (111 loc) · 4.73 KB
/
writejson.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import json
import readjson
# 打开配置文件
jsonfile = file("/etc/v2ray/config.json")
config = json.load(jsonfile)
# 写入配置文件
def Write():
myjsondump = json.dumps(config, indent=1)
openjsonfile = file("/etc/v2ray/config.json", "w+")
openjsonfile.writelines(myjsondump)
openjsonfile.close()
def EnDynPort(en):
if en == 1:
config[u"inbound"][u"settings"].update(
{u"detour": {u"to": "dynamicPort"}})
dyn_port = file("/usr/local/v2ray.fun/json_template/dyn_port.json")
srtp = json.load(dyn_port)
config[u"inboundDetour"] = srtp
config[u"inboundDetour"][0][u"settings"][u"default"][u"alterId"] = int(
readjson.ConfAlterId)
else:
config[u"inboundDetour"] = []
if "detour" in config[u"inbound"][u"settings"]:
del config[u"inbound"][u"settings"][u"detour"]
Write()
def UpdateDynPort(min_port, max_port):
config[u"inboundDetour"][0][u"port"] = str(min_port) + '-' + str(max_port)
Write()
# 更改UUID
def WriteUUID(myuuid):
config[u"inbound"][u"settings"][u"clients"][0][u"id"] = str(myuuid)
Write()
# change alter ID
def WriteAlterId(alterId):
config[u"inbound"][u"settings"][u"clients"][0][u"alterId"] = int(alterId)
Write()
# 更改端口
def WritePort(myport):
config[u"inbound"][u"port"] = int(myport)
Write()
# 更改加密方式
def WriteSecurity(mysecurity):
config[u"inbound"][u"settings"][u"clients"][0][u"security"] = str(
mysecurity)
Write()
# 更改底层传输设置
def WriteStreamNetwork(network, para):
security_backup = config[u"inbound"][u"streamSettings"][u"security"]
tls_settings_backup = config[u"inbound"][u"streamSettings"][u"tlsSettings"]
if (network == "tcp" and para == "none"):
streamfile = file("/usr/local/v2ray.fun/json_template/tcp.json")
tcp = json.load(streamfile)
config[u"inbound"][u"streamSettings"] = tcp
if (network == "tcp" and para != "none"):
streamfile = file("/usr/local/v2ray.fun/json_template/http.json")
http = json.load(streamfile)
http[u"tcpSettings"][u"header"][u"request"][u"headers"][u"Host"] = para
config[u"inbound"][u"streamSettings"] = http
if (network == "ws"):
streamfile = file("/usr/local/v2ray.fun/json_template/ws.json")
ws = json.load(streamfile)
config[u"inbound"][u"streamSettings"] = ws
config[u"inbound"][u"streamSettings"][u"wsSettings"][u"headers"][u"host"] = para
if (network == "mkcp" and para == "none"):
streamfile = file("/usr/local/v2ray.fun/json_template/kcp.json")
kcp = json.load(streamfile)
config[u"inbound"][u"streamSettings"] = kcp
if (network == "mkcp" and para == "kcp utp"):
streamfile = file("/usr/local/v2ray.fun/json_template/kcp_utp.json")
utp = json.load(streamfile)
config[u"inbound"][u"streamSettings"] = utp
if (network == "mkcp" and para == "kcp srtp"):
streamfile = file("/usr/local/v2ray.fun/json_template/kcp_srtp.json")
srtp = json.load(streamfile)
config[u"inbound"][u"streamSettings"] = srtp
if (network == "mkcp" and para == "kcp wechat-video"):
streamfile = file("/usr/local/v2ray.fun/json_template/kcp_wechat.json")
wechat = json.load(streamfile)
config[u"inbound"][u"streamSettings"] = wechat
config[u"inbound"][u"streamSettings"][u"security"] = security_backup
config[u"inbound"][u"streamSettings"][u"tlsSettings"] = tls_settings_backup
Write()
# 更改TLS设置
def WriteTLS(action, domain):
if action == "on":
crt_file = "/root/.acme.sh/" + domain + "_ecc" + "/fullchain.cer"
key_file = "/root/.acme.sh/" + domain + "_ecc" + "/" + domain + ".key"
config[u"inbound"][u"streamSettings"][u"security"] = "tls"
tls_file = file("/usr/local/v2ray.fun/json_template/tlssettings.json")
tls_settings = json.load(tls_file)
tls_settings[u"certificates"][0][u"certificateFile"] = crt_file
tls_settings[u"certificates"][0][u"keyFile"] = key_file
config[u"inbound"][u"streamSettings"][u"tlsSettings"] = tls_settings
domainfile = file("/usr/local/v2ray.fun/mydomain", "w+")
domainfile.writelines(str(domain))
domainfile.close()
Write()
elif action == "off":
config[u"inbound"][u"streamSettings"][u"security"] = ""
config[u"inbound"][u"streamSettings"][u"tlsSettings"] = {}
Write()
# 更改广告拦截功能
def WriteAD(action):
if action == "on":
config[u"routing"][u"settings"][u"rules"][1][u"outboundTag"] = "blocked"
else:
config[u"routing"][u"settings"][u"rules"][1][u"outboundTag"] = "direct"
Write()