xtunnel 1.0.6 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/default.json +2 -2
- package/core/config.json +2 -3
- package/index.js +20 -25
- package/package.json +1 -1
package/config/default.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"setting": {
|
3
|
-
"localHttpPort": "
|
3
|
+
"localHttpPort": "10870",
|
4
4
|
"localSockPort": "1080",
|
5
5
|
"subscribeLink": "",
|
6
6
|
"selectedServer": "",
|
@@ -33,7 +33,7 @@
|
|
33
33
|
"tpl": {
|
34
34
|
"log": {
|
35
35
|
"error": "",
|
36
|
-
"loglevel": "
|
36
|
+
"loglevel": "error",
|
37
37
|
"access": ""
|
38
38
|
},
|
39
39
|
"inbounds": [
|
package/core/config.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"log": {
|
3
3
|
"error": "",
|
4
|
-
"loglevel": "
|
4
|
+
"loglevel": "error",
|
5
5
|
"access": ""
|
6
6
|
},
|
7
7
|
"inbounds": [
|
@@ -18,8 +18,7 @@
|
|
18
18
|
"listen": "127.0.0.1",
|
19
19
|
"protocol": "http",
|
20
20
|
"settings": {
|
21
|
-
"timeout": 360
|
22
|
-
"port": "1087"
|
21
|
+
"timeout": 360
|
23
22
|
},
|
24
23
|
"port": "1087"
|
25
24
|
}
|
package/index.js
CHANGED
@@ -5,63 +5,58 @@ const axios = require('axios')
|
|
5
5
|
const path = require('path')
|
6
6
|
const fs = require('fs')
|
7
7
|
const child_process = require('child_process')
|
8
|
-
|
9
|
-
console.log(path.join(__dirname, './config/default.json'))
|
10
8
|
const config = JSON.parse(fs.readFileSync(path.join(__dirname, './config/default.json')))
|
11
9
|
|
12
10
|
let rayProcess = null
|
13
11
|
|
14
|
-
|
12
|
+
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => {
|
13
|
+
process.on(eventType, stop.bind(null, eventType))
|
14
|
+
})
|
15
15
|
|
16
16
|
program.version('1.0.0').description('Tunnel CLI')
|
17
|
-
program.command('* <url>').action(url => url &&
|
17
|
+
program.command('* <url>').action(url => url && run(url))
|
18
18
|
program.parse(process.argv)
|
19
19
|
|
20
|
-
async function
|
20
|
+
async function run(url) {
|
21
21
|
try {
|
22
22
|
let res = await axios.get(url)
|
23
23
|
if (res.data) {
|
24
24
|
subItems = Buffer.from(res.data, 'base64').toString().split("vmess://").map(o => Buffer.from(o, 'base64').toString()).filter(o => o)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
25
|
+
let server = subItems.map(o => JSON.parse(o)).filter(o => o.verify_cert)[0]
|
26
|
+
config.tpl.inbounds[1].port = config.setting.localHttpPort
|
27
|
+
config.tpl.outbounds[0].settings.vnext[0].address = server.add
|
28
|
+
config.tpl.outbounds[0].settings.vnext[0].port = server.port
|
29
|
+
config.tpl.outbounds[0].settings.vnext[0].users[0].id = server.id
|
30
|
+
fs.writeFile(path.join(__dirname, './core/config.json'), JSON.stringify(config.tpl), err => !err && start())
|
32
31
|
}
|
33
32
|
} catch (error) {
|
34
33
|
console.error(error)
|
34
|
+
console.error('SUBSCRIBE LINK ERROR')
|
35
35
|
}
|
36
36
|
}
|
37
37
|
|
38
|
-
function switchServer(server) {
|
39
|
-
// 切换服务器
|
40
|
-
config.tpl.inbounds[1].settings.port = config.setting.localHttpPort
|
41
|
-
config.tpl.outbounds[0].settings.vnext[0].address = server.add
|
42
|
-
config.tpl.outbounds[0].settings.vnext[0].port = server.port
|
43
|
-
config.tpl.outbounds[0].settings.vnext[0].users[0].id = server.id
|
44
|
-
console.log(path.join(__dirname, './core/config.json'))
|
45
|
-
fs.writeFile(path.join(__dirname, './core/config.json'), JSON.stringify(config.tpl), err => !err && start())
|
46
|
-
}
|
47
|
-
|
48
38
|
function start() {
|
39
|
+
console.log('TUNNEL START')
|
49
40
|
// 关闭上个进程
|
50
41
|
rayProcess && rayProcess.kill('SIGINT')
|
51
42
|
// 设置系统代理
|
52
|
-
console.log(config.setting.localHttpPort)
|
53
43
|
setSystemProxy(config.setting.localHttpPort)
|
54
44
|
// 根据操作系统平台-启动新进程
|
55
|
-
rayProcess = child_process.exec(path.join(__dirname, './core/xray-linux-x64'), (error, stdout, stderr) => error && stop()
|
45
|
+
rayProcess = child_process.exec(path.join(__dirname, './core/xray-linux-x64'), (error, stdout, stderr) => error && stop(true))
|
56
46
|
rayProcess.stdout.on('data', console.log)
|
57
47
|
rayProcess.stderr.on('data', console.error)
|
58
48
|
}
|
59
49
|
|
60
|
-
function stop() {
|
50
|
+
function stop(isRestart) {
|
51
|
+
console.log('TUNNEL STOP')
|
61
52
|
// 关闭上个进程
|
62
53
|
rayProcess && rayProcess.kill('SIGINT')
|
63
54
|
// 取消系统代理
|
64
55
|
setSystemProxy()
|
56
|
+
if (isRestart) {
|
57
|
+
console.error('启动失败(请检查权限/端口占用),重新启动中...')
|
58
|
+
start()
|
59
|
+
}
|
65
60
|
return true
|
66
61
|
}
|
67
62
|
|