From cebcd970c1a7169e05c696c32bb83c7c97709b57 Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 16 Feb 2023 16:26:52 +0400 Subject: [PATCH 1/9] readme fix --- readme.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index d0fe81c24..196219d7a 100644 --- a/readme.md +++ b/readme.md @@ -2,10 +2,13 @@ Examples of interface and output:
-[TavernAI Download](https://github.com/TavernAI/TavernAI/archive/refs/heads/main.zip)
-[TavernAI Run Online](https://colab.research.google.com/github/TavernAI/TavernAI/blob/main/colab/GPU.ipynb)

-[TavetnAI Boosty](https://boosty.to/tavernai)
-[TavernAI Discord](https://discord.gg/zmK2gmr45t)
+###### Download: +* [Win x64 exe](https://sourceforge.net/projects/tavernaimain/files/TavernAI.rar/download)  |  [Node.js version](https://github.com/TavernAI/TavernAI/archive/refs/heads/main.zip)
+###### Run online: +* [TavernAI Colab](https://colab.research.google.com/github/TavernAI/TavernAI/blob/main/colab/GPU.ipynb)
+###### Links: +* [TavetnAI Boosty](https://boosty.to/tavernai) +* [TavernAI Discord](https://discord.gg/zmK2gmr45t) ## Features * Creating characters with personality setup From 82323fb2eb05d733661e2d9fa930366c53589c81 Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 16 Feb 2023 16:27:40 +0400 Subject: [PATCH 2/9] readme fix --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 196219d7a..12caab523 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ Examples of interface and output:
###### Download: -* [Win x64 exe](https://sourceforge.net/projects/tavernaimain/files/TavernAI.rar/download)  |  [Node.js version](https://github.com/TavernAI/TavernAI/archive/refs/heads/main.zip)
+* [Win x64 .exe](https://sourceforge.net/projects/tavernaimain/files/TavernAI.rar/download)  |  [Node.js version](https://github.com/TavernAI/TavernAI/archive/refs/heads/main.zip)
###### Run online: * [TavernAI Colab](https://colab.research.google.com/github/TavernAI/TavernAI/blob/main/colab/GPU.ipynb)
###### Links: From 5e272e91d2ee90a3c50f6463698515fd5e368f33 Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 16 Feb 2023 16:30:59 +0400 Subject: [PATCH 3/9] readme fix --- readme.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/readme.md b/readme.md index 12caab523..0bf1a964b 100644 --- a/readme.md +++ b/readme.md @@ -43,10 +43,4 @@ If the message is not finished, you can simply send the request again, TavernAI https://www.reddit.com/user/Crataco/comments/zuowi9/opensource_chatbot_companions/ ## For contacts * Discord: Humi#5044 -## For thanks and support -TavernAI is being developed with love and care on a voluntary basis. If you like the project and want to support it, your donation would make a huge impact! - -BTC 1LASziomyYNkZ2zk8Sa4ZLTkvczBMrjyjP
-ETH 0x975E5C91042ce8168B3d37b17F99949c5eFB3Dfe
-TRX TCiBKCt6xEGrsjpgQA2jDXWJLyUh1KN2Sn


From 7b9837fd06e3df9d3a1eb12ac2883c32bb74c7fc Mon Sep 17 00:00:00 2001 From: Ash Date: Fri, 17 Feb 2023 02:42:49 +0400 Subject: [PATCH 4/9] fix --- server.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 5175e033a..67e92dc29 100644 --- a/server.js +++ b/server.js @@ -20,7 +20,7 @@ const cookieParser = require('cookie-parser'); const crypto = require('crypto'); -const config = require('./config.conf'); +const config = require(path.join(process.cwd(), './config.conf')); const server_port = config.port; const whitelist = config.whitelist; const whitelistMode = config.whitelistMode; @@ -107,7 +107,7 @@ app.use(function (req, res, next) { //Security app.use((req, res, next) => { if (req.url.startsWith('/characters/') && is_colab && process.env.googledrive == 2) { - const filePath = path.join(charactersPath, req.url.substr('/characters'.length)); + const filePath = path.join(charactersPath, decodeURIComponent(req.url.substr('/characters'.length))); fs.access(filePath, fs.constants.R_OK, (err) => { if (!err) { res.sendFile(filePath); @@ -126,7 +126,7 @@ app.use(express.static(__dirname + "/public", { refresh: true })); app.use('/backgrounds', (req, res) => { - const filePath = path.join(process.cwd(), 'public/backgrounds', req.url); + const filePath = decodeURIComponent(path.join(process.cwd(), 'public/backgrounds', req.url.replace(/%20/g, ' '))); fs.readFile(filePath, (err, data) => { if (err) { res.status(404).send('File not found'); @@ -137,7 +137,7 @@ app.use('/backgrounds', (req, res) => { }); }); app.use('/characters', (req, res) => { - const filePath = path.join(process.cwd(), charactersPath, req.url); + const filePath = decodeURIComponent(path.join(process.cwd(), charactersPath, req.url.replace(/%20/g, ' '))); fs.readFile(filePath, (err, data) => { if (err) { res.status(404).send('File not found'); From 6cf2d951445493ed40a98f3071c67f66344ca042 Mon Sep 17 00:00:00 2001 From: Ash Date: Fri, 17 Feb 2023 02:58:07 +0400 Subject: [PATCH 5/9] ip whitelist check fix --- package-lock.json | 30 +++++++++++++++++++++++------- package.json | 40 ++++++++++++++++++++-------------------- server.js | 16 ++++++++++++++-- 3 files changed, 57 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 09b5cdb9e..321b19654 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "cors": "^2.8.5", "csrf-csrf": "^2.2.3", "express": "^4.18.2", + "ipaddr.js": "^2.0.1", "multer": "^1.4.5-lts.1", "node-rest-client": "^3.1.1", "open": "^8.4.0", @@ -715,11 +716,11 @@ "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" }, "node_modules/ipaddr.js": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", - "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.0.1.tgz", + "integrity": "sha512-1qTgH9NG+IIJ4yfKs2e6Pp1bZg8wbDbKHT21HrLIeYBTRLgMYKnMTPAuI3Lcs61nfx5h1xlXnbJtH1kX5/d/ng==", "engines": { - "node": ">= 0.10" + "node": ">= 10" } }, "node_modules/is-arrayish": { @@ -1065,6 +1066,14 @@ "node": ">= 0.10" } }, + "node_modules/proxy-addr/node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", @@ -2052,9 +2061,9 @@ "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" }, "ipaddr.js": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", - "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.0.1.tgz", + "integrity": "sha512-1qTgH9NG+IIJ4yfKs2e6Pp1bZg8wbDbKHT21HrLIeYBTRLgMYKnMTPAuI3Lcs61nfx5h1xlXnbJtH1kX5/d/ng==" }, "is-arrayish": { "version": "0.3.2", @@ -2307,6 +2316,13 @@ "requires": { "forwarded": "0.2.0", "ipaddr.js": "1.9.1" + }, + "dependencies": { + "ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" + } } }, "pump": { diff --git a/package.json b/package.json index 5d1b7fd34..2811a5ea8 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,30 @@ { "dependencies": { - "express": "^4.18.2", - "multer": "^1.4.5-lts.1", - "node-rest-client": "^3.1.1", - "open": "^8.4.0", - "png-chunk-text": "^1.0.0", - "png-chunks-encode": "^1.0.0", - "png-chunks-extract": "^1.0.0", - "rimraf": "^3.0.2", - "sharp": "^0.31.3", - "csrf-csrf": "^2.2.3", - "cookie-parser": "^1.4.6", - "cors": "^2.8.5" + "cookie-parser": "^1.4.6", + "cors": "^2.8.5", + "csrf-csrf": "^2.2.3", + "express": "^4.18.2", + "ipaddr.js": "^2.0.1", + "multer": "^1.4.5-lts.1", + "node-rest-client": "^3.1.1", + "open": "^8.4.0", + "png-chunk-text": "^1.0.0", + "png-chunks-encode": "^1.0.0", + "png-chunks-extract": "^1.0.0", + "rimraf": "^3.0.2", + "sharp": "^0.31.3" }, "name": "TavernAI", "version": "1.2.8", "bin": { - "TavernAI": "server.js" + "TavernAI": "server.js" }, - "rules":{ - "no-path-concat":"off", - "no-var":"off" - + "rules": { + "no-path-concat": "off", + "no-var": "off" }, - "pkg":{ - "assets":[ + "pkg": { + "assets": [ "node_modules/sharp/build/Release/**/*", "node_modules/sharp/vendor/lib/**/*", "node_modules/open/xdg-open/", @@ -32,4 +32,4 @@ "uploads" ] } -} \ No newline at end of file +} diff --git a/server.js b/server.js index 67e92dc29..cd3395f4c 100644 --- a/server.js +++ b/server.js @@ -18,7 +18,7 @@ const path = require('path'); const cookieParser = require('cookie-parser'); const crypto = require('crypto'); - +const ipaddr = require('ipaddr.js'); const config = require(path.join(process.cwd(), './config.conf')); const server_port = config.port; @@ -26,6 +26,8 @@ const whitelist = config.whitelist; const whitelistMode = config.whitelistMode; const autorun = config.autorun; + + var Client = require('node-rest-client').Client; var client = new Client(); @@ -96,7 +98,17 @@ const CORS = cors({ app.use(CORS); app.use(function (req, res, next) { //Security - const clientIp = req.connection.remoteAddress.split(':').pop(); + let clientIp = req.connection.remoteAddress; + const ip = ipaddr.parse(clientIp); + + // Check if the IP address is IPv4-mapped IPv6 address + if (ip.kind() === 'ipv6' && ip.isIPv4MappedAddress()) { + const ipv4 = ip.toIPv4Address().toString(); + clientIp = ipv4; + } else { + clientIp = ip; + } + //clientIp = req.connection.remoteAddress.split(':').pop(); if (whitelistMode === true && !whitelist.includes(clientIp)) { console.log('Forbidden: Connection attempt from '+ clientIp+'. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.conf in root of TavernAI folder.\n'); return res.status(403).send('Forbidden: Connection attempt from '+ clientIp+'. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.conf in root of TavernAI folder.'); From d6afa075607cb121432745b9bbea57ee9c72923d Mon Sep 17 00:00:00 2001 From: Ash Date: Fri, 17 Feb 2023 14:52:08 +0400 Subject: [PATCH 6/9] favicon --- public/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/public/index.html b/public/index.html index f82a2514d..0251e90a1 100644 --- a/public/index.html +++ b/public/index.html @@ -7,6 +7,7 @@ +