mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into neo-server
This commit is contained in:
@ -71,7 +71,7 @@ export class Popup {
|
|||||||
this.ok.textContent = okButton ?? 'OK';
|
this.ok.textContent = okButton ?? 'OK';
|
||||||
this.cancel.textContent = cancelButton ?? 'Cancel';
|
this.cancel.textContent = cancelButton ?? 'Cancel';
|
||||||
|
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case POPUP_TYPE.TEXT: {
|
case POPUP_TYPE.TEXT: {
|
||||||
this.input.style.display = 'none';
|
this.input.style.display = 'none';
|
||||||
this.cancel.style.display = 'none';
|
this.cancel.style.display = 'none';
|
||||||
@ -107,9 +107,16 @@ export class Popup {
|
|||||||
// illegal argument
|
// illegal argument
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ok.addEventListener('click', ()=>this.completeAffirmative());
|
this.input.addEventListener('keydown', (evt) => {
|
||||||
this.cancel.addEventListener('click', ()=>this.completeNegative());
|
if (evt.key != 'Enter' || evt.altKey || evt.ctrlKey || evt.shiftKey) return;
|
||||||
const keyListener = (evt)=>{
|
evt.preventDefault();
|
||||||
|
evt.stopPropagation();
|
||||||
|
this.completeAffirmative();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.ok.addEventListener('click', () => this.completeAffirmative());
|
||||||
|
this.cancel.addEventListener('click', () => this.completeNegative());
|
||||||
|
const keyListener = (evt) => {
|
||||||
switch (evt.key) {
|
switch (evt.key) {
|
||||||
case 'Escape': {
|
case 'Escape': {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
@ -127,7 +134,7 @@ export class Popup {
|
|||||||
async show() {
|
async show() {
|
||||||
document.body.append(this.dom);
|
document.body.append(this.dom);
|
||||||
this.dom.style.display = 'block';
|
this.dom.style.display = 'block';
|
||||||
switch(this.type) {
|
switch (this.type) {
|
||||||
case POPUP_TYPE.INPUT: {
|
case POPUP_TYPE.INPUT: {
|
||||||
this.input.focus();
|
this.input.focus();
|
||||||
break;
|
break;
|
||||||
@ -196,7 +203,7 @@ export class Popup {
|
|||||||
duration: animation_duration,
|
duration: animation_duration,
|
||||||
easing: animation_easing,
|
easing: animation_easing,
|
||||||
});
|
});
|
||||||
delay(animation_duration).then(()=>{
|
delay(animation_duration).then(() => {
|
||||||
this.dom.remove();
|
this.dom.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -219,7 +226,7 @@ export function callGenericPopup(text, type, inputValue = '', { okButton, cancel
|
|||||||
text,
|
text,
|
||||||
type,
|
type,
|
||||||
inputValue,
|
inputValue,
|
||||||
{ okButton, rows, wide, large, allowHorizontalScrolling, allowVerticalScrolling, cancelButton },
|
{ okButton, cancelButton, rows, wide, large, allowHorizontalScrolling, allowVerticalScrolling },
|
||||||
);
|
);
|
||||||
return popup.show();
|
return popup.show();
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,27 @@ if (fs.existsSync(whitelistPath)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the client IP address from the request headers.
|
||||||
|
* @param {import('express').Request} req Express request object
|
||||||
|
* @returns {string|undefined} The client IP address
|
||||||
|
*/
|
||||||
|
function getForwardedIp(req) {
|
||||||
|
// Check if X-Real-IP is available
|
||||||
|
if (req.headers['x-real-ip']) {
|
||||||
|
return req.headers['x-real-ip'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for X-Forwarded-For and parse if available
|
||||||
|
if (req.headers['x-forwarded-for']) {
|
||||||
|
const ipList = req.headers['x-forwarded-for'].split(',').map(ip => ip.trim());
|
||||||
|
return ipList[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If none of the headers are available, return undefined
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a middleware function that checks if the client IP is in the whitelist.
|
* Returns a middleware function that checks if the client IP is in the whitelist.
|
||||||
* @param {boolean} whitelistMode If whitelist mode is enabled via config or command line
|
* @param {boolean} whitelistMode If whitelist mode is enabled via config or command line
|
||||||
@ -27,6 +48,7 @@ if (fs.existsSync(whitelistPath)) {
|
|||||||
function whitelistMiddleware(whitelistMode, listen) {
|
function whitelistMiddleware(whitelistMode, listen) {
|
||||||
return function (req, res, next) {
|
return function (req, res, next) {
|
||||||
const clientIp = getIpFromRequest(req);
|
const clientIp = getIpFromRequest(req);
|
||||||
|
const forwardedIp = getForwardedIp(req);
|
||||||
|
|
||||||
if (listen && !knownIPs.has(clientIp)) {
|
if (listen && !knownIPs.has(clientIp)) {
|
||||||
const userAgent = req.headers['user-agent'];
|
const userAgent = req.headers['user-agent'];
|
||||||
@ -44,9 +66,13 @@ function whitelistMiddleware(whitelistMode, listen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//clientIp = req.connection.remoteAddress.split(':').pop();
|
//clientIp = req.connection.remoteAddress.split(':').pop();
|
||||||
if (whitelistMode === true && !whitelist.some(x => ipMatching.matches(clientIp, ipMatching.getMatch(x)))) {
|
if (whitelistMode === true && !whitelist.some(x => ipMatching.matches(clientIp, ipMatching.getMatch(x)))
|
||||||
console.log(color.red('Forbidden: Connection attempt from ' + clientIp + '. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.yaml in root of SillyTavern folder.\n'));
|
|| forwardedIp && whitelistMode === true && !whitelist.some(x => ipMatching.matches(forwardedIp, ipMatching.getMatch(x)))
|
||||||
return res.status(403).send('<b>Forbidden</b>: Connection attempt from <b>' + clientIp + '</b>. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.yaml in root of SillyTavern folder.');
|
) {
|
||||||
|
// Log the connection attempt with real IP address
|
||||||
|
const ipDetails = forwardedIp ? `${clientIp} (forwarded from ${forwardedIp})` : clientIp;
|
||||||
|
console.log(color.red('Forbidden: Connection attempt from ' + ipDetails + '. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.yaml in root of SillyTavern folder.\n'));
|
||||||
|
return res.status(403).send('<b>Forbidden</b>: Connection attempt from <b>' + ipDetails + '</b>. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.yaml in root of SillyTavern folder.');
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user