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.
- package/CHANGELOG.md +45 -0
- package/README.md +158 -67
- package/bin/tunli +4 -5
- package/dist/api-client/ApiClient.d.ts +18 -0
- package/dist/api-client/ApiClient.d.ts.map +1 -0
- package/dist/api-client/ApiClient.js +100 -0
- package/dist/api-client/ApiClient.js.map +1 -0
- package/dist/api-client/types.d.ts +26 -0
- package/dist/api-client/types.d.ts.map +1 -0
- package/dist/api-client/types.js +2 -0
- package/dist/api-client/types.js.map +1 -0
- package/dist/api-client/utils.d.ts +4 -0
- package/dist/api-client/utils.d.ts.map +1 -0
- package/dist/api-client/utils.js +13 -0
- package/dist/api-client/utils.js.map +1 -0
- package/dist/cli-app/AppEventEmitter.d.ts +57 -0
- package/dist/cli-app/AppEventEmitter.d.ts.map +1 -0
- package/dist/cli-app/AppEventEmitter.js +11 -0
- package/dist/cli-app/AppEventEmitter.js.map +1 -0
- package/dist/cli-app/Dashboard.d.ts +4 -0
- package/dist/cli-app/Dashboard.d.ts.map +1 -0
- package/dist/cli-app/Dashboard.js +241 -0
- package/dist/cli-app/Dashboard.js.map +1 -0
- package/dist/cli-app/LiveLog.d.ts +4 -0
- package/dist/cli-app/LiveLog.d.ts.map +1 -0
- package/dist/cli-app/LiveLog.js +28 -0
- package/dist/cli-app/LiveLog.js.map +1 -0
- package/dist/cli-app/types.d.ts +10 -0
- package/dist/cli-app/types.d.ts.map +1 -0
- package/dist/cli-app/types.js +2 -0
- package/dist/cli-app/types.js.map +1 -0
- package/dist/cli-app/versionCheck.d.ts +4 -0
- package/dist/cli-app/versionCheck.d.ts.map +1 -0
- package/dist/cli-app/versionCheck.js +46 -0
- package/dist/cli-app/versionCheck.js.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +75 -0
- package/dist/client.js.map +1 -0
- package/dist/commander/Argument.d.ts +19 -0
- package/dist/commander/Argument.d.ts.map +1 -0
- package/dist/commander/Argument.js +25 -0
- package/dist/commander/Argument.js.map +1 -0
- package/dist/commander/Command.d.ts +23 -0
- package/dist/commander/Command.d.ts.map +1 -0
- package/dist/commander/Command.js +159 -0
- package/dist/commander/Command.js.map +1 -0
- package/dist/commander/InvalidArgumentError.d.ts +5 -0
- package/dist/commander/InvalidArgumentError.d.ts.map +1 -0
- package/dist/commander/InvalidArgumentError.js +8 -0
- package/dist/commander/InvalidArgumentError.js.map +1 -0
- package/dist/commander/Option.d.ts +15 -0
- package/dist/commander/Option.d.ts.map +1 -0
- package/dist/commander/Option.js +43 -0
- package/dist/commander/Option.js.map +1 -0
- package/dist/commander/index.d.ts +7 -0
- package/dist/commander/index.d.ts.map +1 -0
- package/dist/commander/index.js +5 -0
- package/dist/commander/index.js.map +1 -0
- package/dist/commander/types.d.ts +2 -0
- package/dist/commander/types.d.ts.map +1 -0
- package/dist/commander/types.js +2 -0
- package/dist/commander/types.js.map +1 -0
- package/dist/commands/CommandAuth/CommandAuth.d.ts +4 -0
- package/dist/commands/CommandAuth/CommandAuth.d.ts.map +1 -0
- package/dist/commands/CommandAuth/CommandAuth.js +24 -0
- package/dist/commands/CommandAuth/CommandAuth.js.map +1 -0
- package/dist/commands/CommandConfig/CommandConfig.d.ts +4 -0
- package/dist/commands/CommandConfig/CommandConfig.d.ts.map +1 -0
- package/dist/commands/CommandConfig/CommandConfig.js +37 -0
- package/dist/commands/CommandConfig/CommandConfig.js.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.d.ts +4 -0
- package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.d.ts.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.js +20 -0
- package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.js.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configGetCommand.d.ts +5 -0
- package/dist/commands/CommandConfig/sub-commands/configGetCommand.d.ts.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configGetCommand.js +23 -0
- package/dist/commands/CommandConfig/sub-commands/configGetCommand.js.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configSetCommand.d.ts +4 -0
- package/dist/commands/CommandConfig/sub-commands/configSetCommand.d.ts.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configSetCommand.js +69 -0
- package/dist/commands/CommandConfig/sub-commands/configSetCommand.js.map +1 -0
- package/dist/commands/CommandConfig/types.d.ts +6 -0
- package/dist/commands/CommandConfig/types.d.ts.map +1 -0
- package/dist/commands/CommandConfig/types.js +2 -0
- package/dist/commands/CommandConfig/types.js.map +1 -0
- package/dist/commands/CommandConfig/utils/preparePrimaryOptions.d.ts +3 -0
- package/dist/commands/CommandConfig/utils/preparePrimaryOptions.d.ts.map +1 -0
- package/dist/commands/CommandConfig/utils/preparePrimaryOptions.js +8 -0
- package/dist/commands/CommandConfig/utils/preparePrimaryOptions.js.map +1 -0
- package/dist/commands/CommandConfig/utils/resolveConfig.d.ts +8 -0
- package/dist/commands/CommandConfig/utils/resolveConfig.d.ts.map +1 -0
- package/dist/commands/CommandConfig/utils/resolveConfig.js +33 -0
- package/dist/commands/CommandConfig/utils/resolveConfig.js.map +1 -0
- package/dist/commands/CommandConfig/utils/sharedOptions.d.ts +3 -0
- package/dist/commands/CommandConfig/utils/sharedOptions.d.ts.map +1 -0
- package/dist/commands/CommandConfig/utils/sharedOptions.js +14 -0
- package/dist/commands/CommandConfig/utils/sharedOptions.js.map +1 -0
- package/dist/commands/CommandDaemon/CommandDaemon.d.ts +4 -0
- package/dist/commands/CommandDaemon/CommandDaemon.d.ts.map +1 -0
- package/dist/commands/CommandDaemon/CommandDaemon.js +57 -0
- package/dist/commands/CommandDaemon/CommandDaemon.js.map +1 -0
- package/dist/commands/CommandDashboard/CommandDashboard.d.ts +4 -0
- package/dist/commands/CommandDashboard/CommandDashboard.d.ts.map +1 -0
- package/dist/commands/CommandDashboard/CommandDashboard.js +54 -0
- package/dist/commands/CommandDashboard/CommandDashboard.js.map +1 -0
- package/dist/commands/CommandHTTP/CommandHttp.d.ts +4 -0
- package/dist/commands/CommandHTTP/CommandHttp.d.ts.map +1 -0
- package/dist/commands/CommandHTTP/CommandHttp.js +50 -0
- package/dist/commands/CommandHTTP/CommandHttp.js.map +1 -0
- package/dist/commands/CommandInit/CommandInit.d.ts +4 -0
- package/dist/commands/CommandInit/CommandInit.d.ts.map +1 -0
- package/dist/commands/CommandInit/CommandInit.js +36 -0
- package/dist/commands/CommandInit/CommandInit.js.map +1 -0
- package/dist/commands/CommandList/CommandList.d.ts +4 -0
- package/dist/commands/CommandList/CommandList.d.ts.map +1 -0
- package/dist/commands/CommandList/CommandList.js +54 -0
- package/dist/commands/CommandList/CommandList.js.map +1 -0
- package/dist/commands/CommandLogs/CommandLogs.d.ts +4 -0
- package/dist/commands/CommandLogs/CommandLogs.d.ts.map +1 -0
- package/dist/commands/CommandLogs/CommandLogs.js +33 -0
- package/dist/commands/CommandLogs/CommandLogs.js.map +1 -0
- package/dist/commands/CommandProfile/CommandProfile.d.ts +5 -0
- package/dist/commands/CommandProfile/CommandProfile.d.ts.map +1 -0
- package/dist/commands/CommandProfile/CommandProfile.js +64 -0
- package/dist/commands/CommandProfile/CommandProfile.js.map +1 -0
- package/dist/commands/CommandRegister/CommandRegister.d.ts +4 -0
- package/dist/commands/CommandRegister/CommandRegister.d.ts.map +1 -0
- package/dist/commands/CommandRegister/CommandRegister.js +43 -0
- package/dist/commands/CommandRegister/CommandRegister.js.map +1 -0
- package/dist/commands/CommandRestart/CommandRestart.d.ts +4 -0
- package/dist/commands/CommandRestart/CommandRestart.d.ts.map +1 -0
- package/dist/commands/CommandRestart/CommandRestart.js +62 -0
- package/dist/commands/CommandRestart/CommandRestart.js.map +1 -0
- package/dist/commands/CommandServer/CommandServer.d.ts +4 -0
- package/dist/commands/CommandServer/CommandServer.d.ts.map +1 -0
- package/dist/commands/CommandServer/CommandServer.js +24 -0
- package/dist/commands/CommandServer/CommandServer.js.map +1 -0
- package/dist/commands/CommandStop/CommandStop.d.ts +4 -0
- package/dist/commands/CommandStop/CommandStop.d.ts.map +1 -0
- package/dist/commands/CommandStop/CommandStop.js +25 -0
- package/dist/commands/CommandStop/CommandStop.js.map +1 -0
- package/dist/commands/CommandUpdate/CommandUpdate.d.ts +4 -0
- package/dist/commands/CommandUpdate/CommandUpdate.d.ts.map +1 -0
- package/dist/commands/CommandUpdate/CommandUpdate.js +38 -0
- package/dist/commands/CommandUpdate/CommandUpdate.js.map +1 -0
- package/dist/commands/CommandUseProfile/CommandUseProfile.d.ts +4 -0
- package/dist/commands/CommandUseProfile/CommandUseProfile.d.ts.map +1 -0
- package/dist/commands/CommandUseProfile/CommandUseProfile.js +63 -0
- package/dist/commands/CommandUseProfile/CommandUseProfile.js.map +1 -0
- package/dist/commands/helper/Help.d.ts +4 -0
- package/dist/commands/helper/Help.d.ts.map +1 -0
- package/dist/commands/helper/Help.js +134 -0
- package/dist/commands/helper/Help.js.map +1 -0
- package/dist/commands/helper/Parser.d.ts +55 -0
- package/dist/commands/helper/Parser.d.ts.map +1 -0
- package/dist/commands/helper/Parser.js +280 -0
- package/dist/commands/helper/Parser.js.map +1 -0
- package/dist/commands/shared/allowDenyCidrCommand.d.ts +3 -0
- package/dist/commands/shared/allowDenyCidrCommand.d.ts.map +1 -0
- package/dist/commands/shared/allowDenyCidrCommand.js +10 -0
- package/dist/commands/shared/allowDenyCidrCommand.js.map +1 -0
- package/dist/commands/shared/configServersCommand.d.ts +4 -0
- package/dist/commands/shared/configServersCommand.d.ts.map +1 -0
- package/dist/commands/shared/configServersCommand.js +19 -0
- package/dist/commands/shared/configServersCommand.js.map +1 -0
- package/dist/commands/utils.d.ts +3 -0
- package/dist/commands/utils.d.ts.map +1 -0
- package/dist/commands/utils.js +17 -0
- package/dist/commands/utils.js.map +1 -0
- package/dist/config/ParsedConfig.d.ts +31 -0
- package/dist/config/ParsedConfig.d.ts.map +1 -0
- package/dist/config/ParsedConfig.js +116 -0
- package/dist/config/ParsedConfig.js.map +1 -0
- package/dist/config/ParsedGlobalConfig.d.ts +5 -0
- package/dist/config/ParsedGlobalConfig.d.ts.map +1 -0
- package/dist/config/ParsedGlobalConfig.js +7 -0
- package/dist/config/ParsedGlobalConfig.js.map +1 -0
- package/dist/config/ParsedLocalConfig.d.ts +5 -0
- package/dist/config/ParsedLocalConfig.d.ts.map +1 -0
- package/dist/config/ParsedLocalConfig.js +7 -0
- package/dist/config/ParsedLocalConfig.js.map +1 -0
- package/dist/config/ParsedProfileConfig.d.ts +46 -0
- package/dist/config/ParsedProfileConfig.d.ts.map +1 -0
- package/dist/config/ParsedProfileConfig.js +120 -0
- package/dist/config/ParsedProfileConfig.js.map +1 -0
- package/dist/config/ParsedServerConfig.d.ts +20 -0
- package/dist/config/ParsedServerConfig.d.ts.map +1 -0
- package/dist/config/ParsedServerConfig.js +55 -0
- package/dist/config/ParsedServerConfig.js.map +1 -0
- package/dist/config/TempProfileConfig.d.ts +8 -0
- package/dist/config/TempProfileConfig.d.ts.map +1 -0
- package/dist/config/TempProfileConfig.js +13 -0
- package/dist/config/TempProfileConfig.js.map +1 -0
- package/dist/config/utils.d.ts +2 -0
- package/dist/config/utils.d.ts.map +1 -0
- package/dist/config/utils.js +8 -0
- package/dist/config/utils.js.map +1 -0
- package/dist/config/validations/validateProfileConfig.d.ts +4 -0
- package/dist/config/validations/validateProfileConfig.d.ts.map +1 -0
- package/dist/config/validations/validateProfileConfig.js +76 -0
- package/dist/config/validations/validateProfileConfig.js.map +1 -0
- package/dist/core/FS/utils.d.ts +12 -0
- package/dist/core/FS/utils.d.ts.map +1 -0
- package/dist/core/FS/utils.js +55 -0
- package/dist/core/FS/utils.js.map +1 -0
- package/dist/daemon/DaemonClient.d.ts +16 -0
- package/dist/daemon/DaemonClient.d.ts.map +1 -0
- package/dist/daemon/DaemonClient.js +158 -0
- package/dist/daemon/DaemonClient.js.map +1 -0
- package/dist/daemon/DaemonServer.d.ts +8 -0
- package/dist/daemon/DaemonServer.d.ts.map +1 -0
- package/dist/daemon/DaemonServer.js +201 -0
- package/dist/daemon/DaemonServer.js.map +1 -0
- package/dist/daemon/protocol.d.ts +101 -0
- package/dist/daemon/protocol.d.ts.map +1 -0
- package/dist/daemon/protocol.js +2 -0
- package/dist/daemon/protocol.js.map +1 -0
- package/dist/daemon-main.d.ts +2 -0
- package/dist/daemon-main.d.ts.map +1 -0
- package/dist/daemon-main.js +13 -0
- package/dist/daemon-main.js.map +1 -0
- package/dist/launcher-main.d.ts +2 -0
- package/dist/launcher-main.d.ts.map +1 -0
- package/dist/launcher-main.js +57 -0
- package/dist/launcher-main.js.map +1 -0
- package/dist/lib/Flow/applyUpdate.d.ts +3 -0
- package/dist/lib/Flow/applyUpdate.d.ts.map +1 -0
- package/dist/lib/Flow/applyUpdate.js +34 -0
- package/dist/lib/Flow/applyUpdate.js.map +1 -0
- package/dist/lib/Flow/downloadBinaryUpdate.d.ts +3 -0
- package/dist/lib/Flow/downloadBinaryUpdate.d.ts.map +1 -0
- package/dist/lib/Flow/downloadBinaryUpdate.js +54 -0
- package/dist/lib/Flow/downloadBinaryUpdate.js.map +1 -0
- package/dist/lib/Flow/getLatestVersion.d.ts +2 -0
- package/dist/lib/Flow/getLatestVersion.d.ts.map +1 -0
- package/dist/lib/Flow/getLatestVersion.js +13 -0
- package/dist/lib/Flow/getLatestVersion.js.map +1 -0
- package/dist/lib/defs.d.ts +18 -0
- package/dist/lib/defs.d.ts.map +1 -0
- package/dist/lib/defs.js +33 -0
- package/dist/lib/defs.js.map +1 -0
- package/dist/logger/logger.d.ts +6 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/logger/logger.js +34 -0
- package/dist/logger/logger.js.map +1 -0
- package/dist/output-formats/colors.d.ts +7 -0
- package/dist/output-formats/colors.d.ts.map +1 -0
- package/dist/output-formats/colors.js +8 -0
- package/dist/output-formats/colors.js.map +1 -0
- package/dist/output-formats/formatConfig.d.ts +3 -0
- package/dist/output-formats/formatConfig.d.ts.map +1 -0
- package/dist/output-formats/formatConfig.js +59 -0
- package/dist/output-formats/formatConfig.js.map +1 -0
- package/dist/output-formats/formatConfigPath.d.ts +4 -0
- package/dist/output-formats/formatConfigPath.d.ts.map +1 -0
- package/dist/output-formats/formatConfigPath.js +7 -0
- package/dist/output-formats/formatConfigPath.js.map +1 -0
- package/dist/output-formats/formatPath.d.ts +2 -0
- package/dist/output-formats/formatPath.d.ts.map +1 -0
- package/dist/output-formats/formatPath.js +6 -0
- package/dist/output-formats/formatPath.js.map +1 -0
- package/dist/output-formats/formatProfile.d.ts +3 -0
- package/dist/output-formats/formatProfile.d.ts.map +1 -0
- package/dist/output-formats/formatProfile.js +35 -0
- package/dist/output-formats/formatProfile.js.map +1 -0
- package/dist/output-formats/formatProfilesShort.d.ts +3 -0
- package/dist/output-formats/formatProfilesShort.d.ts.map +1 -0
- package/dist/output-formats/formatProfilesShort.js +19 -0
- package/dist/output-formats/formatProfilesShort.js.map +1 -0
- package/dist/output-formats/formatSaveResult.d.ts +4 -0
- package/dist/output-formats/formatSaveResult.d.ts.map +1 -0
- package/dist/output-formats/formatSaveResult.js +7 -0
- package/dist/output-formats/formatSaveResult.js.map +1 -0
- package/dist/output-formats/table.d.ts +8 -0
- package/dist/output-formats/table.d.ts.map +1 -0
- package/dist/output-formats/table.js +15 -0
- package/dist/output-formats/table.js.map +1 -0
- package/dist/package-json/packageJson.d.ts +6 -0
- package/dist/package-json/packageJson.d.ts.map +1 -0
- package/dist/package-json/packageJson.js +12 -0
- package/dist/package-json/packageJson.js.map +1 -0
- package/dist/proxy/Proxy.d.ts +6 -0
- package/dist/proxy/Proxy.d.ts.map +1 -0
- package/dist/proxy/Proxy.js +203 -0
- package/dist/proxy/Proxy.js.map +1 -0
- package/dist/sea-main.d.ts +2 -0
- package/dist/sea-main.d.ts.map +1 -0
- package/dist/sea-main.js +20 -0
- package/dist/sea-main.js.map +1 -0
- package/dist/types/types.d.ts +55 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/arrayFunctions.d.ts +24 -0
- package/dist/utils/arrayFunctions.d.ts.map +1 -0
- package/dist/utils/arrayFunctions.js +43 -0
- package/dist/utils/arrayFunctions.js.map +1 -0
- package/dist/utils/assertFunctions.d.ts +7 -0
- package/dist/utils/assertFunctions.d.ts.map +1 -0
- package/dist/utils/assertFunctions.js +20 -0
- package/dist/utils/assertFunctions.js.map +1 -0
- package/dist/utils/checkFunctions.d.ts +34 -0
- package/dist/utils/checkFunctions.d.ts.map +1 -0
- package/dist/utils/checkFunctions.js +87 -0
- package/dist/utils/checkFunctions.js.map +1 -0
- package/dist/utils/cliFunctions.d.ts +10 -0
- package/dist/utils/cliFunctions.d.ts.map +1 -0
- package/dist/utils/cliFunctions.js +68 -0
- package/dist/utils/cliFunctions.js.map +1 -0
- package/dist/utils/hashFunctions.d.ts +10 -0
- package/dist/utils/hashFunctions.d.ts.map +1 -0
- package/dist/utils/hashFunctions.js +11 -0
- package/dist/utils/hashFunctions.js.map +1 -0
- package/dist/utils/npmFunctions.d.ts +3 -0
- package/dist/utils/npmFunctions.d.ts.map +1 -0
- package/dist/utils/npmFunctions.js +28 -0
- package/dist/utils/npmFunctions.js.map +1 -0
- package/dist/utils/stringFunctions.d.ts +12 -0
- package/dist/utils/stringFunctions.d.ts.map +1 -0
- package/dist/utils/stringFunctions.js +37 -0
- package/dist/utils/stringFunctions.js.map +1 -0
- package/package.json +39 -16
- package/client.js +0 -33
- package/src/cli-app/Dashboard.js +0 -220
- package/src/cli-app/Screen/FullScreenModal.js +0 -63
- package/src/cli-app/Screen.js +0 -140
- package/src/cli-app/elements/ElementNode.js +0 -97
- package/src/cli-app/elements/Line.js +0 -21
- package/src/cli-app/elements/List/List.js +0 -227
- package/src/cli-app/elements/List/ListCell.js +0 -83
- package/src/cli-app/elements/List/ListColumn.js +0 -52
- package/src/cli-app/elements/List/ListRow.js +0 -118
- package/src/cli-app/elements/Row.js +0 -38
- package/src/cli-app/helper/utils.js +0 -42
- package/src/commands/Action/addDelValuesAction.js +0 -56
- package/src/commands/CommandAuth.js +0 -32
- package/src/commands/CommandClearAll.js +0 -27
- package/src/commands/CommandConfig.js +0 -59
- package/src/commands/CommandHTTP.js +0 -192
- package/src/commands/CommandInvite.js +0 -38
- package/src/commands/CommandRefresh.js +0 -35
- package/src/commands/CommandRegister.js +0 -48
- package/src/commands/Option/DeleteOption.js +0 -6
- package/src/commands/Option/ProfileListOption.js +0 -65
- package/src/commands/Option/SelectConfigOption.js +0 -52
- package/src/commands/SubCommand/AllowDenyCidrCommand.js +0 -28
- package/src/commands/SubCommand/HostCommand.js +0 -22
- package/src/commands/SubCommand/PortCommand.js +0 -20
- package/src/commands/SubCommand/ProtocolCommand.js +0 -21
- package/src/commands/helper/AliasResolver.js +0 -13
- package/src/commands/helper/BindArgs.js +0 -53
- package/src/commands/helper/SharedArg.js +0 -32
- package/src/commands/utils.js +0 -96
- package/src/config/ConfigAbstract.js +0 -353
- package/src/config/ConfigManager.js +0 -70
- package/src/config/GlobalConfig.js +0 -14
- package/src/config/GlobalLocalShardConfigAbstract.js +0 -98
- package/src/config/LocalConfig.js +0 -7
- package/src/config/PropertyConfig.js +0 -122
- package/src/config/SystemConfig.js +0 -31
- package/src/core/FS/utils.js +0 -60
- package/src/core/Ref.js +0 -70
- package/src/lib/Flow/getCurrentIp.js +0 -18
- package/src/lib/Flow/getLatestVersion.js +0 -13
- package/src/lib/Flow/proxyUrl.js +0 -35
- package/src/lib/Flow/validateAuthToken.js +0 -19
- package/src/lib/HttpClient.js +0 -61
- package/src/lib/Proxy.js +0 -42
- package/src/lib/defs.js +0 -13
- package/src/net/IPV4.js +0 -139
- package/src/net/http/IncomingMessage.js +0 -92
- package/src/net/http/ServerResponse.js +0 -126
- package/src/net/http/TunliRequest.js +0 -1
- package/src/net/http/TunliResponse.js +0 -1
- package/src/net/http/TunnelRequest.js +0 -229
- package/src/net/http/TunnelResponse.js +0 -119
- package/src/tunnel-client/TunnelClient.js +0 -144
- package/src/utils/arrayFunctions.js +0 -45
- package/src/utils/checkFunctions.js +0 -182
- package/src/utils/cliFunctions.js +0 -63
- package/src/utils/createRequest.js +0 -12
- package/src/utils/hashFunctions.js +0 -9
- package/src/utils/httpFunction.js +0 -23
- package/src/utils/npmFunctions.js +0 -27
- package/src/utils/stringFunctions.js +0 -59
- package/types/index.d.ts +0 -119
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @callback validationCallback
|
|
3
|
-
* @template T
|
|
4
|
-
* @param {T} value
|
|
5
|
-
* @throws Error
|
|
6
|
-
* @returns {T}
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Class representing the configuration of a property.
|
|
11
|
-
*/
|
|
12
|
-
export class PropertyConfig {
|
|
13
|
-
/**
|
|
14
|
-
* The raw configuration data.
|
|
15
|
-
* @type {Object}
|
|
16
|
-
*/
|
|
17
|
-
#data
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The visibility level of the property.
|
|
21
|
-
* @type {number}
|
|
22
|
-
*/
|
|
23
|
-
#visibility
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Indicates if the property is writeable.
|
|
27
|
-
* When true, the property can be written to.
|
|
28
|
-
* If an instance of ConfigAbstract, only that instance can change the value.
|
|
29
|
-
* @type {boolean|ConfigAbstract}
|
|
30
|
-
*/
|
|
31
|
-
#writeable
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The validation function for the property.
|
|
35
|
-
* @type {validationCallback}
|
|
36
|
-
*/
|
|
37
|
-
#validate
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Default value for the property.
|
|
41
|
-
* @type {any}
|
|
42
|
-
*/
|
|
43
|
-
#defaultValue
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The type of the property.
|
|
47
|
-
* @type {Object}
|
|
48
|
-
*/
|
|
49
|
-
#type
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Create a PropertyConfig.
|
|
53
|
-
* @param {Object} data - The configuration data for the property.
|
|
54
|
-
* @param {number} data.visibility - The visibility level of the property.
|
|
55
|
-
* @param {boolean|ConfigAbstract} data.writeable - Indicates if the property is writeable.
|
|
56
|
-
* @param {validationCallback} data.validate - The validation function for the property.
|
|
57
|
-
* @param {any} data.defaultValue - The default value of the property.
|
|
58
|
-
* @param {Object} data.type - The type of the property.
|
|
59
|
-
*/
|
|
60
|
-
constructor(data) {
|
|
61
|
-
this.#data = data
|
|
62
|
-
this.#visibility = data.visibility
|
|
63
|
-
this.#writeable = data.writeable
|
|
64
|
-
this.#validate = data.validate
|
|
65
|
-
this.#defaultValue = data.defaultValue
|
|
66
|
-
this.#type = data.type
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Get the visibility of the property.
|
|
71
|
-
* @returns {number} The visibility level of the property.
|
|
72
|
-
*/
|
|
73
|
-
get visibility() {
|
|
74
|
-
return this.#visibility
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Check if the property is writeable.
|
|
79
|
-
* @returns {boolean|ConfigAbstract} True if the property is writeable, false otherwise.
|
|
80
|
-
*/
|
|
81
|
-
get writeable() {
|
|
82
|
-
return this.#writeable
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Get the validation function for the property.
|
|
87
|
-
* @returns {validationCallback} The validation function.
|
|
88
|
-
*/
|
|
89
|
-
get validate() {
|
|
90
|
-
return this.#validate
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Get the default value of the property.
|
|
95
|
-
* @returns {*} The default value of the property.
|
|
96
|
-
*/
|
|
97
|
-
get defaultValue() {
|
|
98
|
-
return this.#defaultValue
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Get the type of the property.
|
|
103
|
-
* @returns {Object} The type of the property.
|
|
104
|
-
*/
|
|
105
|
-
get type() {
|
|
106
|
-
return this.#type
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Factory function to create a PropertyConfig instance.
|
|
112
|
-
* @param {Object} propertySetup - The setup configuration for the property.
|
|
113
|
-
* @param {boolean|ConfigAbstract} propertySetup.writeable - Indicates if the property is writeable.
|
|
114
|
-
* @param {Object} propertySetup.type - The type of the property.
|
|
115
|
-
* @param {function} [propertySetup.validate] - The validation function for the property.
|
|
116
|
-
* @param {number} propertySetup.visibility - The visibility level of the property.
|
|
117
|
-
* @param {any} [propertySetup.defaultValue] - The default value of the property.
|
|
118
|
-
* @returns {PropertyConfig} The instance of PropertyConfig.
|
|
119
|
-
*/
|
|
120
|
-
export const property = (propertySetup) => {
|
|
121
|
-
return new PropertyConfig(propertySetup)
|
|
122
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {GLOBAL_CONFIG_DIR} from "#lib/defs";
|
|
2
|
-
import {resolve} from "path";
|
|
3
|
-
import {ConfigAbstract, VISIBILITY_PRIVATE} from "#src/config/ConfigAbstract";
|
|
4
|
-
import {property} from "#src/config/PropertyConfig";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Class representing the system configuration.
|
|
9
|
-
* Extends ConfigAbstract to provide specific configuration for system settings.
|
|
10
|
-
*/
|
|
11
|
-
export class SystemConfig extends ConfigAbstract {
|
|
12
|
-
/**
|
|
13
|
-
* Create a SystemConfig instance.
|
|
14
|
-
* @param {Object} data - Initial data to prefill the configuration.
|
|
15
|
-
*/
|
|
16
|
-
constructor(data) {
|
|
17
|
-
const alias = 'default'
|
|
18
|
-
const configFilePath = resolve(GLOBAL_CONFIG_DIR, `${alias}.json`)
|
|
19
|
-
|
|
20
|
-
super(data, configFilePath)
|
|
21
|
-
|
|
22
|
-
this.prepare({
|
|
23
|
-
authToken: property({
|
|
24
|
-
visibility: VISIBILITY_PRIVATE,
|
|
25
|
-
writeable: SystemConfig,
|
|
26
|
-
type: String
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
this.useSystem()
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/core/FS/utils.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {existsSync, lstatSync, mkdirSync, readFileSync} from "fs";
|
|
2
|
-
import {dirname, join, parse} from "path";
|
|
3
|
-
import {fileURLToPath} from "url";
|
|
4
|
-
|
|
5
|
-
export const ensureDirectoryExists = (directory) => {
|
|
6
|
-
if (!existsSync(directory)) {
|
|
7
|
-
mkdirSync(directory)
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const searchDirInDirectoryTree = (dirnameToSearch, dir = process.cwd(), excludeDirectories = []) => {
|
|
12
|
-
|
|
13
|
-
dir ??= process.cwd()
|
|
14
|
-
|
|
15
|
-
while (dir !== parse(dir).root) {
|
|
16
|
-
const configPath = join(dir, dirnameToSearch);
|
|
17
|
-
|
|
18
|
-
dir = dirname(dir);
|
|
19
|
-
|
|
20
|
-
if (excludeDirectories.includes(configPath)) {
|
|
21
|
-
continue
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (existsSync(configPath) && lstatSync(configPath).isDirectory()) {
|
|
25
|
-
return configPath
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
export const searchFileInDirectoryTree = (filenameToSearch, dir = process.cwd(), excludeDirectories = []) => {
|
|
32
|
-
|
|
33
|
-
dir ??= process.cwd()
|
|
34
|
-
|
|
35
|
-
while (dir !== parse(dir).root) {
|
|
36
|
-
const configPath = join(dir, filenameToSearch);
|
|
37
|
-
dir = dirname(dir);
|
|
38
|
-
|
|
39
|
-
if (excludeDirectories.includes(configPath)) {
|
|
40
|
-
continue
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (existsSync(configPath) && lstatSync(configPath).isFile()) {
|
|
44
|
-
return configPath
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const readJsonFile = (configFilePath) => {
|
|
52
|
-
return JSON.parse(readFileSync(configFilePath, 'utf8'))
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const dirnameFromMeta = (importMeta) => {
|
|
56
|
-
return dirname(filenameFromMeta(importMeta));
|
|
57
|
-
}
|
|
58
|
-
export const filenameFromMeta = (importMeta) => {
|
|
59
|
-
return fileURLToPath(importMeta.url);
|
|
60
|
-
}
|
package/src/core/Ref.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'node:events'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A class representing a reference to a value.
|
|
5
|
-
* This class is useful for creating mutable references to values,
|
|
6
|
-
* allowing for controlled access and modification.
|
|
7
|
-
*/
|
|
8
|
-
export class Ref extends EventEmitter {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @type {any}
|
|
12
|
-
* Private field to store the value.
|
|
13
|
-
*/
|
|
14
|
-
#value
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Constructor for the Ref class.
|
|
18
|
-
* If the provided value is an instance of Ref, it uses its value.
|
|
19
|
-
* Otherwise, it stores the provided value.
|
|
20
|
-
* @param {any} value - The value to store.
|
|
21
|
-
*/
|
|
22
|
-
constructor(value) {
|
|
23
|
-
super()
|
|
24
|
-
if (value instanceof Ref) {
|
|
25
|
-
this.#value = value.#value
|
|
26
|
-
} else {
|
|
27
|
-
this.#value = { value }
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Getter for the stored value.
|
|
33
|
-
* @returns {any} - The stored value.
|
|
34
|
-
*/
|
|
35
|
-
get value() {
|
|
36
|
-
return this.#value.value
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Setter for the stored value.
|
|
41
|
-
* @param {any} value - The new value.
|
|
42
|
-
*/
|
|
43
|
-
set value(value) {
|
|
44
|
-
const oldValue = this.#value.value
|
|
45
|
-
this.#value.value = value
|
|
46
|
-
// Emit an event if the value has changed
|
|
47
|
-
if (oldValue !== value) {
|
|
48
|
-
this.emit('update', value, oldValue)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @template T
|
|
55
|
-
* Creates a new Ref instance.
|
|
56
|
-
* @param {T} [value] - The value to store.
|
|
57
|
-
* @returns {Ref} - A new Ref instance.
|
|
58
|
-
*/
|
|
59
|
-
export const ref = (value) => {
|
|
60
|
-
return new Ref(value)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Checks if the value is an instance of Ref.
|
|
65
|
-
* @param {any} value - The value to check.
|
|
66
|
-
* @returns {boolean} - True if the value is an instance of Ref, otherwise false.
|
|
67
|
-
*/
|
|
68
|
-
export const isRef = (value) => {
|
|
69
|
-
return value instanceof Ref
|
|
70
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {httpClient} from "#lib/HttpClient";
|
|
2
|
-
import {checkIpV4Cidr} from "#src/utils/checkFunctions";
|
|
3
|
-
|
|
4
|
-
export const getCurrentIp = async () => {
|
|
5
|
-
const {data, error} = await httpClient.get(`/ip`);
|
|
6
|
-
|
|
7
|
-
if (error) {
|
|
8
|
-
console.error(error)
|
|
9
|
-
process.exit(1)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
return checkIpV4Cidr(data)
|
|
14
|
-
} catch {
|
|
15
|
-
console.log(`invalid ip v4 address "${data}"`)
|
|
16
|
-
process.exit(1)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {npmApiClient} from "#lib/HttpClient";
|
|
2
|
-
|
|
3
|
-
export const getLatestVersion = async () => {
|
|
4
|
-
|
|
5
|
-
await new Promise(resolve => setTimeout(resolve, 2000))
|
|
6
|
-
const {data, error} = await npmApiClient.get('/-/package/tunli/dist-tags')
|
|
7
|
-
|
|
8
|
-
if (error) {
|
|
9
|
-
return false
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return data.latest
|
|
13
|
-
}
|
package/src/lib/Flow/proxyUrl.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {securedHttpClient} from "#lib/HttpClient";
|
|
2
|
-
import {TUNLI_PROXY_URL} from "#lib/defs";
|
|
3
|
-
import {replaceTemplatePlaceholders} from "#src/utils/stringFunctions";
|
|
4
|
-
|
|
5
|
-
export const requestNewProxyUrl = async (token) => {
|
|
6
|
-
|
|
7
|
-
const {data, error} = await securedHttpClient(token).get('/create');
|
|
8
|
-
|
|
9
|
-
if (error) {
|
|
10
|
-
console.error('Auth failed as server response error, status: ', error);
|
|
11
|
-
process.exit(1)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return replaceTemplatePlaceholders(TUNLI_PROXY_URL, {
|
|
15
|
-
uuid: data
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const renewProxyUrlRegistration = async (proxyUrl, token) => {
|
|
20
|
-
|
|
21
|
-
const subDomain = new URL(proxyUrl).hostname.split('.', 1)[0]
|
|
22
|
-
|
|
23
|
-
const {data, error} = await securedHttpClient(token).get(`/renew/${subDomain}`);
|
|
24
|
-
|
|
25
|
-
if (data === false) {
|
|
26
|
-
return false
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!data) {
|
|
30
|
-
console.error('Renew failed, request a new URL', error);
|
|
31
|
-
process.exit(1)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return proxyUrl
|
|
35
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {Command} from "commander";
|
|
2
|
-
import {Ref} from "#src/core/Ref";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {Ref} configRef
|
|
7
|
-
* @param {Command} cmd
|
|
8
|
-
*/
|
|
9
|
-
export const validateAuthToken = (cmd, configRef) => {
|
|
10
|
-
cmd.hook('preAction', (thisCommand, actionCommand) => {
|
|
11
|
-
|
|
12
|
-
/** @type {LocalConfig|GlobalConfig} */
|
|
13
|
-
const config = configRef.value
|
|
14
|
-
|
|
15
|
-
if (!config.authToken) {
|
|
16
|
-
actionCommand.error("error: Missing authToken. Please run register firstly");
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
}
|
package/src/lib/HttpClient.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import {AUTH_SERVER_URL} from "#lib/defs";
|
|
3
|
-
|
|
4
|
-
const createClient = (options = {}) => {
|
|
5
|
-
|
|
6
|
-
const defaultOptions = {
|
|
7
|
-
baseURL: AUTH_SERVER_URL,
|
|
8
|
-
headers: {
|
|
9
|
-
'user-agent': 'tunli/1.0'
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const headers = {...defaultOptions.headers, ...options.headers ?? {}};
|
|
14
|
-
options = {...defaultOptions, ...options, headers};
|
|
15
|
-
|
|
16
|
-
const httpClient = axios.create(options)
|
|
17
|
-
httpClient.interceptors.response.use((response) => {
|
|
18
|
-
return {
|
|
19
|
-
data: response.data
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
(error) => {
|
|
23
|
-
if (error.code === 'ECONNREFUSED') {
|
|
24
|
-
console.error('Connection refused to', error.config.url);
|
|
25
|
-
}
|
|
26
|
-
const message = error.response?.data ? error.response?.data : null
|
|
27
|
-
return Promise.resolve({
|
|
28
|
-
error: message ?? {
|
|
29
|
-
code: error.code,
|
|
30
|
-
message: error.message
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
return httpClient
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @type {AxiosInstance}
|
|
41
|
-
*/
|
|
42
|
-
export const httpClient = createClient();
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @type {AxiosInstance}
|
|
46
|
-
*/
|
|
47
|
-
export const npmApiClient = createClient({
|
|
48
|
-
baseURL: 'https://registry.npmjs.org/'
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @param {string} token - Der Authentifizierungs-Token.
|
|
53
|
-
* @returns {AxiosInstance} - Eine konfigurierte Axios-Instanz mit Authentifizierung.
|
|
54
|
-
*/
|
|
55
|
-
export const securedHttpClient = (token) => {
|
|
56
|
-
return createClient({
|
|
57
|
-
headers: {
|
|
58
|
-
authorization: `Bearer ${token}`,
|
|
59
|
-
},
|
|
60
|
-
})
|
|
61
|
-
}
|
package/src/lib/Proxy.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {ConfigManager} from "#src/config/ConfigManager";
|
|
2
|
-
import {TunnelClient} from "#src/tunnel-client/TunnelClient";
|
|
3
|
-
import {renewProxyUrlRegistration} from "#lib/Flow/proxyUrl";
|
|
4
|
-
|
|
5
|
-
const prepareOptions = async (options) => {
|
|
6
|
-
|
|
7
|
-
options ??= {}
|
|
8
|
-
const localConf = ConfigManager.loadLocalOnly()
|
|
9
|
-
const globalConf = ConfigManager.loadGlobalOnly()
|
|
10
|
-
|
|
11
|
-
const authToken = globalConf.authToken
|
|
12
|
-
|
|
13
|
-
let preparedOptions = {authToken, ...localConf.dump(), ...options}
|
|
14
|
-
|
|
15
|
-
preparedOptions.server = await renewProxyUrlRegistration(preparedOptions.proxyURL, preparedOptions.authToken)
|
|
16
|
-
preparedOptions.denyCidr ??= []
|
|
17
|
-
preparedOptions.allowCidr ??= []
|
|
18
|
-
|
|
19
|
-
console.log(preparedOptions)
|
|
20
|
-
|
|
21
|
-
return preparedOptions
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @param {tunliProxyOptions} options
|
|
27
|
-
*/
|
|
28
|
-
export const proxy = async (options) => {
|
|
29
|
-
|
|
30
|
-
options = await prepareOptions(options)
|
|
31
|
-
const client = new TunnelClient(options)
|
|
32
|
-
|
|
33
|
-
await client.init()
|
|
34
|
-
console.log('INIT')
|
|
35
|
-
return options
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const tunli = {
|
|
39
|
-
proxy
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default tunli
|
package/src/lib/defs.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {resolve} from "path";
|
|
2
|
-
import {homedir} from "os";
|
|
3
|
-
|
|
4
|
-
export const SERVER_HOST = 'tunli.app'
|
|
5
|
-
|
|
6
|
-
export const TUNLI_PROXY_URL = process.env.TUNLI_PROXY_URL ?? 'https://{{ uuid }}.tunli.app'
|
|
7
|
-
|
|
8
|
-
export const CONFIG_DIR_NAME = '.tunli'
|
|
9
|
-
|
|
10
|
-
export const AUTH_SERVER_URL = process.env.TUNLI_API_SERVER_URL ?? 'https://api.tunli.app'
|
|
11
|
-
|
|
12
|
-
export const GLOBAL_CONFIG_DIR = resolve(homedir(), CONFIG_DIR_NAME);
|
|
13
|
-
export const CONFIG_FILENAME = 'default.json'
|
package/src/net/IPV4.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
export const ipV4 = (address) => {
|
|
2
|
-
|
|
3
|
-
if (address instanceof IPV4) {
|
|
4
|
-
return address
|
|
5
|
-
}
|
|
6
|
-
return new IPV4(address)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class IPV4 {
|
|
10
|
-
|
|
11
|
-
#ipv4Address
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @type {IPV4}
|
|
15
|
-
*/
|
|
16
|
-
#subnet
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @type {boolean}
|
|
20
|
-
*/
|
|
21
|
-
#isValid
|
|
22
|
-
|
|
23
|
-
constructor(ipv4Address) {
|
|
24
|
-
|
|
25
|
-
this._ipv4Address = this.#ipv4Address = this.#prepare(ipv4Address)
|
|
26
|
-
this.#isValid = this.#ipv4Address !== null
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @returns {boolean}
|
|
31
|
-
*/
|
|
32
|
-
get isValid() {
|
|
33
|
-
return this.#isValid
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @return {number|null}
|
|
38
|
-
*/
|
|
39
|
-
get cidrSuffix() {
|
|
40
|
-
return this.#ipv4Address?.cidrSuffix ?? null
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get subnetAddress() {
|
|
44
|
-
this.#subnet ??= this.#calculateSubnet()
|
|
45
|
-
return this.#subnet
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
#calculateSubnet() {
|
|
49
|
-
|
|
50
|
-
const mask = ipV4(~((1 << (32 - this.cidrSuffix)) - 1) >>> 0)
|
|
51
|
-
const octets = []
|
|
52
|
-
|
|
53
|
-
for (let i = 0; i < 4; i++) {
|
|
54
|
-
const maskPart = mask.#ipv4Address.octetsAsIntegers[i]
|
|
55
|
-
const ipPart = this.#ipv4Address.octetsAsIntegers[i]
|
|
56
|
-
octets.push(maskPart & ipPart)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return ipV4(octets.join('.'))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
#prepare(ipv4Address) {
|
|
63
|
-
|
|
64
|
-
const typeOfAddress = typeof ipv4Address
|
|
65
|
-
let octets = []
|
|
66
|
-
let octetsAsIntegers = []
|
|
67
|
-
let octetsAsBinaryString = []
|
|
68
|
-
let ipv4AddressAsInt;
|
|
69
|
-
let ipv4AddressAsString;
|
|
70
|
-
let cidrSuffix = 32;
|
|
71
|
-
|
|
72
|
-
if (typeOfAddress === 'number') {
|
|
73
|
-
ipv4AddressAsInt = ipv4Address
|
|
74
|
-
const binaryRepresentation = ipv4Address.toString(2)
|
|
75
|
-
const chunkSize = 8
|
|
76
|
-
for (let i = binaryRepresentation.length; i > 0; i -= chunkSize) {
|
|
77
|
-
const octetAsBin = binaryRepresentation.substring(i - chunkSize, i).padStart(8, '0')
|
|
78
|
-
const octetAsInt = parseInt(octetAsBin, 2)
|
|
79
|
-
|
|
80
|
-
octetsAsBinaryString.unshift(octetAsBin);
|
|
81
|
-
octetsAsIntegers.unshift(octetAsInt);
|
|
82
|
-
octets.unshift(octetAsInt.toString());
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
ipv4AddressAsString = octets.join('.')
|
|
86
|
-
} else if (typeOfAddress === 'string') {
|
|
87
|
-
|
|
88
|
-
const parts = ipv4Address.split('/')
|
|
89
|
-
if (parts.length > 2) {
|
|
90
|
-
return null
|
|
91
|
-
} else if (parts.length === 2) {
|
|
92
|
-
cidrSuffix = parseInt(parts[1])
|
|
93
|
-
if (isNaN(cidrSuffix)) {
|
|
94
|
-
return null
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
octetsAsIntegers = parts[0].split('.').map(Number)
|
|
99
|
-
octets = octetsAsIntegers.map(x => x.toString())
|
|
100
|
-
ipv4AddressAsString = octets.join('.')
|
|
101
|
-
octetsAsBinaryString = octetsAsIntegers.map(x => x.toString(2).padStart(8, '0'))
|
|
102
|
-
} else {
|
|
103
|
-
return null
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (octetsAsIntegers.filter(x => x <= 255).length !== 4) {
|
|
107
|
-
return null
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
asString: ipv4AddressAsString,
|
|
112
|
-
octets,
|
|
113
|
-
octetsAsIntegers,
|
|
114
|
-
octetsAsBinaryString,
|
|
115
|
-
asInt: ipv4AddressAsInt,
|
|
116
|
-
cidrSuffix
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
isInSubnet(subnet) {
|
|
121
|
-
subnet = ipV4(subnet)
|
|
122
|
-
const mask = ~((1 << (32 - subnet.cidrSuffix)) - 1) >>> 0;
|
|
123
|
-
return (this.toInteger() & mask) === (subnet.toInteger() & mask)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
toString() {
|
|
127
|
-
return this.#ipv4Address?.asString ?? null
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
toInteger() {
|
|
131
|
-
if (!this.#ipv4Address) {
|
|
132
|
-
return null
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
this.#ipv4Address.asInt ??= parseInt(this.#ipv4Address.octetsAsBinaryString.join(''), 2)
|
|
136
|
-
return this.#ipv4Address.asInt
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|