tunli 0.0.27 → 0.2.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.
Files changed (388) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +158 -67
  3. package/bin/tunli +4 -5
  4. package/dist/api-client/ApiClient.d.ts +18 -0
  5. package/dist/api-client/ApiClient.d.ts.map +1 -0
  6. package/dist/api-client/ApiClient.js +100 -0
  7. package/dist/api-client/ApiClient.js.map +1 -0
  8. package/dist/api-client/types.d.ts +26 -0
  9. package/dist/api-client/types.d.ts.map +1 -0
  10. package/dist/api-client/types.js +2 -0
  11. package/dist/api-client/types.js.map +1 -0
  12. package/dist/api-client/utils.d.ts +4 -0
  13. package/dist/api-client/utils.d.ts.map +1 -0
  14. package/dist/api-client/utils.js +13 -0
  15. package/dist/api-client/utils.js.map +1 -0
  16. package/dist/cli-app/AppEventEmitter.d.ts +57 -0
  17. package/dist/cli-app/AppEventEmitter.d.ts.map +1 -0
  18. package/dist/cli-app/AppEventEmitter.js +11 -0
  19. package/dist/cli-app/AppEventEmitter.js.map +1 -0
  20. package/dist/cli-app/Dashboard.d.ts +4 -0
  21. package/dist/cli-app/Dashboard.d.ts.map +1 -0
  22. package/dist/cli-app/Dashboard.js +241 -0
  23. package/dist/cli-app/Dashboard.js.map +1 -0
  24. package/dist/cli-app/LiveLog.d.ts +4 -0
  25. package/dist/cli-app/LiveLog.d.ts.map +1 -0
  26. package/dist/cli-app/LiveLog.js +28 -0
  27. package/dist/cli-app/LiveLog.js.map +1 -0
  28. package/dist/cli-app/types.d.ts +10 -0
  29. package/dist/cli-app/types.d.ts.map +1 -0
  30. package/dist/cli-app/types.js +2 -0
  31. package/dist/cli-app/types.js.map +1 -0
  32. package/dist/cli-app/versionCheck.d.ts +4 -0
  33. package/dist/cli-app/versionCheck.d.ts.map +1 -0
  34. package/dist/cli-app/versionCheck.js +46 -0
  35. package/dist/cli-app/versionCheck.js.map +1 -0
  36. package/dist/client.d.ts +2 -0
  37. package/dist/client.d.ts.map +1 -0
  38. package/dist/client.js +75 -0
  39. package/dist/client.js.map +1 -0
  40. package/dist/commander/Argument.d.ts +19 -0
  41. package/dist/commander/Argument.d.ts.map +1 -0
  42. package/dist/commander/Argument.js +25 -0
  43. package/dist/commander/Argument.js.map +1 -0
  44. package/dist/commander/Command.d.ts +23 -0
  45. package/dist/commander/Command.d.ts.map +1 -0
  46. package/dist/commander/Command.js +159 -0
  47. package/dist/commander/Command.js.map +1 -0
  48. package/dist/commander/InvalidArgumentError.d.ts +5 -0
  49. package/dist/commander/InvalidArgumentError.d.ts.map +1 -0
  50. package/dist/commander/InvalidArgumentError.js +8 -0
  51. package/dist/commander/InvalidArgumentError.js.map +1 -0
  52. package/dist/commander/Option.d.ts +15 -0
  53. package/dist/commander/Option.d.ts.map +1 -0
  54. package/dist/commander/Option.js +43 -0
  55. package/dist/commander/Option.js.map +1 -0
  56. package/dist/commander/index.d.ts +7 -0
  57. package/dist/commander/index.d.ts.map +1 -0
  58. package/dist/commander/index.js +5 -0
  59. package/dist/commander/index.js.map +1 -0
  60. package/dist/commander/types.d.ts +2 -0
  61. package/dist/commander/types.d.ts.map +1 -0
  62. package/dist/commander/types.js +2 -0
  63. package/dist/commander/types.js.map +1 -0
  64. package/dist/commands/CommandAuth/CommandAuth.d.ts +4 -0
  65. package/dist/commands/CommandAuth/CommandAuth.d.ts.map +1 -0
  66. package/dist/commands/CommandAuth/CommandAuth.js +24 -0
  67. package/dist/commands/CommandAuth/CommandAuth.js.map +1 -0
  68. package/dist/commands/CommandConfig/CommandConfig.d.ts +4 -0
  69. package/dist/commands/CommandConfig/CommandConfig.d.ts.map +1 -0
  70. package/dist/commands/CommandConfig/CommandConfig.js +37 -0
  71. package/dist/commands/CommandConfig/CommandConfig.js.map +1 -0
  72. package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.d.ts +4 -0
  73. package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.d.ts.map +1 -0
  74. package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.js +20 -0
  75. package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.js.map +1 -0
  76. package/dist/commands/CommandConfig/sub-commands/configGetCommand.d.ts +5 -0
  77. package/dist/commands/CommandConfig/sub-commands/configGetCommand.d.ts.map +1 -0
  78. package/dist/commands/CommandConfig/sub-commands/configGetCommand.js +23 -0
  79. package/dist/commands/CommandConfig/sub-commands/configGetCommand.js.map +1 -0
  80. package/dist/commands/CommandConfig/sub-commands/configSetCommand.d.ts +4 -0
  81. package/dist/commands/CommandConfig/sub-commands/configSetCommand.d.ts.map +1 -0
  82. package/dist/commands/CommandConfig/sub-commands/configSetCommand.js +69 -0
  83. package/dist/commands/CommandConfig/sub-commands/configSetCommand.js.map +1 -0
  84. package/dist/commands/CommandConfig/types.d.ts +6 -0
  85. package/dist/commands/CommandConfig/types.d.ts.map +1 -0
  86. package/dist/commands/CommandConfig/types.js +2 -0
  87. package/dist/commands/CommandConfig/types.js.map +1 -0
  88. package/dist/commands/CommandConfig/utils/preparePrimaryOptions.d.ts +3 -0
  89. package/dist/commands/CommandConfig/utils/preparePrimaryOptions.d.ts.map +1 -0
  90. package/dist/commands/CommandConfig/utils/preparePrimaryOptions.js +8 -0
  91. package/dist/commands/CommandConfig/utils/preparePrimaryOptions.js.map +1 -0
  92. package/dist/commands/CommandConfig/utils/resolveConfig.d.ts +8 -0
  93. package/dist/commands/CommandConfig/utils/resolveConfig.d.ts.map +1 -0
  94. package/dist/commands/CommandConfig/utils/resolveConfig.js +33 -0
  95. package/dist/commands/CommandConfig/utils/resolveConfig.js.map +1 -0
  96. package/dist/commands/CommandConfig/utils/sharedOptions.d.ts +3 -0
  97. package/dist/commands/CommandConfig/utils/sharedOptions.d.ts.map +1 -0
  98. package/dist/commands/CommandConfig/utils/sharedOptions.js +14 -0
  99. package/dist/commands/CommandConfig/utils/sharedOptions.js.map +1 -0
  100. package/dist/commands/CommandDaemon/CommandDaemon.d.ts +4 -0
  101. package/dist/commands/CommandDaemon/CommandDaemon.d.ts.map +1 -0
  102. package/dist/commands/CommandDaemon/CommandDaemon.js +57 -0
  103. package/dist/commands/CommandDaemon/CommandDaemon.js.map +1 -0
  104. package/dist/commands/CommandDashboard/CommandDashboard.d.ts +4 -0
  105. package/dist/commands/CommandDashboard/CommandDashboard.d.ts.map +1 -0
  106. package/dist/commands/CommandDashboard/CommandDashboard.js +54 -0
  107. package/dist/commands/CommandDashboard/CommandDashboard.js.map +1 -0
  108. package/dist/commands/CommandHTTP/CommandHttp.d.ts +4 -0
  109. package/dist/commands/CommandHTTP/CommandHttp.d.ts.map +1 -0
  110. package/dist/commands/CommandHTTP/CommandHttp.js +50 -0
  111. package/dist/commands/CommandHTTP/CommandHttp.js.map +1 -0
  112. package/dist/commands/CommandInit/CommandInit.d.ts +4 -0
  113. package/dist/commands/CommandInit/CommandInit.d.ts.map +1 -0
  114. package/dist/commands/CommandInit/CommandInit.js +36 -0
  115. package/dist/commands/CommandInit/CommandInit.js.map +1 -0
  116. package/dist/commands/CommandList/CommandList.d.ts +4 -0
  117. package/dist/commands/CommandList/CommandList.d.ts.map +1 -0
  118. package/dist/commands/CommandList/CommandList.js +54 -0
  119. package/dist/commands/CommandList/CommandList.js.map +1 -0
  120. package/dist/commands/CommandLogs/CommandLogs.d.ts +4 -0
  121. package/dist/commands/CommandLogs/CommandLogs.d.ts.map +1 -0
  122. package/dist/commands/CommandLogs/CommandLogs.js +33 -0
  123. package/dist/commands/CommandLogs/CommandLogs.js.map +1 -0
  124. package/dist/commands/CommandProfile/CommandProfile.d.ts +5 -0
  125. package/dist/commands/CommandProfile/CommandProfile.d.ts.map +1 -0
  126. package/dist/commands/CommandProfile/CommandProfile.js +64 -0
  127. package/dist/commands/CommandProfile/CommandProfile.js.map +1 -0
  128. package/dist/commands/CommandRegister/CommandRegister.d.ts +4 -0
  129. package/dist/commands/CommandRegister/CommandRegister.d.ts.map +1 -0
  130. package/dist/commands/CommandRegister/CommandRegister.js +43 -0
  131. package/dist/commands/CommandRegister/CommandRegister.js.map +1 -0
  132. package/dist/commands/CommandRestart/CommandRestart.d.ts +4 -0
  133. package/dist/commands/CommandRestart/CommandRestart.d.ts.map +1 -0
  134. package/dist/commands/CommandRestart/CommandRestart.js +62 -0
  135. package/dist/commands/CommandRestart/CommandRestart.js.map +1 -0
  136. package/dist/commands/CommandServer/CommandServer.d.ts +4 -0
  137. package/dist/commands/CommandServer/CommandServer.d.ts.map +1 -0
  138. package/dist/commands/CommandServer/CommandServer.js +24 -0
  139. package/dist/commands/CommandServer/CommandServer.js.map +1 -0
  140. package/dist/commands/CommandStop/CommandStop.d.ts +4 -0
  141. package/dist/commands/CommandStop/CommandStop.d.ts.map +1 -0
  142. package/dist/commands/CommandStop/CommandStop.js +25 -0
  143. package/dist/commands/CommandStop/CommandStop.js.map +1 -0
  144. package/dist/commands/CommandUpdate/CommandUpdate.d.ts +4 -0
  145. package/dist/commands/CommandUpdate/CommandUpdate.d.ts.map +1 -0
  146. package/dist/commands/CommandUpdate/CommandUpdate.js +38 -0
  147. package/dist/commands/CommandUpdate/CommandUpdate.js.map +1 -0
  148. package/dist/commands/CommandUseProfile/CommandUseProfile.d.ts +4 -0
  149. package/dist/commands/CommandUseProfile/CommandUseProfile.d.ts.map +1 -0
  150. package/dist/commands/CommandUseProfile/CommandUseProfile.js +63 -0
  151. package/dist/commands/CommandUseProfile/CommandUseProfile.js.map +1 -0
  152. package/dist/commands/helper/Help.d.ts +4 -0
  153. package/dist/commands/helper/Help.d.ts.map +1 -0
  154. package/dist/commands/helper/Help.js +134 -0
  155. package/dist/commands/helper/Help.js.map +1 -0
  156. package/dist/commands/helper/Parser.d.ts +55 -0
  157. package/dist/commands/helper/Parser.d.ts.map +1 -0
  158. package/dist/commands/helper/Parser.js +280 -0
  159. package/dist/commands/helper/Parser.js.map +1 -0
  160. package/dist/commands/shared/allowDenyCidrCommand.d.ts +3 -0
  161. package/dist/commands/shared/allowDenyCidrCommand.d.ts.map +1 -0
  162. package/dist/commands/shared/allowDenyCidrCommand.js +10 -0
  163. package/dist/commands/shared/allowDenyCidrCommand.js.map +1 -0
  164. package/dist/commands/shared/configServersCommand.d.ts +4 -0
  165. package/dist/commands/shared/configServersCommand.d.ts.map +1 -0
  166. package/dist/commands/shared/configServersCommand.js +19 -0
  167. package/dist/commands/shared/configServersCommand.js.map +1 -0
  168. package/dist/commands/utils.d.ts +3 -0
  169. package/dist/commands/utils.d.ts.map +1 -0
  170. package/dist/commands/utils.js +17 -0
  171. package/dist/commands/utils.js.map +1 -0
  172. package/dist/config/ParsedConfig.d.ts +31 -0
  173. package/dist/config/ParsedConfig.d.ts.map +1 -0
  174. package/dist/config/ParsedConfig.js +116 -0
  175. package/dist/config/ParsedConfig.js.map +1 -0
  176. package/dist/config/ParsedGlobalConfig.d.ts +5 -0
  177. package/dist/config/ParsedGlobalConfig.d.ts.map +1 -0
  178. package/dist/config/ParsedGlobalConfig.js +7 -0
  179. package/dist/config/ParsedGlobalConfig.js.map +1 -0
  180. package/dist/config/ParsedLocalConfig.d.ts +5 -0
  181. package/dist/config/ParsedLocalConfig.d.ts.map +1 -0
  182. package/dist/config/ParsedLocalConfig.js +7 -0
  183. package/dist/config/ParsedLocalConfig.js.map +1 -0
  184. package/dist/config/ParsedProfileConfig.d.ts +46 -0
  185. package/dist/config/ParsedProfileConfig.d.ts.map +1 -0
  186. package/dist/config/ParsedProfileConfig.js +120 -0
  187. package/dist/config/ParsedProfileConfig.js.map +1 -0
  188. package/dist/config/ParsedServerConfig.d.ts +20 -0
  189. package/dist/config/ParsedServerConfig.d.ts.map +1 -0
  190. package/dist/config/ParsedServerConfig.js +55 -0
  191. package/dist/config/ParsedServerConfig.js.map +1 -0
  192. package/dist/config/TempProfileConfig.d.ts +8 -0
  193. package/dist/config/TempProfileConfig.d.ts.map +1 -0
  194. package/dist/config/TempProfileConfig.js +13 -0
  195. package/dist/config/TempProfileConfig.js.map +1 -0
  196. package/dist/config/utils.d.ts +2 -0
  197. package/dist/config/utils.d.ts.map +1 -0
  198. package/dist/config/utils.js +8 -0
  199. package/dist/config/utils.js.map +1 -0
  200. package/dist/config/validations/validateProfileConfig.d.ts +4 -0
  201. package/dist/config/validations/validateProfileConfig.d.ts.map +1 -0
  202. package/dist/config/validations/validateProfileConfig.js +76 -0
  203. package/dist/config/validations/validateProfileConfig.js.map +1 -0
  204. package/dist/core/FS/utils.d.ts +12 -0
  205. package/dist/core/FS/utils.d.ts.map +1 -0
  206. package/dist/core/FS/utils.js +55 -0
  207. package/dist/core/FS/utils.js.map +1 -0
  208. package/dist/daemon/DaemonClient.d.ts +16 -0
  209. package/dist/daemon/DaemonClient.d.ts.map +1 -0
  210. package/dist/daemon/DaemonClient.js +158 -0
  211. package/dist/daemon/DaemonClient.js.map +1 -0
  212. package/dist/daemon/DaemonServer.d.ts +8 -0
  213. package/dist/daemon/DaemonServer.d.ts.map +1 -0
  214. package/dist/daemon/DaemonServer.js +201 -0
  215. package/dist/daemon/DaemonServer.js.map +1 -0
  216. package/dist/daemon/protocol.d.ts +101 -0
  217. package/dist/daemon/protocol.d.ts.map +1 -0
  218. package/dist/daemon/protocol.js +2 -0
  219. package/dist/daemon/protocol.js.map +1 -0
  220. package/dist/daemon-main.d.ts +2 -0
  221. package/dist/daemon-main.d.ts.map +1 -0
  222. package/dist/daemon-main.js +13 -0
  223. package/dist/daemon-main.js.map +1 -0
  224. package/dist/launcher-main.d.ts +2 -0
  225. package/dist/launcher-main.d.ts.map +1 -0
  226. package/dist/launcher-main.js +57 -0
  227. package/dist/launcher-main.js.map +1 -0
  228. package/dist/lib/Flow/applyUpdate.d.ts +3 -0
  229. package/dist/lib/Flow/applyUpdate.d.ts.map +1 -0
  230. package/dist/lib/Flow/applyUpdate.js +34 -0
  231. package/dist/lib/Flow/applyUpdate.js.map +1 -0
  232. package/dist/lib/Flow/downloadBinaryUpdate.d.ts +3 -0
  233. package/dist/lib/Flow/downloadBinaryUpdate.d.ts.map +1 -0
  234. package/dist/lib/Flow/downloadBinaryUpdate.js +54 -0
  235. package/dist/lib/Flow/downloadBinaryUpdate.js.map +1 -0
  236. package/dist/lib/Flow/getLatestVersion.d.ts +2 -0
  237. package/dist/lib/Flow/getLatestVersion.d.ts.map +1 -0
  238. package/dist/lib/Flow/getLatestVersion.js +13 -0
  239. package/dist/lib/Flow/getLatestVersion.js.map +1 -0
  240. package/dist/lib/defs.d.ts +18 -0
  241. package/dist/lib/defs.d.ts.map +1 -0
  242. package/dist/lib/defs.js +33 -0
  243. package/dist/lib/defs.js.map +1 -0
  244. package/dist/logger/logger.d.ts +6 -0
  245. package/dist/logger/logger.d.ts.map +1 -0
  246. package/dist/logger/logger.js +34 -0
  247. package/dist/logger/logger.js.map +1 -0
  248. package/dist/output-formats/colors.d.ts +7 -0
  249. package/dist/output-formats/colors.d.ts.map +1 -0
  250. package/dist/output-formats/colors.js +8 -0
  251. package/dist/output-formats/colors.js.map +1 -0
  252. package/dist/output-formats/formatConfig.d.ts +3 -0
  253. package/dist/output-formats/formatConfig.d.ts.map +1 -0
  254. package/dist/output-formats/formatConfig.js +59 -0
  255. package/dist/output-formats/formatConfig.js.map +1 -0
  256. package/dist/output-formats/formatConfigPath.d.ts +4 -0
  257. package/dist/output-formats/formatConfigPath.d.ts.map +1 -0
  258. package/dist/output-formats/formatConfigPath.js +7 -0
  259. package/dist/output-formats/formatConfigPath.js.map +1 -0
  260. package/dist/output-formats/formatPath.d.ts +2 -0
  261. package/dist/output-formats/formatPath.d.ts.map +1 -0
  262. package/dist/output-formats/formatPath.js +6 -0
  263. package/dist/output-formats/formatPath.js.map +1 -0
  264. package/dist/output-formats/formatProfile.d.ts +3 -0
  265. package/dist/output-formats/formatProfile.d.ts.map +1 -0
  266. package/dist/output-formats/formatProfile.js +35 -0
  267. package/dist/output-formats/formatProfile.js.map +1 -0
  268. package/dist/output-formats/formatProfilesShort.d.ts +3 -0
  269. package/dist/output-formats/formatProfilesShort.d.ts.map +1 -0
  270. package/dist/output-formats/formatProfilesShort.js +19 -0
  271. package/dist/output-formats/formatProfilesShort.js.map +1 -0
  272. package/dist/output-formats/formatSaveResult.d.ts +4 -0
  273. package/dist/output-formats/formatSaveResult.d.ts.map +1 -0
  274. package/dist/output-formats/formatSaveResult.js +7 -0
  275. package/dist/output-formats/formatSaveResult.js.map +1 -0
  276. package/dist/output-formats/table.d.ts +8 -0
  277. package/dist/output-formats/table.d.ts.map +1 -0
  278. package/dist/output-formats/table.js +15 -0
  279. package/dist/output-formats/table.js.map +1 -0
  280. package/dist/package-json/packageJson.d.ts +6 -0
  281. package/dist/package-json/packageJson.d.ts.map +1 -0
  282. package/dist/package-json/packageJson.js +12 -0
  283. package/dist/package-json/packageJson.js.map +1 -0
  284. package/dist/proxy/Proxy.d.ts +6 -0
  285. package/dist/proxy/Proxy.d.ts.map +1 -0
  286. package/dist/proxy/Proxy.js +203 -0
  287. package/dist/proxy/Proxy.js.map +1 -0
  288. package/dist/sea-main.d.ts +2 -0
  289. package/dist/sea-main.d.ts.map +1 -0
  290. package/dist/sea-main.js +20 -0
  291. package/dist/sea-main.js.map +1 -0
  292. package/dist/types/types.d.ts +55 -0
  293. package/dist/types/types.d.ts.map +1 -0
  294. package/dist/types/types.js +2 -0
  295. package/dist/types/types.js.map +1 -0
  296. package/dist/utils/arrayFunctions.d.ts +24 -0
  297. package/dist/utils/arrayFunctions.d.ts.map +1 -0
  298. package/dist/utils/arrayFunctions.js +43 -0
  299. package/dist/utils/arrayFunctions.js.map +1 -0
  300. package/dist/utils/assertFunctions.d.ts +7 -0
  301. package/dist/utils/assertFunctions.d.ts.map +1 -0
  302. package/dist/utils/assertFunctions.js +20 -0
  303. package/dist/utils/assertFunctions.js.map +1 -0
  304. package/dist/utils/checkFunctions.d.ts +34 -0
  305. package/dist/utils/checkFunctions.d.ts.map +1 -0
  306. package/dist/utils/checkFunctions.js +87 -0
  307. package/dist/utils/checkFunctions.js.map +1 -0
  308. package/dist/utils/cliFunctions.d.ts +10 -0
  309. package/dist/utils/cliFunctions.d.ts.map +1 -0
  310. package/dist/utils/cliFunctions.js +68 -0
  311. package/dist/utils/cliFunctions.js.map +1 -0
  312. package/dist/utils/hashFunctions.d.ts +10 -0
  313. package/dist/utils/hashFunctions.d.ts.map +1 -0
  314. package/dist/utils/hashFunctions.js +11 -0
  315. package/dist/utils/hashFunctions.js.map +1 -0
  316. package/dist/utils/npmFunctions.d.ts +3 -0
  317. package/dist/utils/npmFunctions.d.ts.map +1 -0
  318. package/dist/utils/npmFunctions.js +28 -0
  319. package/dist/utils/npmFunctions.js.map +1 -0
  320. package/dist/utils/stringFunctions.d.ts +12 -0
  321. package/dist/utils/stringFunctions.d.ts.map +1 -0
  322. package/dist/utils/stringFunctions.js +37 -0
  323. package/dist/utils/stringFunctions.js.map +1 -0
  324. package/package.json +39 -16
  325. package/client.js +0 -33
  326. package/src/cli-app/Dashboard.js +0 -220
  327. package/src/cli-app/Screen/FullScreenModal.js +0 -63
  328. package/src/cli-app/Screen.js +0 -140
  329. package/src/cli-app/elements/ElementNode.js +0 -97
  330. package/src/cli-app/elements/Line.js +0 -21
  331. package/src/cli-app/elements/List/List.js +0 -227
  332. package/src/cli-app/elements/List/ListCell.js +0 -83
  333. package/src/cli-app/elements/List/ListColumn.js +0 -52
  334. package/src/cli-app/elements/List/ListRow.js +0 -118
  335. package/src/cli-app/elements/Row.js +0 -38
  336. package/src/cli-app/helper/utils.js +0 -42
  337. package/src/commands/Action/addDelValuesAction.js +0 -56
  338. package/src/commands/CommandAuth.js +0 -32
  339. package/src/commands/CommandClearAll.js +0 -27
  340. package/src/commands/CommandConfig.js +0 -59
  341. package/src/commands/CommandHTTP.js +0 -192
  342. package/src/commands/CommandInvite.js +0 -38
  343. package/src/commands/CommandRefresh.js +0 -35
  344. package/src/commands/CommandRegister.js +0 -48
  345. package/src/commands/Option/DeleteOption.js +0 -6
  346. package/src/commands/Option/ProfileListOption.js +0 -65
  347. package/src/commands/Option/SelectConfigOption.js +0 -52
  348. package/src/commands/SubCommand/AllowDenyCidrCommand.js +0 -28
  349. package/src/commands/SubCommand/HostCommand.js +0 -22
  350. package/src/commands/SubCommand/PortCommand.js +0 -20
  351. package/src/commands/SubCommand/ProtocolCommand.js +0 -21
  352. package/src/commands/helper/AliasResolver.js +0 -13
  353. package/src/commands/helper/BindArgs.js +0 -53
  354. package/src/commands/helper/SharedArg.js +0 -32
  355. package/src/commands/utils.js +0 -96
  356. package/src/config/ConfigAbstract.js +0 -353
  357. package/src/config/ConfigManager.js +0 -70
  358. package/src/config/GlobalConfig.js +0 -14
  359. package/src/config/GlobalLocalShardConfigAbstract.js +0 -98
  360. package/src/config/LocalConfig.js +0 -7
  361. package/src/config/PropertyConfig.js +0 -122
  362. package/src/config/SystemConfig.js +0 -31
  363. package/src/core/FS/utils.js +0 -60
  364. package/src/core/Ref.js +0 -70
  365. package/src/lib/Flow/getCurrentIp.js +0 -18
  366. package/src/lib/Flow/getLatestVersion.js +0 -13
  367. package/src/lib/Flow/proxyUrl.js +0 -35
  368. package/src/lib/Flow/validateAuthToken.js +0 -19
  369. package/src/lib/HttpClient.js +0 -61
  370. package/src/lib/Proxy.js +0 -42
  371. package/src/lib/defs.js +0 -13
  372. package/src/net/IPV4.js +0 -139
  373. package/src/net/http/IncomingMessage.js +0 -92
  374. package/src/net/http/ServerResponse.js +0 -126
  375. package/src/net/http/TunliRequest.js +0 -1
  376. package/src/net/http/TunliResponse.js +0 -1
  377. package/src/net/http/TunnelRequest.js +0 -229
  378. package/src/net/http/TunnelResponse.js +0 -119
  379. package/src/tunnel-client/TunnelClient.js +0 -144
  380. package/src/utils/arrayFunctions.js +0 -45
  381. package/src/utils/checkFunctions.js +0 -182
  382. package/src/utils/cliFunctions.js +0 -63
  383. package/src/utils/createRequest.js +0 -12
  384. package/src/utils/hashFunctions.js +0 -9
  385. package/src/utils/httpFunction.js +0 -23
  386. package/src/utils/npmFunctions.js +0 -27
  387. package/src/utils/stringFunctions.js +0 -59
  388. package/types/index.d.ts +0 -119
@@ -1,59 +0,0 @@
1
- import {Command} from "commander";
2
- import {ref} from "#src/core/Ref";
3
- import {allowDenyCidrCommand} from "#commands/SubCommand/AllowDenyCidrCommand";
4
- import {portCommand} from "#commands/SubCommand/PortCommand";
5
- import {hostCommand} from "#commands/SubCommand/HostCommand";
6
- import {selectConfigOption} from "#commands/Option/SelectConfigOption";
7
- import {addExample, extendUsage} from "#commands/utils";
8
- import {protocolCommand} from "#commands/SubCommand/ProtocolCommand";
9
-
10
- /**
11
- *
12
- * @param {Ref} configRef
13
- * @param {Command} program
14
- * @returns {(function(*, *, *): void)|*}
15
- */
16
- const exec = (configRef, program) => {
17
-
18
- return async (key, value, options) => {
19
-
20
- /** @type {LocalConfig|GlobalConfig} */
21
- const config = configRef.value
22
-
23
- const maxKeyLength = Math.max(...Object.keys(config.dump()).map(x => x.length))
24
- console.log('location: ', config.configPath, "\n")
25
- for (const [k, v] of Object.entries(config.dump())) {
26
- console.log(k.padEnd(maxKeyLength, ' '), '=', v)
27
- console.log(''.padEnd(maxKeyLength + 3 + (v?.length ?? 9), '-'))
28
- }
29
- }
30
- }
31
- /**
32
- *
33
- * @param {Command} program
34
- */
35
- export const createCommandConfig = (program) => {
36
-
37
- const configRef = ref()
38
-
39
- const cmd = new Command('config')
40
-
41
- cmd.addCommand(allowDenyCidrCommand('allowCidr', cmd, configRef))
42
- cmd.addCommand(allowDenyCidrCommand('denyCidr', cmd, configRef))
43
- cmd.addCommand(portCommand(configRef))
44
- cmd.addCommand(hostCommand(configRef))
45
- cmd.addCommand(protocolCommand(configRef))
46
-
47
- selectConfigOption(cmd, configRef, true)
48
- .action(exec(configRef, program));
49
-
50
- extendUsage(program, cmd)
51
- //
52
- addExample('config host localhost', 'Set the host for the local configuration')
53
- addExample('config port 80', 'Set the port for the local configuration')
54
- addExample('config', 'Show the local configuration')
55
- addExample('config --global', 'Show the global configuration')
56
-
57
- return cmd
58
- }
59
-
@@ -1,192 +0,0 @@
1
- import {Command} from "commander";
2
- import {checkHost, checkPort} from "#src/utils/checkFunctions";
3
- import {isSharedArg, sharedArg} from "#commands/helper/SharedArg";
4
- import {addExample, validateArrayArguments, validateIpV4} from "#commands/utils";
5
- import {bindArgs} from "#commands/helper/BindArgs";
6
- import {ref} from "#src/core/Ref";
7
- import {selectConfigOption} from "#commands/Option/SelectConfigOption";
8
- import {TunnelClient} from "#src/tunnel-client/TunnelClient";
9
- import {renewProxyUrlRegistration, requestNewProxyUrl} from "#lib/Flow/proxyUrl";
10
- import {getCurrentIp} from "#lib/Flow/getCurrentIp";
11
- import {arrayUnique} from "#src/utils/arrayFunctions";
12
- import {initDashboard} from "#src/cli-app/Dashboard";
13
- import {md5} from "#src/utils/hashFunctions";
14
-
15
-
16
- /**
17
- *
18
- * @param {AppConfig} config
19
- * @param {tunnelClientOptions} options
20
- */
21
- const computeProxyURL = async (config, options) => {
22
-
23
- // console.log(new URL(`${options.protocol}://${options.host ?? config.host}:${options.port ?? config.port}`).toString())
24
-
25
- const targetUrlHash = md5(new URL(`${options.protocol}://${options.host ?? config.host}:${options.port ?? config.port}`))
26
-
27
- if (config.profile === 'default') {
28
- let proxyUrl = config.proxyURLs[targetUrlHash]
29
-
30
- if (proxyUrl) {
31
- proxyUrl = await renewProxyUrlRegistration(proxyUrl, config.authToken)
32
- }
33
-
34
- if (!proxyUrl) {
35
- proxyUrl = await requestNewProxyUrl(config.authToken)
36
- config.proxyURLs[targetUrlHash] = proxyUrl
37
- config.update({proxyURLs: config.proxyURLs})
38
- }
39
-
40
- config.proxyURL = proxyUrl
41
-
42
- console.log(config.proxyURL)
43
- return
44
- }
45
-
46
- if (config.proxyURL) {
47
- config.proxyURL = await renewProxyUrlRegistration(config.proxyURL, config.authToken)
48
- }
49
-
50
- if (!config.proxyURL) {
51
- config.proxyURL = await requestNewProxyUrl(config.authToken)
52
- config.update({proxyURL: config.proxyURL})
53
- }
54
- }
55
-
56
- /**
57
- * @callback httpCommandExec
58
- * @param {number} port
59
- * @param {string} host
60
- * @param {tunnelClientOptions} options
61
- * @returns {Promise<void>}
62
- */
63
-
64
- /**
65
- * @param {Ref} configRef
66
- * @returns {httpCommandExec}
67
- */
68
- const exec = (configRef, cmd, program) => {
69
-
70
- return async (port, host, options) => {
71
-
72
- let protocol
73
-
74
- if (['http', 'https'].includes(cmd.parent.args[0])) {
75
- protocol = cmd.parent.args[0]
76
- }
77
-
78
- /** @type {AppConfig} */
79
- const config = configRef.value
80
-
81
- if (options.self) {
82
- options.allowCidr ??= []
83
- options.allowCidr.push(await getCurrentIp())
84
- options.allowCidr = arrayUnique(options.allowCidr)
85
- }
86
-
87
- if (!config.authToken) {
88
- console.error("error: Missing authToken. Please run register firstly")
89
- process.exit()
90
- }
91
-
92
- if (isSharedArg(port)) {
93
- protocol ??= port.value.url?.protocol
94
- host ??= port.value.host ?? port.value.url?.host
95
- port = port.value.port ?? port.value.url?.port
96
- options.port ??= port
97
- options.host ??= host
98
- }
99
-
100
- options.port ??= port
101
- options.host ??= host
102
- options.protocol ??= protocol ?? 'http'
103
-
104
- await computeProxyURL(config, options)
105
-
106
- const save = options.save
107
- delete options.save
108
-
109
- if (save && save !== true) {
110
- config.copyCurrentProfileTo(save).use(save)
111
- }
112
-
113
- for (const [k, v] of Object.entries(options)) {
114
- if (v !== undefined) {
115
- config[k] = v
116
- }
117
- }
118
-
119
- if (save) {
120
- config.save()
121
- }
122
-
123
- /**
124
- * @type {tunnelClientOptions}
125
- */
126
- const clientOptions = {
127
- port: options.port ?? config.port,
128
- host: options.host ?? config.host,
129
- authToken: config.authToken,
130
- server: config.proxyURL,
131
- path: undefined,
132
- allowCidr: options.allowCidr ?? config.allowCidr,
133
- denyCidr: options.denyCidr ?? config.denyCidr,
134
- protocol: options.protocol
135
- }
136
-
137
- const useDashboard = process.env.TUNLI_DASHBOARD !== 'off'
138
-
139
- const client = new TunnelClient(clientOptions)
140
-
141
- client.once('tunnel-connection-error', async (error) => {
142
- error.stopPropagation = true
143
- if (error.data?.connection_exists) {
144
- clientOptions.server = await requestNewProxyUrl(config.authToken)
145
-
146
- if (useDashboard) {
147
- dashboard.forwardingUrl = clientOptions.server
148
- }
149
-
150
- await client.init()
151
- }
152
- })
153
-
154
- const dashboard = useDashboard ? initDashboard(client, clientOptions, config) : null
155
- await client.init(dashboard)
156
-
157
- if (!useDashboard) {
158
- console.log(clientOptions)
159
- }
160
- }
161
- }
162
- /**
163
- * @param {Command} program
164
- */
165
- export const createCommandHTTP = (program) => {
166
-
167
- const configRef = ref()
168
- const cmd = new Command('http')
169
- cmd.alias('https')
170
-
171
- selectConfigOption(cmd, configRef)
172
- // validateAuthToken(cmd, configRef)
173
-
174
- const sharedArgument = sharedArg({})
175
- cmd.argument('[PORT]', 'port welcher durch den proxy erreichbar sein soll (default: "80")', bindArgs(checkPort, sharedArgument, true))
176
- cmd.argument('[HOST]', 'host welcher durch den proxy erreichbar sein soll (default: "localhost"/"config.value")', bindArgs(checkHost, sharedArgument, true))
177
-
178
- cmd.option('--host <string>', 'setting hostname', bindArgs(checkHost, sharedArgument, false))
179
- cmd.option('--port <string>', 'setting port', bindArgs(checkPort, sharedArgument, false))
180
- cmd.option('--allow, --allow-cidr <string>', 'allow-cidr', validateArrayArguments(validateIpV4))
181
- cmd.option('--deny, --deny-cidr <string>', 'deny-cidr', validateArrayArguments(validateIpV4))
182
- cmd.option('--allow-self, --self', 'allow self only', false)
183
- cmd.option('--save [alias]', 'save current settings as alias/local')
184
- cmd.action(exec(configRef, cmd, program))
185
-
186
- addExample('http localhost:80', 'HTTP Forward to localhost:80')
187
- addExample('', 'Forward to port from default config, host from default config')
188
- // extendUsage(program, cmd)
189
- // .option('-o, --origin <string>', 'change request origin')
190
-
191
- return cmd
192
- }
@@ -1,38 +0,0 @@
1
- import {Command} from "commander";
2
- import {httpClient, securedHttpClient} from "#lib/HttpClient";
3
- import {addExample, extendUsage} from "#commands/utils";
4
- import {ConfigManager} from "#src/config/ConfigManager";
5
-
6
- /**
7
- *
8
- * @returns {(function(): void)|*}
9
- */
10
- const exec = () => {
11
-
12
- return async () => {
13
- const config = ConfigManager.loadSystem()
14
- const {data, error} = await securedHttpClient(config.authToken).get('/invite')
15
-
16
- if (error) {
17
- console.error(error)
18
- process.exit(1)
19
- }
20
-
21
- console.log('Done.', data)
22
- }
23
- }
24
-
25
- /**
26
- *
27
- * @param {Command} program
28
- */
29
- export const createCommandInvite = (program) => {
30
-
31
- const cmd = new Command('invite')
32
- .action(exec())
33
-
34
- extendUsage(program, cmd)
35
- addExample('invite', 'create sharable registration token')
36
- return cmd
37
-
38
- }
@@ -1,35 +0,0 @@
1
- import {Command} from "commander";
2
- import {selectConfigOption} from "#commands/Option/SelectConfigOption";
3
- import {ref} from "#src/core/Ref";
4
- import {validateAuthToken} from "#lib/Flow/validateAuthToken";
5
- import {requestNewProxyUrl} from "#lib/Flow/proxyUrl";
6
-
7
- /**
8
- * @param {Ref} configRef
9
- * @returns {(function(*, *): void)|*}
10
- */
11
- const exec = (configRef) => {
12
- return async () => {
13
- /** @type {LocalConfig|GlobalConfig} */
14
- const config = configRef.value
15
- config.proxyURL = await requestNewProxyUrl(config.authToken)
16
- config.save()
17
- console.log('done')
18
- }
19
- }
20
- /**
21
- * @param {Command} program
22
- */
23
- export const createCommandRefresh = (program) => {
24
-
25
- const configRef = ref()
26
- const cmd = new Command('refresh')
27
-
28
- selectConfigOption(cmd, configRef)
29
- validateAuthToken(cmd, configRef)
30
-
31
- cmd.action(exec(configRef))
32
- // extendUsage(program, cmd)
33
-
34
- return cmd
35
- }
@@ -1,48 +0,0 @@
1
- import {Command} from "commander";
2
- import {httpClient} from "#lib/HttpClient";
3
- import {ConfigManager} from "#src/config/ConfigManager";
4
-
5
- /**
6
- *
7
- * @returns {(function(): void)|*}
8
- */
9
- const exec = () => {
10
-
11
- return async (options) => {
12
-
13
- const forceRenew = options.f === true
14
- const config = ConfigManager.loadSystem()
15
-
16
- if (config.authToken && !forceRenew) {
17
- console.log(`Auth token exists. use -f to renew: ${config.authToken}`)
18
- process.exit()
19
- }
20
-
21
- const {data, error} = await httpClient.get('/register')
22
-
23
- if (error) {
24
- console.error(error)
25
- process.exit(1)
26
- }
27
-
28
- config.authToken = data
29
- config.save()
30
- console.log('Done.',config.authToken)
31
- }
32
- }
33
-
34
-
35
- /**
36
- *
37
- * @param {Command} program
38
- */
39
- export const createCommandRegister = (program) => {
40
-
41
- const cmd = new Command('register')
42
- .option('-f', 'fore renew auth token')
43
- .action(exec())
44
-
45
- return cmd
46
- // extendUsage(program, cmd)
47
- // addExample('register', 'register call')
48
- }
@@ -1,6 +0,0 @@
1
- import {Option} from "commander";
2
-
3
- export const deleteOption = (desc = 'delete config entry') => {
4
- const option = new Option('--del', desc)
5
- return option
6
- }
@@ -1,65 +0,0 @@
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
- }
@@ -1,52 +0,0 @@
1
- import {ConfigManager} from "#src/config/ConfigManager";
2
-
3
- /**
4
- * @template T
5
- * @param {T} command
6
- * @param {Ref} [configRef]
7
- * @param {boolean} strictMode
8
- * @returns {T}
9
- */
10
- export const selectConfigOption = (command, configRef, strictMode = false) => {
11
-
12
- command.option('--global', 'Use the global configuration file (default)')
13
- .option('--local, --workdir', 'Use the configuration file for the current working directory')
14
- .option('-p --alias <string>', 'setting alias name', 'default')
15
-
16
- if (configRef) {
17
- command.hook('preAction', (thisCommand, actionCommand) => {
18
-
19
- let {alias, workdir, global} = thisCommand.opts()
20
-
21
- if (strictMode) {
22
- if (global) {
23
- workdir = false
24
- }
25
- if (workdir) {
26
- global = false
27
- }
28
- global ??= true
29
- workdir ??= false
30
- } else {
31
- if (workdir) {
32
- global ??= false
33
- }
34
- if (global) {
35
- workdir ??= false
36
- }
37
- global ??= true
38
- workdir ??= true
39
- }
40
-
41
- if (global && workdir) {
42
- configRef.value = ConfigManager.loadCombined(alias)
43
- } else if (global) {
44
- configRef.value = ConfigManager.loadGlobalOnly(alias)
45
- } else {
46
- configRef.value = ConfigManager.loadLocalOnly(alias, !strictMode)
47
- }
48
- })
49
- }
50
-
51
- return command
52
- }
@@ -1,28 +0,0 @@
1
- import {Command} from "commander";
2
- import {addDelValuesAction} from "#commands/Action/addDelValuesAction";
3
- import {validateArrayArguments, validateIpV4} from "#commands/utils";
4
-
5
- /**
6
- * @param {string} commandName
7
- * @param {Command} configCommand
8
- * @param {Ref} configRef
9
- * @returns {Command}
10
- */
11
- export const allowDenyCidrCommand = (commandName, configCommand, configRef) => {
12
- const cmd = new Command(commandName)
13
-
14
- cmd
15
- .argument('[values...]', 'config value', validateArrayArguments(validateIpV4))
16
- .option('-d --del [ip-address]', 'del values', validateArrayArguments(validateIpV4))
17
- .option('-a --add [ip-address]', 'add values', validateArrayArguments(validateIpV4))
18
- .action(addDelValuesAction(commandName, configRef))
19
- .hook('preAction', (thisCommand, actionCommand) => {
20
- const {del, add} = actionCommand.opts()
21
-
22
- if (!actionCommand.args.length && !del && !add) {
23
- // actionCommand.error("error: --add, --del oder values, einer muss mindestens gesetzt sein");
24
- }
25
- })
26
-
27
- return cmd
28
- }
@@ -1,22 +0,0 @@
1
- import {Command} from "commander";
2
-
3
- import {checkHost} from "#src/utils/checkFunctions";
4
- import {deleteOption} from "#commands/Option/DeleteOption";
5
- import {addGetDeleteValueAction} from "#commands/Action/addDelValuesAction";
6
-
7
- export const hostCommand = (configRef) => {
8
- const cmd = new Command('host')
9
-
10
-
11
- cmd.description('default forweard host (127.0.0.1)')
12
- .argument('[HOST]', 'füge eine kurze beschreibung ein', checkHost)
13
- .hook('preAction', (thisCommand, actionCommand) => {
14
- if (thisCommand.args.length && thisCommand.opts().del) {
15
- actionCommand.error("error: wenn delete dann keine argumente");
16
- }
17
- })
18
- .addOption(deleteOption())
19
- .action(addGetDeleteValueAction('host', configRef))
20
-
21
- return cmd
22
- }
@@ -1,20 +0,0 @@
1
- import {Command} from "commander";
2
- import {checkPort} from "#src/utils/checkFunctions";
3
- import {addGetDeleteValueAction} from "#commands/Action/addDelValuesAction";
4
- import {deleteOption} from "#commands/Option/DeleteOption";
5
-
6
- export const portCommand = (configRef) => {
7
- const cmd = new Command('port')
8
- cmd.description('default forweard port (80)')
9
- .argument('[PORT]', 'set port for config', checkPort)
10
- .action(addGetDeleteValueAction('port', configRef))
11
- .addOption(deleteOption())
12
-
13
- return cmd
14
- }
15
-
16
- //
17
- // if (!config.isPublic(configKey)) {
18
- // console.error('Ungültiger Konfigurationsdirektive')
19
- // process.exit()
20
- // }
@@ -1,21 +0,0 @@
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,13 +0,0 @@
1
- export const argumentAliasResolver = () => {
2
- let args = []
3
- for (let i = 0; i < process.argv.length; i++) {
4
- const arg = process.argv[i]
5
- if (arg.charAt(0) === '@') {
6
- args.push('--alias')
7
- args.push(arg.substring(1))
8
- } else {
9
- args.push(arg)
10
- }
11
- }
12
- return args
13
- }
@@ -1,53 +0,0 @@
1
- import {ipV4} from "#src/net/IPV4";
2
-
3
- /**
4
- * Binds arguments to a function.
5
- * @param {Function} fn - The function to bind arguments to.
6
- * @param {...any} args - The arguments to bind.
7
- * @returns {Function} - The bound function.
8
- */
9
- export const bindArgs = (fn, ...args) => {
10
- return fn.bind(null, ...args)
11
- }
12
-
13
- /**
14
- * Validates a remote address against allowed and denied CIDR ranges.
15
- * @param {string} remoteAddress - The remote address to check.
16
- * @param {Object} options - The options containing allowCidr and denyCidr arrays.
17
- * @param {ipCidr[]} options.allowCidr - Array of CIDR ranges that are allowed.
18
- * @param {ipCidr[]} options.denyCidr - Array of CIDR ranges that are denied.
19
- * @returns {boolean} - True if the address is valid, otherwise false.
20
- */
21
- export const isValidRemoteAddress = (() => {
22
- const cache = {}
23
-
24
- /**
25
- * Checks if a remote address is within a given subnet.
26
- * Uses a cache to store results for performance improvement.
27
- * @param {string} remoteAddress - The remote address to check.
28
- * @param {string} subnet - The CIDR subnet to check against.
29
- * @returns {boolean} - True if the remote address is in the subnet, otherwise false.
30
- */
31
- const isInSubnet = (remoteAddress, subnet) => {
32
- return cache[`${remoteAddress}#${subnet}`] ??= ipV4(remoteAddress).isInSubnet(subnet)
33
- }
34
-
35
- return (remoteAddress, {allowCidr, denyCidr}) => {
36
- // Check against denied CIDR ranges
37
- for (const deny of denyCidr) {
38
- if (isInSubnet(remoteAddress, deny)) {
39
- return false
40
- }
41
- }
42
-
43
- // Check against allowed CIDR ranges
44
- for (const allow of allowCidr) {
45
- if (isInSubnet(remoteAddress, allow)) {
46
- return true
47
- }
48
- }
49
-
50
- // If there are no allowed CIDR ranges, allow the address
51
- return allowCidr.length === 0
52
- }
53
- })();