1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-26 22:13:53 +01:00

community tunnel, minor bugfixes

This commit is contained in:
Marek Farkaš
2025-11-30 22:49:00 +01:00
parent 7f6957e162
commit 531a0f23e6
10 changed files with 108 additions and 24 deletions

View File

@@ -240,6 +240,23 @@ function checkIPv6Support(callback) {
});
}
function checkLatency(host) {
return new Promise(resolve => {
const start = Date.now();
const req = http.get({ host, timeout: 2000 }, res => {
res.resume(); // discard body
resolve(Date.now() - start);
});
req.on("error", () => resolve(null)); // server offline
req.on("timeout", () => {
req.destroy();
resolve(null);
});
});
}
function antispamProtection(message, clientIp, ws, userCommands, lastWarn, userCommandHistory, lengthCommands, endpointName) {
const command = message.toString();
const now = Date.now();
@@ -313,5 +330,5 @@ const escapeHtml = (unsafe) => {
module.exports = {
authenticateWithXdrd, parseMarkdown, handleConnect, removeMarkdown, formatUptime, resolveDataBuffer, kickClient, checkIPv6Support, antispamProtection, escapeHtml
authenticateWithXdrd, parseMarkdown, handleConnect, removeMarkdown, formatUptime, resolveDataBuffer, kickClient, checkIPv6Support, checkLatency, antispamProtection, escapeHtml
}