def write_stream_network(network, index_dict, **kw): part_json = locate_json(index_dict) origin_protocol = part_json["protocol"] if origin_protocol != "mtproto" and origin_protocol != "shadowsocks": security_backup = part_json["streamSettings"]["security"] tls_settings_backup = part_json["streamSettings"]["tlsSettings"] #mtproto换成其他协议时, 减少mtproto int和out的路由绑定 if origin_protocol == "mtproto" and network != "mtproto": del_mtproto_routing(part_json) #原来是socks/mtproto/shadowsocks协议 则先切换为标准的inbound if origin_protocol == "mtproto" or origin_protocol == "socks" or origin_protocol == "shadowsocks": with open('/usr/local/multi-v2ray/json_template/server.json', 'r') as stream_file: vmess = json.load(stream_file) vmess["inbound"]["port"] = part_json["port"] set_locate_json(index_dict, vmess["inbound"]) part_json = locate_json(index_dict) if (network == "tcp" and not kw): with open('/usr/local/multi-v2ray/json_template/tcp.json', 'r') as stream_file: tcp = json.load(stream_file) part_json["streamSettings"] = tcp elif (network == "tcp" and "para" in kw): with open('/usr/local/multi-v2ray/json_template/http.json', 'r') as stream_file: http = json.load(stream_file) http["tcpSettings"]["header"]["request"]["headers"]["Host"] = kw[ "para"] part_json["streamSettings"] = http elif (network == "socks" and "user" in kw and "pass" in kw): with open('/usr/local/multi-v2ray/json_template/socks.json', 'r') as stream_file: socks = json.load(stream_file) with open('/usr/local/multi-v2ray/json_template/tcp.json', 'r') as stream_file: tcp = json.load(stream_file) socks["accounts"][0]["user"] = kw["user"] socks["accounts"][0]["pass"] = kw["pass"] part_json["settings"] = socks part_json["protocol"] = "socks" part_json["streamSettings"] = tcp elif (network == "shadowsocks" and "password" in kw and "method" in kw): with open('/usr/local/multi-v2ray/json_template/ss.json', 'r') as stream_file: ss = json.load(stream_file) ss["port"] = part_json["port"] ss["settings"]["method"] = kw["method"] ss["settings"]["password"] = kw["password"] set_locate_json(index_dict, ss) elif (network == "mtproto"): with open('/usr/local/multi-v2ray/json_template/mtproto.json', 'r') as stream_file: mtproto = json.load(stream_file) mtproto_in = mtproto["mtproto-in"] mtproto_in["port"] = part_json["port"] mtproto_in["tag"] = index_dict["group"] salt = "abcdef" + string.digits secret = ''.join([random.choice(salt) for _ in range(32)]) mtproto_in["settings"]["users"][0]["secret"] = secret set_locate_json(index_dict, mtproto_in) has_outbound = False for outbound in config["outboundDetour"]: if "protocol" in outbound and outbound["protocol"] == "mtproto": has_outbound = True break if not has_outbound: mtproto_out = mtproto["mtproto-out"] config["outboundDetour"].append(mtproto_out) rules = config["routing"]["settings"]["rules"] has_bind = False for rule in rules: if rule["outboundTag"] == "tg-out": has_bind = True inbound_tag_set = set(rule["inboundTag"]) inbound_tag_set.add(index_dict["group"]) rule["inboundTag"] = list(inbound_tag_set) break if not has_bind: routing_bind = mtproto["routing-bind"] routing_bind["inboundTag"][0] = index_dict["group"] rules.append(routing_bind) elif (network == "h2"): with open('/usr/local/multi-v2ray/json_template/http2.json', 'r') as stream_file: http2 = json.load(stream_file) part_json["streamSettings"] = http2 #随机生成8位的伪装path salt = '/' + ''.join( random.sample(string.ascii_letters + string.digits, 8)) + '/' part_json["streamSettings"]["httpSettings"]["path"] = salt if (security_backup != "tls" or not "certificates" in tls_settings_backup): from base_util import v2ray_util v2ray_util.change_tls("on", index_dict) return elif (network == "ws" and "para" in kw): with open('/usr/local/multi-v2ray/json_template/ws.json', 'r') as stream_file: ws = json.load(stream_file) part_json["streamSettings"] = ws part_json["streamSettings"]["wsSettings"]["headers"]["Host"] = kw[ "para"] #随机生成8位的伪装path salt = '/' + ''.join( random.sample(string.ascii_letters + string.digits, 8)) + '/' part_json["streamSettings"]["wsSettings"]["path"] = salt elif (network == "mkcp" and not kw): with open('/usr/local/multi-v2ray/json_template/kcp.json', 'r') as stream_file: kcp = json.load(stream_file) part_json["streamSettings"] = kcp elif (network == "mkcp" and kw["para"] == "kcp utp"): with open('/usr/local/multi-v2ray/json_template/kcp_utp.json', 'r') as stream_file: utp = json.load(stream_file) part_json["streamSettings"] = utp elif (network == "mkcp" and kw["para"] == "kcp srtp"): with open('/usr/local/multi-v2ray/json_template/kcp_srtp.json', 'r') as stream_file: srtp = json.load(stream_file) part_json["streamSettings"] = srtp elif (network == "mkcp" and kw["para"] == "kcp wechat-video"): with open('/usr/local/multi-v2ray/json_template/kcp_wechat.json', 'r') as stream_file: wechat = json.load(stream_file) part_json["streamSettings"] = wechat elif (network == "mkcp" and "para" in kw and kw["para"] == "kcp dtls"): with open('/usr/local/multi-v2ray/json_template/kcp_dtls.json', 'r') as stream_file: dtls = json.load(stream_file) part_json["streamSettings"] = dtls if network != "mtproto" and origin_protocol != "mtproto" and network != "shadowsocks" and origin_protocol != "shadowsocks": part_json["streamSettings"]["security"] = security_backup part_json["streamSettings"]["tlsSettings"] = tls_settings_backup write()
def write_stream_network(network, index_dict, **kw): part_json = locate_json(index_dict) security_backup = part_json["streamSettings"]["security"] tls_settings_backup = part_json["streamSettings"]["tlsSettings"] #原来是socks协议改其他协议则会修改protocol和settings if part_json["protocol"] == "socks" and network != "socks": part_json["protocol"] = "vmess" setting = {"clients": [{"id": str(uuid.uuid1()), "alterId": 64}]} part_json["settings"] = setting if (network == "tcp" and not kw): with open('/usr/local/v2ray.fun/json_template/tcp.json', 'r') as stream_file: tcp = json.load(stream_file) part_json["streamSettings"] = tcp elif (network == "tcp" and "para" in kw): with open('/usr/local/v2ray.fun/json_template/http.json', 'r') as stream_file: http = json.load(stream_file) http["tcpSettings"]["header"]["request"]["headers"]["Host"] = kw[ "para"] part_json["streamSettings"] = http elif (network == "socks" and "user" in kw and "pass" in kw): with open('/usr/local/v2ray.fun/json_template/socks.json', 'r') as stream_file: socks = json.load(stream_file) with open('/usr/local/v2ray.fun/json_template/tcp.json', 'r') as stream_file: tcp = json.load(stream_file) socks["accounts"][0]["user"] = kw["user"] socks["accounts"][0]["pass"] = kw["pass"] part_json["settings"] = socks part_json["protocol"] = "socks" part_json["streamSettings"] = tcp elif (network == "h2"): with open('/usr/local/v2ray.fun/json_template/http2.json', 'r') as stream_file: http2 = json.load(stream_file) part_json["streamSettings"] = http2 #随机生成8位的伪装path salt = '/' + ''.join( random.sample(string.ascii_letters + string.digits, 8)) + '/' part_json["streamSettings"]["httpSettings"]["path"] = salt if (security_backup != "tls" or not "certificates" in tls_settings_backup): from base_util import v2ray_util v2ray_util.change_tls("on", index_dict) return elif (network == "ws" and "para" in kw): with open('/usr/local/v2ray.fun/json_template/ws.json', 'r') as stream_file: ws = json.load(stream_file) part_json["streamSettings"] = ws part_json["streamSettings"]["wsSettings"]["headers"]["Host"] = kw[ "para"] #随机生成8位的伪装path salt = '/' + ''.join( random.sample(string.ascii_letters + string.digits, 8)) + '/' part_json["streamSettings"]["wsSettings"]["path"] = salt elif (network == "mkcp" and not kw): with open('/usr/local/v2ray.fun/json_template/kcp.json', 'r') as stream_file: kcp = json.load(stream_file) part_json["streamSettings"] = kcp elif (network == "mkcp" and kw["para"] == "kcp utp"): with open('/usr/local/v2ray.fun/json_template/kcp_utp.json', 'r') as stream_file: utp = json.load(stream_file) part_json["streamSettings"] = utp elif (network == "mkcp" and kw["para"] == "kcp srtp"): with open('/usr/local/v2ray.fun/json_template/kcp_srtp.json', 'r') as stream_file: srtp = json.load(stream_file) part_json["streamSettings"] = srtp elif (network == "mkcp" and kw["para"] == "kcp wechat-video"): with open('/usr/local/v2ray.fun/json_template/kcp_wechat.json', 'r') as stream_file: wechat = json.load(stream_file) part_json["streamSettings"] = wechat elif (network == "mkcp" and "para" in kw and kw["para"] == "kcp dtls"): with open('/usr/local/v2ray.fun/json_template/kcp_dtls.json', 'r') as stream_file: dtls = json.load(stream_file) part_json["streamSettings"] = dtls part_json["streamSettings"]["security"] = security_backup part_json["streamSettings"]["tlsSettings"] = tls_settings_backup write()
choice = 'A' if length > 1: import server_info choice=input("请输入要改tls的节点Group字母:") choice=choice.upper() if length == 1 or (len(choice)==1 and re.match(r'[A-Z]', choice) and choice <= mul_user_conf[-1]['indexDict']['group']): for sin_user_conf in mul_user_conf: if sin_user_conf['indexDict']['group'] == choice: index_dict = sin_user_conf['indexDict'] if (sin_user_conf['tls']=="tls"): my_stream_security="TLS:开启" else: my_stream_security="TLS:关闭" break print("当前选择组节点状态:\n" + my_stream_security) print("") print("1.开启TLS") print("2.关闭TLS") choice = input("请输入数字选择功能:") if choice == "1": v2ray_util.change_tls("on", index_dict) elif choice == "2": v2ray_util.change_tls("off", index_dict) else: print("输入错误,请重试!") else: print ("输入错误,请检查是否符合范围中")
import server_info choice=input("请输入要改tls的节点Group字母:") choice=choice.upper() if length == 1 or (len(choice)==1 and re.match(r'[A-Z]', choice) and choice <= mul_user_conf[-1]['indexDict']['group']): for sin_user_conf in mul_user_conf: if sin_user_conf['indexDict']['group'] == choice: index_dict = sin_user_conf['indexDict'] if sin_user_conf["protocol"] == "mtproto": print("\nv2ray MTProto协议不支持https!!!\n") exit() if (sin_user_conf['tls']=="tls"): my_stream_security="TLS:开启" else: my_stream_security="TLS:关闭" break print("当前选择组节点状态:\n" + my_stream_security) print("") print("1.开启TLS") print("2.关闭TLS") choice = input("请输入数字选择功能:") if choice == "1": v2ray_util.change_tls("on", index_dict) elif choice == "2": v2ray_util.change_tls("off", index_dict) else: print("输入错误,请重试!") else: print ("输入错误,请检查是否符合范围中")
def write_stream_network(network, para, index_dict): part_json = locate_json(index_dict) security_backup = part_json[u"streamSettings"][u"security"] tls_settings_backup = part_json[u"streamSettings"][u"tlsSettings"] if (network == "tcp" and para == "none"): with open('/usr/local/v2ray.fun/json_template/tcp.json', 'r') as stream_file: tcp = json.load(stream_file) part_json[u"streamSettings"] = tcp if (network == "tcp" and para != "none"): with open('/usr/local/v2ray.fun/json_template/http.json', 'r') as stream_file: http = json.load(stream_file) http[u"tcpSettings"][u"header"][u"request"][u"headers"][u"Host"] = para part_json[u"streamSettings"] = http if (network == "h2"): with open('/usr/local/v2ray.fun/json_template/http2.json', 'r') as stream_file: http2 = json.load(stream_file) part_json[u"streamSettings"] = http2 #随机生成8位的伪装path salt = '/' + ''.join( random.sample(string.ascii_letters + string.digits, 8)) + '/' part_json[u"streamSettings"][u"httpSettings"][u"path"] = salt if (security_backup != "tls" or not "certificates" in tls_settings_backup): from base_util import v2ray_util v2ray_util.change_tls("on", index_dict) return if (network == "ws"): with open('/usr/local/v2ray.fun/json_template/ws.json', 'r') as stream_file: ws = json.load(stream_file) part_json[u"streamSettings"] = ws part_json[u"streamSettings"][u"wsSettings"][u"headers"][u"host"] = para if (network == "mkcp" and para == "none"): with open('json_template/kcp.json', 'r') as stream_file: kcp = json.load(stream_file) part_json[u"streamSettings"] = kcp if (network == "mkcp" and para == "kcp utp"): with open('/usr/local/v2ray.fun/json_template/kcp_utp.json', 'r') as stream_file: utp = json.load(stream_file) part_json[u"streamSettings"] = utp if (network == "mkcp" and para == "kcp srtp"): with open('/usr/local/v2ray.fun/json_template/kcp_srtp.json', 'r') as stream_file: srtp = json.load(stream_file) part_json[u"streamSettings"] = srtp if (network == "mkcp" and para == "kcp wechat-video"): with open('/usr/local/v2ray.fun/json_template/kcp_wechat.json', 'r') as stream_file: wechat = json.load(stream_file) part_json[u"streamSettings"] = wechat if (network == "mkcp" and para == "kcp dtls"): with open('/usr/local/v2ray.fun/json_template/kcp_dtls.json', 'r') as stream_file: dtls = json.load(stream_file) part_json[u"streamSettings"] = dtls part_json[u"streamSettings"][u"security"] = security_backup part_json[u"streamSettings"][u"tlsSettings"] = tls_settings_backup write()
def write_stream_network(network, index_dict, **kw): part_json = locate_json(index_dict) security_backup = part_json["streamSettings"]["security"] tls_settings_backup = part_json["streamSettings"]["tlsSettings"] #原来是socks协议改其他协议则会修改protocol和settings if part_json["protocol"] == "socks" and network != "socks": part_json["protocol"] = "vmess" setting = {"clients":[{"id":str(uuid.uuid1()), "alterId": 64}]} part_json["settings"] = setting if (network == "tcp" and not kw): with open('/usr/local/v2ray.fun/json_template/tcp.json', 'r') as stream_file: tcp = json.load(stream_file) part_json["streamSettings"]=tcp elif (network == "tcp" and "para" in kw): with open('/usr/local/v2ray.fun/json_template/http.json', 'r') as stream_file: http = json.load(stream_file) http["tcpSettings"]["header"]["request"]["headers"]["Host"]=kw["para"] part_json["streamSettings"]=http elif (network == "socks" and "user" in kw and "pass" in kw): with open('/usr/local/v2ray.fun/json_template/socks.json', 'r') as stream_file: socks = json.load(stream_file) with open('/usr/local/v2ray.fun/json_template/tcp.json', 'r') as stream_file: tcp = json.load(stream_file) socks["accounts"][0]["user"]=kw["user"] socks["accounts"][0]["pass"]=kw["pass"] part_json["settings"]=socks part_json["protocol"]="socks" part_json["streamSettings"]=tcp elif (network == "h2"): with open('/usr/local/v2ray.fun/json_template/http2.json', 'r') as stream_file: http2 = json.load(stream_file) part_json["streamSettings"]=http2 #随机生成8位的伪装path salt = '/' + ''.join(random.sample(string.ascii_letters + string.digits, 8)) + '/' part_json["streamSettings"]["httpSettings"]["path"]=salt if (security_backup != "tls" or not "certificates" in tls_settings_backup): from base_util import v2ray_util v2ray_util.change_tls("on", index_dict) return elif (network == "ws" and "para" in kw): with open('/usr/local/v2ray.fun/json_template/ws.json', 'r') as stream_file: ws = json.load(stream_file) part_json["streamSettings"]=ws part_json["streamSettings"]["wsSettings"]["headers"]["Host"] = kw["para"] #随机生成8位的伪装path salt = '/' + ''.join(random.sample(string.ascii_letters + string.digits, 8)) + '/' part_json["streamSettings"]["wsSettings"]["path"]=salt elif (network == "mkcp" and not kw): with open('/usr/local/v2ray.fun/json_template/kcp.json', 'r') as stream_file: kcp = json.load(stream_file) part_json["streamSettings"]=kcp elif (network == "mkcp" and kw["para"]=="kcp utp"): with open('/usr/local/v2ray.fun/json_template/kcp_utp.json', 'r') as stream_file: utp = json.load(stream_file) part_json["streamSettings"]=utp elif (network == "mkcp" and kw["para"]=="kcp srtp"): with open('/usr/local/v2ray.fun/json_template/kcp_srtp.json', 'r') as stream_file: srtp = json.load(stream_file) part_json["streamSettings"]=srtp elif (network == "mkcp" and kw["para"]=="kcp wechat-video"): with open('/usr/local/v2ray.fun/json_template/kcp_wechat.json', 'r') as stream_file: wechat = json.load(stream_file) part_json["streamSettings"]=wechat elif (network == "mkcp" and "para" in kw and kw["para"]=="kcp dtls"): with open('/usr/local/v2ray.fun/json_template/kcp_dtls.json', 'r') as stream_file: dtls = json.load(stream_file) part_json["streamSettings"]=dtls part_json["streamSettings"]["security"] = security_backup part_json["streamSettings"]["tlsSettings"] = tls_settings_backup write()