| 1 |
a47eb4c |
Dawsh |
2y ago |
from enum import Enum |
| 2 |
01cdf2e |
Dawsh |
2y ago |
|
| 3 |
2127962 |
Dawsh |
2y ago |
from pydantic import ConfigDict, BaseModel, Field, field_validator |
| 4 |
a47eb4c |
Dawsh |
2y ago |
|
| 5 |
db68a58 |
Dawsh |
2y ago |
from app.models.node import Node |
| 6 |
a47eb4c |
Dawsh |
2y ago |
|
| 7 |
a47eb4c |
Dawsh |
2y ago |
|
| 8 |
a47eb4c |
Dawsh |
2y ago |
class ProxyTypes(str, Enum): |
| 9 |
a47eb4c |
Dawsh |
2y ago |
# proxy_type = protocol |
| 10 |
a47eb4c |
Dawsh |
2y ago |
VMess = "vmess" |
| 11 |
a47eb4c |
Dawsh |
2y ago |
VLESS = "vless" |
| 12 |
a47eb4c |
Dawsh |
2y ago |
Trojan = "trojan" |
| 13 |
a47eb4c |
Dawsh |
2y ago |
Shadowsocks = "shadowsocks" |
| 14 |
0f3112a |
Dawsh |
2y ago |
Shadowsocks2022 = "shadowsocks2022" |
| 15 |
dd32f70 |
Dawsh |
2y ago |
Hysteria2 = "hysteria2" |
| 16 |
0f3112a |
Dawsh |
2y ago |
WireGuard = "wireguard" |
| 17 |
0f3112a |
Dawsh |
2y ago |
TUIC = "tuic" |
| 18 |
70b35e2 |
Dawsh |
1y ago |
ShadowTLS = "shadowtls" |
| 19 |
a47eb4c |
Dawsh |
2y ago |
|
| 20 |
a47eb4c |
Dawsh |
2y ago |
|
| 21 |
a47eb4c |
Dawsh |
2y ago |
class InboundHostSecurity(str, Enum): |
| 22 |
a47eb4c |
Dawsh |
2y ago |
inbound_default = "inbound_default" |
| 23 |
a47eb4c |
Dawsh |
2y ago |
none = "none" |
| 24 |
a47eb4c |
Dawsh |
2y ago |
tls = "tls" |
| 25 |
a47eb4c |
Dawsh |
2y ago |
|
| 26 |
a47eb4c |
Dawsh |
2y ago |
|
| 27 |
a47eb4c |
Dawsh |
2y ago |
InboundHostALPN = Enum( |
| 28 |
a47eb4c |
Dawsh |
2y ago |
"ProxyHostALPN", |
| 29 |
a47eb4c |
Dawsh |
2y ago |
{ |
| 30 |
244c9d8 |
Dawsh |
2y ago |
"none": "none", |
| 31 |
a47eb4c |
Dawsh |
2y ago |
"h2": "h2", |
| 32 |
a47eb4c |
Dawsh |
2y ago |
"http/1.1": "http/1.1", |
| 33 |
a47eb4c |
Dawsh |
2y ago |
"h2,http/1.1": "h2,http/1.1", |
| 34 |
cba39e7 |
Mardin |
2y ago |
"h3": "h3", |
| 35 |
cba39e7 |
Mardin |
2y ago |
"h3,h2": "h3,h2", |
| 36 |
cba39e7 |
Mardin |
2y ago |
"h3,h2,http/1.1": "h3,h2,http/1.1", |
| 37 |
a47eb4c |
Dawsh |
2y ago |
}, |
| 38 |
a47eb4c |
Dawsh |
2y ago |
) |
| 39 |
a47eb4c |
Dawsh |
2y ago |
|
| 40 |
a47eb4c |
Dawsh |
2y ago |
|
| 41 |
a47eb4c |
Dawsh |
2y ago |
InboundHostFingerprint = Enum( |
| 42 |
a47eb4c |
Dawsh |
2y ago |
"ProxyHostFingerprint", |
| 43 |
a47eb4c |
Dawsh |
2y ago |
{ |
| 44 |
a47eb4c |
Dawsh |
2y ago |
"none": "", |
| 45 |
a47eb4c |
Dawsh |
2y ago |
"chrome": "chrome", |
| 46 |
a47eb4c |
Dawsh |
2y ago |
"firefox": "firefox", |
| 47 |
a47eb4c |
Dawsh |
2y ago |
"safari": "safari", |
| 48 |
a47eb4c |
Dawsh |
2y ago |
"ios": "ios", |
| 49 |
a47eb4c |
Dawsh |
2y ago |
"android": "android", |
| 50 |
a47eb4c |
Dawsh |
2y ago |
"edge": "edge", |
| 51 |
a47eb4c |
Dawsh |
2y ago |
"360": "360", |
| 52 |
a47eb4c |
Dawsh |
2y ago |
"qq": "qq", |
| 53 |
a47eb4c |
Dawsh |
2y ago |
"random": "random", |
| 54 |
a47eb4c |
Dawsh |
2y ago |
"randomized": "randomized", |
| 55 |
a47eb4c |
Dawsh |
2y ago |
}, |
| 56 |
a47eb4c |
Dawsh |
2y ago |
) |
| 57 |
a47eb4c |
Dawsh |
2y ago |
|
| 58 |
a47eb4c |
Dawsh |
2y ago |
|
| 59 |
a47eb4c |
Dawsh |
2y ago |
class FormatVariables(dict): |
| 60 |
a47eb4c |
Dawsh |
2y ago |
def __missing__(self, key): |
| 61 |
a47eb4c |
Dawsh |
2y ago |
return key.join("{}") |
| 62 |
a47eb4c |
Dawsh |
2y ago |
|
| 63 |
a47eb4c |
Dawsh |
2y ago |
|
| 64 |
0b152b5 |
Mrdn |
2y ago |
class FragmentSettings(BaseModel): |
| 65 |
0b152b5 |
Mrdn |
2y ago |
packets: str = Field(pattern=r"^(:?tlshello|[\d-]{1,32})$") |
| 66 |
0b152b5 |
Mrdn |
2y ago |
length: str = Field(pattern=r"^[\d-]{1,32}$") |
| 67 |
0b152b5 |
Mrdn |
2y ago |
interval: str = Field(pattern=r"^[\d-]{1,32}$") |
| 68 |
0b152b5 |
Mrdn |
2y ago |
|
| 69 |
0b152b5 |
Mrdn |
2y ago |
|
| 70 |
4056c66 |
Dawsh |
1y ago |
class XrayNoise(BaseModel): |
| 71 |
d636f3f |
Dawsh |
2y ago |
type: str = Field(pattern=r"^(:?rand|str|base64)$") |
| 72 |
d636f3f |
Dawsh |
2y ago |
packet: str = Field() |
| 73 |
4056c66 |
Dawsh |
1y ago |
delay: str = Field(pattern=r"^\d{1,10}(-\d{1,10})?$") |
| 74 |
4056c66 |
Dawsh |
1y ago |
|
| 75 |
4056c66 |
Dawsh |
1y ago |
|
| 76 |
4056c66 |
Dawsh |
1y ago |
class XMuxSettings(BaseModel): |
| 77 |
4056c66 |
Dawsh |
1y ago |
max_concurrency: str | None = Field( |
| 78 |
4056c66 |
Dawsh |
1y ago |
None, pattern=r"^\d{1,10}(-\d{1,10})?$" |
| 79 |
4056c66 |
Dawsh |
1y ago |
) |
| 80 |
4056c66 |
Dawsh |
1y ago |
max_connections: str | None = Field( |
| 81 |
4056c66 |
Dawsh |
1y ago |
None, pattern=r"^\d{1,10}(-\d{1,10})?$" |
| 82 |
4056c66 |
Dawsh |
1y ago |
) |
| 83 |
4056c66 |
Dawsh |
1y ago |
max_reuse_times: str | None = Field( |
| 84 |
4056c66 |
Dawsh |
1y ago |
None, pattern=r"^\d{1,10}(-\d{1,10})?$" |
| 85 |
4056c66 |
Dawsh |
1y ago |
) |
| 86 |
4056c66 |
Dawsh |
1y ago |
max_lifetime: str | None = Field(None, pattern=r"^\d{1,10}(-\d{1,10})?$") |
| 87 |
4056c66 |
Dawsh |
1y ago |
max_request_times: str | None = Field(None) |
| 88 |
4056c66 |
Dawsh |
1y ago |
keep_alive_period: int | None = Field(None) |
| 89 |
4056c66 |
Dawsh |
1y ago |
|
| 90 |
4056c66 |
Dawsh |
1y ago |
|
| 91 |
4056c66 |
Dawsh |
1y ago |
class SplitHttpSettings(BaseModel): |
| 92 |
4056c66 |
Dawsh |
1y ago |
mode: str | None = None |
| 93 |
4056c66 |
Dawsh |
1y ago |
no_grpc_header: bool | None = None |
| 94 |
4056c66 |
Dawsh |
1y ago |
padding_bytes: str | None = None |
| 95 |
4056c66 |
Dawsh |
1y ago |
xmux: XMuxSettings | None = None |
| 96 |
4056c66 |
Dawsh |
1y ago |
|
| 97 |
4056c66 |
Dawsh |
1y ago |
|
| 98 |
4056c66 |
Dawsh |
1y ago |
class SingBoxMuxSettings(BaseModel): |
| 99 |
4056c66 |
Dawsh |
1y ago |
max_connections: int | None = Field(None) |
| 100 |
4056c66 |
Dawsh |
1y ago |
max_streams: int | None = Field(None) |
| 101 |
4056c66 |
Dawsh |
1y ago |
min_streams: int | None = Field(None) |
| 102 |
4056c66 |
Dawsh |
1y ago |
padding: bool | None = Field(None) |
| 103 |
4056c66 |
Dawsh |
1y ago |
|
| 104 |
4056c66 |
Dawsh |
1y ago |
|
| 105 |
4056c66 |
Dawsh |
1y ago |
class MuxCoolSettings(BaseModel): |
| 106 |
4056c66 |
Dawsh |
1y ago |
concurrency: int | None = None |
| 107 |
4056c66 |
Dawsh |
1y ago |
xudp_concurrency: int | None = None |
| 108 |
4056c66 |
Dawsh |
1y ago |
xudp_proxy_443: str | None = None |
| 109 |
4056c66 |
Dawsh |
1y ago |
|
| 110 |
4056c66 |
Dawsh |
1y ago |
|
| 111 |
4056c66 |
Dawsh |
1y ago |
class MuxSettings(BaseModel): |
| 112 |
4056c66 |
Dawsh |
1y ago |
protocol: str |
| 113 |
4056c66 |
Dawsh |
1y ago |
sing_box_mux_settings: SingBoxMuxSettings | None = None |
| 114 |
4056c66 |
Dawsh |
1y ago |
mux_cool_settings: MuxCoolSettings | None = None |
| 115 |
d636f3f |
Dawsh |
2y ago |
|
| 116 |
d636f3f |
Dawsh |
2y ago |
|
| 117 |
a47eb4c |
Dawsh |
2y ago |
class InboundHost(BaseModel): |
| 118 |
a47eb4c |
Dawsh |
2y ago |
remark: str |
| 119 |
a47eb4c |
Dawsh |
2y ago |
address: str |
| 120 |
4056c66 |
Dawsh |
1y ago |
uuid: str | None = None |
| 121 |
4056c66 |
Dawsh |
1y ago |
password: str | None = None |
| 122 |
4056c66 |
Dawsh |
1y ago |
protocol: ProxyTypes | str | None = None |
| 123 |
4056c66 |
Dawsh |
1y ago |
network: str | None = None |
| 124 |
db68a58 |
Dawsh |
2y ago |
port: int | None = Field(None) |
| 125 |
db68a58 |
Dawsh |
2y ago |
sni: str | None = Field(None) |
| 126 |
db68a58 |
Dawsh |
2y ago |
host: str | None = Field(None) |
| 127 |
db68a58 |
Dawsh |
2y ago |
path: str | None = Field(None) |
| 128 |
a47eb4c |
Dawsh |
2y ago |
security: InboundHostSecurity = InboundHostSecurity.inbound_default |
| 129 |
a47eb4c |
Dawsh |
2y ago |
alpn: InboundHostALPN = InboundHostALPN.none |
| 130 |
a47eb4c |
Dawsh |
2y ago |
fingerprint: InboundHostFingerprint = InboundHostFingerprint.none |
| 131 |
d636f3f |
Dawsh |
2y ago |
allowinsecure: bool | None = False |
| 132 |
d636f3f |
Dawsh |
2y ago |
is_disabled: bool | None = False |
| 133 |
db68a58 |
Dawsh |
2y ago |
fragment: FragmentSettings | None = Field(None) |
| 134 |
4056c66 |
Dawsh |
1y ago |
noise: list[XrayNoise] | None = None |
| 135 |
4056c66 |
Dawsh |
1y ago |
http_headers: dict[str, str] | None = Field(default_factory=dict) |
| 136 |
d636f3f |
Dawsh |
2y ago |
mtu: int | None = None |
| 137 |
d636f3f |
Dawsh |
2y ago |
dns_servers: str | None = None |
| 138 |
b584c6c |
Dawsh |
2y ago |
allowed_ips: str | None = None |
| 139 |
4056c66 |
Dawsh |
1y ago |
header_type: str | None = None |
| 140 |
4056c66 |
Dawsh |
1y ago |
reality_public_key: str | None = None |
| 141 |
4056c66 |
Dawsh |
1y ago |
reality_short_ids: list[str] | None = None |
| 142 |
4056c66 |
Dawsh |
1y ago |
flow: str | None = None |
| 143 |
4056c66 |
Dawsh |
1y ago |
shadowtls_version: int | None = None |
| 144 |
4056c66 |
Dawsh |
1y ago |
shadowsocks_method: str | None = None |
| 145 |
4056c66 |
Dawsh |
1y ago |
splithttp_settings: SplitHttpSettings | None = None |
| 146 |
4056c66 |
Dawsh |
1y ago |
early_data: int | None = None |
| 147 |
4056c66 |
Dawsh |
1y ago |
mux_settings: MuxSettings | None = None |
| 148 |
4056c66 |
Dawsh |
1y ago |
universal: bool = False |
| 149 |
4056c66 |
Dawsh |
1y ago |
service_ids: list[int] = Field(default_factory=list) |
| 150 |
e422d72 |
Dawsh |
2y ago |
weight: int = 1 |
| 151 |
d636f3f |
Dawsh |
2y ago |
inbound_id: int | None = None |
| 152 |
4056c66 |
Dawsh |
1y ago |
chain_ids: list[int] = Field(default_factory=list) |
| 153 |
4056c66 |
Dawsh |
1y ago |
|
| 154 |
a47eb4c |
Dawsh |
2y ago |
model_config = ConfigDict(from_attributes=True) |
| 155 |
a47eb4c |
Dawsh |
2y ago |
|
| 156 |
2127962 |
Dawsh |
2y ago |
@field_validator("remark", "address", "path") |
| 157 |
2127962 |
Dawsh |
2y ago |
@classmethod |
| 158 |
2127962 |
Dawsh |
2y ago |
def validate_fmt_variables(cls, v: str) -> str: |
| 159 |
a47eb4c |
Dawsh |
2y ago |
if not v: |
| 160 |
a47eb4c |
Dawsh |
2y ago |
return v |
| 161 |
2127962 |
Dawsh |
2y ago |
|
| 162 |
2127962 |
Dawsh |
2y ago |
v.format_map(FormatVariables()) |
| 163 |
a47eb4c |
Dawsh |
2y ago |
|
| 164 |
a47eb4c |
Dawsh |
2y ago |
return v |
| 165 |
a47eb4c |
Dawsh |
2y ago |
|
| 166 |
244c9d8 |
Dawsh |
2y ago |
@field_validator("alpn", mode="before") |
| 167 |
244c9d8 |
Dawsh |
2y ago |
@classmethod |
| 168 |
244c9d8 |
Dawsh |
2y ago |
def validate_alpn(cls, v): |
| 169 |
244c9d8 |
Dawsh |
2y ago |
if not v: |
| 170 |
244c9d8 |
Dawsh |
2y ago |
return InboundHostALPN.none |
| 171 |
244c9d8 |
Dawsh |
2y ago |
return v |
| 172 |
244c9d8 |
Dawsh |
2y ago |
|
| 173 |
a47eb4c |
Dawsh |
2y ago |
|
| 174 |
2de9d72 |
Dawsh |
2y ago |
class InboundHostResponse(InboundHost): |
| 175 |
2de9d72 |
Dawsh |
2y ago |
id: int |
| 176 |
2de9d72 |
Dawsh |
2y ago |
|
| 177 |
2de9d72 |
Dawsh |
2y ago |
|
| 178 |
db68a58 |
Dawsh |
2y ago |
class Inbound(BaseModel): |
| 179 |
db68a58 |
Dawsh |
2y ago |
id: int |
| 180 |
db68a58 |
Dawsh |
2y ago |
tag: str |
| 181 |
db68a58 |
Dawsh |
2y ago |
protocol: ProxyTypes |
| 182 |
4d647dd |
Dawsh |
2y ago |
config: str |
| 183 |
db68a58 |
Dawsh |
2y ago |
node: Node |
| 184 |
db68a58 |
Dawsh |
2y ago |
service_ids: list[int] |
| 185 |
a47eb4c |
Dawsh |
2y ago |
model_config = ConfigDict(from_attributes=True) |