-
Notifications
You must be signed in to change notification settings - Fork 2
/
protocols.py
executable file
·165 lines (129 loc) · 4.58 KB
/
protocols.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
from abc import ABC,abstractmethod
from enum import Enum
from inbound_finder import InboundSetting
import os
class EnviromentVariables(str,Enum):
VPN_NAME = "VPN_NAME"
DOMAIN_NAME = "DOMAIN_NAME"
CND_NAME = "CDN_NAME"
REQUEST_HOST ="REQUEST_HOST"
class V2rayConfig:
def __init__(self) -> None:
pass
class Protocols:
def __init__(self) -> None:
self.vpn_name = self.get_vpn_name()
self.domain_name = self.get_domain_name()
self.cdn_name = self.get_cdn_name()
self.request_host = self.get_request_host()
def get_vpn_name(self,name= ""):
if(name == ""):
name = os.getenv(EnviromentVariables.VPN_NAME,"ERROR")
return name
def get_domain_name(self,domain= ""):
if domain == "":
domain = os.getenv(EnviromentVariables.DOMAIN_NAME,"ERROR")
return domain
def get_cdn_name(self,cdn= ""):
if cdn == "":
cdn = os.getenv(EnviromentVariables.CND_NAME,"ERROR")
return cdn
def get_request_host(self,request_host=""):
if request_host == "":
request_host = os.getenv(EnviromentVariables.REQUEST_HOST)
return request_host
class Vmess(Protocols):
def __init__(self) -> None:
super().__init__()
self.vmess_dict_base = {
"v": "2",
"ps": "",
"add": "",
"port": "",
"id": "",
"aid": "",
"scy": "",
"net": "",
"type": "",
"host": "",
"path": "",
"tls": "",
"sni": "",
"alpn": ""
}
def _base(self):
# setting the vpn name
self.vmess_dict_base["ps"] = self.domain_name
def url_ws_tls_nginx(self,id, inboubd: InboundSetting,append_vpn_name: str):
name = self.vpn_name
name = name+"-"+append_vpn_name
vmess_dict = self.vmess_dict_base
vmess_dict["ps"] = name
vmess_dict["add"] = self.domain_name
vmess_dict["port"] = 443
vmess_dict["id"] = id
vmess_dict["aid"] = 0
vmess_dict["scy"] = "chacha20-poly1305"
vmess_dict["net"] = inboubd.network
vmess_dict["type"] = "none"
vmess_dict["host"] = ""
vmess_dict["path"] = inboubd.path
vmess_dict["tls"] = "tls"
vmess_dict["sni"] = self.domain_name
vmess_dict["alpn"] = ""
return vmess_dict
def url_ws_tls_nginx_proxy(self,id, inboubd: InboundSetting,append_vpn_name: str):
name = self.vpn_name
name = name+"-"+append_vpn_name
vmess_dict = self.vmess_dict_base
vmess_dict["ps"] = name
vmess_dict["add"] = self.cdn_name
vmess_dict["port"] = 443
vmess_dict["id"] = id
vmess_dict["aid"] = 0
vmess_dict["scy"] = "chacha20-poly1305"
vmess_dict["net"] = inboubd.network
vmess_dict["type"] = "none"
vmess_dict["host"] = ""
vmess_dict["path"] = inboubd.path
vmess_dict["tls"] = "tls"
vmess_dict["sni"] = self.domain_name
vmess_dict["alpn"] = ""
return vmess_dict
def url_ws_tls(self,id, inboubd: InboundSetting,append_vpn_name: str):
name = self.vpn_name
name = name+"-"+append_vpn_name
vmess_dict = self.vmess_dict_base
vmess_dict["ps"] = name
vmess_dict["add"] = self.domain_name
vmess_dict["port"] = inboubd.port
vmess_dict["id"] = id
vmess_dict["aid"] = 0
vmess_dict["scy"] = "chacha20-poly1305"
vmess_dict["net"] = inboubd.network
vmess_dict["type"] = "none"
vmess_dict["host"] = ""
vmess_dict["path"] = inboubd.path
vmess_dict["tls"] = "tls"
vmess_dict["sni"] = self.domain_name
vmess_dict["alpn"] = f"{inboubd.alpn[0]},{inboubd.alpn[1]}"
return vmess_dict
def url_tcp_obfs(self,id, inboubd: InboundSetting,append_vpn_name: str):
name = self.vpn_name
name = name+"-"+append_vpn_name
vmess_dict = self.vmess_dict_base
vmess_dict["ps"] = name
vmess_dict["add"] = self.domain_name
vmess_dict["port"] = inboubd.port
vmess_dict["id"] = id
vmess_dict["aid"] = 0
vmess_dict["scy"] = "chacha20-poly1305"
vmess_dict["net"] = inboubd.network
vmess_dict["type"] = inboubd.tcp_setting_header_type
vmess_dict["host"] = self.request_host
vmess_dict["path"] = inboubd.path
vmess_dict["tls"] = ""
vmess_dict["sni"] = ""
vmess_dict["alpn"] = ""
return vmess_dict