xtunnel 1.0.7 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
package/core/config.json CHANGED
@@ -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
@@ -9,7 +9,9 @@ const config = JSON.parse(fs.readFileSync(path.join(__dirname, './config/default
9
9
 
10
10
  let rayProcess = null
11
11
 
12
- process.on('exit', () => stop())
12
+ [`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`].forEach((eventType) => {
13
+ process.on(eventType, stop.bind(null, eventType))
14
+ })
13
15
 
14
16
  program.version('1.0.0').description('Tunnel CLI')
15
17
  program.command('* <url>').action(url => url && run(url))
@@ -21,7 +23,7 @@ async function run(url) {
21
23
  if (res.data) {
22
24
  subItems = Buffer.from(res.data, 'base64').toString().split("vmess://").map(o => Buffer.from(o, 'base64').toString()).filter(o => o)
23
25
  let server = subItems.map(o => JSON.parse(o)).filter(o => o.verify_cert)[0]
24
- config.tpl.inbounds[1].settings.port = config.setting.localHttpPort
26
+ config.tpl.inbounds[1].port = config.setting.localHttpPort
25
27
  config.tpl.outbounds[0].settings.vnext[0].address = server.add
26
28
  config.tpl.outbounds[0].settings.vnext[0].port = server.port
27
29
  config.tpl.outbounds[0].settings.vnext[0].users[0].id = server.id
@@ -29,25 +31,32 @@ async function run(url) {
29
31
  }
30
32
  } catch (error) {
31
33
  console.error(error)
34
+ console.error('SUBSCRIBE LINK ERROR')
32
35
  }
33
36
  }
34
37
 
35
38
  function start() {
39
+ console.log('TUNNEL START')
36
40
  // 关闭上个进程
37
41
  rayProcess && rayProcess.kill('SIGINT')
38
42
  // 设置系统代理
39
43
  setSystemProxy(config.setting.localHttpPort)
40
44
  // 根据操作系统平台-启动新进程
41
- rayProcess = child_process.exec(path.join(__dirname, './core/xray-linux-x64'), (error, stdout, stderr) => error && stop() && console.error('启动失败,请检查权限/端口占用'))
45
+ rayProcess = child_process.exec(path.join(__dirname, './core/xray-linux-x64'), (error, stdout, stderr) => error && stop(true))
42
46
  rayProcess.stdout.on('data', console.log)
43
47
  rayProcess.stderr.on('data', console.error)
44
48
  }
45
49
 
46
- function stop() {
50
+ function stop(isRestart) {
51
+ console.log('TUNNEL STOP')
47
52
  // 关闭上个进程
48
53
  rayProcess && rayProcess.kill('SIGINT')
49
54
  // 取消系统代理
50
55
  setSystemProxy()
56
+ if (isRestart) {
57
+ console.error('启动失败(请检查权限/端口占用),重新启动中...')
58
+ start()
59
+ }
51
60
  return true
52
61
  }
53
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xtunnel",
3
- "version": "1.0.7",
3
+ "version": "1.1.1",
4
4
  "description": "xtunnel",
5
5
  "main": "index.js",
6
6
  "scripts": {},