-
Notifications
You must be signed in to change notification settings - Fork 284
/
v2ray.ts
84 lines (71 loc) · 2.03 KB
/
v2ray.ts
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
84
/**
* @license
* Copyright 2020 Xingwang Liao <kuoruan@gmail.com>
*
* Licensed to the public under the MIT License.
*/
"use strict";
// "require baseclass";
"require fs";
"require network";
"require uci";
// @ts-ignore
return L.Class.extend({
getLocalIPs: function (): Promise<string[]> {
return network.getNetworks().then(function (networks: network.Protocol[]) {
const localIPs: string[] = ["127.0.0.1", "0.0.0.0", "::"];
for (const n of networks) {
let IPv4 = n.getIPAddr();
let IPv6 = n.getIP6Addr();
if (IPv4 && (IPv4 = IPv4.split("/")[0]) && localIPs.indexOf(IPv4) < 0) {
localIPs.push(IPv4);
}
if (IPv6 && (IPv6 = IPv6.split("/")[0]) && localIPs.indexOf(IPv6) < 0) {
localIPs.push(IPv6);
}
}
return localIPs.sort();
});
},
getSections: function (
type: string,
captionKey: string = "alias"
): Promise<SectionItem[]> {
return uci.load("v2ray").then(function () {
const sections: SectionItem[] = [];
uci.sections("v2ray", type, function (s: uci.SectionObject) {
let caption: string;
if ((caption = s[captionKey])) {
sections.push({
caption: caption,
value: s[".name"],
});
}
});
return sections;
});
},
getDokodemoDoorPorts: function (): Promise<SectionItem[]> {
return uci.load("v2ray").then(function () {
const sections: SectionItem[] = [];
uci.sections("v2ray", "inbound", function (s: uci.SectionObject) {
let port: string;
if (s["protocol"] == "dokodemo-door" && (port = s["port"])) {
let alias: string;
if ((alias = s["alias"])) {
sections.push({
caption: "%s - %s".format(alias, port),
value: port,
});
} else {
sections.push({
caption: "%s:%s".format(s["listen"], port),
value: port,
});
}
}
});
return sections;
});
},
});