-
Notifications
You must be signed in to change notification settings - Fork 2
/
inbound_finder.py
86 lines (70 loc) · 2.34 KB
/
inbound_finder.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
class InboundSetting:
def __init__(
self,
listen: str,
port: int,
protocol: str,
network: str,
path: str,
security: str,
alpn: list,
flow: str,
tcp_setting_header_type: str
):
self.listen = listen
self.port = port
self.protocol = protocol
self.network = network
self.path = path
self.security = security
self.alpn = alpn
self.flow = flow
self.tcp_setting_header_type = tcp_setting_header_type
@staticmethod
def inbound_from_json(json_inbound: dict):
listen = json_inbound.get("listen")
port = json_inbound.get("port")
protocol = json_inbound.get("protocol")
try :
network = json_inbound["streamSettings"]["network"]
except KeyError:
# Maybe Exiting Program for unsupported Config File
network = "ws"
try :
path = json_inbound["streamSettings"]["wsSettings"]["path"]
except KeyError:
# Maybe Exiting Program for unsupported Config File
path = ""
try:
security = json_inbound["streamSettings"]["security"]
except KeyError :
# Maybe Exiting Program for unsupported Config File
security = "auto"
try:
alpn = json_inbound["streamSettings"]["xtlsSettings"]["alpn"]
except KeyError :
# Maybe Exiting Program for unsupported Config File
alpn = [
"h2",
"http/1.1"
]
try:
flow = json_inbound["streamSettings"]["settings"]["clients"][0]
except KeyError:
# Maybe Exiting Program for unsupported Config File
flow = "none"
try:
tcp_setting_header_type = json_inbound["streamSettings"]["tcpSettings"]["header"]["type"]
except KeyError:
tcp_setting_header_type = "none"
return InboundSetting(
listen=listen,
port=port,
protocol=protocol,
network=network,
path=path,
security=security,
alpn=alpn,
flow = flow,
tcp_setting_header_type=tcp_setting_header_type
)