fixes
This commit is contained in:
@@ -1096,7 +1096,8 @@ minisrv-no-mail-count: true`;
|
|||||||
} else if (shortURL.indexOf('http://') >= 0 || shortURL.indexOf('https://') >= 0 || (use_external_proxy == true && shortURL.indexOf(service_name + "://") >= 0) && !pc_services) {
|
} else if (shortURL.indexOf('http://') >= 0 || shortURL.indexOf('https://') >= 0 || (use_external_proxy == true && shortURL.indexOf(service_name + "://") >= 0) && !pc_services) {
|
||||||
doHTTPProxy(socket, request_headers);
|
doHTTPProxy(socket, request_headers);
|
||||||
} else if (shortURL.startsWith('ftp://')) {
|
} else if (shortURL.startsWith('ftp://')) {
|
||||||
var wtvftp = new WTVFTP(minisrv_config, sendToClient);
|
if (minisrv_config.config.debug_flags.show_headers) console.debug(" * Incoming FTP request on WTVP socket ID", socket.id, await wtvshared.decodePostData(await wtvshared.filterRequestLog(await wtvshared.filterSSID(request_headers))));
|
||||||
|
var wtvftp = new WTVFTP(wtvshared, sendToClient);
|
||||||
wtvftp.handleFTPRequest(socket, request_headers);
|
wtvftp.handleFTPRequest(socket, request_headers);
|
||||||
} else if (shortURL.indexOf('file://') >= 0) {
|
} else if (shortURL.indexOf('file://') >= 0) {
|
||||||
shortURL = shortURL.replace("file://",'').replace("romcache", "ROMCache");
|
shortURL = shortURL.replace("file://",'').replace("romcache", "ROMCache");
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const dns = require('dns');
|
||||||
|
|
||||||
class WTVFTP {
|
class WTVFTP {
|
||||||
wtvshared = null;
|
wtvshared = null;
|
||||||
wtvmime = null;
|
wtvmime = null;
|
||||||
@@ -14,18 +16,15 @@ class WTVFTP {
|
|||||||
const WTVMime = require("./WTVMime.js");
|
const WTVMime = require("./WTVMime.js");
|
||||||
this.url = require('url');
|
this.url = require('url');
|
||||||
this.ftp = require('ftp');
|
this.ftp = require('ftp');
|
||||||
this.wtvshared = new WTVShared();
|
this.wtvshared = new WTVShared(minisrv_config);
|
||||||
this.wtvmime = new WTVMime();
|
this.wtvmime = new WTVMime(minisrv_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFTPRequest(socket, request_headers) {
|
handleFTPRequest(socket, request_headers) {
|
||||||
// Handle the FTP request here
|
|
||||||
// Assume request_headers.url contains the FTP URL
|
|
||||||
this.request_headers = request_headers;
|
this.request_headers = request_headers;
|
||||||
const ftpUrl = request_headers.request_url;
|
const ftpUrl = request_headers.request_url;
|
||||||
const parsed = this.url.parse(ftpUrl);
|
const parsed = this.url.parse(ftpUrl);
|
||||||
|
|
||||||
// Extract user, pass, and host
|
|
||||||
let user = null;
|
let user = null;
|
||||||
let pass = null;
|
let pass = null;
|
||||||
let host = parsed.hostname;
|
let host = parsed.hostname;
|
||||||
@@ -36,10 +35,6 @@ class WTVFTP {
|
|||||||
pass = password || null;
|
pass = password || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example usage: log the parsed values
|
|
||||||
|
|
||||||
|
|
||||||
// You can now use user, pass, and host as needed
|
|
||||||
if (!user && !pass) {
|
if (!user && !pass) {
|
||||||
user = "anonymous";
|
user = "anonymous";
|
||||||
pass = "anonymous@eff.org";
|
pass = "anonymous@eff.org";
|
||||||
@@ -51,7 +46,6 @@ class WTVFTP {
|
|||||||
let dir = path;
|
let dir = path;
|
||||||
let filename = null;
|
let filename = null;
|
||||||
|
|
||||||
// Determine if path is a file or directory
|
|
||||||
if (path && path !== '/') {
|
if (path && path !== '/') {
|
||||||
const parts = path.split('/');
|
const parts = path.split('/');
|
||||||
if (parts[parts.length - 1] && !path.endsWith('/')) {
|
if (parts[parts.length - 1] && !path.endsWith('/')) {
|
||||||
@@ -63,7 +57,6 @@ class WTVFTP {
|
|||||||
ftpClient.on('ready', () => {
|
ftpClient.on('ready', () => {
|
||||||
if (filename) {
|
if (filename) {
|
||||||
var totalsize = 0;
|
var totalsize = 0;
|
||||||
// Change to directory and get file
|
|
||||||
ftpClient.cwd(dir, (err) => {
|
ftpClient.cwd(dir, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.sendToClient(socket, { 'Status': '500 Failed to change directory', 'Content-Type': 'text/plain' }, 'Failed to change directory');
|
this.sendToClient(socket, { 'Status': '500 Failed to change directory', 'Content-Type': 'text/plain' }, 'Failed to change directory');
|
||||||
@@ -107,7 +100,6 @@ class WTVFTP {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// List directory
|
|
||||||
ftpClient.list(dir, (err, list) => {
|
ftpClient.list(dir, (err, list) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.sendToClient(socket, { 'Status': '500 Failed to list directory', 'Content-Type': 'text/plain' }, 'Failed to list directory');
|
this.sendToClient(socket, { 'Status': '500 Failed to list directory', 'Content-Type': 'text/plain' }, 'Failed to list directory');
|
||||||
@@ -125,16 +117,23 @@ class WTVFTP {
|
|||||||
this.sendToClient(socket, { 'Status': '500 FTP connection error', 'Content-Type': 'text/plain' }, 'FTP connection error');
|
this.sendToClient(socket, { 'Status': '500 FTP connection error', 'Content-Type': 'text/plain' }, 'FTP connection error');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// FIX: Resolve host to IPv4 address before connecting
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
ftpClient.connect({
|
ftpClient.connect({
|
||||||
host: host,
|
host: address,
|
||||||
port: port,
|
port: port,
|
||||||
user: user,
|
user: user,
|
||||||
password: pass
|
password: pass
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
formatDirectoryListing(list) {
|
formatDirectoryListing(list) {
|
||||||
// Format the directory listing as needed
|
|
||||||
let html = `<html>
|
let html = `<html>
|
||||||
<head>
|
<head>
|
||||||
<title>FTP Directory Listing</title>
|
<title>FTP Directory Listing</title>
|
||||||
|
|||||||
Reference in New Issue
Block a user