config.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. import 'package:json_annotation/json_annotation.dart';
  2. part 'config.g.dart';
  3. @JsonSerializable(includeIfNull: false)
  4. class XrayConfig {
  5. Log? log;
  6. Dns? dns;
  7. List<Inbound>? inbounds;
  8. List<Outbound>? outbounds;
  9. Routing? routing;
  10. Api? api;
  11. Policy? policy;
  12. Stats? stats;
  13. XrayConfig({
  14. this.log,
  15. this.dns,
  16. this.inbounds,
  17. this.outbounds,
  18. this.routing,
  19. this.api,
  20. this.policy,
  21. this.stats,
  22. });
  23. factory XrayConfig.fromJson(Map<String, dynamic> json) =>
  24. _$XrayConfigFromJson(json);
  25. Map<String, dynamic> toJson() => _$XrayConfigToJson(this);
  26. }
  27. @JsonSerializable(includeIfNull: false)
  28. class Sniffing {
  29. bool enabled = true;
  30. List<String> destOverride = ['http', 'tls'];
  31. Sniffing();
  32. factory Sniffing.fromJson(Map<String, dynamic> json) =>
  33. _$SniffingFromJson(json);
  34. Map<String, dynamic> toJson() => _$SniffingToJson(this);
  35. }
  36. @JsonSerializable(includeIfNull: false)
  37. class Dns {
  38. List<DnsServer> servers;
  39. Dns({
  40. required this.servers,
  41. });
  42. factory Dns.fromJson(Map<String, dynamic> json) => _$DnsFromJson(json);
  43. Map<String, dynamic> toJson() => _$DnsToJson(this);
  44. }
  45. @JsonSerializable(includeIfNull: false)
  46. class DnsServer {
  47. String address;
  48. List<String>? domains;
  49. bool? skipFallback;
  50. DnsServer({
  51. required this.address,
  52. this.domains,
  53. this.skipFallback,
  54. });
  55. factory DnsServer.fromJson(Map<String, dynamic> json) =>
  56. _$DnsServerFromJson(json);
  57. Map<String, dynamic> toJson() => _$DnsServerToJson(this);
  58. }
  59. @JsonSerializable(includeIfNull: false)
  60. class Log {
  61. String? access;
  62. String? error;
  63. String loglevel;
  64. Log({
  65. this.access,
  66. this.error,
  67. required this.loglevel,
  68. });
  69. factory Log.fromJson(Map<String, dynamic> json) => _$LogFromJson(json);
  70. Map<String, dynamic> toJson() => _$LogToJson(this);
  71. }
  72. @JsonSerializable(includeIfNull: false)
  73. class Inbound {
  74. String? tag;
  75. int port;
  76. String listen;
  77. String protocol;
  78. Sniffing? sniffing;
  79. InboundSetting settings;
  80. Inbound({
  81. this.tag,
  82. required this.port,
  83. required this.listen,
  84. required this.protocol,
  85. this.sniffing,
  86. required this.settings,
  87. });
  88. factory Inbound.fromJson(Map<String, dynamic> json) =>
  89. _$InboundFromJson(json);
  90. Map<String, dynamic> toJson() => _$InboundToJson(this);
  91. }
  92. @JsonSerializable(includeIfNull: false)
  93. class InboundSetting {
  94. String? auth;
  95. List<Accounts>? accounts;
  96. bool? udp;
  97. String? address;
  98. InboundSetting({
  99. this.auth,
  100. this.accounts,
  101. this.udp,
  102. this.address,
  103. });
  104. factory InboundSetting.fromJson(Map<String, dynamic> json) =>
  105. _$InboundSettingFromJson(json);
  106. Map<String, dynamic> toJson() => _$InboundSettingToJson(this);
  107. }
  108. @JsonSerializable(includeIfNull: false)
  109. class Accounts {
  110. String user;
  111. String pass;
  112. Accounts({
  113. required this.user,
  114. required this.pass,
  115. });
  116. factory Accounts.fromJson(Map<String, dynamic> json) =>
  117. _$AccountsFromJson(json);
  118. Map<String, dynamic> toJson() => _$AccountsToJson(this);
  119. }
  120. @JsonSerializable(includeIfNull: false)
  121. class Outbound {
  122. String? tag;
  123. String protocol;
  124. OutboundSetting? settings;
  125. StreamSettings? streamSettings;
  126. Mux? mux;
  127. Outbound({
  128. this.tag,
  129. required this.protocol,
  130. this.settings,
  131. this.streamSettings,
  132. this.mux,
  133. });
  134. factory Outbound.fromJson(Map<String, dynamic> json) =>
  135. _$OutboundFromJson(json);
  136. Map<String, dynamic> toJson() => _$OutboundToJson(this);
  137. }
  138. @JsonSerializable(includeIfNull: false)
  139. class OutboundSetting {
  140. List<Vnext>? vnext;
  141. List<dynamic>? servers;
  142. OutboundSetting({
  143. this.vnext,
  144. this.servers,
  145. });
  146. factory OutboundSetting.fromJson(Map<String, dynamic> json) =>
  147. _$OutboundSettingFromJson(json);
  148. Map<String, dynamic> toJson() => _$OutboundSettingToJson(this);
  149. }
  150. @JsonSerializable(includeIfNull: false)
  151. class Socks {
  152. String address;
  153. int port;
  154. List<User>? users;
  155. Socks({
  156. required this.address,
  157. required this.port,
  158. this.users,
  159. });
  160. factory Socks.fromJson(Map<String, dynamic> json) => _$SocksFromJson(json);
  161. Map<String, dynamic> toJson() => _$SocksToJson(this);
  162. }
  163. @JsonSerializable(includeIfNull: false)
  164. class Vnext {
  165. String address;
  166. int port;
  167. List<User> users;
  168. Vnext({
  169. required this.address,
  170. required this.port,
  171. required this.users,
  172. });
  173. factory Vnext.fromJson(Map<String, dynamic> json) => _$VnextFromJson(json);
  174. Map<String, dynamic> toJson() => _$VnextToJson(this);
  175. }
  176. @JsonSerializable(includeIfNull: false)
  177. class Shadowsocks {
  178. String address;
  179. int port;
  180. String method;
  181. String password;
  182. Shadowsocks({
  183. required this.address,
  184. required this.port,
  185. required this.method,
  186. required this.password,
  187. });
  188. factory Shadowsocks.fromJson(Map<String, dynamic> json) =>
  189. _$ShadowsocksFromJson(json);
  190. Map<String, dynamic> toJson() => _$ShadowsocksToJson(this);
  191. }
  192. @JsonSerializable(includeIfNull: false)
  193. class Trojan {
  194. String address;
  195. int port;
  196. String password;
  197. Trojan({
  198. required this.address,
  199. required this.port,
  200. required this.password,
  201. });
  202. factory Trojan.fromJson(Map<String, dynamic> json) => _$TrojanFromJson(json);
  203. Map<String, dynamic> toJson() => _$TrojanToJson(this);
  204. }
  205. @JsonSerializable(includeIfNull: false)
  206. class User {
  207. String? user;
  208. String? pass;
  209. String? id;
  210. int? alterId;
  211. String? security;
  212. String? encryption;
  213. String? flow;
  214. User({
  215. this.user,
  216. this.pass,
  217. this.id,
  218. this.alterId,
  219. this.security,
  220. this.encryption,
  221. this.flow,
  222. });
  223. factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
  224. Map<String, dynamic> toJson() => _$UserToJson(this);
  225. }
  226. @JsonSerializable(includeIfNull: false)
  227. class StreamSettings {
  228. String network;
  229. String security;
  230. TlsSettings? tlsSettings;
  231. RealitySettings? realitySettings;
  232. TcpSettings? tcpSettings;
  233. WsSettings? wsSettings;
  234. GrpcSettings? grpcSettings;
  235. StreamSettings({
  236. required this.network,
  237. required this.security,
  238. this.tlsSettings,
  239. this.realitySettings,
  240. this.tcpSettings,
  241. this.wsSettings,
  242. this.grpcSettings,
  243. });
  244. factory StreamSettings.fromJson(Map<String, dynamic> json) =>
  245. _$StreamSettingsFromJson(json);
  246. Map<String, dynamic> toJson() => _$StreamSettingsToJson(this);
  247. }
  248. @JsonSerializable(includeIfNull: false)
  249. class TcpSettings {
  250. Header? header;
  251. TcpSettings({
  252. this.header,
  253. });
  254. factory TcpSettings.fromJson(Map<String, dynamic> json) =>
  255. _$TcpSettingsFromJson(json);
  256. Map<String, dynamic> toJson() => _$TcpSettingsToJson(this);
  257. }
  258. @JsonSerializable(includeIfNull: false)
  259. class Header {
  260. String? type;
  261. Request? request;
  262. Header({
  263. this.type,
  264. this.request,
  265. });
  266. factory Header.fromJson(Map<String, dynamic> json) => _$HeaderFromJson(json);
  267. Map<String, dynamic> toJson() => _$HeaderToJson(this);
  268. }
  269. @JsonSerializable(includeIfNull: false)
  270. class Request {
  271. String? version;
  272. String? method;
  273. List<String>? path;
  274. TcpHeaders? headers;
  275. Request({
  276. this.version,
  277. this.method,
  278. this.path,
  279. this.headers,
  280. });
  281. factory Request.defaults() => Request(
  282. version: '1.1',
  283. method: 'GET',
  284. path: ['/'],
  285. headers: TcpHeaders.defaults(),
  286. );
  287. factory Request.fromJson(Map<String, dynamic> json) =>
  288. _$RequestFromJson(json);
  289. Map<String, dynamic> toJson() => _$RequestToJson(this);
  290. }
  291. @JsonSerializable(includeIfNull: false)
  292. class TcpHeaders {
  293. @JsonKey(name: 'Host')
  294. List<String>? host;
  295. @JsonKey(name: 'User-Agent')
  296. List<String>? userAgent;
  297. @JsonKey(name: 'Accept-Encoding')
  298. List<String>? acceptEncoding;
  299. @JsonKey(name: 'Connection')
  300. List<String>? connection;
  301. @JsonKey(name: 'Pragma')
  302. String? pragma;
  303. TcpHeaders({
  304. this.host,
  305. this.userAgent,
  306. this.acceptEncoding,
  307. this.connection,
  308. this.pragma,
  309. });
  310. factory TcpHeaders.defaults() => TcpHeaders(
  311. host: [''],
  312. userAgent: [''],
  313. acceptEncoding: ['gzip, deflate'],
  314. connection: ['keep-alive'],
  315. pragma: 'no-cache',
  316. );
  317. factory TcpHeaders.fromJson(Map<String, dynamic> json) =>
  318. _$TcpHeadersFromJson(json);
  319. Map<String, dynamic> toJson() => _$TcpHeadersToJson(this);
  320. }
  321. @JsonSerializable(includeIfNull: false)
  322. class GrpcSettings {
  323. String? serviceName;
  324. bool? multiMode;
  325. GrpcSettings({
  326. this.serviceName,
  327. this.multiMode,
  328. });
  329. factory GrpcSettings.fromJson(Map<String, dynamic> json) =>
  330. _$GrpcSettingsFromJson(json);
  331. Map<String, dynamic> toJson() => _$GrpcSettingsToJson(this);
  332. }
  333. @JsonSerializable(includeIfNull: false)
  334. class WsSettings {
  335. String path;
  336. Headers? headers;
  337. WsSettings({
  338. required this.path,
  339. this.headers,
  340. });
  341. factory WsSettings.fromJson(Map<String, dynamic> json) =>
  342. _$WsSettingsFromJson(json);
  343. Map<String, dynamic> toJson() => _$WsSettingsToJson(this);
  344. }
  345. @JsonSerializable(includeIfNull: false)
  346. class Headers {
  347. String? host;
  348. Headers({
  349. this.host,
  350. });
  351. factory Headers.fromJson(Map<String, dynamic> json) =>
  352. _$HeadersFromJson(json);
  353. Map<String, dynamic> toJson() => _$HeadersToJson(this);
  354. }
  355. @JsonSerializable(includeIfNull: false)
  356. class TlsSettings {
  357. bool allowInsecure;
  358. String? serverName;
  359. String? fingerprint;
  360. TlsSettings({
  361. required this.allowInsecure,
  362. this.serverName,
  363. this.fingerprint,
  364. });
  365. factory TlsSettings.fromJson(Map<String, dynamic> json) =>
  366. _$TlsSettingsFromJson(json);
  367. Map<String, dynamic> toJson() => _$TlsSettingsToJson(this);
  368. }
  369. @JsonSerializable(includeIfNull: false)
  370. class RealitySettings {
  371. String? serverName;
  372. String fingerprint;
  373. String? shortID;
  374. String publicKey;
  375. String? spiderX;
  376. RealitySettings({
  377. this.serverName,
  378. required this.fingerprint,
  379. this.shortID,
  380. required this.publicKey,
  381. this.spiderX,
  382. });
  383. factory RealitySettings.fromJson(Map<String, dynamic> json) =>
  384. _$RealitySettingsFromJson(json);
  385. Map<String, dynamic> toJson() => _$RealitySettingsToJson(this);
  386. }
  387. @JsonSerializable(includeIfNull: false)
  388. class Mux {
  389. bool enabled;
  390. int concurrency;
  391. Mux({
  392. required this.enabled,
  393. required this.concurrency,
  394. });
  395. factory Mux.fromJson(Map<String, dynamic> json) => _$MuxFromJson(json);
  396. Map<String, dynamic> toJson() => _$MuxToJson(this);
  397. }
  398. @JsonSerializable(includeIfNull: false)
  399. class Routing {
  400. String domainStrategy;
  401. String domainMatcher;
  402. List<XrayRule> rules;
  403. Routing({
  404. required this.domainStrategy,
  405. required this.domainMatcher,
  406. required this.rules,
  407. });
  408. factory Routing.fromJson(Map<String, dynamic> json) =>
  409. _$RoutingFromJson(json);
  410. Map<String, dynamic> toJson() => _$RoutingToJson(this);
  411. }
  412. @JsonSerializable(includeIfNull: false)
  413. class XrayRule {
  414. String? name;
  415. bool enabled;
  416. String type;
  417. String? inboundTag;
  418. String? outboundTag;
  419. List<String>? domain;
  420. List<String>? ip;
  421. String? port;
  422. XrayRule({
  423. this.name,
  424. required this.enabled,
  425. required this.type,
  426. this.inboundTag,
  427. this.outboundTag,
  428. this.domain,
  429. this.ip,
  430. this.port,
  431. });
  432. factory XrayRule.fromJson(Map<String, dynamic> json) =>
  433. _$XrayRuleFromJson(json);
  434. Map<String, dynamic> toJson() => _$XrayRuleToJson(this);
  435. }
  436. @JsonSerializable(includeIfNull: false)
  437. class Api {
  438. String tag;
  439. List<String>? services;
  440. Api({
  441. required this.tag,
  442. this.services,
  443. });
  444. factory Api.fromJson(Map<String, dynamic> json) => _$ApiFromJson(json);
  445. Map<String, dynamic> toJson() => _$ApiToJson(this);
  446. }
  447. @JsonSerializable(includeIfNull: false)
  448. class Policy {
  449. System system;
  450. Policy({
  451. required this.system,
  452. });
  453. factory Policy.fromJson(Map<String, dynamic> json) => _$PolicyFromJson(json);
  454. Map<String, dynamic> toJson() => _$PolicyToJson(this);
  455. }
  456. @JsonSerializable(includeIfNull: false)
  457. class System {
  458. bool? statsInboundUplink;
  459. bool? statsInboundDownlink;
  460. bool? statsOutboundUplink;
  461. bool? statsOutboundDownlink;
  462. System({
  463. this.statsInboundUplink,
  464. this.statsInboundDownlink,
  465. this.statsOutboundUplink,
  466. this.statsOutboundDownlink,
  467. });
  468. factory System.fromJson(Map<String, dynamic> json) => _$SystemFromJson(json);
  469. Map<String, dynamic> toJson() => _$SystemToJson(this);
  470. }
  471. @JsonSerializable(includeIfNull: false)
  472. class Stats {
  473. Stats();
  474. factory Stats.fromJson(Map<String, dynamic> json) => _$StatsFromJson(json);
  475. Map<String, dynamic> toJson() => _$StatsToJson(this);
  476. }