tunli 0.0.20 → 0.0.21
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/client.js +2 -0
- package/package.json +1 -1
- package/src/commands/CommandConfig.js +2 -0
- package/src/commands/CommandHTTP.js +5 -4
- package/src/commands/Option/ProfileListOption.js +65 -0
- package/src/commands/Option/SelectConfigOption.js +1 -1
- package/src/commands/SubCommand/ProtocolCommand.js +21 -0
- package/src/config/ConfigAbstract.js +12 -1
- package/src/config/GlobalLocalShardConfigAbstract.js +10 -1
- package/src/tunnel-client/TunnelClient.js +1 -1
- package/src/utils/checkFunctions.js +12 -0
- package/types/index.d.ts +1 -0
package/client.js
CHANGED
|
@@ -8,6 +8,7 @@ import {createCommandRefresh} from "#commands/CommandRefresh";
|
|
|
8
8
|
import {argumentAliasResolver} from "#commands/helper/AliasResolver";
|
|
9
9
|
import {createCommandInvite} from "#commands/CommandInvite";
|
|
10
10
|
import {addExamples, addUsage} from "#commands/utils";
|
|
11
|
+
import {profileListOption} from "#commands/Option/ProfileListOption";
|
|
11
12
|
|
|
12
13
|
program
|
|
13
14
|
.name('tunli')
|
|
@@ -17,6 +18,7 @@ program
|
|
|
17
18
|
console.log(`tunli: ${packageJson.version}`)
|
|
18
19
|
process.exit()
|
|
19
20
|
})
|
|
21
|
+
.addOption(profileListOption())
|
|
20
22
|
|
|
21
23
|
program.addCommand(createCommandConfig(program))
|
|
22
24
|
program.addCommand(createCommandHTTP(program), {isDefault: true})
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import {portCommand} from "#commands/SubCommand/PortCommand";
|
|
|
5
5
|
import {hostCommand} from "#commands/SubCommand/HostCommand";
|
|
6
6
|
import {selectConfigOption} from "#commands/Option/SelectConfigOption";
|
|
7
7
|
import {addExample, extendUsage} from "#commands/utils";
|
|
8
|
+
import {protocolCommand} from "#commands/SubCommand/ProtocolCommand";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
*
|
|
@@ -41,6 +42,7 @@ export const createCommandConfig = (program) => {
|
|
|
41
42
|
cmd.addCommand(allowDenyCidrCommand('denyCidr', cmd, configRef))
|
|
42
43
|
cmd.addCommand(portCommand(configRef))
|
|
43
44
|
cmd.addCommand(hostCommand(configRef))
|
|
45
|
+
cmd.addCommand(protocolCommand(configRef))
|
|
44
46
|
|
|
45
47
|
selectConfigOption(cmd, configRef, true)
|
|
46
48
|
.action(exec(configRef, program));
|
|
@@ -61,6 +61,7 @@ const exec = (configRef, cmd, program) => {
|
|
|
61
61
|
|
|
62
62
|
options.port ??= port
|
|
63
63
|
options.host ??= host
|
|
64
|
+
options.protocol ??= protocol ?? 'http'
|
|
64
65
|
|
|
65
66
|
const save = options.save
|
|
66
67
|
delete options.save
|
|
@@ -90,7 +91,7 @@ const exec = (configRef, cmd, program) => {
|
|
|
90
91
|
path: undefined,
|
|
91
92
|
allowCidr: options.allowCidr ?? config.allowCidr,
|
|
92
93
|
denyCidr: options.denyCidr ?? config.denyCidr,
|
|
93
|
-
protocol: protocol
|
|
94
|
+
protocol: options.protocol
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
const client = new TunnelClient(clientOptions)
|
|
@@ -116,9 +117,9 @@ export const createCommandHTTP = (program) => {
|
|
|
116
117
|
|
|
117
118
|
cmd.option('--host <string>', 'setting hostname', bindArgs(checkHost, sharedArgument, false))
|
|
118
119
|
cmd.option('--port <string>', 'setting port', bindArgs(checkPort, sharedArgument, false))
|
|
119
|
-
cmd.option('--allow-cidr <string>', 'allow-cidr', validateArrayArguments(validateIpV4))
|
|
120
|
-
cmd.option('--deny-cidr <string>', 'deny-cidr', validateArrayArguments(validateIpV4))
|
|
121
|
-
cmd.option('--self', 'allow self only', false)
|
|
120
|
+
cmd.option('--allow, --allow-cidr <string>', 'allow-cidr', validateArrayArguments(validateIpV4))
|
|
121
|
+
cmd.option('--deny, --deny-cidr <string>', 'deny-cidr', validateArrayArguments(validateIpV4))
|
|
122
|
+
cmd.option('--allow-self, --self', 'allow self only', false)
|
|
122
123
|
cmd.option('--save [alias]', 'save current settings as alias/local')
|
|
123
124
|
cmd.action(exec(configRef, cmd, program))
|
|
124
125
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {Option} from "commander";
|
|
2
|
+
import {ConfigManager} from "#src/config/ConfigManager";
|
|
3
|
+
|
|
4
|
+
export const profileListOption = () => {
|
|
5
|
+
const option = new Option('-l, --list', 'profile list')
|
|
6
|
+
option.argParser(() => {
|
|
7
|
+
/**
|
|
8
|
+
* @param label
|
|
9
|
+
* @param {ConfigAbstract} config
|
|
10
|
+
* @return {string}
|
|
11
|
+
*/
|
|
12
|
+
const createOutput = (label, config) => {
|
|
13
|
+
const profiles = [...config.profiles]
|
|
14
|
+
const maxLabelLength = Math.max(...profiles.map(x => x.length))
|
|
15
|
+
const whitespace = ''.padEnd(2)
|
|
16
|
+
const rows = [`${label}`, '']
|
|
17
|
+
// const rows = [`${label}${profiles.shift()}`]
|
|
18
|
+
const overview = {}
|
|
19
|
+
const proxyURLs = []
|
|
20
|
+
for (const profile of profiles) {
|
|
21
|
+
|
|
22
|
+
const info = config.use(profile)
|
|
23
|
+
const host = info.host
|
|
24
|
+
const port = info.port
|
|
25
|
+
const protocol = info.protocol
|
|
26
|
+
let proxyURL = info.proxyURL
|
|
27
|
+
|
|
28
|
+
let targetUrl = new URL(`${protocol}://${host}:${port}`).toString()
|
|
29
|
+
if (proxyURL) {
|
|
30
|
+
proxyURL = proxyURL.substring(0, proxyURL.length - 1)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
targetUrl = targetUrl.substring(0, targetUrl.length - 1)
|
|
34
|
+
proxyURLs.push(proxyURL.length)
|
|
35
|
+
overview[profile] = {
|
|
36
|
+
host,
|
|
37
|
+
port,
|
|
38
|
+
targetUrl,
|
|
39
|
+
proxyURL
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const maxProxyUrlLength = Math.max(...proxyURLs)
|
|
44
|
+
|
|
45
|
+
for (const profile of profiles) {
|
|
46
|
+
let {targetUrl, proxyURL} = overview[profile]
|
|
47
|
+
proxyURL = proxyURL.padEnd(maxProxyUrlLength)
|
|
48
|
+
rows.push(`${whitespace}${profile.padEnd(maxLabelLength)} ${proxyURL} -> ${targetUrl}`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return rows.join("\n") + "\n"
|
|
52
|
+
}
|
|
53
|
+
const localConf = ConfigManager.loadLocalOnly()
|
|
54
|
+
const globalConf = ConfigManager.loadGlobalOnly()
|
|
55
|
+
|
|
56
|
+
if (localConf.exists()) {
|
|
57
|
+
console.log(createOutput('Alias local config: ', localConf))
|
|
58
|
+
}
|
|
59
|
+
if (globalConf.exists()) {
|
|
60
|
+
console.log(createOutput('Alias global config: ', globalConf))
|
|
61
|
+
}
|
|
62
|
+
process.exit()
|
|
63
|
+
})
|
|
64
|
+
return option
|
|
65
|
+
}
|
|
@@ -10,7 +10,7 @@ import {ConfigManager} from "#src/config/ConfigManager";
|
|
|
10
10
|
export const selectConfigOption = (command, configRef, strictMode = false) => {
|
|
11
11
|
|
|
12
12
|
command.option('--global', 'Use the global configuration file (default)')
|
|
13
|
-
.option('--workdir', 'Use the configuration file for the current working directory')
|
|
13
|
+
.option('--local, --workdir', 'Use the configuration file for the current working directory')
|
|
14
14
|
.option('-p --alias <string>', 'setting alias name', 'default')
|
|
15
15
|
|
|
16
16
|
if (configRef) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {Command} from "commander";
|
|
2
|
+
|
|
3
|
+
import {checkProtocol} from "#src/utils/checkFunctions";
|
|
4
|
+
import {deleteOption} from "#commands/Option/DeleteOption";
|
|
5
|
+
import {addGetDeleteValueAction} from "#commands/Action/addDelValuesAction";
|
|
6
|
+
|
|
7
|
+
export const protocolCommand = (configRef) => {
|
|
8
|
+
const cmd = new Command('protocol')
|
|
9
|
+
|
|
10
|
+
cmd.description('default protocol "http"')
|
|
11
|
+
.argument('[PROTOCOL]', 'füge eine kurze beschreibung ein', checkProtocol)
|
|
12
|
+
.hook('preAction', (thisCommand, actionCommand) => {
|
|
13
|
+
if (thisCommand.args.length && thisCommand.opts().del) {
|
|
14
|
+
actionCommand.error("error: wenn delete dann keine argumente");
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
.addOption(deleteOption())
|
|
18
|
+
.action(addGetDeleteValueAction('protocol', configRef))
|
|
19
|
+
|
|
20
|
+
return cmd
|
|
21
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {writeFileSync} from "fs"
|
|
1
|
+
import {existsSync, writeFileSync} from "fs"
|
|
2
2
|
import {dirname} from 'path'
|
|
3
3
|
import {ensureDirectoryExists} from "#src/core/FS/utils";
|
|
4
4
|
import {PropertyConfig} from "#src/config/PropertyConfig";
|
|
@@ -143,6 +143,17 @@ export class ConfigAbstract {
|
|
|
143
143
|
return this.#activeProfile
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
/**
|
|
147
|
+
* @return {string[]}
|
|
148
|
+
*/
|
|
149
|
+
get profiles() {
|
|
150
|
+
return Object.keys(this.#profileData.profile)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
exists() {
|
|
154
|
+
return existsSync(this.#path)
|
|
155
|
+
}
|
|
156
|
+
|
|
146
157
|
/**
|
|
147
158
|
* Prepare the configuration by defining properties.
|
|
148
159
|
* @param {{[p: string]: PropertyConfig}} propertyConfig - The configuration properties.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {checkHost, checkIpV4Cidr, checkPort, checkUrl} from "#src/utils/checkFunctions";
|
|
1
|
+
import {checkHost, checkInArray, checkIpV4Cidr, checkPort, checkUrl} from "#src/utils/checkFunctions";
|
|
2
2
|
import {ConfigAbstract, VISIBILITY_PUBLIC} from "#src/config/ConfigAbstract";
|
|
3
3
|
import {property} from "#src/config/PropertyConfig";
|
|
4
4
|
import {ConfigManager} from "#src/config/ConfigManager";
|
|
@@ -58,6 +58,15 @@ export class GlobalLocalShardConfigAbstract extends ConfigAbstract {
|
|
|
58
58
|
return checkHost(val)
|
|
59
59
|
}
|
|
60
60
|
}),
|
|
61
|
+
protocol: property({
|
|
62
|
+
visibility: VISIBILITY_PUBLIC,
|
|
63
|
+
writeable: true,
|
|
64
|
+
type: String,
|
|
65
|
+
defaultValue: 'http',
|
|
66
|
+
validate(val) {
|
|
67
|
+
return checkInArray(val, ['http', 'https'])
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
/**
|
|
@@ -159,3 +159,15 @@ export const checkPort = (valueOrSharedArg, isArgument = false, value) => {
|
|
|
159
159
|
|
|
160
160
|
return value
|
|
161
161
|
}
|
|
162
|
+
|
|
163
|
+
export const checkProtocol = (value) => {
|
|
164
|
+
return checkInArray(value, ['http', 'https'])
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const checkInArray = (val, arr) => {
|
|
168
|
+
if (!arr.includes(val)) {
|
|
169
|
+
throw new InvalidArgumentError(`Value must be one of (${arr.join(', ')})`)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return val
|
|
173
|
+
}
|