xfuture 1.5.1 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
package/config.js CHANGED
@@ -1,447 +1,448 @@
1
1
 
2
+ let os = require("os");
3
+
2
4
  class xConfiguration {
3
5
 
4
6
  }
5
7
 
6
8
  const xConfig = new xConfiguration;
7
- xConfig.ai = {
8
- "log": {
9
- "level": "warn",
10
- "timestamp": true
11
- },
12
- "dns": {
13
- "servers": [
14
- {
15
- "tag": "remote",
16
- "address": "tcp://8.8.8.8",
17
- "detour": "proxy"
18
- },
19
- {
20
- "tag": "local",
21
- "address": "223.5.5.5",
22
- "detour": "direct"
23
- },
24
- {
25
- "tag": "block",
26
- "address": "rcode://success"
27
- },
28
- {
29
- "tag": "local_local",
30
- "address": "223.5.5.5",
31
- "detour": "direct"
32
- }
33
- ],
34
- "rules": [
35
- {
36
- "server": "local",
37
- "disable_cache": true,
38
- "geosite": [
39
- "cn"
40
- ]
41
- },
42
- {
43
- "server": "block",
44
- "disable_cache": true,
45
- "geosite": [
46
- "category-ads-all"
47
- ]
48
- },
49
- {
50
- "outbound": "any",
51
- "server": "local_local"
52
- }
53
- ],
54
- "strategy": "ipv4_only"
55
- },
56
- "inbounds": [
57
- {
58
- "type": "tun",
59
- "tag": "tun-in",
60
- "interface_name": "singbox_tun",
61
- "inet4_address": "172.19.0.1/30",
62
- "inet6_address": "fdfe:dcba:9876::1/126",
63
- "mtu": 9000,
64
- "auto_route": true,
65
- "strict_route": true,
66
- "stack": "gvisor",
67
- "sniff": true
68
- }
69
- ],
70
- "outbounds": [
9
+
10
+
11
+ xConfig.dns = {
12
+ "servers": [
71
13
  {
72
- "type": "socks",
73
- "tag": "proxy",
74
- "server": "127.0.0.1",
75
- "server_port": 1081
14
+ "tag": "remote",
15
+ "address": "tcp://8.8.8.8",
16
+ "detour": "proxy"
76
17
  },
77
18
  {
78
- "type": "direct",
79
- "tag": "direct"
19
+ "tag": "local",
20
+ "address": "223.5.5.5",
21
+ "detour": "direct"
80
22
  },
81
23
  {
82
- "type": "block",
83
- "tag": "block"
24
+ "tag": "block",
25
+ "address": "rcode://success"
84
26
  },
85
27
  {
86
- "type": "dns",
87
- "tag": "dns_out"
28
+ "tag": "local_local",
29
+ "address": "223.5.5.5",
30
+ "detour": "direct"
88
31
  }
89
32
  ],
90
- "route": {
91
- "auto_detect_interface": true,
92
- "geoip":{
93
- "path":"D:\\linkv\\maodou\\xfuture\\resources\\geoip.db"
33
+ "rules": [
34
+ {
35
+ "server": "local",
36
+ "disable_cache": true,
37
+ "geosite": [
38
+ "cn"
39
+ ]
94
40
  },
95
- "geosite":{
96
- "path":"D:\\linkv\\maodou\\xfuture\\resources\\geosite.db"
41
+ {
42
+ "server": "block",
43
+ "disable_cache": true,
44
+ "geosite": [
45
+ "category-ads-all"
46
+ ]
97
47
  },
98
- "rules": [
99
- {
100
- "outbound": "dns_out",
101
- "inbound": [
102
- "dns_in"
103
- ]
104
- },
105
- {
106
- "outbound": "dns_out",
107
- "protocol": [
108
- "dns"
109
- ]
110
- },
111
- {
112
- "outbound": "block",
113
- "network": "udp",
114
- "port": [
115
- 135,
116
- 137,
117
- 138,
118
- 139,
119
- 5353
120
- ]
121
- },
122
- {
123
- "outbound": "block",
124
- "ip_cidr": [
125
- "224.0.0.0/3",
126
- "ff00::/8"
127
- ]
128
- },
129
- {
130
- "outbound": "block",
131
- "source_ip_cidr": [
132
- "224.0.0.0/3",
133
- "ff00::/8"
134
- ]
135
- },
136
- {
137
- "outbound": "dns_out",
138
- "port": [
139
- 53
140
- ],
141
- "process_name": [
142
- "wv2ray.exe",
143
- "v2ray.exe",
144
- "SagerNet.exe",
145
- "v2ray.exe",
146
- "v2ray.exe",
147
- "xray.exe",
148
- "wxray.exe",
149
- "clash-windows-amd64-v3.exe",
150
- "clash-windows-amd64.exe",
151
- "clash-windows-386.exe",
152
- "clash.exe",
153
- "Clash.Meta-windows-amd64-compatible.exe",
154
- "Clash.Meta-windows-amd64.exe",
155
- "Clash.Meta-windows-386.exe",
156
- "Clash.Meta.exe",
157
- "clash.exe",
158
- "hysteria-windows-amd64.exe",
159
- "hysteria-windows-386.exe",
160
- "hysteria.exe",
161
- "naiveproxy.exe",
162
- "naive.exe",
163
- "tuic-client.exe",
164
- "tuic.exe",
165
- "juicity-client.exe",
166
- "juicity.exe",
167
- "electron.exe",
168
- "maodou.exe"
169
- ]
170
- },
171
- {
172
- "outbound": "direct",
173
- "process_name": [
174
- "wv2ray.exe",
175
- "v2ray.exe",
176
- "SagerNet.exe",
177
- "v2ray.exe",
178
- "v2ray.exe",
179
- "xray.exe",
180
- "wxray.exe",
181
- "clash-windows-amd64-v3.exe",
182
- "clash-windows-amd64.exe",
183
- "clash-windows-386.exe",
184
- "clash.exe",
185
- "Clash.Meta-windows-amd64-compatible.exe",
186
- "Clash.Meta-windows-amd64.exe",
187
- "Clash.Meta-windows-386.exe",
188
- "Clash.Meta.exe",
189
- "clash.exe",
190
- "hysteria-windows-amd64.exe",
191
- "hysteria-windows-386.exe",
192
- "hysteria.exe",
193
- "naiveproxy.exe",
194
- "naive.exe",
195
- "tuic-client.exe",
196
- "tuic.exe",
197
- "sing-box-client.exe",
198
- "sing-box.exe",
199
- "juicity-client.exe",
200
- "juicity.exe",
201
- "electron.exe",
202
- "maodou.exe"
203
- ]
204
- },
205
- {
206
- "outbound": "direct",
207
- "domain": [
208
- "example-example.com",
209
- "example-example2.com"
210
- ],
211
- "domain_suffix": [
212
- ".example-example.com",
213
- ".example-example2.com"
214
- ]
215
- },
216
- {
217
- "outbound": "block",
218
- "geosite": [
219
- "category-ads-all"
220
- ]
221
- },
222
- {
223
- "outbound": "direct",
224
- "geosite": [
225
- "cn"
226
- ]
227
- },
228
- {
229
- "outbound": "direct",
230
- "geoip": [
231
- "private",
232
- "cn"
233
- ]
234
- }
235
- ]
236
- }
48
+ {
49
+ "outbound": "any",
50
+ "server": "local_local"
51
+ }
52
+ ],
53
+ "strategy": "ipv4_only"
237
54
  }
238
55
 
239
- xConfig.global = {
240
- "log": {
241
- "level": "warn",
242
- "timestamp": true
56
+ xConfig.general = {
57
+ "geoip":{
58
+ "path":"D:\\linkv\\maodou\\xfuture\\resources\\geoip.db"
243
59
  },
244
- "dns": {
245
- "servers": [
246
- {
247
- "tag": "remote",
248
- "address": "tcp://8.8.8.8",
249
- "detour": "proxy"
250
- },
251
- {
252
- "tag": "local",
253
- "address": "223.5.5.5",
254
- "detour": "direct"
255
- },
256
- {
257
- "tag": "block",
258
- "address": "rcode://success"
259
- },
260
- {
261
- "tag": "local_local",
262
- "address": "223.5.5.5",
263
- "detour": "direct"
264
- }
265
- ],
266
- "rules": [
267
- {
268
- "server": "local",
269
- "disable_cache": true,
270
- "geosite": [
271
- "cn"
272
- ]
273
- },
274
- {
275
- "server": "block",
276
- "disable_cache": true,
277
- "geosite": [
278
- "category-ads-all"
279
- ]
280
- },
281
- {
282
- "outbound": "any",
283
- "server": "local_local"
284
- }
285
- ],
286
- "strategy": "ipv4_only"
60
+ "geosite":{
61
+ "path":"D:\\linkv\\maodou\\xfuture\\resources\\geosite.db"
287
62
  },
288
- "inbounds": [
63
+ "auto_detect_interface": true,
64
+ "rules": [
289
65
  {
290
- "type": "tun",
291
- "tag": "tun-in",
292
- "interface_name": "singbox_tun",
293
- "inet4_address": "172.19.0.1/30",
294
- "inet6_address": "fdfe:dcba:9876::1/126",
295
- "mtu": 9000,
296
- "auto_route": true,
297
- "strict_route": true,
298
- "stack": "gvisor",
299
- "sniff": true
300
- }
301
- ],
302
- "outbounds": [
66
+ "outbound": "dns_out",
67
+ "inbound": [
68
+ "dns_in"
69
+ ]
70
+ },
303
71
  {
304
- "type": "socks",
305
- "tag": "proxy",
306
- "server": "127.0.0.1",
307
- "server_port": 1081
72
+ "outbound": "dns_out",
73
+ "protocol": [
74
+ "dns"
75
+ ]
308
76
  },
309
77
  {
310
- "type": "direct",
311
- "tag": "direct"
78
+ "outbound": "block",
79
+ "network": "udp",
80
+ "port": [
81
+ 135,
82
+ 137,
83
+ 138,
84
+ 139,
85
+ 5353
86
+ ]
312
87
  },
313
88
  {
314
- "type": "block",
315
- "tag": "block"
89
+ "outbound": "block",
90
+ "ip_cidr": [
91
+ "224.0.0.0/3",
92
+ "ff00::/8"
93
+ ]
316
94
  },
317
95
  {
318
- "type": "dns",
319
- "tag": "dns_out"
320
- }
321
- ],
322
- "route": {
323
- "geoip":{
324
- "path":"D:\\linkv\\maodou\\xfuture\\resources\\geoip.db"
96
+ "outbound": "block",
97
+ "source_ip_cidr": [
98
+ "224.0.0.0/3",
99
+ "ff00::/8"
100
+ ]
325
101
  },
326
- "geosite":{
327
- "path":"D:\\linkv\\maodou\\xfuture\\resources\\geosite.db"
102
+ {
103
+ "outbound": "dns_out",
104
+ "port": [
105
+ 53
106
+ ],
107
+ "process_name": [
108
+ "wv2ray.exe",
109
+ "v2ray.exe",
110
+ "SagerNet.exe",
111
+ "v2ray.exe",
112
+ "v2ray.exe",
113
+ "xray.exe",
114
+ "wxray.exe",
115
+ "clash-windows-amd64-v3.exe",
116
+ "clash-windows-amd64.exe",
117
+ "clash-windows-386.exe",
118
+ "clash.exe",
119
+ "Clash.Meta-windows-amd64-compatible.exe",
120
+ "Clash.Meta-windows-amd64.exe",
121
+ "Clash.Meta-windows-386.exe",
122
+ "Clash.Meta.exe",
123
+ "clash.exe",
124
+ "hysteria-windows-amd64.exe",
125
+ "hysteria-windows-386.exe",
126
+ "hysteria.exe",
127
+ "naiveproxy.exe",
128
+ "naive.exe",
129
+ "tuic-client.exe",
130
+ "tuic.exe",
131
+ "juicity-client.exe",
132
+ "juicity.exe",
133
+ "electron.exe",
134
+ "maodou.exe"
135
+ ]
328
136
  },
329
- "auto_detect_interface": true,
330
- "rules": [
331
- {
332
- "outbound": "dns_out",
333
- "inbound": [
334
- "dns_in"
335
- ]
336
- },
337
- {
338
- "outbound": "dns_out",
339
- "protocol": [
340
- "dns"
341
- ]
342
- },
343
- {
344
- "outbound": "block",
345
- "network": "udp",
346
- "port": [
347
- 135,
348
- 137,
349
- 138,
350
- 139,
351
- 5353
352
- ]
353
- },
354
- {
355
- "outbound": "block",
356
- "ip_cidr": [
357
- "224.0.0.0/3",
358
- "ff00::/8"
359
- ]
360
- },
361
- {
362
- "outbound": "block",
363
- "source_ip_cidr": [
364
- "224.0.0.0/3",
365
- "ff00::/8"
366
- ]
367
- },
368
- {
369
- "outbound": "dns_out",
370
- "port": [
371
- 53
372
- ],
373
- "process_name": [
374
- "wv2ray.exe",
375
- "v2ray.exe",
376
- "SagerNet.exe",
377
- "v2ray.exe",
378
- "v2ray.exe",
379
- "xray.exe",
380
- "wxray.exe",
381
- "clash-windows-amd64-v3.exe",
382
- "clash-windows-amd64.exe",
383
- "clash-windows-386.exe",
384
- "clash.exe",
385
- "Clash.Meta-windows-amd64-compatible.exe",
386
- "Clash.Meta-windows-amd64.exe",
387
- "Clash.Meta-windows-386.exe",
388
- "Clash.Meta.exe",
389
- "clash.exe",
390
- "hysteria-windows-amd64.exe",
391
- "hysteria-windows-386.exe",
392
- "hysteria.exe",
393
- "naiveproxy.exe",
394
- "naive.exe",
395
- "tuic-client.exe",
396
- "tuic.exe",
397
- "juicity-client.exe",
398
- "juicity.exe",
399
- "electron.exe",
400
- "maodou.exe"
401
- ]
402
- },
403
- {
404
- "outbound": "direct",
405
- "process_name": [
406
- "wv2ray.exe",
407
- "v2ray.exe",
408
- "SagerNet.exe",
409
- "v2ray.exe",
410
- "v2ray.exe",
411
- "xray.exe",
412
- "wxray.exe",
413
- "clash-windows-amd64-v3.exe",
414
- "clash-windows-amd64.exe",
415
- "clash-windows-386.exe",
416
- "clash.exe",
417
- "Clash.Meta-windows-amd64-compatible.exe",
418
- "Clash.Meta-windows-amd64.exe",
419
- "Clash.Meta-windows-386.exe",
420
- "Clash.Meta.exe",
421
- "clash.exe",
422
- "hysteria-windows-amd64.exe",
423
- "hysteria-windows-386.exe",
424
- "hysteria.exe",
425
- "naiveproxy.exe",
426
- "naive.exe",
427
- "tuic-client.exe",
428
- "tuic.exe",
429
- "sing-box-client.exe",
430
- "sing-box.exe",
431
- "juicity-client.exe",
432
- "juicity.exe",
433
- "electron.exe",
434
- "maodou.exe"
435
- ]
436
- },
437
- {
438
- "outbound": "proxy",
439
- "port_range": [
440
- "0:65535"
441
- ]
137
+ {
138
+ "outbound": "direct",
139
+ "process_name": [
140
+ "wv2ray.exe",
141
+ "v2ray.exe",
142
+ "SagerNet.exe",
143
+ "v2ray.exe",
144
+ "v2ray.exe",
145
+ "xray.exe",
146
+ "wxray.exe",
147
+ "clash-windows-amd64-v3.exe",
148
+ "clash-windows-amd64.exe",
149
+ "clash-windows-386.exe",
150
+ "clash.exe",
151
+ "Clash.Meta-windows-amd64-compatible.exe",
152
+ "Clash.Meta-windows-amd64.exe",
153
+ "Clash.Meta-windows-386.exe",
154
+ "Clash.Meta.exe",
155
+ "clash.exe",
156
+ "hysteria-windows-amd64.exe",
157
+ "hysteria-windows-386.exe",
158
+ "hysteria.exe",
159
+ "naiveproxy.exe",
160
+ "naive.exe",
161
+ "tuic-client.exe",
162
+ "tuic.exe",
163
+ "sing-box-client.exe",
164
+ "sing-box.exe",
165
+ "juicity-client.exe",
166
+ "juicity.exe",
167
+ "electron.exe",
168
+ "maodou.exe"
169
+ ]
170
+ }
171
+ ]
172
+ }
173
+
174
+ xConfig.rules = [];
175
+
176
+ xConfig.setRouterConfiguration = function(rules) {
177
+ this.rules = rules;
178
+ if (rules == null || rules == undefined) {
179
+ this.rules = [];
180
+ }
181
+ }
182
+
183
+ function get_external_rules(){
184
+
185
+ var rules = [];
186
+
187
+ var ips_direct = [];
188
+ var ips_block = [];
189
+ var ips_proxy = [];
190
+
191
+ var domains_direct = [];
192
+ var domains_block = [];
193
+ var domains_proxy = [];
194
+
195
+ for (let index = 0; index < xConfig.rules.length; index++) {
196
+ const element = xConfig.rules[index];
197
+ if (element.type == "domain") {
198
+ if (element.method == "block") {
199
+ domains_block.push(element.content);
442
200
  }
201
+ else if (element.method == "direct") {
202
+ domains_direct.push(element.content);
203
+ }
204
+ else {
205
+ domains_proxy.push(element.content);
206
+ }
207
+ }
208
+ else {
209
+ if (element.method == "block") {
210
+ ips_block.push(element.content + "");
211
+ }
212
+ else if (element.method == "direct") {
213
+ ips_direct.push(element.content);
214
+ }
215
+ else {
216
+ ips_proxy.push(element.content);
217
+ }
218
+ }
219
+
220
+ if (ips_block.length > 0) {
221
+ var x = {};
222
+ x.outbound = "block";
223
+ x.ip_cidr = ips_block;
224
+ rules.push(x);
225
+ }
226
+
227
+ if (ips_direct.length > 0) {
228
+ var x = {};
229
+ x.outbound = "direct";
230
+ x.ip_cidr = ips_direct;
231
+ rules.push(x);
232
+ }
233
+
234
+ if (ips_proxy.length > 0) {
235
+ var x = {};
236
+ x.outbound = "proxy";
237
+ x.ip_cidr = ips_proxy;
238
+ rules.push(x);
239
+ }
240
+
241
+ if (domains_block.length > 0) {
242
+ var x = {};
243
+ x.outbound = "block";
244
+ x.domain = domains_block;
245
+ rules.push(x);
246
+ }
247
+
248
+ if (domains_direct.length > 0) {
249
+ var x = {};
250
+ x.outbound = "direct";
251
+ x.domain = domains_direct;
252
+ rules.push(x);
253
+ }
254
+
255
+ if (domains_proxy.length > 0) {
256
+ var x = {};
257
+ x.outbound = "proxy";
258
+ x.domain = domains_proxy;
259
+ rules.push(x);
260
+ }
261
+ }
262
+ return rules;
263
+ }
264
+
265
+ function get_global_rules(server){
266
+ var route = JSON.parse(JSON.stringify(xConfig.general));
267
+ var rules = route.rules;
268
+
269
+ if (server != null && server != undefined) {
270
+
271
+ // Regular expression to check if string is a IP address
272
+ const regexExp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gi;
273
+ var ll = regexExp.test(server); // true
274
+ if (ll) {
275
+ var x = {
276
+ outbound: "direct",
277
+ ip_cidr: [server]
278
+ }
279
+ rules.push(x);
280
+ }
281
+ else {
282
+ var x = {
283
+ outbound: "direct",
284
+ domain: [server]
285
+ }
286
+ rules.push(x);
287
+ }
288
+ }
289
+
290
+ var externals = get_external_rules();
291
+ rules = [...rules,...externals];
292
+
293
+ var address = {
294
+ outbound: "proxy",
295
+ port_range: [
296
+ "0:65535"
443
297
  ]
444
298
  }
299
+ rules.push(address);
300
+ route.rules = rules;
301
+ return route;
302
+ }
303
+
304
+ function get_ai_rules(server) {
305
+
306
+ var route = JSON.parse(JSON.stringify(xConfig.general));
307
+ var rules = route.rules;
308
+
309
+ if (server != null && server != undefined) {
310
+
311
+ // Regular expression to check if string is a IP address
312
+ const regexExp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gi;
313
+ var ll = regexExp.test(server); // true
314
+ if (ll) {
315
+ var x = {
316
+ outbound: "direct",
317
+ ip_cidr: [server]
318
+ }
319
+ rules.push(x);
320
+ }
321
+ else {
322
+ var x = {
323
+ outbound: "direct",
324
+ domain: [server]
325
+ }
326
+ rules.push(x);
327
+ }
328
+ }
329
+
330
+ var externals = get_external_rules();
331
+ rules = [...rules,...externals];
332
+ var address = {
333
+ "outbound": "direct",
334
+ "domain": [
335
+ "example-example.com",
336
+ "example-example2.com"
337
+ ],
338
+ "domain_suffix": [
339
+ ".example-example.com",
340
+ ".example-example2.com"
341
+ ]
342
+ };
343
+ var address_2 = {
344
+ "outbound": "block",
345
+ "geosite": [
346
+ "category-ads-all"
347
+ ]
348
+ };
349
+
350
+ var address_3 = {
351
+ "outbound": "direct",
352
+ "geosite": [
353
+ "cn"
354
+ ]
355
+ };
356
+
357
+ var address_4 = {
358
+ "outbound": "direct",
359
+ "geoip": [
360
+ "private",
361
+ "cn"
362
+ ]
363
+ };
364
+ rules.push(address);
365
+ rules.push(address_2);
366
+ rules.push(address_3);
367
+ rules.push(address_4);
368
+ route.rules = rules;
369
+
370
+ return route;
371
+ }
372
+
373
+ xConfig.outbounds = [
374
+ {
375
+ "type": "socks",
376
+ "tag": "proxy",
377
+ "server": "127.0.0.1",
378
+ "server_port": 1081
379
+ },
380
+ {
381
+ "type": "direct",
382
+ "tag": "direct"
383
+ },
384
+ {
385
+ "type": "block",
386
+ "tag": "block"
387
+ },
388
+ {
389
+ "type": "dns",
390
+ "tag": "dns_out"
391
+ }
392
+ ];
393
+
394
+
395
+ function get_tun_name() {
396
+ let isMac = (os.platform() === "darwin");
397
+ if (isMac) {
398
+ return "utun10";
399
+ }
400
+ else {
401
+ return "singbox_tun";
402
+ }
403
+ }
404
+
405
+ xConfig.inbounds = [
406
+ {
407
+ "type": "tun",
408
+ "tag": "tun-in",
409
+ "interface_name": get_tun_name(),
410
+ "inet4_address": "172.19.0.1/30",
411
+ "inet6_address": "fdfe:dcba:9876::1/126",
412
+ "mtu": 9000,
413
+ "auto_route": true,
414
+ "strict_route": true,
415
+ "stack": "gvisor",
416
+ "sniff": true
417
+ }
418
+ ]
419
+
420
+ xConfig.ai = function(address){
421
+ var x = {
422
+ "log": {
423
+ "level": "warn",
424
+ "timestamp": true
425
+ },
426
+ "dns": xConfig.dns,
427
+ "inbounds": xConfig.inbounds,
428
+ "outbounds": xConfig.outbounds,
429
+ "route": get_ai_rules(address)
430
+ }
431
+ return x;
432
+ }
433
+
434
+ xConfig.global = function(address){
435
+ var x = {
436
+ "log": {
437
+ "level": "warn",
438
+ "timestamp": true
439
+ },
440
+ "dns": xConfig.dns,
441
+ "inbounds": xConfig.inbounds,
442
+ "outbounds": xConfig.outbounds,
443
+ "route": get_global_rules(address)
444
+ }
445
+ return x;
445
446
  }
446
447
 
447
448
  module.exports = xConfig;
package/index.js CHANGED
@@ -35,7 +35,7 @@ class xFuture {
35
35
  StartTunnel(url){
36
36
  if(this.driver.length == 0) return false;
37
37
  var xray_json = JSON.stringify(parser.parse(url));
38
- var sing_json = JSON.stringify(parser.getSingBox());
38
+ var sing_json = JSON.stringify(parser.getSingBox(url));
39
39
  console.log("json:", xray_json, " sing_json:", sing_json);
40
40
  var ok = ff.StartTunnel(xray_json, url, sing_json);
41
41
  if (ok) {
@@ -55,11 +55,11 @@ class xFuture {
55
55
  try {
56
56
  let process = spawn(this.driver, ["global", "socks=127.0.0.1:1081"])
57
57
  process.on('close', (code) => {
58
- console.info('[sysproxy open] close:', code)
58
+ console.info('[sysproxy open]:', code)
59
59
  this.invoke(2);
60
60
  });
61
61
  } catch(err) {
62
- console.warn('[sysproxy open] failed', err)
62
+ console.warn('[sysproxy open] failed:', err)
63
63
  this.invoke(3);
64
64
  this.StopTunnel();
65
65
  ret = false;
@@ -73,10 +73,10 @@ class xFuture {
73
73
  try {
74
74
  let process = spawn(this.driver, ["off"])
75
75
  process.on('close', function (code) {
76
- console.info('[sysproxy stop] close:', code)
76
+ console.info('[sysproxy stop]:', code)
77
77
  });
78
78
  } catch(err) {
79
- console.warn('[sysproxy stop] failed', err)
79
+ console.warn('[sysproxy stop] failed:', err)
80
80
  }
81
81
  }
82
82
  ff.StopProxy();
@@ -85,7 +85,7 @@ class xFuture {
85
85
  ChangeURL(url){
86
86
 
87
87
  var xray_json = JSON.stringify(parser.parse(url));
88
- var sing_json = JSON.stringify(parser.getSingBox());
88
+ var sing_json = JSON.stringify(parser.getSingBox(url));
89
89
  console.log("ChangeURL: ", xray_json, " sing-box:", sing_json);
90
90
  return ff.ChangeURL(xray_json, url, false, sing_json);
91
91
  }
@@ -102,7 +102,7 @@ class xFuture {
102
102
  if (this.GetCurrentStatus() == K_Connected) {
103
103
  var url = this.GetCurrentURI();
104
104
  var xray_json = JSON.stringify(parser.parse(url));
105
- var sing_json = JSON.stringify(parser.getSingBox());
105
+ var sing_json = JSON.stringify(parser.getSingBox(url));
106
106
  ff.ChangeURL(xray_json, url, true, sing_json);
107
107
  console.log("Change URL:", url, " force:", true, " xray_json:", xray_json, " sing-box:", sing_json);
108
108
  }
@@ -13,13 +13,13 @@ NS_ASSUME_NONNULL_BEGIN
13
13
 
14
14
  +(instancetype)sharedManager;
15
15
 
16
- -(void)setGlobalProxyEnable:(BOOL)enable dir:(NSString *)dir;
16
+ -(void)setResourceDirectory:(NSString *)dir;
17
17
 
18
- -(BOOL)startTunnel:(NSString *)url;
18
+ -(BOOL)startTunnel:(NSString *)uri json:(NSString *)json;
19
19
 
20
20
  -(void)stopTunnel;
21
21
 
22
- -(BOOL)changeURL:(NSString *)url;
22
+ -(BOOL)changeURL:(NSString *)url json:(NSString *)json;
23
23
  @end
24
24
 
25
25
  NS_ASSUME_NONNULL_END
@@ -15,7 +15,7 @@
15
15
  <dict>
16
16
  <key>hash2</key>
17
17
  <data>
18
- fg8MWdsOFHa8jehaqM37qZbkcsL4Q43UUK1K77v6uMc=
18
+ Dq7JDpXZbyGk67BnP3LQN2HDYaDHUec6e5KBbMv8s8U=
19
19
  </data>
20
20
  </dict>
21
21
  <key>Headers/xFuture.h</key>
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xfuture",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "electron vpn sdk",
5
5
  "main": "x.js",
6
6
  "scripts": {
package/parser.js CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
2
  const config = require('./config');
3
+ let os = require("os");
3
4
 
4
5
  class xParser {
5
6
 
@@ -52,9 +53,8 @@ class xParser {
52
53
  var port = ipPorts[1] * 1
53
54
 
54
55
  var routing = {};
55
- var rules = [];
56
+ var rules = this.getRules();
56
57
  if (!this.isGlobalMode) {
57
- rules = this.getRules();
58
58
  routing.domainStrategy = "IPIfNonMatch";
59
59
  }
60
60
  else{
@@ -98,9 +98,8 @@ class xParser {
98
98
 
99
99
  var remark = suffix[1];
100
100
  var routing = {};
101
- var rules = [];
101
+ var rules = this.getRules();
102
102
  if (!this.isGlobalMode) {
103
- rules = this.getRules();
104
103
  routing.domainStrategy = "IPIfNonMatch";
105
104
  }
106
105
  else{
@@ -141,9 +140,8 @@ class xParser {
141
140
 
142
141
  var remark = suffix[1];
143
142
  var routing = {};
144
- var rules = [];
143
+ var rules = this.getRules();
145
144
  if (!this.isGlobalMode) {
146
- rules = this.getRules();
147
145
  routing.domainStrategy = "IPIfNonMatch";
148
146
  }
149
147
  else{
@@ -171,9 +169,8 @@ class xParser {
171
169
  remark = info.ps;
172
170
  }
173
171
  var routing = {};
174
- var rules = [];
172
+ var rules = this.getRules();
175
173
  if (!this.isGlobalMode) {
176
- rules = this.getRules();
177
174
  routing.domainStrategy = "IPIfNonMatch";
178
175
  }
179
176
  else{
@@ -190,8 +187,91 @@ class xParser {
190
187
 
191
188
  getRules() {
192
189
  var rules = [];
190
+ if (!this.isTunMode) {
191
+ var ips_direct = [];
192
+ var ips_block = [];
193
+ var ips_proxy = [];
194
+
195
+ var domains_direct = [];
196
+ var domains_block = [];
197
+ var domains_proxy = [];
198
+
199
+ for (let index = 0; index < this.rules.length; index++) {
200
+ const element = this.rules[index];
201
+ if (element.type == "domain") {
202
+ if (element.method == "block") {
203
+ domains_block.push(element.content);
204
+ }
205
+ else if (element.method == "direct") {
206
+ domains_direct.push(element.content);
207
+ }
208
+ else {
209
+ domains_proxy.push(element.content);
210
+ }
211
+ }
212
+ else {
213
+ if (element.method == "block") {
214
+ ips_block.push(element.content);
215
+ }
216
+ else if (element.method == "direct") {
217
+ ips_direct.push(element.content);
218
+ }
219
+ else {
220
+ ips_proxy.push(element.content);
221
+ }
222
+ }
223
+ }
224
+
225
+ if (ips_block.length > 0) {
226
+ var x = {};
227
+ x.type = "field";
228
+ x.outboundTag = "block";
229
+ x.ip = ips_block;
230
+ rules.push(x);
231
+ }
232
+
233
+ if (ips_direct.length > 0) {
234
+ var x = {};
235
+ x.type = "field";
236
+ x.outboundTag = "direct";
237
+ x.ip = ips_direct;
238
+ rules.push(x);
239
+ }
240
+
241
+ if (ips_proxy.length > 0) {
242
+ var x = {};
243
+ x.type = "field";
244
+ x.outboundTag = "proxy";
245
+ x.ip = ips_proxy;
246
+ rules.push(x);
247
+ }
248
+
249
+ if (domains_block.length > 0) {
250
+ var x = {};
251
+ x.type = "field";
252
+ x.outboundTag = "block";
253
+ x.domain = domains_block;
254
+ rules.push(x);
255
+ }
256
+
257
+ if (domains_direct.length > 0) {
258
+ var x = {};
259
+ x.type = "field";
260
+ x.outboundTag = "direct";
261
+ x.domain = domains_direct;
262
+ rules.push(x);
263
+ }
264
+
265
+ if (domains_proxy.length > 0) {
266
+ var x = {};
267
+ x.type = "field";
268
+ x.outboundTag = "proxy";
269
+ x.domain = domains_proxy;
270
+ rules.push(x);
271
+ }
272
+ }
193
273
  if (!this.isGlobalMode && !this.isTunMode) {
194
- rules = [
274
+ var rules_geo = [
195
275
  {
196
276
  "type":"field",
197
277
  "domain":["geosite:cn"],
@@ -208,6 +288,7 @@ class xParser {
208
288
  "outboundTag":"proxy"
209
289
  }
210
290
  ]
291
+ rules = [...rules, ...rules_geo];
211
292
  }
212
293
  return rules;
213
294
  }
@@ -275,24 +356,33 @@ class xParser {
275
356
  }
276
357
  return base;
277
358
  }
278
- getSingBox(){
359
+ getSingBox(url){
360
+ let isMac = (os.platform() === "darwin");
361
+ var x = this.parse(url);
279
362
  if (!this.isGlobalMode) {
280
- var json = config.ai;
281
- json.route.geoip.path = this.workingDir + "\\geoip.db";
282
- json.route.geosite.path = this.workingDir + "\\geosite.db";
363
+ var json = config.ai(x.address);
364
+ json.route.geoip.path = this.workingDir + (isMac ? "/geoip.db" : "\\geoip.db");
365
+ json.route.geosite.path = this.workingDir + (isMac ? "/geosite.db" : "\\geosite.db");
283
366
  return json;
284
367
  }
285
368
  else{
286
- var json = config.global
287
- json.route.geoip.path = this.workingDir + "\\geoip.db";
288
- json.route.geosite.path = this.workingDir + "\\geosite.db";
369
+ var json = config.global(x.address)
370
+ json.route.geoip.path = this.workingDir + (isMac ? "/geoip.db" : "\\geoip.db");
371
+ json.route.geosite.path = this.workingDir + (isMac ? "/geosite.db" : "\\geosite.db");
289
372
  return json;
290
373
  }
291
374
  }
375
+
376
+ setRouterConfiguration(rules) {
377
+ config.setRouterConfiguration(rules);
378
+ this.rules = rules;
379
+ }
380
+
292
381
  }
293
382
 
294
383
  const xParserInstance = new xParser;
295
384
  xParserInstance.isGlobalMode = false;
296
- xParserInstance.isTunMode = true;
385
+ xParserInstance.isTunMode = false;
297
386
  xParserInstance.workingDir = "";
387
+ xParserInstance.rules = [];
298
388
  module.exports = xParserInstance;