@ying-tunnel/cli 1.0.0 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ying-tunnel/cli
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - remove cac and use commander
8
+
9
+ ## 1.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Author information update
14
+ - Updated dependencies
15
+ - @ying-tunnel/lib@1.0.1
16
+
3
17
  ## 1.0.0
4
18
 
5
19
  ### Major Changes
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jack Ying
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -6,10 +6,18 @@
6
6
  npm i @ying-tunnel/cli -g
7
7
  ```
8
8
 
9
+ ```bash
10
+ pnpm i @ying-tunnel/cli -g
11
+ ```
12
+
9
13
  ### 使用示例
10
14
 
11
15
  ```bash
12
- ying-tunnel <要连接的服务ip或域名> <要连接的服务端口> <对应的token配置>
16
+ ying-tunnel -v
17
+ ```
18
+
19
+ ```bash
20
+ ying-tunnel <要连接的服务ip或域名> <要连接的服务端口> <对应的key>
13
21
  ```
14
22
 
15
23
  ```bash
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.connectTunnel = connectTunnel;
4
+ const lib_1 = require("@ying-tunnel/lib");
5
+ function connectTunnel(host, port, key) {
6
+ const tunnelClient = new lib_1.TunnelClient({ host, port: Number(port), key });
7
+ const tcpProxyClient = new lib_1.TCPProxyClient();
8
+ tunnelClient.on('message', unpackData => {
9
+ switch (unpackData.header.type) {
10
+ case lib_1.TunnelPackageType.TCPRequestStart:
11
+ const host = unpackData.header.localHost.split(':');
12
+ tcpProxyClient.createConnection(host[0], Number(host[1]), unpackData.header.sign);
13
+ break;
14
+ case lib_1.TunnelPackageType.TCPRequestStream:
15
+ tcpProxyClient.write(unpackData.header.sign, unpackData.bodyBuffer);
16
+ break;
17
+ case lib_1.TunnelPackageType.TCPRequestClose:
18
+ tcpProxyClient.destroy(unpackData.header.sign);
19
+ break;
20
+ }
21
+ });
22
+ tcpProxyClient.on('data', (sign, chunk) => {
23
+ tunnelClient.sendMessage(lib_1.TunnelPackage.pack({
24
+ type: lib_1.TunnelPackageType.TCPResponseStream,
25
+ sign
26
+ }, chunk));
27
+ });
28
+ tcpProxyClient.on('close', sign => {
29
+ tunnelClient.sendMessage(lib_1.TunnelPackage.pack({
30
+ type: lib_1.TunnelPackageType.TCPResponseClose,
31
+ sign
32
+ }));
33
+ });
34
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackageJson = getPackageJson;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ function getPackageJson() {
7
+ const data = (0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '../package.json'));
8
+ return JSON.parse(data.toString());
9
+ }
package/dist/main.js CHANGED
@@ -1,43 +1,19 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
3
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const cac_1 = __importDefault(require("cac"));
7
- const lib_1 = require("@ying-tunnel/lib");
8
- const cli = (0, cac_1.default)();
9
- cli.command("<host> <port> <token>", "link to tcp socket.").action(init);
10
- cli.help();
11
- cli.parse();
12
- function init(host, port, token) {
13
- const proxyClient = new lib_1.ProxyClient();
14
- const tunnelClient = new lib_1.TunnelClient({ host, port: Number(port), token });
15
- tunnelClient.on("message", (unpackData) => {
16
- switch (unpackData.header.type) {
17
- case lib_1.TunnelPackageType.TCPRequestStart:
18
- const host = unpackData.header.localHost.split(":");
19
- proxyClient.start(host[0], Number(host[1]), unpackData.header.sign);
20
- break;
21
- case lib_1.TunnelPackageType.TCPRequestStream:
22
- proxyClient.stream(unpackData.header.sign, unpackData.bodyBuffer);
23
- break;
24
- case lib_1.TunnelPackageType.TCPRequestClose:
25
- proxyClient.destroy(unpackData.header.sign);
26
- break;
27
- }
28
- });
29
- proxyClient.on("data", (sign, chunk) => {
30
- console.log(`proxyClient: 请求${sign}数据`, chunk.length);
31
- tunnelClient.sendMessage(lib_1.TunnelPackage.pack({
32
- type: lib_1.TunnelPackageType.TCPResponseStream,
33
- sign,
34
- }, chunk));
35
- });
36
- proxyClient.on("close", (sign) => {
37
- console.log(`proxyClient: 请求${sign}关闭`);
38
- tunnelClient.sendMessage(lib_1.TunnelPackage.pack({
39
- type: lib_1.TunnelPackageType.TCPResponseClose,
40
- sign,
41
- }));
42
- });
43
- }
4
+ const commander_1 = require("commander");
5
+ const connect_tunnel_1 = require("./connect-tunnel");
6
+ const get_package_json_1 = require("./get-package-json");
7
+ const pkg = (0, get_package_json_1.getPackageJson)();
8
+ commander_1.program
9
+ .name('ying-tunnel')
10
+ .version(`${pkg.version}`, '-v --version')
11
+ .description('CLI program for connecting to tunnel server.')
12
+ .helpOption(true);
13
+ commander_1.program
14
+ .command('connect', { isDefault: true })
15
+ .argument('<host>', 'The server IP or domain name to connect to')
16
+ .argument('<port>', 'The server port to connect to')
17
+ .argument('<key>', 'corresponding key')
18
+ .action(connect_tunnel_1.connectTunnel);
19
+ commander_1.program.parse(process.argv);
package/package.json CHANGED
@@ -1,29 +1,37 @@
1
1
  {
2
2
  "name": "@ying-tunnel/cli",
3
- "version": "1.0.0",
4
- "description": "",
5
- "keywords": [],
6
- "author": "",
7
- "license": "ISC",
3
+ "version": "1.1.0",
4
+ "description": "ying-tunnel 内网穿透工具的连接客户端",
5
+ "keywords": [
6
+ "内网穿透",
7
+ "tunnel",
8
+ "typescript",
9
+ "nodejs"
10
+ ],
11
+ "author": {
12
+ "name": "jackying007",
13
+ "email": "yingjack007@gmail.com",
14
+ "url": "https://jackying007.github.io/"
15
+ },
16
+ "license": "MIT",
17
+ "files": [
18
+ "dist",
19
+ "package.json",
20
+ "CHANGELOG.md",
21
+ "README.md"
22
+ ],
8
23
  "bin": {
9
- "ying-tunnel": "./bin/index.js"
24
+ "ying-tunnel": "./dist/main.js"
10
25
  },
11
26
  "publishConfig": {
12
27
  "access": "public"
13
28
  },
14
- "nodemonConfig": {
15
- "watch": [
16
- "src"
17
- ],
18
- "ext": "ts",
19
- "exec": "ts-node src/main.ts 127.0.0.1 4948 OxFhMdko9XkAJM37l8RC2"
20
- },
21
29
  "dependencies": {
22
- "cac": "^6.7.14",
23
- "@ying-tunnel/lib": "^1.0.0"
30
+ "commander": "^15.0.0",
31
+ "@ying-tunnel/lib": "1.0.1"
24
32
  },
25
33
  "scripts": {
26
- "dev": "nodemon",
34
+ "dev": "tsx watch --clear-screen=false src/main.ts 127.0.0.1 4948 OxFhMdko9XkAJM37l8RC2",
27
35
  "build": "tsc"
28
36
  }
29
37
  }
package/bin/index.js DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- require("../dist/main.js");