tunli 0.0.19

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.
Files changed (63) hide show
  1. package/LICENSE.md +595 -0
  2. package/README.md +135 -0
  3. package/bin/tunli +11 -0
  4. package/client.js +31 -0
  5. package/package.json +51 -0
  6. package/src/cli-app/Dashboard.js +146 -0
  7. package/src/cli-app/Screen.js +135 -0
  8. package/src/cli-app/elements/ElementNode.js +97 -0
  9. package/src/cli-app/elements/Line.js +21 -0
  10. package/src/cli-app/elements/List/List.js +227 -0
  11. package/src/cli-app/elements/List/ListCell.js +83 -0
  12. package/src/cli-app/elements/List/ListColumn.js +52 -0
  13. package/src/cli-app/elements/List/ListRow.js +118 -0
  14. package/src/cli-app/elements/Row.js +38 -0
  15. package/src/cli-app/helper/utils.js +42 -0
  16. package/src/commands/Action/addDelValuesAction.js +56 -0
  17. package/src/commands/CommandAuth.js +32 -0
  18. package/src/commands/CommandClearAll.js +27 -0
  19. package/src/commands/CommandConfig.js +57 -0
  20. package/src/commands/CommandHTTP.js +131 -0
  21. package/src/commands/CommandInvite.js +38 -0
  22. package/src/commands/CommandRefresh.js +35 -0
  23. package/src/commands/CommandRegister.js +48 -0
  24. package/src/commands/Option/DeleteOption.js +6 -0
  25. package/src/commands/Option/SelectConfigOption.js +52 -0
  26. package/src/commands/SubCommand/AllowDenyCidrCommand.js +28 -0
  27. package/src/commands/SubCommand/HostCommand.js +22 -0
  28. package/src/commands/SubCommand/PortCommand.js +20 -0
  29. package/src/commands/helper/AliasResolver.js +13 -0
  30. package/src/commands/helper/BindArgs.js +53 -0
  31. package/src/commands/helper/SharedArg.js +32 -0
  32. package/src/commands/utils.js +96 -0
  33. package/src/config/ConfigAbstract.js +318 -0
  34. package/src/config/ConfigManager.js +70 -0
  35. package/src/config/GlobalConfig.js +14 -0
  36. package/src/config/GlobalLocalShardConfigAbstract.js +76 -0
  37. package/src/config/LocalConfig.js +7 -0
  38. package/src/config/PropertyConfig.js +122 -0
  39. package/src/config/SystemConfig.js +31 -0
  40. package/src/core/FS/utils.js +60 -0
  41. package/src/core/Ref.js +70 -0
  42. package/src/lib/Flow/getCurrentIp.js +18 -0
  43. package/src/lib/Flow/getLatestVersion.js +13 -0
  44. package/src/lib/Flow/proxyUrl.js +32 -0
  45. package/src/lib/Flow/validateAuthToken.js +19 -0
  46. package/src/lib/HttpClient.js +61 -0
  47. package/src/lib/defs.js +10 -0
  48. package/src/net/IPV4.js +139 -0
  49. package/src/net/http/IncomingMessage.js +92 -0
  50. package/src/net/http/ServerResponse.js +126 -0
  51. package/src/net/http/TunliRequest.js +1 -0
  52. package/src/net/http/TunliResponse.js +1 -0
  53. package/src/net/http/TunnelRequest.js +177 -0
  54. package/src/net/http/TunnelResponse.js +119 -0
  55. package/src/tunnel-client/TunnelClient.js +136 -0
  56. package/src/utils/arrayFunctions.js +45 -0
  57. package/src/utils/checkFunctions.js +161 -0
  58. package/src/utils/cliFunctions.js +62 -0
  59. package/src/utils/createRequest.js +12 -0
  60. package/src/utils/httpFunction.js +23 -0
  61. package/src/utils/npmFunctions.js +27 -0
  62. package/src/utils/stringFunctions.js +34 -0
  63. package/types/index.d.ts +112 -0
@@ -0,0 +1,23 @@
1
+ import {IncomingMessage} from "#src/net/http/IncomingMessage"
2
+ import {Socket} from "socket.io-client"
3
+
4
+ /**
5
+ * Retrieves the remote address from the request headers.
6
+ * @param {http.IncomingMessage|SocketIoRawRequestObject} request - The incoming HTTP or Socket.IO request object.
7
+ * @return {string} - The remote address.
8
+ */
9
+ export const getRemoteAddress = (request) => {
10
+ return request.headers['x-real-ip']
11
+ ?? request.headers['x-forwarded-for']
12
+ }
13
+
14
+ /**
15
+ * Creates an IncomingMessage instance from a raw Socket.IO request object.
16
+ * @param {SocketIoRawRequestObject} req - The raw Socket.IO request object.
17
+ * @param {string} requestId - The unique request identifier.
18
+ * @param {Socket} socket - The socket associated with the request.
19
+ * @return {IncomingMessage} - The created IncomingMessage instance.
20
+ */
21
+ export const createRequestFromRaw = (req, requestId, socket) => {
22
+ return new IncomingMessage(req, requestId, socket)
23
+ }
@@ -0,0 +1,27 @@
1
+ import {exec} from 'child_process';
2
+ import {dirname, join} from 'path';
3
+
4
+ export const checkGlobalInstallation = (packageName) => {
5
+ return new Promise((resolve, reject) => {
6
+ exec(`npm list -g --depth=0 ${packageName}`, (error, stdout, stderr) => {
7
+ if (stdout.includes(packageName)) {
8
+ resolve(true)
9
+ } else {
10
+ resolve(false)
11
+ }
12
+ });
13
+ });
14
+ };
15
+
16
+ export const checkLocalInstallation = (packageName) => {
17
+ const localPath = join(process.cwd(), 'node_modules', packageName)
18
+ return new Promise((resolve, reject) => {
19
+ exec(`npm list --depth=0 ${packageName}`, {cwd: dirname(process.argv[1])}, (error, stdout, stderr) => {
20
+ if (stdout.includes(localPath)) {
21
+ resolve(true)
22
+ } else {
23
+ resolve(false)
24
+ }
25
+ })
26
+ })
27
+ }
@@ -0,0 +1,34 @@
1
+ export const trimEnd = (string, trimChar = ' ') => {
2
+ const regex = new RegExp(`${trimChar}+$`)
3
+ return string.replace(regex, '')
4
+ }
5
+
6
+ export const trimStart = (string, trimChar) => {
7
+ const regex = new RegExp(`^${trimChar}+`)
8
+ return string.replace(regex, '')
9
+ }
10
+
11
+ export const removeControlChars = (string) => {
12
+ const removeControlCharsRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
13
+ return string.replace(removeControlCharsRegex, '')
14
+ }
15
+
16
+ export const padEndIgnoreControlChars = (string, maxLength, fillString = ' ', autoSubstring = false) => {
17
+
18
+ if (maxLength < 0) {
19
+ return string
20
+ }
21
+
22
+ const stringWithoutCC = removeControlChars(string)
23
+
24
+ if (autoSubstring !== false && stringWithoutCC.length > maxLength) {
25
+ if (autoSubstring !== true) {
26
+ return stringWithoutCC.substring(0, maxLength - autoSubstring.length) + autoSubstring
27
+ } else {
28
+ return stringWithoutCC.substring(0, maxLength)
29
+ }
30
+ }
31
+
32
+ const padding = ''.padEnd(maxLength - stringWithoutCC.length, fillString)
33
+ return `${string}${padding}`
34
+ }
@@ -0,0 +1,112 @@
1
+ import {Socket} from 'socket.io-client';
2
+
3
+ export interface Headers {
4
+
5
+ host: string
6
+
7
+ [name: string]: string
8
+ }
9
+
10
+ export type RequestMethod = "GET" | "POST" | "PATCH" | "DELETE" | "HEAD" | "OPTION" | "PUT"
11
+
12
+ export type RequestId = string
13
+
14
+ export type IncomingSocketIoRequest = {
15
+ method: RequestMethod
16
+ headers: Headers
17
+ path: string
18
+ port: number
19
+ hostname: string
20
+ }
21
+
22
+ export type SocketIoRawRequestObject = {
23
+ method: RequestMethod
24
+ headers: Headers
25
+ path: string
26
+ requestId?: string
27
+ tunnelSocket?: Socket
28
+ }
29
+
30
+ export type cliListOption = {
31
+ maxLength?: number
32
+ minLength?: number
33
+ length?: number
34
+ reverse?: boolean
35
+ minWidth?: number | Array<number|string|boolean>
36
+ maxWidth?: number | Array<number|string|boolean>
37
+ }
38
+
39
+ export type profileDump = {}
40
+ export type proxyURL = string
41
+ export type profileConfig = {
42
+ system: {}
43
+ profile: {}
44
+ }
45
+
46
+ interface ConfigAbstract {
47
+ }
48
+
49
+ export interface AppConfig {
50
+
51
+ port: number
52
+ host: string
53
+ authToken: string
54
+ proxyURL: proxyURL
55
+ path: undefined
56
+ origin: string
57
+ denyCidr?: ipCidr[]
58
+ allowCidr?: ipCidr[]
59
+
60
+ get fallbackConfig(): AppConfig
61
+
62
+ get profileData(): profileConfig
63
+
64
+ get configPath(): string
65
+
66
+ get profile(): profileAlias
67
+
68
+ copyCurrentProfileTo(profile: profileAlias): this
69
+
70
+ save(): this
71
+
72
+ useSystem(): AppConfig
73
+
74
+ use(profile: profileAlias): AppConfig
75
+
76
+ del(configKey: string): AppConfig
77
+
78
+ copyCurrentProfileTo(profile: profileAlias): this
79
+
80
+ dump(): profileDump
81
+ }
82
+
83
+ export type protocol = "http" | "https"
84
+ export type ipCidr = string
85
+ export type profileAlias = string
86
+ export type tunnelClientOptions = {
87
+ protocol: protocol
88
+ self: boolean
89
+ port: number
90
+ host: string
91
+ authToken: string
92
+ server: proxyURL
93
+ path?: string
94
+ origin?: string
95
+ save?: profileAlias | true
96
+ denyCidr?: ipCidr[]
97
+ allowCidr?: ipCidr[]
98
+ allowSelf?: ipCidr[]
99
+ }
100
+
101
+ export type keypressEventDetails = {
102
+ sequence: string
103
+ name: string
104
+ ctrl: boolean
105
+ meta: boolean
106
+ shift: boolean
107
+ full: string
108
+ }
109
+
110
+ export interface keypressEventListener {
111
+ (char: string, details: keypressEventDetails): void
112
+ }