Merge pull request #113 from sanskar-mk2/whitelist-txt-feature

optional whitelist.txt
This commit is contained in:
Cohee
2023-04-20 16:12:09 +03:00
committed by GitHub
3 changed files with 24 additions and 2 deletions

1
.gitignore vendored
View File

@@ -13,3 +13,4 @@ config.conf
.DS_Store
public/settings.json
/thumbnails
whitelist.txt

View File

@@ -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

View File

@@ -31,7 +31,17 @@ 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;
const whitelistPath = path.join(process.cwd(), "./whitelist.txt");
let whitelist = config.whitelist;
if (fs.existsSync(whitelistPath)) {
try {
let whitelistTxt = fs.readFileSync(whitelistPath, 'utf-8');
whitelist = whitelistTxt.split("\n").filter(ip => ip).map(ip => ip.trim());
} catch (e) { }
}
const whitelistMode = config.whitelistMode;
const autorun = config.autorun;
const enableExtensions = config.enableExtensions;
@@ -2494,4 +2504,4 @@ function ensurePublicDirectoriesExist() {
fs.mkdirSync(dir, { recursive: true });
}
}
}
}