config.dart 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. import 'package:json_annotation/json_annotation.dart';
  2. part 'config.g.dart';
  3. @JsonSerializable(includeIfNull: false)
  4. class SingBoxConfig {
  5. Log? log;
  6. Dns? dns;
  7. Route? route;
  8. List<Inbound>? inbounds;
  9. List<Outbound>? outbounds;
  10. Experimental? experimental;
  11. SingBoxConfig({
  12. this.log,
  13. this.dns,
  14. this.route,
  15. this.inbounds,
  16. this.outbounds,
  17. this.experimental,
  18. });
  19. factory SingBoxConfig.fromJson(Map<String, dynamic> json) =>
  20. _$SingBoxConfigFromJson(json);
  21. Map<String, dynamic> toJson() => _$SingBoxConfigToJson(this);
  22. }
  23. @JsonSerializable(includeIfNull: false)
  24. class Log {
  25. bool disabled;
  26. String? level;
  27. String? output;
  28. bool timestamp;
  29. Log({
  30. required this.disabled,
  31. this.level,
  32. this.output,
  33. required this.timestamp,
  34. });
  35. factory Log.fromJson(Map<String, dynamic> json) => _$LogFromJson(json);
  36. Map<String, dynamic> toJson() => _$LogToJson(this);
  37. }
  38. @JsonSerializable(includeIfNull: false)
  39. class Dns {
  40. List<DnsServer> servers;
  41. List<DnsRule> rules;
  42. Dns({
  43. required this.servers,
  44. required this.rules,
  45. });
  46. factory Dns.fromJson(Map<String, dynamic> json) => _$DnsFromJson(json);
  47. Map<String, dynamic> toJson() => _$DnsToJson(this);
  48. }
  49. @JsonSerializable(includeIfNull: false)
  50. class DnsServer {
  51. String tag;
  52. String address;
  53. @JsonKey(name: 'address_resolver')
  54. String? addressResolver;
  55. String? strategy;
  56. String? detour;
  57. DnsServer({
  58. required this.tag,
  59. required this.address,
  60. this.addressResolver,
  61. this.strategy,
  62. this.detour,
  63. });
  64. factory DnsServer.fromJson(Map<String, dynamic> json) =>
  65. _$DnsServerFromJson(json);
  66. Map<String, dynamic> toJson() => _$DnsServerToJson(this);
  67. }
  68. @JsonSerializable(includeIfNull: false)
  69. class RouteRule {
  70. String? protocol;
  71. List<String>? geosite;
  72. List<String>? geoip;
  73. List<String>? domain;
  74. @JsonKey(name: 'ip_cidr')
  75. List<String>? ipCidr;
  76. List<int>? port;
  77. @JsonKey(name: 'port_range')
  78. List<String>? portRange;
  79. String? outbound;
  80. @JsonKey(name: 'process_name')
  81. List<String>? processName;
  82. RouteRule({
  83. this.protocol,
  84. this.geosite,
  85. this.geoip,
  86. this.domain,
  87. this.ipCidr,
  88. this.port,
  89. this.portRange,
  90. this.outbound,
  91. this.processName,
  92. });
  93. factory RouteRule.fromJson(Map<String, dynamic> json) =>
  94. _$RouteRuleFromJson(json);
  95. Map<String, dynamic> toJson() => _$RouteRuleToJson(this);
  96. }
  97. @JsonSerializable(includeIfNull: false)
  98. class DnsRule {
  99. List<String>? geosite;
  100. List<String>? geoip;
  101. List<String>? domain;
  102. String? server;
  103. @JsonKey(name: 'disable_cache')
  104. bool? disableCache;
  105. List<String>? outbound;
  106. DnsRule({
  107. this.geosite,
  108. this.geoip,
  109. this.domain,
  110. this.server,
  111. this.disableCache,
  112. this.outbound,
  113. });
  114. factory DnsRule.fromJson(Map<String, dynamic> json) =>
  115. _$DnsRuleFromJson(json);
  116. Map<String, dynamic> toJson() => _$DnsRuleToJson(this);
  117. }
  118. @JsonSerializable(includeIfNull: false)
  119. class Route {
  120. Geoip? geoip;
  121. Geosite? geosite;
  122. List<RouteRule>? rules;
  123. @JsonKey(name: 'auto_detect_interface')
  124. bool autoDetectInterface;
  125. @JsonKey(name: 'final')
  126. String? finalTag;
  127. Route({
  128. this.geoip,
  129. this.geosite,
  130. this.rules,
  131. required this.autoDetectInterface,
  132. this.finalTag,
  133. });
  134. factory Route.fromJson(Map<String, dynamic> json) => _$RouteFromJson(json);
  135. Map<String, dynamic> toJson() => _$RouteToJson(this);
  136. }
  137. @JsonSerializable(includeIfNull: false)
  138. class Geoip {
  139. String path;
  140. Geoip({
  141. required this.path,
  142. });
  143. factory Geoip.fromJson(Map<String, dynamic> json) => _$GeoipFromJson(json);
  144. Map<String, dynamic> toJson() => _$GeoipToJson(this);
  145. }
  146. @JsonSerializable(includeIfNull: false)
  147. class Geosite {
  148. String path;
  149. Geosite({
  150. required this.path,
  151. });
  152. factory Geosite.fromJson(Map<String, dynamic> json) =>
  153. _$GeositeFromJson(json);
  154. Map<String, dynamic> toJson() => _$GeositeToJson(this);
  155. }
  156. @JsonSerializable(includeIfNull: false)
  157. class Inbound {
  158. String type;
  159. String? tag;
  160. String? listen;
  161. @JsonKey(name: 'listen_port')
  162. int? listenPort;
  163. List<User>? users;
  164. @JsonKey(name: 'interface_name')
  165. String? interfaceName;
  166. @JsonKey(name: 'inet4_address')
  167. String? inet4Address;
  168. @JsonKey(name: 'inet6_address')
  169. String? inet6Address;
  170. int? mtu;
  171. @JsonKey(name: 'auto_route')
  172. bool? autoRoute;
  173. @JsonKey(name: 'strict_route')
  174. bool? strictRoute;
  175. String? stack;
  176. bool? sniff;
  177. Inbound({
  178. required this.type,
  179. this.tag,
  180. this.listen,
  181. this.listenPort,
  182. this.users,
  183. this.interfaceName,
  184. this.inet4Address,
  185. this.inet6Address,
  186. this.mtu,
  187. this.autoRoute,
  188. this.strictRoute,
  189. this.stack,
  190. this.sniff,
  191. });
  192. factory Inbound.fromJson(Map<String, dynamic> json) =>
  193. _$InboundFromJson(json);
  194. Map<String, dynamic> toJson() => _$InboundToJson(this);
  195. }
  196. @JsonSerializable(includeIfNull: false)
  197. class Outbound {
  198. String type;
  199. String? tag;
  200. String? server;
  201. @JsonKey(name: 'server_port')
  202. int? serverPort;
  203. String? version;
  204. String? username;
  205. String? method;
  206. String? password;
  207. String? plugin;
  208. @JsonKey(name: 'plugin_opts')
  209. String? pluginOpts;
  210. String? uuid;
  211. String? flow;
  212. String? security;
  213. @JsonKey(name: 'alter_id')
  214. int? alterId;
  215. String? network;
  216. Tls? tls;
  217. Transport? transport;
  218. int? upMbps;
  219. int? downMbps;
  220. String? obfs;
  221. String? auth;
  222. @JsonKey(name: 'auth_str')
  223. String? authStr;
  224. @JsonKey(name: 'recv_window_conn')
  225. int? recvWindowConn;
  226. @JsonKey(name: 'recv_window')
  227. int? recvWindow;
  228. @JsonKey(name: 'disable_mtu_discovery')
  229. int? disableMtuDiscovery;
  230. Outbound({
  231. required this.type,
  232. this.tag,
  233. this.server,
  234. this.serverPort,
  235. this.version,
  236. this.username,
  237. this.method,
  238. this.password,
  239. this.plugin,
  240. this.pluginOpts,
  241. this.uuid,
  242. this.flow,
  243. this.security,
  244. this.alterId,
  245. this.network,
  246. this.tls,
  247. this.transport,
  248. this.upMbps,
  249. this.downMbps,
  250. this.obfs,
  251. this.auth,
  252. this.authStr,
  253. this.recvWindowConn,
  254. this.recvWindow,
  255. this.disableMtuDiscovery,
  256. });
  257. factory Outbound.fromJson(Map<String, dynamic> json) =>
  258. _$OutboundFromJson(json);
  259. Map<String, dynamic> toJson() => _$OutboundToJson(this);
  260. }
  261. @JsonSerializable(includeIfNull: false)
  262. class Tls {
  263. bool enabled;
  264. @JsonKey(name: 'server_name')
  265. String serverName;
  266. bool insecure;
  267. List<String>? alpn;
  268. UTls? utls;
  269. Reality? reality;
  270. Tls({
  271. required this.enabled,
  272. required this.serverName,
  273. required this.insecure,
  274. this.alpn,
  275. this.utls,
  276. this.reality,
  277. });
  278. factory Tls.fromJson(Map<String, dynamic> json) => _$TlsFromJson(json);
  279. Map<String, dynamic> toJson() => _$TlsToJson(this);
  280. }
  281. @JsonSerializable(includeIfNull: false)
  282. class UTls {
  283. bool enabled;
  284. String? fingerprint;
  285. UTls({
  286. required this.enabled,
  287. this.fingerprint,
  288. });
  289. factory UTls.fromJson(Map<String, dynamic> json) => _$UTlsFromJson(json);
  290. Map<String, dynamic> toJson() => _$UTlsToJson(this);
  291. }
  292. @JsonSerializable(includeIfNull: false)
  293. class Reality {
  294. bool enabled;
  295. @JsonKey(name: 'public_key')
  296. String publicKey;
  297. @JsonKey(name: "short_id")
  298. String? shortId;
  299. Reality({
  300. required this.enabled,
  301. required this.publicKey,
  302. this.shortId,
  303. });
  304. factory Reality.fromJson(Map<String, dynamic> json) =>
  305. _$RealityFromJson(json);
  306. Map<String, dynamic> toJson() => _$RealityToJson(this);
  307. }
  308. @JsonSerializable(includeIfNull: false)
  309. class Transport {
  310. String type;
  311. String? host;
  312. String? path;
  313. @JsonKey(name: 'service_name')
  314. String? serviceName;
  315. Transport({
  316. required this.type,
  317. this.host,
  318. this.path,
  319. this.serviceName,
  320. });
  321. factory Transport.fromJson(Map<String, dynamic> json) =>
  322. _$TransportFromJson(json);
  323. Map<String, dynamic> toJson() => _$TransportToJson(this);
  324. }
  325. @JsonSerializable(includeIfNull: false)
  326. class User {
  327. String? username;
  328. String? password;
  329. User({
  330. this.username,
  331. this.password,
  332. });
  333. factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
  334. Map<String, dynamic> toJson() => _$UserToJson(this);
  335. }
  336. @JsonSerializable(includeIfNull: false)
  337. class Experimental {
  338. @JsonKey(name: 'clash_api')
  339. ClashApi? clashApi;
  340. Experimental({
  341. this.clashApi,
  342. });
  343. factory Experimental.fromJson(Map<String, dynamic> json) =>
  344. _$ExperimentalFromJson(json);
  345. Map<String, dynamic> toJson() => _$ExperimentalToJson(this);
  346. }
  347. @JsonSerializable(includeIfNull: false)
  348. class ClashApi {
  349. @JsonKey(name: 'external_controller')
  350. String externalController;
  351. @JsonKey(name: 'store_selected')
  352. bool storeSelected;
  353. @JsonKey(name: 'cache_file')
  354. String? cacheFile;
  355. ClashApi({
  356. required this.externalController,
  357. required this.storeSelected,
  358. this.cacheFile,
  359. });
  360. factory ClashApi.fromJson(Map<String, dynamic> json) =>
  361. _$ClashApiFromJson(json);
  362. Map<String, dynamic> toJson() => _$ClashApiToJson(this);
  363. }