1cattunnel 0.1.2-b.1
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/README.md +28 -0
- package/bin/1cattunnel.js +95 -0
- package/dist/client-linux.json +14 -0
- package/dist/client-windows.json +14 -0
- package/dist/tunnel-client-linux-amd64 +0 -0
- package/dist/tunnel-client-windows-amd64.exe +0 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# 1cattunnel
|
|
2
|
+
|
|
3
|
+
Global npm wrapper for the 1Cat Tunnel client.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g 1cattunnel
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Run
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
1cattunnel
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The package bundles Windows/Linux amd64 client binaries. On first run it creates a writable user config:
|
|
18
|
+
|
|
19
|
+
- Windows: `%APPDATA%\\1cat-tunnel\\client-windows.json`
|
|
20
|
+
- Linux: `~/.config/1cat-tunnel/client-linux.json`
|
|
21
|
+
|
|
22
|
+
Default config connects to `dx.1catai.com:50001` with enrollment password `SuperYMZX666`. The server then issues a per-node runtime credential automatically.
|
|
23
|
+
|
|
24
|
+
Use a custom config if needed:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
1cattunnel -config ./client-linux.json
|
|
28
|
+
```
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
|
|
9
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
10
|
+
const platform = process.platform;
|
|
11
|
+
const arch = process.arch;
|
|
12
|
+
|
|
13
|
+
function fail(message) {
|
|
14
|
+
console.error(`1cattunnel: ${message}`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (arch !== 'x64') {
|
|
19
|
+
fail(`unsupported CPU ${arch}; this package currently bundles amd64/x64 clients only`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const isWindows = platform === 'win32';
|
|
23
|
+
const isLinux = platform === 'linux';
|
|
24
|
+
if (!isWindows && !isLinux) {
|
|
25
|
+
fail(`unsupported platform ${platform}; use Windows or Linux`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const binaryName = isWindows ? 'tunnel-client-windows-amd64.exe' : 'tunnel-client-linux-amd64';
|
|
29
|
+
const configName = isWindows ? 'client-windows.json' : 'client-linux.json';
|
|
30
|
+
const binaryPath = path.join(packageRoot, 'dist', binaryName);
|
|
31
|
+
const templatePath = path.join(packageRoot, 'dist', configName);
|
|
32
|
+
|
|
33
|
+
if (!fs.existsSync(binaryPath)) {
|
|
34
|
+
fail(`bundled client binary not found: ${binaryPath}`);
|
|
35
|
+
}
|
|
36
|
+
if (!fs.existsSync(templatePath)) {
|
|
37
|
+
fail(`bundled default config not found: ${templatePath}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function configRoot() {
|
|
41
|
+
if (isWindows) {
|
|
42
|
+
return path.join(process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'), '1cat-tunnel');
|
|
43
|
+
}
|
|
44
|
+
return path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), '1cat-tunnel');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function safeNodeName() {
|
|
48
|
+
const host = (os.hostname() || 'customer-node').trim().toLowerCase();
|
|
49
|
+
const safe = host.replace(/[^a-z0-9_.-]+/g, '-').replace(/^-+|-+$/g, '');
|
|
50
|
+
return safe || 'customer-node';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function hasConfigArg(args) {
|
|
54
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
55
|
+
const arg = args[i];
|
|
56
|
+
if (arg === '-config' || arg === '--config') {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (arg.startsWith('-config=') || arg.startsWith('--config=')) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function ensureUserConfig() {
|
|
67
|
+
const dir = configRoot();
|
|
68
|
+
const target = path.join(dir, configName);
|
|
69
|
+
if (fs.existsSync(target)) {
|
|
70
|
+
return target;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
74
|
+
const config = JSON.parse(fs.readFileSync(templatePath, 'utf8'));
|
|
75
|
+
config.node_name = safeNodeName();
|
|
76
|
+
fs.writeFileSync(target, `${JSON.stringify(config, null, 2)}\n`);
|
|
77
|
+
console.log(`1cattunnel: created default config at ${target}`);
|
|
78
|
+
return target;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const args = process.argv.slice(2);
|
|
82
|
+
if (!hasConfigArg(args)) {
|
|
83
|
+
args.push('-config', ensureUserConfig());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const result = spawnSync(binaryPath, args, {
|
|
87
|
+
stdio: 'inherit',
|
|
88
|
+
windowsHide: false,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (result.error) {
|
|
92
|
+
fail(result.error.message);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
process.exit(typeof result.status === 'number' ? result.status : 1);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"server_addr": "dx.1catai.com:50001",
|
|
3
|
+
"enrollment_password": "SuperYMZX666",
|
|
4
|
+
"node_name": "cust-linux-01",
|
|
5
|
+
"reconnect_interval_sec": 5,
|
|
6
|
+
"presets": [
|
|
7
|
+
{
|
|
8
|
+
"name": "ssh",
|
|
9
|
+
"local_addr": "0.0.0.0:22",
|
|
10
|
+
"description": "Expose local SSH",
|
|
11
|
+
"protocol": "tcp"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"server_addr": "dx.1catai.com:50001",
|
|
3
|
+
"enrollment_password": "SuperYMZX666",
|
|
4
|
+
"node_name": "cust-win-01",
|
|
5
|
+
"reconnect_interval_sec": 5,
|
|
6
|
+
"presets": [
|
|
7
|
+
{
|
|
8
|
+
"name": "rdp",
|
|
9
|
+
"local_addr": "127.0.0.1:3389",
|
|
10
|
+
"description": "Expose local RDP",
|
|
11
|
+
"protocol": "tcp"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "1cattunnel",
|
|
3
|
+
"version": "0.1.2-b.1",
|
|
4
|
+
"description": "1Cat Tunnel client with bundled Windows/Linux amd64 binaries",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"private": false,
|
|
7
|
+
"bin": {
|
|
8
|
+
"1cattunnel": "bin/1cattunnel.js",
|
|
9
|
+
"1cat-tunnel": "bin/1cattunnel.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin/",
|
|
13
|
+
"dist/",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"os": [
|
|
17
|
+
"win32",
|
|
18
|
+
"linux"
|
|
19
|
+
],
|
|
20
|
+
"cpu": [
|
|
21
|
+
"x64"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=14"
|
|
25
|
+
}
|
|
26
|
+
}
|