module updates and fixes
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
const dns = require('dns');
|
||||
|
||||
class WTVFTP {
|
||||
wtvshared = null;
|
||||
wtvmime = null;
|
||||
@@ -9,15 +7,14 @@ class WTVFTP {
|
||||
ftp = null;
|
||||
url = null;
|
||||
|
||||
constructor(minisrv_config, service_name, sendToClient) {
|
||||
constructor(minisrv_config, service_name, wtvshared, sendToClient, wtvmime) {
|
||||
this.minisrv_config = minisrv_config;
|
||||
this.sendToClient = sendToClient;
|
||||
const WTVShared = require("./WTVShared.js")['WTVShared'];
|
||||
const WTVMime = require("./WTVMime.js");
|
||||
this.wtvshared = wtvshared;
|
||||
this.wtvmime = wtvmime;
|
||||
this.url = require('url');
|
||||
this.ftp = require('ftp');
|
||||
this.wtvshared = new WTVShared(minisrv_config);
|
||||
this.wtvmime = new WTVMime(minisrv_config);
|
||||
this.dns = require('dns');
|
||||
}
|
||||
|
||||
handleFTPRequest(socket, request_headers) {
|
||||
@@ -118,7 +115,7 @@ class WTVFTP {
|
||||
});
|
||||
|
||||
// FIX: Resolve host to IPv4 address before connecting
|
||||
dns.lookup(host, { family: 4 }, (err, address) => {
|
||||
this.dns.lookup(host, { family: 4 }, (err, address) => {
|
||||
if (err) {
|
||||
this.sendToClient(socket, { 'Status': '500 DNS resolution error', 'Content-Type': 'text/plain' }, 'DNS resolution error');
|
||||
return;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
const WTVMime = require('./WTVMime.js');
|
||||
const net = require('net');
|
||||
|
||||
class WTVGopher {
|
||||
// Adapted from WebTV Redialed's Gopher support
|
||||
constructor(...[minisrv_config, service_name]) {
|
||||
constructor(...[minisrv_config, service_name, wtvshared, sendToClient, wtvmime]) {
|
||||
this.minisrv_config = minisrv_config;
|
||||
this.wtvmime = new WTVMime(minisrv_config);
|
||||
this.wtvshared = wtvshared;
|
||||
this.wtvmime = wtvmime;
|
||||
this.sendToClient = sendToClient;
|
||||
this.logGopher = minisrv_config.services[service_name].log_raw_gopher || false;
|
||||
}
|
||||
|
||||
@@ -131,12 +132,12 @@ class WTVGopher {
|
||||
return html;
|
||||
}
|
||||
|
||||
async handleGopherRequest(socket, request_headers, wtvshared, sendToClient) {
|
||||
async handleGopherRequest(socket, request_headers) {
|
||||
if (this.minisrv_config.config.debug_flags.show_headers) {
|
||||
console.log("Gopher: Client Request on socket ID",
|
||||
socket.id,
|
||||
await wtvshared.decodePostData(
|
||||
wtvshared.filterRequestLog(wtvshared.filterSSID(request_headers))
|
||||
await this.wtvshared.decodePostData(
|
||||
this.wtvshared.filterRequestLog(this.wtvshared.filterSSID(request_headers))
|
||||
));
|
||||
}
|
||||
|
||||
@@ -225,7 +226,7 @@ class WTVGopher {
|
||||
"Content-Type": mimetype
|
||||
}
|
||||
|
||||
sendToClient(socket, headers, imageData);
|
||||
this.sendToClient(socket, headers, imageData);
|
||||
return;
|
||||
} else {
|
||||
// convert gophermap to html
|
||||
@@ -235,7 +236,7 @@ class WTVGopher {
|
||||
"Status": "200 OK",
|
||||
"Content-Type": "text/html"
|
||||
}
|
||||
sendToClient(socket, headers, htmlData);
|
||||
this.sendToClient(socket, headers, htmlData);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -251,7 +252,7 @@ class WTVGopher {
|
||||
} else if (friendlyErr.includes('ENOTFOUND')) {
|
||||
friendlyErr = "Host not found";
|
||||
}
|
||||
sendToClient(socket, {"Status": "400 Gopher Error: " + friendlyErr}, friendlyErr);
|
||||
this.sendToClient(socket, {"Status": "400 Gopher Error: " + friendlyErr}, friendlyErr);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
const {WTVShared, clientShowAlert} = require('./WTVShared.js');
|
||||
|
||||
class WTVHTTP {
|
||||
constructor(...[minisrv_config, service_name, http, sendToClient]) {
|
||||
constructor(...[minisrv_config, service_name, wtvshared, sendToClient, http]) {
|
||||
this.minisrv_config = minisrv_config;
|
||||
this.service_name = service_name;
|
||||
this.wtvshared = new WTVShared(minisrv_config);
|
||||
this.wtvshared = wtvshared;
|
||||
this.sendToClient = sendToClient;
|
||||
this.http = http;
|
||||
this.https = require('follow-redirects').https
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
// If the hash matches, the client is authenticated and the server starts sending UDP packets.
|
||||
|
||||
const net = require('net');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const dgram = require('dgram');
|
||||
const { WTVShared } = require('./WTVShared.js');
|
||||
|
||||
class WTVPNM {
|
||||
minisrv_config = null;
|
||||
@@ -30,11 +27,11 @@ class WTVPNM {
|
||||
wtvshared = null;
|
||||
sessions = new Map();
|
||||
|
||||
constructor(...[minisrv_config, service_name]) {
|
||||
constructor(...[minisrv_config, service_name, wtvshared, sendToClient]) {
|
||||
this.minisrv_config = minisrv_config;
|
||||
this.service_name = service_name;
|
||||
this.service_config = minisrv_config.services[service_name] || {};
|
||||
this.wtvshared = new WTVShared(minisrv_config, true);
|
||||
this.wtvshared = wtvshared;
|
||||
this.server = net.createServer((socket) => this.handleConnection(socket));
|
||||
|
||||
// Descriptor server-id mapping uses full 16-bit source UDP port:
|
||||
@@ -676,7 +673,7 @@ class WTVPNM {
|
||||
for (const variant of extensionVariants) {
|
||||
const candidate = this.wtvshared.makeSafePath(base, variant);
|
||||
this.debugLog('testing media candidate', candidate);
|
||||
if (candidate && fs.existsSync(candidate) && fs.lstatSync(candidate).isFile()) {
|
||||
if (candidate && this.wtvshared.fs.existsSync(candidate) && this.wtvshared.fs.lstatSync(candidate).isFile()) {
|
||||
if (this.service_config.debug) {
|
||||
this.debugLog('media file found', variant, '->', candidate);
|
||||
}
|
||||
@@ -694,7 +691,7 @@ class WTVPNM {
|
||||
const requestedPath = this.normalizeRequestedMediaPath(requestedMedia);
|
||||
if (!requestedPath) return [];
|
||||
|
||||
const ext = path.posix.extname(requestedPath).toLowerCase();
|
||||
const ext = this.wtvshared.path.posix.extname(requestedPath).toLowerCase();
|
||||
const stem = ext.length > 0 ? requestedPath.slice(0, -ext.length) : requestedPath;
|
||||
const variants = [requestedPath];
|
||||
|
||||
@@ -1172,13 +1169,13 @@ class WTVPNM {
|
||||
prepareMediaData(session) {
|
||||
if (!session || session.mediaFrames) return;
|
||||
|
||||
if (!session.mediaPath || !fs.existsSync(session.mediaPath)) {
|
||||
if (!session.mediaPath || !this.wtvshared.fs.existsSync(session.mediaPath)) {
|
||||
this.debugLog('prepareMediaData: media path missing or not found', session.id, session.mediaPath);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const media = fs.readFileSync(session.mediaPath);
|
||||
const media = this.wtvshared.fs.readFileSync(session.mediaPath);
|
||||
this.debugLog('prepareMediaData: loaded media file', session.id, `size=${media.length} bytes`);
|
||||
|
||||
const classicRa = this.parseClassicRaHeader(media);
|
||||
@@ -1830,7 +1827,7 @@ class WTVPNM {
|
||||
let raBuffer = null;
|
||||
if (session && session.mediaPath) {
|
||||
try {
|
||||
raBuffer = fs.readFileSync(session.mediaPath);
|
||||
raBuffer = this.wtvshared.fs.readFileSync(session.mediaPath);
|
||||
} catch(e) {
|
||||
this.debugLog('buildDescriptor error reading media', session.mediaPath, e.message);
|
||||
}
|
||||
@@ -2400,8 +2397,8 @@ class WTVPNM {
|
||||
const challengeBuf = Buffer.from(challenge, 'latin1');
|
||||
const requestedMedia = session?.requestedMedia || '';
|
||||
const requestedMediaPath = this.normalizeRequestedMediaPath(requestedMedia);
|
||||
const resolvedBase = session?.mediaPath ? path.basename(session.mediaPath) : '';
|
||||
const requestedDir = requestedMediaPath ? path.posix.dirname(requestedMediaPath) : '';
|
||||
const resolvedBase = session?.mediaPath ? this.wtvshared.path.basename(session.mediaPath) : '';
|
||||
const requestedDir = requestedMediaPath ? this.wtvshared.path.posix.dirname(requestedMediaPath) : '';
|
||||
const resolvedMedia = resolvedBase
|
||||
? (requestedDir && requestedDir !== '.' ? `${requestedDir}/${resolvedBase}` : resolvedBase)
|
||||
: requestedMediaPath;
|
||||
|
||||
Reference in New Issue
Block a user