fix/optimize the rest

This commit is contained in:
zefie
2025-08-12 20:53:04 -04:00
parent 6827746799
commit 20efece22b
6 changed files with 52 additions and 52 deletions

View File

@@ -73,7 +73,7 @@ const fileList = recursiveDirList(service_vault_dir);
if (fileList.length > 0) {
const diskmap = {};
diskmap[group_name] = {};
if (client_dest.substring(client_dest.length - 1, 1) != '/') client_dest += '/';
if (client_dest.slice(client_dest.length - 1, 1) != '/') client_dest += '/';
diskmap[group_name].base = client_dest;
diskmap[group_name].location = service_vault_subdir;
diskmap[group_name].files = [];

View File

@@ -1,12 +1,12 @@
'use strict';
const path = require('path');
var classPath = path.resolve(__dirname + path.sep + "includes" + path.sep + "classes" + path.sep) + path.sep;
const classPath = path.resolve(__dirname + path.sep + "includes" + path.sep + "classes" + path.sep) + path.sep;
require(classPath + "Prototypes.js");
const WTVIRC = require(classPath + "WTVIRC.js");
const { WTVShared, clientShowAlert } = require(classPath + "WTVShared.js");
const wtvshared = new WTVShared(); // creates minisrv_config
var minisrv_config = wtvshared.readMiniSrvConfig(true, false, true);
const minisrv_config = wtvshared.readMiniSrvConfig(true, false, true);
minisrv_config.version = require('./package.json').version;
const ircServer = new WTVIRC(minisrv_config, '0.0.0.0', minisrv_config.config.irc.port, true);
ircServer.start();

View File

@@ -1,8 +1,8 @@
'use strict';
const path = require('path');
var classPath = path.resolve(__dirname + path.sep + "includes" + path.sep + "classes" + path.sep) + path.sep; require(classPath + "Prototypes.js");
const classPath = path.resolve(__dirname + path.sep + "includes" + path.sep + "classes" + path.sep) + path.sep; require(classPath + "Prototypes.js");
const { WTVShared } = require(classPath + "/WTVShared.js");
var wtvshared = new WTVShared(null, true);
const wtvshared = new WTVShared(null, true);
const fs = require('fs');
function showUsage() {
@@ -12,8 +12,8 @@ function showUsage() {
if (process.argv) {
if (process.argv[2]) {
var reverse = false;
var file = process.argv[2];
let reverse = false;
let file = process.argv[2];
if (file == "-d") {
file = process.argv[3];
reverse = true;
@@ -21,9 +21,9 @@ if (process.argv) {
if (fs.existsSync(file)) {
console.log(` * Processing ${file} ...`)
if (reverse) {
var outfile = file.replace(/\.cb64\.txt/,'') + ".dec.txt";
var encodedData = fs.readFileSync(file);
var rawdata = wtvshared.unpackCompressedB64(encodedData);
const outfile = file.replace(/\.cb64\.txt/,'') + ".dec.txt";
const encodedData = fs.readFileSync(file);
const rawdata = wtvshared.unpackCompressedB64(encodedData);
try {
fs.writeFileSync(outfile, rawdata);
console.log(` * Successfully decoded into ${outfile}`)
@@ -32,9 +32,9 @@ if (process.argv) {
process.exit(1);
}
} else {
var outfile = file + ".cb64.txt";
var rawdata = fs.readFileSync(file);
var encodedData = wtvshared.packCompressedB64(rawdata);
const outfile = file + ".cb64.txt";
const rawdata = fs.readFileSync(file);
const encodedData = wtvshared.packCompressedB64(rawdata);
try {
fs.writeFileSync(outfile, encodedData);
console.log(` * Successfully encoded into ${outfile}`)

View File

@@ -8,14 +8,14 @@ const groups_to_sync = [
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
var classPath = __dirname + "/includes/";
let classPath = __dirname + "/includes/";
const { WTVShared } = require(classPath + "WTVShared.js");
const wtvshared = new WTVShared(); // creates minisrv_config
classPath = wtvshared.getAbsolutePath(classPath, __dirname);
const minisrv_config = wtvshared.getMiniSrvConfig();
const WTVNews = require(classPath + "/WTVNews.js");
const WTVNewsServer = require(classPath + "/WTVNewsServer.js");
var data_path = wtvshared.getAbsolutePath(minisrv_config.config.SessionStore + '/minisrv_internal_nntp');
const data_path = wtvshared.getAbsolutePath(minisrv_config.config.SessionStore + '/minisrv_internal_nntp');
const service_name = "wtv-news";
if (!minisrv_config.services[service_name].upstream_address) {
@@ -39,28 +39,28 @@ const wtvnews = new WTVNews(minisrv_config, service_name);
if (service_config.upstream_auth) {
wtvnews.initializeUsenet(service_config.upstream_address, service_config.upstream_port, service_config.upstream_tls || null, service_config.upstream_auth.username || null, service_config.upstream_auth.password || null);
} else {
wtvnews.initializeUsenet(service_config.upstream_address, service_configupstream_port, service_config.upstream_tls || null);
wtvnews.initializeUsenet(service_config.upstream_address, service_config.upstream_port, service_config.upstream_tls || null);
}
function verifyMessage(group, articleNumber, article) {
var g = wtvnewsserver.getGroupPath(group);
var file = g + path.sep + articleNumber + ".newz";
const g = wtvnewsserver.getGroupPath(group);
const file = g + path.sep + articleNumber + ".newz";
if (!fs.existsSync(file)) return false;
var old_data = fs.readFileSync(file);
var new_data = JSON.stringify(article.article);
const old_data = fs.readFileSync(file);
const new_data = JSON.stringify(article.article);
var old_data_hash = crypto.createHash('md5').update(old_data).digest("hex");
var new_data_hash = crypto.createHash('md5').update(new_data).digest("hex");
const old_data_hash = crypto.createHash('md5').update(old_data).digest("hex");
const new_data_hash = crypto.createHash('md5').update(new_data).digest("hex");
return (old_data_hash === new_data_hash);
}
function deleteMissing(group, articles) {
var g = wtvnewsserver.getGroupPath(group);
const g = wtvnewsserver.getGroupPath(group);
try {
fs.readdirSync(g).forEach(file => {
var articleNumber = parseInt(file.split('.')[0]);
const articleNumber = parseInt(file.split('.')[0]);
file = g + path.sep + file;
if (!articles.find(e => (e == articleNumber))) {
console.log(" * ", group, "article", articleNumber, "deleted from upstream, removing locally")
@@ -79,15 +79,15 @@ wtvnews.connectUsenet().then((res) => {
groups_to_sync.forEach((group) => {
console.log(group);
wtvnews.selectGroup(group).then((res) => {
var range = {
const range = {
start: res.group.low,
end: res.group.high
}
wtvnews.listGroup(group, null, null, range).then((res) => {
if (res.group.articleNumbers) {
var promises = [];
const promises = [];
wtvnewsserver.createGroup(group);
var meta = wtvnewsserver.getMetadata(group);
const meta = wtvnewsserver.getMetadata(group);
meta.last_article_id = res.group.high;
wtvnewsserver.saveMetadata(group, meta);
//deleteMissing(group, res.group.articleNumbers)

View File

@@ -4,7 +4,7 @@ const fs = require('fs');
const readdir = promisify(fs.readdir);
const stat = promisify(fs.stat);
const { exec } = require("child_process");
var path = require('path');
const path = require('path');
// Usage: node test.js [filename|directory]
// If no argument is provided, checks all JavaScript files in the project
@@ -130,7 +130,7 @@ function checkScopeErrors(file) {
// Look for patterns like includes/ServiceVault/wtv-servicename or includes/ServiceDeps/.../wtv-servicename
const serviceMatch = normalizedFile.match(/includes\/Service(?:Vault|Deps)(?:\/[^\/]*)*?\/(wtv-[a-z0-9-]+|[a-z0-9-]+)(?:\/|$)/);
if (serviceMatch) {
let serviceName = serviceMatch[1];
const serviceName = serviceMatch[1];
// Try both with and without wtv- prefix
const serviceNameWithPrefix = serviceName.startsWith('wtv-') ? serviceName : `wtv-${serviceName}`;

View File

@@ -599,7 +599,7 @@ class WebTVPcapAnalyzer {
const headers = headerEndIndex >= 0 ? lines.slice(0, headerEndIndex) : lines;
// Process headers for handshake info
let wtvInfo = this.extractWebTVInfo(messageStr, connection);
const wtvInfo = this.extractWebTVInfo(messageStr, connection);
if (wtvInfo) {
this.processWebTVHandshakeInfo(wtvInfo, connection, messageStr);
}
@@ -763,7 +763,7 @@ class WebTVPcapAnalyzer {
this.output.push('FLOW ANALYSIS SUMMARY');
this.output.push('='.repeat(80));
let totalFlows = flows.size;
const totalFlows = flows.size;
let encryptedFlows = 0;
let challengesSeen = 0;
let secureOnSeen = 0;
@@ -789,7 +789,7 @@ class WebTVPcapAnalyzer {
this.output.push('ANALYSIS SUMMARY');
this.output.push('='.repeat(80));
let totalConnections = connectionGroups.size;
const totalConnections = connectionGroups.size;
let encryptedConnections = 0;
let challengesSeen = 0;
let secureOnSeen = 0;
@@ -1344,7 +1344,7 @@ class WebTVPcapAnalyzer {
const incarnationIndex = headerText.indexOf('wtv-incarnation');
const contextStart = Math.max(0, incarnationIndex - 20);
const contextEnd = Math.min(headerText.length, incarnationIndex + 50);
const context = headerText.substring(contextStart, contextEnd);
const context = headerText.slice(contextStart, contextEnd);
this.debugLog(`Context around incarnation: "${context}"`);
this.debugLog(`Context bytes: ${Buffer.from(context, 'utf8').toString('hex')}`);
}
@@ -1360,8 +1360,8 @@ class WebTVPcapAnalyzer {
} else {
const colonIndex = line.indexOf(':');
if (colonIndex > 0) {
const key = line.substring(0, colonIndex).toLowerCase();
const value = line.substring(colonIndex + 1).trim();
const key = line.slice(0, colonIndex).toLowerCase();
const value = line.slice(colonIndex + 1).trim();
// Debug incarnation header parsing
if (key === 'wtv-incarnation') {
@@ -1393,13 +1393,13 @@ class WebTVPcapAnalyzer {
const bodyBuffer = Buffer.from(bodyText, 'binary');
const isProprietary = headers['wtv-initial-key'] &&
(bodyText.startsWith('ANDY') ||
bodyBuffer.slice(0, 4).toString() === 'ANDY' ||
bodyBuffer.slice(0, 4).equals(Buffer.from([0x41, 0x4e, 0x44, 0x59])));
bodyBuffer.subarray(0, 4).toString() === 'ANDY' ||
bodyBuffer.subarray(0, 4).equals(Buffer.from([0x41, 0x4e, 0x44, 0x59])));
if (isProprietary) {
this.output.push(` Body (${bodyText.length} bytes): [PROPRIETARY FORMAT - NOT ENCRYPTED]`);
// Show a preview of the proprietary data
const previewText = bodyText.substring(0, 100).replace(/[\x00-\x1f\x7f-\xff]/g, '�');
const previewText = bodyText.slice(0, 100).replace(/[\x00-\x1f\x7f-\xff]/g, '�');
this.output.push(` ${previewText}${bodyText.length > 100 ? '...' : ''}`);
} else if (headers['wtv-encrypted'] === 'true' && connection.wtvsec) {
// Handle encrypted body - decrypt first, then decompress
@@ -1428,11 +1428,11 @@ class WebTVPcapAnalyzer {
}
statusLabel += ']:';
this.output.push(` ${statusLabel}`);
this.output.push(` ${finalText.length <= 500 ? finalText : finalText.substring(0, 500) + '...'}`);
this.output.push(` ${finalText.length <= 500 ? finalText : finalText.slice(0, 500) + '...'}`);
} catch (error) {
this.debugLog(`Body decryption failed: ${error.message}`);
this.output.push(` [ENCRYPTED - decryption failed: ${error.message}]`);
this.output.push(` ${bodyText.substring(0, 500)}${bodyText.length > 500 ? '...' : ''}`);
this.output.push(` ${bodyText.slice(0, 500)}${bodyText.length > 500 ? '...' : ''}`);
}
} else {
// Regular unencrypted body - try decompression
@@ -1456,7 +1456,7 @@ class WebTVPcapAnalyzer {
if (finalText.length <= 500) {
this.output.push(` ${finalText}`);
} else {
this.output.push(` ${finalText.substring(0, 500)}...`);
this.output.push(` ${finalText.slice(0, 500)}...`);
}
}
}
@@ -1509,8 +1509,8 @@ class WebTVPcapAnalyzer {
} else {
const colonIndex = line.indexOf(':');
if (colonIndex > 0) {
const key = line.substring(0, colonIndex).toLowerCase();
const value = line.substring(colonIndex + 1).trim();
const key = line.slice(0, colonIndex).toLowerCase();
const value = line.slice(colonIndex + 1).trim();
headers[key] = value;
this.output.push(` ${key}: ${value}`);
}
@@ -1553,7 +1553,7 @@ class WebTVPcapAnalyzer {
}
statusLabel += ']:';
this.output.push(` ${statusLabel}`);
this.output.push(` ${finalText.length <= 500 ? finalText : finalText.substring(0, 500) + '...'}`);
this.output.push(` ${finalText.length <= 500 ? finalText : finalText.slice(0, 500) + '...'}`);
} catch (error) {
this.debugLog(`Body decryption failed: ${error.message}`);
this.output.push(` [ENCRYPTED - decryption failed: ${error.message}]`);
@@ -1572,7 +1572,7 @@ class WebTVPcapAnalyzer {
}
}
this.output.push(` ${statusLabel}:`);
this.output.push(` ${finalText.length <= 500 ? finalText : finalText.substring(0, 500) + '...'}`);
this.output.push(` ${finalText.length <= 500 ? finalText : finalText.slice(0, 500) + '...'}`);
}
}
}
@@ -1639,8 +1639,8 @@ class WebTVPcapAnalyzer {
} else {
const colonIndex = line.indexOf(':');
if (colonIndex > 0) {
const key = line.substring(0, colonIndex).toLowerCase();
const value = line.substring(colonIndex + 1).trim();
const key = line.slice(0, colonIndex).toLowerCase();
const value = line.slice(colonIndex + 1).trim();
headers[key] = value;
this.output.push(` ${key}: ${value}`);
}
@@ -1653,7 +1653,7 @@ class WebTVPcapAnalyzer {
// Look for body content
const bodyStart = text.indexOf('\r\n\r\n');
if (bodyStart >= 0) {
const bodyText = text.substring(bodyStart + 4);
const bodyText = text.slice(bodyStart + 4);
if (bodyText.length > 0) {
// Check if this is a proprietary format that should not be decrypted
const bodyBuffer = Buffer.from(bodyText, 'binary');
@@ -1665,7 +1665,7 @@ class WebTVPcapAnalyzer {
if (isProprietary) {
this.output.push(` Body (${bodyText.length} bytes): [PROPRIETARY FORMAT - NOT ENCRYPTED]`);
// Show a preview of the proprietary data
const previewText = bodyText.substring(0, 100).replace(/[\x00-\x1f\x7f-\xff]/g, '�');
const previewText = bodyText.slice(0, 100).replace(/[\x00-\x1f\x7f-\xff]/g, '�');
this.output.push(` ${previewText}${bodyText.length > 1000 ? '...' : ''}`);
} else if (headers['wtv-encrypted'] === 'true' && connection.wtvsec) {
// Avoid this text-path for decryption to prevent byte corruption; handled in processWebTVMessageBuffer.
@@ -1692,7 +1692,7 @@ class WebTVPcapAnalyzer {
if (finalText.length <= 500) {
this.output.push(` ${finalText}`);
} else {
this.output.push(` ${finalText.substring(0, 1000)}...`);
this.output.push(` ${finalText.slice(0, 1000)}...`);
}
}
}
@@ -2215,7 +2215,7 @@ class WebTVPcapAnalyzer {
this.output.push(` Decrypted with ${keyName} (${decryptedBuffer.length} bytes):`);
if (this.isPrintableText(decryptedText) || this.looksLikeWebTVHeaders(decryptedText)) {
this.output.push(` [*] Decrypted text content:`);
this.output.push(` ${decryptedText.length <= 1000 ? decryptedText : decryptedText.substring(0, 1000) + '...'}`);
this.output.push(` ${decryptedText.length <= 1000 ? decryptedText : decryptedText.slice(0, 1000) + '...'}`);
} else {
this.output.push(` [*] Decrypted binary data:`);
this.output.push(` ${decryptedBuffer.slice(0, 100).toString('hex')}${decryptedBuffer.length > 1000 ? '...' : ''}`);
@@ -2287,7 +2287,7 @@ class WebTVPcapAnalyzer {
if (this.isPrintableText(decryptedText) || this.looksLikeWebTVHeaders(decryptedText)) {
this.output.push(` [*] Decrypted body (text):`);
this.output.push(` ${decryptedText.length <= 500 ? decryptedText : decryptedText.substring(0, 1000) + '...'}`);
this.output.push(` ${decryptedText.length <= 500 ? decryptedText : decryptedText.slice(0, 1000) + '...'}`);
} else {
this.output.push(` [*] Decrypted binary body:`);
this.output.push(` ${decryptedBuffer.slice(0, 100).toString('hex')}${decryptedBuffer.length > 100 ? '...' : ''}`);