From 50792fdef537a32c2b20c55d88eb4859e5bd5b42 Mon Sep 17 00:00:00 2001 From: Sanskar Tiwari Date: Thu, 20 Apr 2023 18:11:20 +0530 Subject: [PATCH] optional whitelist.txt --- .gitignore | 1 + readme.md | 11 +++++++++++ server.js | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 39f745b39..ec1e67404 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ config.conf .DS_Store public/settings.json /thumbnails +whitelist.txt diff --git a/readme.md b/readme.md index 462c1cdaf..80c6c29fc 100644 --- a/readme.md +++ b/readme.md @@ -134,6 +134,17 @@ Restart your TAI server. You will now be able to connect from other devices. +### Managing whitelisted IPs + +You can add or remove whitelisted IPs by editing the `whitelist` array in `config.conf`. You can also provide a `whitelist.txt` file in the same directory as `config.conf` with one IP address per line like: + +```txt +192.168.0.1 +192.168.0.2 +``` + +The `whitelist` array in `config.conf` will be ignored if `whitelist.txt` exists. + ***Disclaimer: Anyone else who knows your IP address and TAI port number will be able to connect as well*** To connect over wifi you'll need your PC's local wifi IP address diff --git a/server.js b/server.js index 9f3302803..09fc073af 100644 --- a/server.js +++ b/server.js @@ -31,7 +31,13 @@ const webp = require('webp-converter'); const config = require(path.join(process.cwd(), './config.conf')); const server_port = process.env.SILLY_TAVERN_PORT || config.port; -const whitelist = config.whitelist; + +let whitelistTxt = null; +try { + whitelistTxt = fs.readFileSync(path.join(process.cwd(), "./whitelist.txt")); +} catch (e) {} +const whitelist = whitelistTxt.toString().split("\n").filter(ip => ip) || config.whitelist; + const whitelistMode = config.whitelistMode; const autorun = config.autorun; const enableExtensions = config.enableExtensions;