-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathjms-parser.yaml
102 lines (93 loc) · 3.44 KB
/
jms-parser.yaml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
parsers:
- url: https://example.com/sub
code: |
module.exports.parse = async (raw, { axios, yaml, notify, console }, { name, url, interval, selected }) => {
/** parse shadowsocks standard share uri */
function parseSS(uri) {
// shadowsocks URI parttern: ss://{server config, base64 encoded}#{server name} ;
// shadowsocks server config pattern: {cipher}:{password}@{server ip/domain}:${port} ,
// but password section maybe contains any character
const SS_URI_PATTERN = /^ss:\/\/(\w+)(#(.+))?$/;
const SS_SERVER_PATTERN = /([\w-]+):(.+)@([\w\.]+):(\d+)/;
let matched = uri.match(SS_URI_PATTERN);
if (matched == null) {
return null;
}
// ciper:password@server:port
let config = atob(matched[1]).match(SS_SERVER_PATTERN);
if (config == null) {
return null;
}
let ciper = config[1];
let password = config[2];
let server = config[3];
let port = config[4];
// get or create config name
let name = matched.length == 4 ? matched[3] : (server + ':' + port);
return {
name: name,
type: "ss",
server: server,
port: parseInt(port),
cipher: ciper,
password: password
// udp: true
}
}
/** parse shadowsocks non-standard share uri (just my socks version) */
function parseVMess(uri) {
// VMess URI pattern: vmess://{server config, base64 encoded}
// server config is a json string, example as follows:
// {
// ps: config name,
// add: server ip/domain,
// port: server port,
// id: user id,
// aid: alter id,
// net: network protocol (tcp/grpc/...),
// type: maybe tcp obfs type?,
// tls: enabled tls?
// }
const VMESS_URI_PATTERN = /^vmess:\/\/(\w+)$/;
let matched = uri.match(VMESS_URI_PATTERN);
if (matched == null) {
return null;
}
// json object
let obj = JSON.parse(atob(matched[1]));
return {
name: obj.ps,
type: "vmess",
server: obj.add,
port: parseInt(obj.port),
uuid: obj.id,
alterId: obj.aid,
cipher: "auto",
//udp: false,
tls: false
//"skip-cert-verify": false,
//servername: servername
}
}
function parse(uri) {
if (uri.startsWith('ss://')) {
return parseSS(uri);
}
if (uri.startsWith('vmess://')) {
return parseVMess(uri);
}
return null;
}
let jmsrsp = raw
let servers = atob(jmsrsp).split('\n').map(line => parse(line)).filter(server => server != null)
let result = {
proxies: servers,
"proxy-groups": [{
name: "jms-proxy",
type: "select",
proxies: servers.map(server => server.name)
}],
rules: ["MATCH,jms-proxy"]
}
return yaml.stringify(result)
}