workaround for object cloning
This commit is contained in:
@@ -135,7 +135,27 @@ Content-Type: audio/wav`;
|
|||||||
headers = doClientError("Please type a message to send to the group.");
|
headers = doClientError("Please type a message to send to the group.");
|
||||||
sendToClient(socket, headers, '');
|
sendToClient(socket, headers, '');
|
||||||
} else {
|
} else {
|
||||||
const wtvnews = new WTVNews(minisrv_config, request_headers.query['discuss-prefix'] || "wtv-news");
|
var local_service_name = request_headers.query['discuss-prefix'] || "wtv-news"
|
||||||
|
const wtvnews = new WTVNews(minisrv_config, local_service_name);
|
||||||
|
var service_config = minisrv_config.services[local_service_name];
|
||||||
|
if (wtvnewsserver) {
|
||||||
|
var tls_path = this.wtvshared.getAbsolutePath(this.minisrv_config.config.ServiceDeps + '/wtv-news');
|
||||||
|
var tls_options = {
|
||||||
|
ca: this.fs.readFileSync(tls_path + '/localserver_ca.pem'),
|
||||||
|
key: this.fs.readFileSync(tls_path + '/localserver_key.pem'),
|
||||||
|
cert: this.fs.readFileSync(tls_path + '/localserver_cert.pem'),
|
||||||
|
checkServerIdentity: () => { return null; }
|
||||||
|
}
|
||||||
|
if (wtvnewsserver.username)
|
||||||
|
wtvnews.initializeUsenet("127.0.0.1", service_config.local_nntp_port, tls_options, wtvnewsserver.username, wtvnewsserver.password);
|
||||||
|
else
|
||||||
|
wtvnews.initializeUsenet("127.0.0.1", service_config.local_nntp_port, tls_options);
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
}
|
||||||
from_addr = userdisplayname + " <" + from_addr + ">";
|
from_addr = userdisplayname + " <" + from_addr + ">";
|
||||||
wtvnews.postToGroup(newsgroup, from_addr, msg_subject, msg_body, article).then(() => {
|
wtvnews.postToGroup(newsgroup, from_addr, msg_subject, msg_body, article).then(() => {
|
||||||
session_data.deleteSessionData("usenet_draft");
|
session_data.deleteSessionData("usenet_draft");
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ if (service_config.local_nntp_port && wtvnewsserver) {
|
|||||||
checkServerIdentity: () => { return null; }
|
checkServerIdentity: () => { return null; }
|
||||||
}
|
}
|
||||||
if (wtvnewsserver.username)
|
if (wtvnewsserver.username)
|
||||||
wtvnews.initializeUsenet("127.0.0.1", minisrv_config.services[service_name].local_nntp_port, tls_options, wtvnewsserver.username, wtvnewsserver.password);
|
wtvnews.initializeUsenet("127.0.0.1", service_config.local_nntp_port, tls_options, wtvnewsserver.username, wtvnewsserver.password);
|
||||||
else
|
else
|
||||||
wtvnews.initializeUsenet("127.0.0.1", minisrv_config.services[service_name].local_nntp_port, tls_options);
|
wtvnews.initializeUsenet("127.0.0.1", service_config.local_nntp_port, tls_options);
|
||||||
} else {
|
} else {
|
||||||
if (service_config.upstream_auth)
|
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);
|
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);
|
||||||
@@ -228,7 +228,6 @@ ${page_start}-${page_end}
|
|||||||
var has_relation = (messages[k].relation !== null) ? true : false;
|
var has_relation = (messages[k].relation !== null) ? true : false;
|
||||||
var date_obj = new Date(Date.parse(message.headers.DATE));
|
var date_obj = new Date(Date.parse(message.headers.DATE));
|
||||||
var date = (isToday(date_obj)) ? strftime("%I:%M %p", date_obj) : strftime("%b %d", date_obj)
|
var date = (isToday(date_obj)) ? strftime("%I:%M %p", date_obj) : strftime("%b %d", date_obj)
|
||||||
console.log(message);
|
|
||||||
data += `
|
data += `
|
||||||
<table cellspacing=0 cellpadding=0>
|
<table cellspacing=0 cellpadding=0>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class WTVNews {
|
|||||||
client = null;
|
client = null;
|
||||||
username = null;
|
username = null;
|
||||||
password = null;
|
password = null;
|
||||||
|
posting_allowed = true;
|
||||||
|
|
||||||
constructor(minisrv_config, service_name) {
|
constructor(minisrv_config, service_name) {
|
||||||
this.minisrv_config = minisrv_config;
|
this.minisrv_config = minisrv_config;
|
||||||
@@ -35,6 +36,7 @@ class WTVNews {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.client.connect().then((response) => {
|
this.client.connect().then((response) => {
|
||||||
if (response.code == 200 || response.code == 201) {
|
if (response.code == 200 || response.code == 201) {
|
||||||
|
if (response.code == 201) this.posting_allowed = false;
|
||||||
if (this.username && this.password) {
|
if (this.username && this.password) {
|
||||||
this.client.authInfoUser(this.username).then((res) => {
|
this.client.authInfoUser(this.username).then((res) => {
|
||||||
if (res.code == "381") {
|
if (res.code == "381") {
|
||||||
@@ -122,19 +124,24 @@ class WTVNews {
|
|||||||
promises.push(new Promise((resolve, reject) => {
|
promises.push(new Promise((resolve, reject) => {
|
||||||
this.client.last().then((res) => {
|
this.client.last().then((res) => {
|
||||||
data.prev_article = res.article.articleNumber;
|
data.prev_article = res.article.articleNumber;
|
||||||
// do it again
|
console.log(data.prev_article, articleID)
|
||||||
this.client.article(data.prev_article).then(() => {
|
if (data.prev_article === articleID) {
|
||||||
this.client.last().then((res) => {
|
// do it again, needed this for CodoSoft NNTPd?
|
||||||
data.prev_article = res.article.articleNumber;
|
this.client.article(data.prev_article).then(() => {
|
||||||
resolve(data.prev_article);
|
this.client.last().then((res) => {
|
||||||
|
data.prev_article = res.article.articleNumber;
|
||||||
|
resolve(data.prev_article);
|
||||||
|
}).catch(() => {
|
||||||
|
data.prev_article = null;
|
||||||
|
resolve(data.prev_article);
|
||||||
|
});
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
data.prev_article = null;
|
data.prev_article = null;
|
||||||
resolve(data.prev_article);
|
resolve(data.prev_article);
|
||||||
});
|
});
|
||||||
}).catch(() => {
|
} else {
|
||||||
data.prev_article = null;
|
|
||||||
resolve(data.prev_article);
|
resolve(data.prev_article);
|
||||||
});
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
data.prev_article = null;
|
data.prev_article = null;
|
||||||
resolve(data.prev_article);
|
resolve(data.prev_article);
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ class WTVNewsServer {
|
|||||||
const { WTVShared } = require("./WTVShared.js");
|
const { WTVShared } = require("./WTVShared.js");
|
||||||
this.wtvshared = new WTVShared(minisrv_config);
|
this.wtvshared = new WTVShared(minisrv_config);
|
||||||
const nntp_server = require('nntp-server');
|
const nntp_server = require('nntp-server');
|
||||||
const nntp_statuses = require('nntp-server/lib/status');
|
var nntp_statuses = require('nntp-server/lib/status');
|
||||||
|
|
||||||
this.username == username || null;
|
this.username == username || null;
|
||||||
this.password == password || null;
|
this.password == password || null;
|
||||||
this.using_auth = using_auth;
|
this.using_auth = using_auth;
|
||||||
@@ -30,42 +31,13 @@ class WTVNewsServer {
|
|||||||
|
|
||||||
var nntp_commands = {
|
var nntp_commands = {
|
||||||
...nntp_server.commands,
|
...nntp_server.commands,
|
||||||
"LAST": {
|
"POST": {
|
||||||
head: 'LAST',
|
head: 'POST',
|
||||||
validate: /^LAST$/i,
|
validate: /^POST$/i,
|
||||||
|
run: function (session, post_data) {
|
||||||
// All supported params are defined in separate files
|
if (!session.posting_allowed) return
|
||||||
run: function (session) {
|
console.log(post_data);
|
||||||
try {
|
throw new Error("not implemented");
|
||||||
if (!session.group.name) return nntp_statuses._412_GRP_NOT_SLCTD;
|
|
||||||
if (!session.group.current_article) return nntp_statuses._420_ARTICLE_NOT_SLCTD;
|
|
||||||
if (!self.articleExists(session.group.name, session.group.current_article)) return nntp_statuses._420_ARTICLE_NOT_SLCTD;
|
|
||||||
var res = self.getLastArticle(session.group.name, session.group.current_article);
|
|
||||||
if (!res) return nntp_statuses._422_NO_LAST_ARTICLE;
|
|
||||||
var last = `${nntp_statuses._223_ARTICLE_EXISTS} ${res.articleNumber} ${res.message_id}`
|
|
||||||
return last
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"NEXT": {
|
|
||||||
head: 'NEXT',
|
|
||||||
validate: /^NEXT$/i,
|
|
||||||
|
|
||||||
// All supported params are defined in separate files
|
|
||||||
run: function (session) {
|
|
||||||
try {
|
|
||||||
if (!session.group.name) return nntp_statuses._412_GRP_NOT_SLCTD;
|
|
||||||
if (!session.group.current_article) return nntp_statuses._420_ARTICLE_NOT_SLCTD;
|
|
||||||
if (!self.articleExists(session.group.name, session.group.current_article)) return nntp_statuses._420_ARTICLE_NOT_SLCTD;
|
|
||||||
var res = self.getNextArticle(session.group.name, session.group.current_article);
|
|
||||||
if (!res) return nntp_statuses._421_NO_NEXT_ARTICLE;
|
|
||||||
var next = `${nntp_statuses._223_ARTICLE_EXISTS} ${res.articleNumber} ${res.message_id}`
|
|
||||||
return next
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,10 +46,31 @@ class WTVNewsServer {
|
|||||||
...nntp_server.prototype,
|
...nntp_server.prototype,
|
||||||
_authenticate: function (session) {
|
_authenticate: function (session) {
|
||||||
// authenticate
|
// authenticate
|
||||||
if (session.authinfo_user == self.username && session.authinfo_pass == self.password) return Promise.resolve(true);
|
if (session.authinfo_user == self.username && session.authinfo_pass == self.password) {
|
||||||
|
session.posting_allowed = true;
|
||||||
|
return Promise.resolve(true);
|
||||||
|
}
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getLast: function (session) {
|
||||||
|
if (!session.group.name) return nntp_statuses._412_GRP_NOT_SLCTD;
|
||||||
|
if (!session.group.current_article) return nntp_statuses._420_ARTICLE_NOT_SLCTD;
|
||||||
|
if (!self.articleExists(session.group.name, session.group.current_article)) return nntp_statuses._420_ARTICLE_NOT_SLCTD;
|
||||||
|
var res = self.getLastArticle(session.group.name, session.group.current_article);
|
||||||
|
if (!res) return nntp_statuses._422_NO_LAST_ARTICLE;
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getNext: function (session) {
|
||||||
|
if (!session.group.name) return nntp_statuses._412_GRP_NOT_SLCTD;
|
||||||
|
if (!session.group.current_article) return nntp_statuses._420_ARTICLE_NOT_SLCTD;
|
||||||
|
if (!self.articleExists(session.group.name, session.group.current_article)) return nntp_statuses._420_ARTICLE_NOT_SLCTD;
|
||||||
|
var res = self.getNextArticle(session.group.name, session.group.current_article);
|
||||||
|
if (!res) return nntp_statuses._421_NO_NEXT_ARTICLE;
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
_selectGroup: function (session, name) {
|
_selectGroup: function (session, name) {
|
||||||
// selectGroup
|
// selectGroup
|
||||||
var res = self.selectGroup(name);
|
var res = self.selectGroup(name);
|
||||||
@@ -107,7 +100,6 @@ class WTVNewsServer {
|
|||||||
// getArticle
|
// getArticle
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var res = self.getArticle(session.group.name, message_id);
|
var res = self.getArticle(session.group.name, message_id);
|
||||||
console.log(res);
|
|
||||||
if (!res.messageId) reject(res);
|
if (!res.messageId) reject(res);
|
||||||
else resolve(res)
|
else resolve(res)
|
||||||
});
|
});
|
||||||
@@ -135,7 +127,7 @@ class WTVNewsServer {
|
|||||||
key: this.fs.readFileSync(tls_path + this.path.sep + 'localserver_key.pem'),
|
key: this.fs.readFileSync(tls_path + this.path.sep + 'localserver_key.pem'),
|
||||||
cert: this.fs.readFileSync(tls_path + this.path.sep + 'localserver_cert.pem'),
|
cert: this.fs.readFileSync(tls_path + this.path.sep + 'localserver_cert.pem'),
|
||||||
}
|
}
|
||||||
this.local_server = new nntp_server({ requireAuth: using_auth, tls: tls_options, secure: true, commands: nntp_commands });
|
this.local_server = new nntp_server({ requireAuth: using_auth, tls: tls_options, secure: true, allow_posting: true, commands: nntp_commands });
|
||||||
this.local_server.listen('nntps://localhost:' + local_server_port);
|
this.local_server.listen('nntps://localhost:' + local_server_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,12 +196,15 @@ class WTVNewsServer {
|
|||||||
var g = this.getGroupPath(group);
|
var g = this.getGroupPath(group);
|
||||||
var res = null;
|
var res = null;
|
||||||
try {
|
try {
|
||||||
|
var articleNumbers = [];
|
||||||
this.fs.readdirSync(g).forEach(file => {
|
this.fs.readdirSync(g).forEach(file => {
|
||||||
var articleNumber = parseInt(file.split('.')[0]);
|
var articleNumber = parseInt(file.split('.')[0]);
|
||||||
if (articleNumber > current) return false;
|
articleNumbers.push(articleNumber);
|
||||||
res = articleNumber;
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
articleNumbers.sort((a, b) => a - b)
|
||||||
|
var index = articleNumbers.findIndex((e) => e = current);
|
||||||
|
console.log('index last', index, "article", articleNumbers[index], "current", current)
|
||||||
|
if (index >= 0) res = articleNumbers[index];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
return e;
|
return e;
|
||||||
@@ -228,13 +223,16 @@ class WTVNewsServer {
|
|||||||
var g = this.getGroupPath(group);
|
var g = this.getGroupPath(group);
|
||||||
var res = null;
|
var res = null;
|
||||||
try {
|
try {
|
||||||
|
var articleNumbers = [];
|
||||||
this.fs.readdirSync(g).forEach(file => {
|
this.fs.readdirSync(g).forEach(file => {
|
||||||
var articleNumber = parseInt(file.split('.')[0]);
|
var articleNumber = parseInt(file.split('.')[0]);
|
||||||
if (articleNumber <= current) return;
|
articleNumbers.push(articleNumber);
|
||||||
|
|
||||||
res = articleNumber;
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
articleNumbers.sort((a, b) => a - b)
|
||||||
|
console.log(articleNumbers)
|
||||||
|
var index = articleNumbers.findIndex((e) => e = current) + 1;
|
||||||
|
console.log('index next', index, "article", articleNumbers[index], "current", current)
|
||||||
|
if (index < articleNumbers.length) res = articleNumbers[index];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
return e;
|
return e;
|
||||||
@@ -274,6 +272,7 @@ class WTVNewsServer {
|
|||||||
console.log(e);
|
console.log(e);
|
||||||
out.failed = e;
|
out.failed = e;
|
||||||
}
|
}
|
||||||
|
articleNumbers.sort((a, b) => a.index - b.index)
|
||||||
if (out.min_index === null) out.min_index = 0;
|
if (out.min_index === null) out.min_index = 0;
|
||||||
return {
|
return {
|
||||||
articleNumbers: articleNumbers,
|
articleNumbers: articleNumbers,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class WTVShared {
|
|||||||
sanitizeHtml = require('sanitize-html');
|
sanitizeHtml = require('sanitize-html');
|
||||||
iconv = require('iconv-lite');
|
iconv = require('iconv-lite');
|
||||||
parentDirectory = process.cwd()
|
parentDirectory = process.cwd()
|
||||||
|
extend = require('util')._extend;
|
||||||
|
|
||||||
minisrv_config = [];
|
minisrv_config = [];
|
||||||
|
|
||||||
@@ -39,8 +40,21 @@ class WTVShared {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cloneObj(obj) {
|
cloneObj(src) {
|
||||||
return JSON.parse(JSON.stringify(obj));
|
if (src instanceof RegExp) {
|
||||||
|
return new RegExp(src);
|
||||||
|
} else if (src instanceof Date) {
|
||||||
|
return new Date(src.getTime());
|
||||||
|
} else if (Array.isArray(src)) {
|
||||||
|
return src.map(this.cloneObj);
|
||||||
|
} else if (typeof src === 'object' && src !== null) {
|
||||||
|
const clone = {};
|
||||||
|
Object.keys(src).forEach(k => {
|
||||||
|
clone[k] = this.cloneObj(src[k]);
|
||||||
|
});
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
getServiceString(service, overrides = {}) {
|
getServiceString(service, overrides = {}) {
|
||||||
@@ -418,17 +432,22 @@ class WTVShared {
|
|||||||
filterRequestLog(obj) {
|
filterRequestLog(obj) {
|
||||||
if (this.minisrv_config.config.filter_passwords_in_logs === true) {
|
if (this.minisrv_config.config.filter_passwords_in_logs === true) {
|
||||||
if (obj.query) {
|
if (obj.query) {
|
||||||
var newobj = this.cloneObj(obj);
|
var newobj = this.cloneObj(obj) || {};
|
||||||
Object.keys(newobj.query).forEach(function (k) {
|
try {
|
||||||
var key = k.toLowerCase();
|
Object.keys(obj.query).forEach(function (k) {
|
||||||
switch (true) {
|
var key = k.toLowerCase();
|
||||||
case /passw(or)?d/.test(key):
|
switch (true) {
|
||||||
case /^pass$/.test(key):
|
case /passw(or)?d/.test(key):
|
||||||
newobj.query[key] = ('*').repeat(newobj.query[key].length);
|
case /^pass$/.test(key):
|
||||||
break;
|
newobj.query[key] = ('*').repeat(newobj.query[key].length);
|
||||||
}
|
break;
|
||||||
});
|
}
|
||||||
return newobj;
|
});
|
||||||
|
return newobj;
|
||||||
|
} catch (e) {
|
||||||
|
if (!this.minisrv_config.config.debug_flags.quiet) console.error(' *** error filtering logs', e);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
|||||||
Reference in New Issue
Block a user