Split up listen address configuration between IPv4 and IPv6
Signed| @@ -7,7 +7,8 @@ cardsCacheCapacity: 100 | |||
| 7 | # Listen for incoming connections | 7 | # Listen for incoming connections |
| 8 | listen: false | 8 | listen: false |
| 9 | # Listen on a specific address, supports IPv4 and IPv6 | 9 | # Listen on a specific address, supports IPv4 and IPv6 |
| 10 | listenAddress: 0.0.0.0 | 10 | listenAddressIPv6: [::] |
| 11 | listenAddressIPv4: 0.0.0.0 | ||
| 11 | # Enables IPv6 and/or IPv4 protocols. Need to have at least one enabled! | 12 | # Enables IPv6 and/or IPv4 protocols. Need to have at least one enabled! |
| 12 | # - Use option "auto" to automatically detect support | 13 | # - Use option "auto" to automatically detect support |
| 13 | # - Use true or false (no qoutes) to enable or disable each protocol | 14 | # - Use true or false (no qoutes) to enable or disable each protocol |
| @@ -131,7 +131,8 @@ if (process.versions && process.versions.node && process.versions.node.match(/20 | |||
| 131 | const DEFAULT_PORT = 8000; | 131 | const DEFAULT_PORT = 8000; |
| 132 | const DEFAULT_AUTORUN = false; | 132 | const DEFAULT_AUTORUN = false; |
| 133 | const DEFAULT_LISTEN = false; | 133 | const DEFAULT_LISTEN = false; |
| 134 | const DEFAULT_LISTEN_ADDRESS = ''; | 134 | const DEFAULT_LISTEN_ADDRESS_IPV6 = '[::]'; |
| 135 | const DEFAULT_LISTEN_ADDRESS_IPV4 = '0.0.0.0'; | ||
| 135 | const DEFAULT_CORS_PROXY = false; | 136 | const DEFAULT_CORS_PROXY = false; |
| 136 | const DEFAULT_WHITELIST = true; | 137 | const DEFAULT_WHITELIST = true; |
| 137 | const DEFAULT_ACCOUNTS = false; | 138 | const DEFAULT_ACCOUNTS = false; |
| @@ -187,10 +188,14 @@ const cliArguments = yargs(hideBin(process.argv)) | |||
| 187 | type: 'boolean', | 188 | type: 'boolean', |
| 188 | default: null, | 189 | default: null, |
| 189 | describe: `SillyTavern is listening on all network interfaces (Wi-Fi, LAN, localhost). If false, will limit it only to internal localhost (127.0.0.1).\nIf not provided falls back to yaml config 'listen'.\n[config default: ${DEFAULT_LISTEN}]`, | 190 | describe: `SillyTavern is listening on all network interfaces (Wi-Fi, LAN, localhost). If false, will limit it only to internal localhost (127.0.0.1).\nIf not provided falls back to yaml config 'listen'.\n[config default: ${DEFAULT_LISTEN}]`, |
| 190 | }).option('listenAddress', { | 191 | }).option('listenAddressIPv6', { |
| 191 | type: 'string', | 192 | type: 'string', |
| 192 | default: null, | 193 | default: null, |
| 193 | describe: 'Set SillyTavern to listen to a specific address. If not set, it will fallback to listen to all.\n[config default: empty ]', | 194 | describe: 'Set SillyTavern to listen to a specific IPv6 address. If not set, it will fallback to listen to all.\n[config default: [::] ]', |
| 195 | }).option('listenAddressIPv4', { | ||
| 196 | type: 'string', | ||
| 197 | default: null, | ||
| 198 | describe: 'Set SillyTavern to listen to a specific IPv4 address. If not set, it will fallback to listen to all.\n[config default: 0.0.0.0 ]', | ||
| 194 | }).option('corsProxy', { | 199 | }).option('corsProxy', { |
| 195 | type: 'boolean', | 200 | type: 'boolean', |
| 196 | default: null, | 201 | default: null, |
| @@ -261,7 +266,9 @@ const autorun = (cliArguments.autorun ?? getConfigValue('autorun', DEFAULT_AUTOR | |||
| 261 | /** @type {boolean} */ | 266 | /** @type {boolean} */ |
| 262 | const listen = cliArguments.listen ?? getConfigValue('listen', DEFAULT_LISTEN); | 267 | const listen = cliArguments.listen ?? getConfigValue('listen', DEFAULT_LISTEN); |
| 263 | /** @type {string} */ | 268 | /** @type {string} */ |
| 264 | const listenAddress = cliArguments.listenAddress ?? getConfigValue('listenAddress', DEFAULT_LISTEN_ADDRESS); | 269 | const listenAddressIPv6 = cliArguments.listenAddressIPv6 ?? getConfigValue('listenAddressIPv6', DEFAULT_LISTEN_ADDRESS_IPV6); |
| 270 | /** @type {string} */ | ||
| 271 | const listenAddressIPv4 = cliArguments.listenAddressIPv4 ?? getConfigValue('listenAddressIPv4', DEFAULT_LISTEN_ADDRESS_IPV4); | ||
| 265 | /** @type {boolean} */ | 272 | /** @type {boolean} */ |
| 266 | const enableCorsProxy = cliArguments.corsProxy ?? getConfigValue('enableCorsProxy', DEFAULT_CORS_PROXY); | 273 | const enableCorsProxy = cliArguments.corsProxy ?? getConfigValue('enableCorsProxy', DEFAULT_CORS_PROXY); |
| 267 | const enableWhitelist = cliArguments.whitelist ?? getConfigValue('whitelistMode', DEFAULT_WHITELIST); | 274 | const enableWhitelist = cliArguments.whitelist ?? getConfigValue('whitelistMode', DEFAULT_WHITELIST); |
| @@ -716,13 +723,13 @@ app.use('/api/azure', azureRouter); | |||
| 716 | 723 | ||
| 717 | const tavernUrlV6 = new URL( | 724 | const tavernUrlV6 = new URL( |
| 718 | (cliArguments.ssl ? 'https://' : 'http://') + | 725 | (cliArguments.ssl ? 'https://' : 'http://') + |
| 719 | (listen ? (ipRegex.v6({ exact: true }).test(listenAddress) ? `[${listenAddress}]` : '[::]') : '[::1]') + | 726 | (listen ? (ipRegex.v6({ exact: true }).test(listenAddressIPv6) ? listenAddressIPv6 : '[::]') : '[::1]') + |
| 720 | (':' + server_port), | 727 | (':' + server_port), |
| 721 | ); | 728 | ); |
| 722 | 729 | ||
| 723 | const tavernUrl = new URL( | 730 | const tavernUrl = new URL( |
| 724 | (cliArguments.ssl ? 'https://' : 'http://') + | 731 | (cliArguments.ssl ? 'https://' : 'http://') + |
| 725 | (listen ? (ipRegex.v4({ exact: true }).test(listenAddress) ? listenAddress : '0.0.0.0') : '127.0.0.1') + | 732 | (listen ? (ipRegex.v4({ exact: true }).test(listenAddressIPv4) ? listenAddressIPv4 : '0.0.0.0') : '127.0.0.1') + |
| 726 | (':' + server_port), | 733 | (':' + server_port), |
| 727 | ); | 734 | ); |
| 728 | 735 | ||
| @@ -789,10 +796,10 @@ const preSetupTasks = async function () { | |||
| 789 | async function getAutorunHostname(useIPv6, useIPv4) { | 796 | async function getAutorunHostname(useIPv6, useIPv4) { |
| 790 | if (autorunHostname === 'auto') { | 797 | if (autorunHostname === 'auto') { |
| 791 | if (listen) { | 798 | if (listen) { |
| 792 | if (ipRegex.v4({ exact: true }).test(listenAddress)) { | 799 | if (ipRegex.v6({ exact: true }).test(listenAddressIPv6)) { |
| 793 | return listenAddress; | 800 | return listenAddressIPv6; |
| 794 | } else if (ipRegex.v6({ exact: true }).test(listenAddress)) { | 801 | } else if (ipRegex.v4({ exact: true }).test(listenAddressIPv4)) { |
| 795 | return `[${listenAddress}]`; | 802 | return listenAddressIPv4; |
| 796 | } | 803 | } |
| 797 | } | 804 | } |
| 798 | 805 | ||
| @@ -858,13 +865,13 @@ const postSetupTasks = async function (v6Failed, v4Failed, useIPv6, useIPv4) { | |||
| 858 | console.log('\n' + getSeparator(plainGoToLog.length) + '\n'); | 865 | console.log('\n' + getSeparator(plainGoToLog.length) + '\n'); |
| 859 | 866 | ||
| 860 | if (listen) { | 867 | if (listen) { |
| 861 | if (ipRegex.v4({ exact: true }).test(listenAddress)) { | 868 | if (ipRegex.v6({ exact: true }).test(listenAddressIPv6)) { |
| 862 | console.log( | 869 | console.log( |
| 863 | `SillyTavern is listening on the address ${listenAddress}. If you want to limit it only to internal localhost ([::1] or 127.0.0.1), change the setting in config.yaml to "listen: false". Check "access.log" file in the SillyTavern directory if you want to inspect incoming connections.\n`, | 870 | `SillyTavern is listening on the address ${listenAddressIPv6}. If you want to limit it only to internal localhost ([::1] or 127.0.0.1), change the setting in config.yaml to "listen: false". Check "access.log" file in the SillyTavern directory if you want to inspect incoming connections.\n`, |
| 864 | ); | 871 | ); |
| 865 | } else if (ipRegex.v6({ exact: true }).test(listenAddress)) { | 872 | } else if (ipRegex.v4({ exact: true }).test(listenAddressIPv4)) { |
| 866 | console.log( | 873 | console.log( |
| 867 | `SillyTavern is listening on the address [${listenAddress}]. If you want to limit it only to internal localhost ([::1] or 127.0.0.1), change the setting in config.yaml to "listen: false". Check "access.log" file in the SillyTavern directory if you want to inspect incoming connections.\n`, | 874 | `SillyTavern is listening on the address ${listenAddressIPv4}. If you want to limit it only to internal localhost ([::1] or 127.0.0.1), change the setting in config.yaml to "listen: false". Check "access.log" file in the SillyTavern directory if you want to inspect incoming connections.\n`, |
| 868 | ); | 875 | ); |
| 869 | } else { | 876 | } else { |
| 870 | console.log( | 877 | console.log( |