usenet ready for local testing

- custom patched nntp-server node module with support for POSTing
- should be able to post locally
- 4 groups are made by default
- can override in user_config.json (look at the config.json changes but dont do them there)
- can sync down from an upstream server with sync_nntp.js
- sync does not push new posts to upstream yet
This commit is contained in:
zefie
2022-10-12 19:08:57 -04:00
parent 048a609756
commit a4adf8414b
7 changed files with 88 additions and 35 deletions

View File

@@ -1,14 +1,6 @@
var minisrv_service_file = true; var minisrv_service_file = true;
// max of 6, any more will be ignored // max of 6, any more will be ignored
var featuredGroups = [
{ "name": "WebTV", "group": "webtv.users", "description": "A moderated discussion with WebTV customers" },
{ "name": "Hacking", "group": "alt.discuss.webtv.hacking", "description": "Not grandma friendly" },
{ "name": "4x4s", "group": "rec.autos.4x4", "description": "The on and off-road four wheel drive vehicle" },
{ "name": "WebTV Plus", "group": "webtv.plus", "description": "bf0 is for bitches and BPS is boring" },
{ "name": "MIDIs", "group": "alt.discuss.midis", "description": "The best music format" },
{ "name": "HTML", "group": "alt.discuss.html", "description": "Every timeline starts with HTML" }
];
headers = `200 OK headers = `200 OK
Connection: Keep-Alive Connection: Keep-Alive
@@ -116,6 +108,7 @@ Featured discussions
<td> <td>
<td WIDTH=198 HEIGHT=200 VALIGN=top ALIGN=left>`; <td WIDTH=198 HEIGHT=200 VALIGN=top ALIGN=left>`;
var featuredGroups = minisrv_config.services[service_name].featuredGroups;
var limit = 6; var limit = 6;
while (featuredGroups.length > limit) featuredGroups.pop(); // remove anything passing our limit while (featuredGroups.length > limit) featuredGroups.pop(); // remove anything passing our limit

View File

@@ -54,7 +54,6 @@ Connection: Keep-Alive
Content-Type: text/html Content-Type: text/html
wtv-expire-all: wtv-setup:/remove-users wtv-expire-all: wtv-setup:/remove-users
wtv-expire-all: wtv-setup:/accounts wtv-expire-all: wtv-setup:/accounts
wtv-visit: ${confirmAlert}
Location: ${confirmAlert}` Location: ${confirmAlert}`
} else { } else {
Object.keys(usersToRemove).forEach(function (k) { Object.keys(usersToRemove).forEach(function (k) {
@@ -69,7 +68,6 @@ Connection: Keep-Alive
Content-Type: text/html Content-Type: text/html
wtv-expire-all: wtv-setup:/remove-users wtv-expire-all: wtv-setup:/remove-users
wtv-expire-all: wtv-setup:/accounts wtv-expire-all: wtv-setup:/accounts
wtv-visit: ${gourl}
Location: ${gourl}` Location: ${gourl}`
} }
} }

View File

@@ -1923,6 +1923,11 @@ Object.keys(minisrv_config.services).forEach(function (k) {
wtvnewsserver = new WTVNewsServer(minisrv_config, minisrv_config.services[k].local_nntp_port); wtvnewsserver = new WTVNewsServer(minisrv_config, minisrv_config.services[k].local_nntp_port);
console.log(" * Configured Service: Local NNTP", "on 127.0.0.1:" + minisrv_config.services[k].local_nntp_port, "(TLS) - Auth required:", local_nntp_using_auth, "- Auth: None"); console.log(" * Configured Service: Local NNTP", "on 127.0.0.1:" + minisrv_config.services[k].local_nntp_port, "(TLS) - Auth required:", local_nntp_using_auth, "- Auth: None");
} }
if (minisrv_config.services["wtv-news"].featuredGroups) {
Object.keys(minisrv_config.services["wtv-news"].featuredGroups).forEach((k) => {
wtvnewsserver.createGroup(minisrv_config.services["wtv-news"].featuredGroups[k].group);
})
}
} }
} }

View File

@@ -29,19 +29,6 @@ class WTVNewsServer {
// nntp-server module overrides // nntp-server module overrides
var self = this; var self = this;
var nntp_commands = {
...nntp_server.commands,
"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");
}
}
}
nntp_server.prototype = { nntp_server.prototype = {
...nntp_server.prototype, ...nntp_server.prototype,
_authenticate: function (session) { _authenticate: function (session) {
@@ -52,7 +39,16 @@ class WTVNewsServer {
} }
return Promise.resolve(false); return Promise.resolve(false);
}, },
_postArticle: function (session) {
try {
session.group.name = self.getHeader(session.post_data, "newsgroups");
if (session.group.name.indexOf(',') >= 0) return false; // cross post not implemented
return self.postArticle(session.group.name, session.post_data)
} catch (e) {
console.log(e)
return false;
}
},
_getLast: function (session) { _getLast: function (session) {
if (!session.group.name) return nntp_statuses._412_GRP_NOT_SLCTD; if (!session.group.name) return nntp_statuses._412_GRP_NOT_SLCTD;
if (!session.group.current_article) return nntp_statuses._420_ARTICLE_NOT_SLCTD; if (!session.group.current_article) return nntp_statuses._420_ARTICLE_NOT_SLCTD;
@@ -91,7 +87,7 @@ class WTVNewsServer {
}, },
_buildHeaderField: function (session, message, field) { _buildHeaderField: function (session, message, field) {
var search = Object.keys(message.headers).find(e => (e.toLowerCase() == field.toLowerCase())); var search = self.getHeader(message, field);
if (search) return message.headers[search]; if (search) return message.headers[search];
else return null; else return null;
}, },
@@ -127,15 +123,54 @@ 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, allow_posting: true, commands: nntp_commands }); this.local_server = new nntp_server({ requireAuth: using_auth, tls: tls_options, secure: true, allow_posting: true });
this.local_server.listen('nntps://localhost:' + local_server_port); this.local_server.listen('nntps://localhost:' + local_server_port);
} }
getHeader(message, header) {
var search = Object.keys(message.headers).find(e => (e.toLowerCase() == header.toLowerCase()));
if (search) return message.headers[search];
return null;
}
createDataStore() { createDataStore() {
if (!this.fs.existsSync(this.data_path)) return this.fs.mkdirSync(this.data_path); if (!this.fs.existsSync(this.data_path)) return this.fs.mkdirSync(this.data_path);
return true; return true;
} }
getNextAvailableArticleID(group) {
return this.selectGroup(group).max_index + 1;
}
postArticle(group, post_data) {
var articleNumber = this.getNextAvailableArticleID(group);
if (!articleNumber) return false;
try {
post_data.articleNumber = articleNumber;
post_data.messageId = this.getHeader(post_data, "message-id");
//Tue, 11 Oct 2022 17:25:16 -0400
post_data.headers.date = this.strftime("%a, %-d %b %Y %H:%M:%S %z", Date.parse(post_data.headers.date))
post_data.headers['INJECTION-DATE'] = this.strftime("%a, %-d %b %Y %H:%M:%S %z", Date.parse(Date.now()))
if (this.articleExists(group, articleNumber)) return false // should not occur, but just in case
return this.createArticle(group, articleNumber, post_data);
} catch (e) {
console.error(" * WTVNewsServer Error: postArticle: ", e);
}
return false;
}
createArticle(group, articleNumber, article) {
var g = this.getGroupPath(group);
var file = g + this.path.sep + articleNumber + ".newz";
try {
this.fs.writeFileSync(file, JSON.stringify(article));
return true;
} catch (e) {
console.error(" * WTVNewsServer Error: createArticle: ", e);
return false;
}
}
getGroupPath(group) { getGroupPath(group) {
return this.data_path + this.path.sep + group; return this.data_path + this.path.sep + group;
} }
@@ -151,7 +186,8 @@ class WTVNewsServer {
} }
createGroup(group) { createGroup(group) {
if (!this.fs.existsSync(getGroupPath(group))) return this.fs.mkdirSync(getGroupPath(group)); var g = this.getGroupPath(group);
if (!this.fs.existsSync(g)) return this.fs.mkdirSync(g);
return true; return true;
} }
@@ -163,7 +199,7 @@ class WTVNewsServer {
data.index = data.articleNumber; data.index = data.articleNumber;
return data return data
} catch (e) { } catch (e) {
console.log(" * WTVNewsServer Error:", e); console.error(" * WTVNewsServer Error: getArticle: ", e);
} }
return null; return null;
} }

View File

@@ -68,6 +68,28 @@
"local_nntp_requires_auth": true, "local_nntp_requires_auth": true,
"modules": [ "modules": [
"WTVNews" "WTVNews"
],
"featuredGroups": [
{
"name": "WebTV",
"group": "webtv.users",
"description": "A moderated discussion with WebTV customers"
},
{
"name": "Hacking",
"group": "alt.discuss.webtv.hacking",
"description": "Not advertiser friendly"
},
{
"name": "minisrv",
"group": "minisrv.users",
"description": "The server behind it all"
},
{
"name": "MIDIs",
"group": "alt.discuss.midis",
"description": "Explore the sounds of Beatnik with your WebTV"
}
] ]
}, },
"wtv-register": { "wtv-register": {

View File

@@ -18,7 +18,7 @@
"iconv-lite": "^0.6.3", "iconv-lite": "^0.6.3",
"mime-types": "^2.1.35", "mime-types": "^2.1.35",
"newsie": "^1.2.1", "newsie": "^1.2.1",
"nntp-server": "^3.1.0", "nntp-server": "github:zefie/nntp-server",
"proxy-agent": "^5.0.0", "proxy-agent": "^5.0.0",
"sanitize-html": "^2.7.2", "sanitize-html": "^2.7.2",
"socks-proxy-agent": "^6.2.1", "socks-proxy-agent": "^6.2.1",
@@ -872,8 +872,8 @@
}, },
"node_modules/nntp-server": { "node_modules/nntp-server": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/nntp-server/-/nntp-server-3.1.0.tgz", "resolved": "git+ssh://git@github.com/zefie/nntp-server.git#bf57c038b6ead946850084cd923445a44aff0128",
"integrity": "sha512-L8U2CnFPHXfDKF+eaYpx07fCW7gbk7gNB0faDWg5fLIEofEP7O/RIUEonl0jGRDf9/eGMj7CRil1faG5YZq4bw==", "license": "MIT",
"dependencies": { "dependencies": {
"debug": "^4.3.3", "debug": "^4.3.3",
"denque": "^2.0.1", "denque": "^2.0.1",
@@ -2075,9 +2075,8 @@
"integrity": "sha512-41jhtKmlpSc27oIBkp681fm4aLURPT/AgeBvSRicxNPWDVeHLaq7tSvG/OsEXz7g41thgv9JMV1ZjYSABMiYVA==" "integrity": "sha512-41jhtKmlpSc27oIBkp681fm4aLURPT/AgeBvSRicxNPWDVeHLaq7tSvG/OsEXz7g41thgv9JMV1ZjYSABMiYVA=="
}, },
"nntp-server": { "nntp-server": {
"version": "3.1.0", "version": "git+ssh://git@github.com/zefie/nntp-server.git#bf57c038b6ead946850084cd923445a44aff0128",
"resolved": "https://registry.npmjs.org/nntp-server/-/nntp-server-3.1.0.tgz", "from": "nntp-server@zefie/nntp-server",
"integrity": "sha512-L8U2CnFPHXfDKF+eaYpx07fCW7gbk7gNB0faDWg5fLIEofEP7O/RIUEonl0jGRDf9/eGMj7CRil1faG5YZq4bw==",
"requires": { "requires": {
"debug": "^4.3.3", "debug": "^4.3.3",
"denque": "^2.0.1", "denque": "^2.0.1",

View File

@@ -36,7 +36,7 @@
"iconv-lite": "^0.6.3", "iconv-lite": "^0.6.3",
"mime-types": "^2.1.35", "mime-types": "^2.1.35",
"newsie": "^1.2.1", "newsie": "^1.2.1",
"nntp-server": "^3.1.0", "nntp-server": "github:zefie/nntp-server",
"proxy-agent": "^5.0.0", "proxy-agent": "^5.0.0",
"sanitize-html": "^2.7.2", "sanitize-html": "^2.7.2",
"socks-proxy-agent": "^6.2.1", "socks-proxy-agent": "^6.2.1",