| @@ -7,7 +7,7 @@ cardsCacheCapacity: 100 | ||
| 7 | 7 | # Listen for incoming connections |
| 8 | 8 | listen: false |
| 9 | 9 | # Listen on a specific address, supports IPv4 and IPv6 |
| 10 | 10 | listenAddress: 1270.0.0.10 |
| 11 | 11 | # Enables IPv6 and/or IPv4 protocols. Need to have at least one enabled! |
| 12 | 12 | # - Use option "auto" to automatically detect support |
| 13 | 13 | # - Use true or false (no qoutes) to enable or disable each protocol |
| @@ -41,6 +41,7 @@ | ||
| 41 | 41 | "html-entities": "^2.5.2", |
| 42 | 42 | "iconv-lite": "^0.6.3", |
| 43 | 43 | "ip-matching": "^2.1.2", |
| 44 | + "ip-regex": "^5.0.0", | |
| 44 | 45 | "ipaddr.js": "^2.0.1", |
| 45 | 46 | "jimp": "^0.22.10", |
| 46 | 47 | "localforage": "^1.10.0", |
| @@ -4628,6 +4629,18 @@ | ||
| 4628 | 4629 | "integrity": "sha512-/ok+VhKMasgR5gvTRViwRFQfc0qYt9Vdowg6TO4/pFlDCob5ZjGPkwuOoQVCd5OrMm20zqh+1vA8KLJZTeWudg==", |
| 4629 | 4630 | "license": "LGPL-3.0-only" |
| 4630 | 4631 | }, |
| 4632 | + "node_modules/ip-regex": { | |
| 4633 | + "version": "5.0.0", | |
| 4634 | + "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-5.0.0.tgz", | |
| 4635 | + "integrity": "sha512-fOCG6lhoKKakwv+C6KdsOnGvgXnmgfmp0myi3bcNwj3qfwPAxRKWEuFhvEFF7ceYIz6+1jRZ+yguLFAmUNPEfw==", | |
| 4636 | + "license": "MIT", | |
| 4637 | + "engines": { | |
| 4638 | + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" | |
| 4639 | + }, | |
| 4640 | + "funding": { | |
| 4641 | + "url": "https://github.com/sponsors/sindresorhus" | |
| 4642 | + } | |
| 4643 | + }, | |
| 4631 | 4644 | "node_modules/ipaddr.js": { |
| 4632 | 4645 | "version": "2.1.0", |
| 4633 | 4646 | "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.1.0.tgz", |
| @@ -31,6 +31,7 @@ | ||
| 31 | 31 | "html-entities": "^2.5.2", |
| 32 | 32 | "iconv-lite": "^0.6.3", |
| 33 | 33 | "ip-matching": "^2.1.2", |
| 34 | + "ip-regex": "^5.0.0", | |
| 34 | 35 | "ipaddr.js": "^2.0.1", |
| 35 | 36 | "jimp": "^0.22.10", |
| 36 | 37 | "localforage": "^1.10.0", |
| @@ -30,6 +30,7 @@ import bodyParser from 'body-parser'; | ||
| 30 | 30 | |
| 31 | 31 | // net related library imports |
| 32 | 32 | import fetch from 'node-fetch'; |
| 33 | +import ipRegex from 'ip-regex'; | |
| 33 | 34 | |
| 34 | 35 | // Unrestrict console logs display limit |
| 35 | 36 | util.inspect.defaultOptions.maxArrayLength = null; |
| @@ -713,17 +714,15 @@ app.use('/api/backends/scale-alt', scaleAltRouter); | ||
| 713 | 714 | app.use('/api/speech', speechRouter); |
| 714 | 715 | app.use('/api/azure', azureRouter); |
| 715 | 716 | |
| 716 | -const ipv6_regex = /^(?:(?:[a-fA-F\d]{1,4}:){7}(?:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,2}|:)|(?:[a-fA-F\d]{1,4}:){4}(?:(?::[a-fA-F\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,3}|:)|(?:[a-fA-F\d]{1,4}:){3}(?:(?::[a-fA-F\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,4}|:)|(?:[a-fA-F\d]{1,4}:){2}(?:(?::[a-fA-F\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,5}|:)|(?:[a-fA-F\d]{1,4}:){1}(?:(?::[a-fA-F\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$/m; | |
| 717 | 717 | const tavernUrlV6 = new URL( |
| 718 | 718 | (cliArguments.ssl ? 'https://' : 'http://') + |
| 719 | 719 | (listen ? (ipv6_regexipRegex.v6({ exact: true }).test(listenAddress) ? `[${listenAddress}]` : '[::]') : '[::1]') + |
| 720 | 720 | (':' + server_port), |
| 721 | 721 | ); |
| 722 | 722 | |
| 723 | -const ipv4_regex = /^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/m; | |
| 724 | 723 | const tavernUrl = new URL( |
| 725 | 724 | (cliArguments.ssl ? 'https://' : 'http://') + |
| 726 | 725 | (listen ? (ipv4_regexipRegex.v4({ exact: true }).test(listenAddress) ? listenAddress : '0.0.0.0') : '127.0.0.1') + |
| 727 | 726 | (':' + server_port), |
| 728 | 727 | ); |
| 729 | 728 | |
| @@ -790,9 +789,9 @@ const preSetupTasks = async function () { | ||
| 790 | 789 | async function getAutorunHostname(useIPv6, useIPv4) { |
| 791 | 790 | if (autorunHostname === 'auto') { |
| 792 | 791 | if (listen) { |
| 793 | 792 | if (ipv4_regexipRegex.v4({ exact: true }).test(listenAddress)) { |
| 794 | 793 | return listenAddress; |
| 795 | 794 | } else if (ipv6_regexipRegex.v6({ exact: true }).test(listenAddress)) { |
| 796 | 795 | return `[${listenAddress}]`; |
| 797 | 796 | } |
| 798 | 797 | } |
| @@ -859,11 +858,11 @@ const postSetupTasks = async function (v6Failed, v4Failed, useIPv6, useIPv4) { | ||
| 859 | 858 | console.log('\n' + getSeparator(plainGoToLog.length) + '\n'); |
| 860 | 859 | |
| 861 | 860 | if (listen) { |
| 862 | 861 | if (ipv4_regexipRegex.v4({ exact: true }).test(listenAddress)) { |
| 863 | 862 | console.log( |
| 864 | 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`, |
| 865 | 864 | ); |
| 866 | 865 | } else if (ipv6_regexipRegex.v6({ exact: true }).test(listenAddress)) { |
| 867 | 866 | console.log( |
| 868 | 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`, |
| 869 | 868 | ); |