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.");
|
||||
sendToClient(socket, headers, '');
|
||||
} 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 + ">";
|
||||
wtvnews.postToGroup(newsgroup, from_addr, msg_subject, msg_body, article).then(() => {
|
||||
session_data.deleteSessionData("usenet_draft");
|
||||
|
||||
@@ -11,9 +11,9 @@ if (service_config.local_nntp_port && wtvnewsserver) {
|
||||
checkServerIdentity: () => { return null; }
|
||||
}
|
||||
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
|
||||
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 {
|
||||
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);
|
||||
@@ -228,7 +228,6 @@ ${page_start}-${page_end}
|
||||
var has_relation = (messages[k].relation !== null) ? true : false;
|
||||
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)
|
||||
console.log(message);
|
||||
data += `
|
||||
<table cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
|
||||
@@ -8,6 +8,7 @@ class WTVNews {
|
||||
client = null;
|
||||
username = null;
|
||||
password = null;
|
||||
posting_allowed = true;
|
||||
|
||||
constructor(minisrv_config, service_name) {
|
||||
this.minisrv_config = minisrv_config;
|
||||
@@ -35,6 +36,7 @@ class WTVNews {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.connect().then((response) => {
|
||||
if (response.code == 200 || response.code == 201) {
|
||||
if (response.code == 201) this.posting_allowed = false;
|
||||
if (this.username && this.password) {
|
||||
this.client.authInfoUser(this.username).then((res) => {
|
||||
if (res.code == "381") {
|
||||
@@ -122,19 +124,24 @@ class WTVNews {
|
||||
promises.push(new Promise((resolve, reject) => {
|
||||
this.client.last().then((res) => {
|
||||
data.prev_article = res.article.articleNumber;
|
||||
// do it again
|
||||
this.client.article(data.prev_article).then(() => {
|
||||
this.client.last().then((res) => {
|
||||
data.prev_article = res.article.articleNumber;
|
||||
resolve(data.prev_article);
|
||||
console.log(data.prev_article, articleID)
|
||||
if (data.prev_article === articleID) {
|
||||
// do it again, needed this for CodoSoft NNTPd?
|
||||
this.client.article(data.prev_article).then(() => {
|
||||
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(() => {
|
||||
data.prev_article = null;
|
||||
resolve(data.prev_article);
|
||||
});
|
||||
}).catch(() => {
|
||||
data.prev_article = null;
|
||||
} else {
|
||||
resolve(data.prev_article);
|
||||
});
|
||||
}
|
||||
}).catch(() => {
|
||||
data.prev_article = null;
|
||||
resolve(data.prev_article);
|
||||
|
||||
@@ -15,7 +15,8 @@ class WTVNewsServer {
|
||||
const { WTVShared } = require("./WTVShared.js");
|
||||
this.wtvshared = new WTVShared(minisrv_config);
|
||||
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.password == password || null;
|
||||
this.using_auth = using_auth;
|
||||
@@ -30,42 +31,13 @@ class WTVNewsServer {
|
||||
|
||||
var nntp_commands = {
|
||||
...nntp_server.commands,
|
||||
"LAST": {
|
||||
head: 'LAST',
|
||||
validate: /^LAST$/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.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);
|
||||
}
|
||||
"POST": {
|
||||
head: 'POST',
|
||||
validate: /^POST$/i,
|
||||
run: function (session, post_data) {
|
||||
if (!session.posting_allowed) return
|
||||
console.log(post_data);
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,10 +46,31 @@ class WTVNewsServer {
|
||||
...nntp_server.prototype,
|
||||
_authenticate: function (session) {
|
||||
// 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);
|
||||
},
|
||||
|
||||
_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
|
||||
var res = self.selectGroup(name);
|
||||
@@ -107,7 +100,6 @@ class WTVNewsServer {
|
||||
// getArticle
|
||||
return new Promise((resolve, reject) => {
|
||||
var res = self.getArticle(session.group.name, message_id);
|
||||
console.log(res);
|
||||
if (!res.messageId) reject(res);
|
||||
else resolve(res)
|
||||
});
|
||||
@@ -135,7 +127,7 @@ class WTVNewsServer {
|
||||
key: this.fs.readFileSync(tls_path + this.path.sep + 'localserver_key.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);
|
||||
}
|
||||
|
||||
@@ -204,12 +196,15 @@ class WTVNewsServer {
|
||||
var g = this.getGroupPath(group);
|
||||
var res = null;
|
||||
try {
|
||||
var articleNumbers = [];
|
||||
this.fs.readdirSync(g).forEach(file => {
|
||||
var articleNumber = parseInt(file.split('.')[0]);
|
||||
if (articleNumber > current) return false;
|
||||
res = articleNumber;
|
||||
return false;
|
||||
articleNumbers.push(articleNumber);
|
||||
});
|
||||
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) {
|
||||
console.log(e);
|
||||
return e;
|
||||
@@ -228,13 +223,16 @@ class WTVNewsServer {
|
||||
var g = this.getGroupPath(group);
|
||||
var res = null;
|
||||
try {
|
||||
var articleNumbers = [];
|
||||
this.fs.readdirSync(g).forEach(file => {
|
||||
var articleNumber = parseInt(file.split('.')[0]);
|
||||
if (articleNumber <= current) return;
|
||||
|
||||
res = articleNumber;
|
||||
return false;
|
||||
articleNumbers.push(articleNumber);
|
||||
});
|
||||
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) {
|
||||
console.log(e);
|
||||
return e;
|
||||
@@ -274,6 +272,7 @@ class WTVNewsServer {
|
||||
console.log(e);
|
||||
out.failed = e;
|
||||
}
|
||||
articleNumbers.sort((a, b) => a.index - b.index)
|
||||
if (out.min_index === null) out.min_index = 0;
|
||||
return {
|
||||
articleNumbers: articleNumbers,
|
||||
|
||||
@@ -13,6 +13,7 @@ class WTVShared {
|
||||
sanitizeHtml = require('sanitize-html');
|
||||
iconv = require('iconv-lite');
|
||||
parentDirectory = process.cwd()
|
||||
extend = require('util')._extend;
|
||||
|
||||
minisrv_config = [];
|
||||
|
||||
@@ -39,8 +40,21 @@ class WTVShared {
|
||||
}
|
||||
}
|
||||
|
||||
cloneObj(obj) {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
cloneObj(src) {
|
||||
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 = {}) {
|
||||
@@ -418,17 +432,22 @@ class WTVShared {
|
||||
filterRequestLog(obj) {
|
||||
if (this.minisrv_config.config.filter_passwords_in_logs === true) {
|
||||
if (obj.query) {
|
||||
var newobj = this.cloneObj(obj);
|
||||
Object.keys(newobj.query).forEach(function (k) {
|
||||
var key = k.toLowerCase();
|
||||
switch (true) {
|
||||
case /passw(or)?d/.test(key):
|
||||
case /^pass$/.test(key):
|
||||
newobj.query[key] = ('*').repeat(newobj.query[key].length);
|
||||
break;
|
||||
}
|
||||
});
|
||||
return newobj;
|
||||
var newobj = this.cloneObj(obj) || {};
|
||||
try {
|
||||
Object.keys(obj.query).forEach(function (k) {
|
||||
var key = k.toLowerCase();
|
||||
switch (true) {
|
||||
case /passw(or)?d/.test(key):
|
||||
case /^pass$/.test(key):
|
||||
newobj.query[key] = ('*').repeat(newobj.query[key].length);
|
||||
break;
|
||||
}
|
||||
});
|
||||
return newobj;
|
||||
} catch (e) {
|
||||
if (!this.minisrv_config.config.debug_flags.quiet) console.error(' *** error filtering logs', e);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
|
||||
Reference in New Issue
Block a user