a lot of usenet updates
- webtv can post attachments - webtv signatures - TODO: user control disable rendering of post signatures - TODO: as above but for mail too
This commit is contained in:
@@ -428,10 +428,6 @@ class WTVClientSessionData {
|
||||
return encoded_passwd.toString(CryptoJS.enc.Base64);
|
||||
}
|
||||
|
||||
generatePassword(len) {
|
||||
return this.wtvshared.generatePassword(len);
|
||||
}
|
||||
|
||||
setUserPassword(passwd) {
|
||||
var encoded_passwd = this.encodePassword(passwd);
|
||||
this.setSessionData("subscriber_password", encoded_passwd);
|
||||
|
||||
@@ -39,7 +39,7 @@ class WTVMail {
|
||||
this.trashMailboxName
|
||||
];
|
||||
this.defaultColors = {
|
||||
bgcolor: "#171726",
|
||||
bgcolor: "#191919",
|
||||
text: "#82A9D9",
|
||||
link: "#BDA73A",
|
||||
vlink: "#62B362"
|
||||
|
||||
@@ -11,7 +11,7 @@ class WTVMime {
|
||||
|
||||
|
||||
constructor(minisrv_config) {
|
||||
var WTVShared = require("./WTVShared.js")['WTVShared'];
|
||||
const { WTVShared } = require("./WTVShared.js");
|
||||
this.minisrv_config = minisrv_config;
|
||||
this.wtvshared = new WTVShared(minisrv_config);
|
||||
if (!String.prototype.reverse) {
|
||||
@@ -200,6 +200,67 @@ class WTVMime {
|
||||
return new Array(wtv_mime_type, modern_mime_type);
|
||||
}
|
||||
|
||||
// modified from https://github.com/sergi/mime-multipart/blob/master/index.js
|
||||
|
||||
generateMultipartMIME(tuples, options) {
|
||||
// modified for creating usenet compliant headers/content from an attachment
|
||||
var CRLF = '\n';
|
||||
if (tuples.length === 0) {
|
||||
// according to rfc1341 there should be at least one encapsulation
|
||||
throw new Error('Missing argument. At least one part to generate is required');
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
var preamble = options.preamble || "This is a multi-part message in MIME format.";
|
||||
var epilogue = options.epilogue;
|
||||
var boundary = options.boundary || "------------" + this.wtvshared.generateString(24);
|
||||
|
||||
if (boundary.length < 1 || boundary.length > 70) {
|
||||
throw new Error('Boundary should be between 1 and 70 characters long');
|
||||
}
|
||||
|
||||
var boundary_header = 'multipart/mixed; boundary="' + boundary + '"';
|
||||
|
||||
var delimiter = CRLF + '--' + boundary;
|
||||
var closeDelimiter = delimiter + '--';
|
||||
|
||||
var wtvshared = this.wtvshared;
|
||||
|
||||
var encapsulations = tuples.map(function (tuple, i) {
|
||||
var mimetype = tuple.mime || 'text/plain';
|
||||
var encoding = tuple.encoding || 'utf-8';
|
||||
var use_base64 = tuple.use_base64 || !wtvshared.isASCII(tuple.content);
|
||||
var is_base64 = tuple.is_base64 || wtvshared.isBase64(tuple.content);
|
||||
var filename = (tuple.filename) ? tuple.filename : (use_base64) ? ('file' + i) : null;
|
||||
|
||||
var headers = [
|
||||
`Content-Type: ${mimetype}; ${(use_base64) ? `name="${filename}"` : `charset=${encoding.toUpperCase()}; format=flowed`}`,
|
||||
];
|
||||
|
||||
if (filename) headers.push(`Content-Disposition: attachment; filename="${filename}"`);
|
||||
headers.push(`Content-Transfer-Encoding: ${(use_base64) ? 'base64' : '7bit'}`);
|
||||
|
||||
var bodyPart = headers.join(CRLF) + CRLF + CRLF;
|
||||
if (use_base64 && !is_base64) bodyPart += wtvshared.lineWrap(Buffer.from(tuple.content).toString('base64'),72) + CRLF;
|
||||
else bodyPart += wtvshared.lineWrap(tuple.content,72);
|
||||
|
||||
return delimiter + CRLF + bodyPart;
|
||||
});
|
||||
|
||||
var multipartBody = [
|
||||
preamble ? preamble : undefined,
|
||||
encapsulations.join(''),
|
||||
closeDelimiter,
|
||||
epilogue ? CRLF + epilogue : undefined,
|
||||
].filter(function (element) { return !!element; });
|
||||
|
||||
return {
|
||||
"mime_version": "1.0",
|
||||
"content_type": boundary_header,
|
||||
"content": multipartBody.join('')
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = WTVMime;
|
||||
|
||||
@@ -66,6 +66,7 @@ class WTVNews {
|
||||
}
|
||||
|
||||
listGroup(group, page = 0, limit = 100, raw_range = null) {
|
||||
// list of articles from group
|
||||
return new Promise((resolve, reject) => {
|
||||
this.selectGroup(group).then((res) => {
|
||||
if (!raw_range) {
|
||||
@@ -90,6 +91,35 @@ class WTVNews {
|
||||
})
|
||||
}
|
||||
|
||||
processGroupList(list) {
|
||||
if (list) return list.newsgroups;
|
||||
else return null;
|
||||
}
|
||||
|
||||
listGroups(search = null) {
|
||||
// list of groups on the server
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('listGroups search', search)
|
||||
if (!search) {
|
||||
this.client.list().then((data) => {
|
||||
console.log('listGroups data', data)
|
||||
resolve(this.processGroupList(data));
|
||||
}).catch((e) => {
|
||||
console.error(" * WTVNews Error:", "Command: listGroups (all)", e);
|
||||
reject(`No such group <b>${group}</b>`);
|
||||
});
|
||||
} else {
|
||||
this.client.listNewsgroups('*' + search + '*').then((data) => {
|
||||
console.log('listGroups data', data)
|
||||
resolve(this.processGroupList(data));
|
||||
}).catch((e) => {
|
||||
console.error(" * WTVNews Error:", "Command: listGroups (all)", e);
|
||||
reject(`No such group <b>${group}</b>`);
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
selectGroup(group) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.group(group).then((response) => {
|
||||
@@ -234,7 +264,7 @@ class WTVNews {
|
||||
});
|
||||
}
|
||||
|
||||
postToGroup(group, from_addr, msg_subject, msg_body, article = null) {
|
||||
postToGroup(group, from_addr, msg_subject, msg_body, article = null, headers = null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var promises = [];
|
||||
var messageid = null;
|
||||
@@ -268,8 +298,13 @@ class WTVNews {
|
||||
'From': from_addr,
|
||||
'Newsgroups': group,
|
||||
'Subject': msg_subject || "(No subject)",
|
||||
'Message-ID': "<" + this.wtvshared.generatePassword(16) + "@" + this.minisrv_config.config.domain_name + ">",
|
||||
'Date': this.strftime('%A, %d-%b-%y %k:%M:%S %z', new Date())
|
||||
'Message-ID': "<" + this.wtvshared.generateString(16) + "@" + this.minisrv_config.config.domain_name + ">",
|
||||
'Date': this.strftime('%a, %-d %b %Y %H:%M:%S %z', new Date())
|
||||
}
|
||||
if (headers) {
|
||||
Object.keys(headers).forEach((k) => {
|
||||
articleData.headers[k] = headers[k];
|
||||
});
|
||||
}
|
||||
if (messageid) {
|
||||
articleData.headers.References = messageid;
|
||||
@@ -286,16 +321,17 @@ class WTVNews {
|
||||
resolve(true);
|
||||
}
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
this.client.quit();
|
||||
reject("Could not send post. Server returned error " + response.code);
|
||||
});
|
||||
} else {
|
||||
this.client.quit();
|
||||
console.log('usenet upstream uncaught error', e);
|
||||
console.error('usenet upstream uncaught error', e);
|
||||
reject("Could not send post. Server returned unknown error");
|
||||
};
|
||||
}).catch((e) => {
|
||||
console.log('could not connect to server', e);
|
||||
console.error('could not connect to server', e);
|
||||
reject("could not connect to server");
|
||||
});
|
||||
});
|
||||
@@ -308,7 +344,7 @@ class WTVNews {
|
||||
this.client.article(articleID).then((data) => {
|
||||
resolve(data.article.messageId);
|
||||
}).catch((e) => {
|
||||
console.log("error getting messageID from article", articleID, e)
|
||||
console.error("error getting messageID from article", articleID, e)
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
@@ -363,8 +399,8 @@ class WTVNews {
|
||||
if (section_header_match) {
|
||||
var section_match = line.match(/^Content\-Type\: (.+)\;/i)
|
||||
if (section_match) {
|
||||
if (section_match[1].match(/text\/(html|plain)/)) {
|
||||
section_type = section_match[1].match(/(text\/(html|plain))/)[1];
|
||||
if (section_match[1].match("text/plain")) {
|
||||
section_type = section_match[1].match("text/plain")[1];
|
||||
message_type = section_type;
|
||||
} else {
|
||||
section_type = section_match[1];
|
||||
@@ -380,7 +416,7 @@ class WTVNews {
|
||||
if (section_match) attachments[i].content_encoding = section_match[1];
|
||||
} else {
|
||||
if (section_type != null) {
|
||||
if (section_type.match(/(text\/[html|plain])/)) message_body += line;
|
||||
if (section_type.match("text/plain")) message_body += line;
|
||||
else {
|
||||
if (attachments[i].data) attachments[i].data += line;
|
||||
else attachments[i].data = line;
|
||||
@@ -393,7 +429,7 @@ class WTVNews {
|
||||
attachments.pop();
|
||||
return {
|
||||
text: message_body,
|
||||
text_type: message_type,
|
||||
text_type: message_type || "text/plain",
|
||||
attachments: attachments
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -11,7 +11,7 @@ class WTVNewsServer {
|
||||
data_path = null;
|
||||
featuredGroups = null
|
||||
|
||||
constructor(minisrv_config, local_server_port, using_auth = false, username = null, password = null) {
|
||||
constructor(minisrv_config, local_server_port, using_auth = false, username = null, password = null, run_server = true) {
|
||||
this.minisrv_config = minisrv_config;
|
||||
const { WTVShared } = require("./WTVShared.js");
|
||||
this.wtvshared = new WTVShared(minisrv_config);
|
||||
@@ -22,129 +22,137 @@ class WTVNewsServer {
|
||||
this.username = username || null;
|
||||
this.password = password || null;
|
||||
this.using_auth = using_auth;
|
||||
if (using_auth && (!username && !password)) {
|
||||
// using auth, but no auth info specified, so randomly generate it
|
||||
this.username = this.wtvshared.generatePassword(8);
|
||||
this.password = this.wtvshared.generatePassword(16);
|
||||
}
|
||||
|
||||
// nntp-server module overrides
|
||||
var self = this;
|
||||
|
||||
nntp_server.prototype = {
|
||||
...nntp_server.prototype,
|
||||
_authenticate: function (session) {
|
||||
// authenticate
|
||||
if (session.authinfo_user == self.username && session.authinfo_pass == self.password) {
|
||||
session.posting_allowed = true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
return Promise.resolve(false);
|
||||
},
|
||||
_postArticle: function (session) {
|
||||
try {
|
||||
console.log(session.post_data);
|
||||
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;
|
||||
}
|
||||
},
|
||||
|
||||
_getGroups: function (session) {
|
||||
return self.getGroups();
|
||||
},
|
||||
_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);
|
||||
if (!res.failed) {
|
||||
session.group = res;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
_buildHead: function (session, message) {
|
||||
var out = "";
|
||||
Object.keys(message.headers).forEach((k) => {
|
||||
if (k.length > 0) out += `${k}: ${message.headers[k]}\r\n`;
|
||||
});
|
||||
out = out.substr(0,out.length - 2);
|
||||
return out;
|
||||
},
|
||||
|
||||
_buildHeaderField: function (session, message, field) {
|
||||
if (field.indexOf(':') > 0) field = field.replace(/\:/g, '');
|
||||
var search = self.getHeader(message, field);
|
||||
if (search) return search;
|
||||
else return null;
|
||||
},
|
||||
|
||||
_getOverviewFmt: function (session) {
|
||||
var headers = [
|
||||
"Subject:",
|
||||
"From:",
|
||||
"Date:",
|
||||
"Message-ID:",
|
||||
"References:",
|
||||
":bytes",
|
||||
":lines"
|
||||
]
|
||||
return headers;
|
||||
},
|
||||
_getArticle: function (session, message_id) {
|
||||
// getArticle
|
||||
return new Promise((resolve, reject) => {
|
||||
var res = self.getArticle(session.group.name, message_id);
|
||||
if (!res.messageId) reject(res);
|
||||
else resolve(res)
|
||||
});
|
||||
},
|
||||
|
||||
_buildBody: function (session, message) {
|
||||
return message.body;
|
||||
},
|
||||
|
||||
_getRange: function (session, first, last) {
|
||||
var res = self.listGroup(session.group.name, first, last)
|
||||
if (res.failed) return false;
|
||||
session.group = res.group_data;
|
||||
return res.articles;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.data_path = this.wtvshared.getAbsolutePath(this.minisrv_config.config.SessionStore + '/minisrv_internal_nntp');
|
||||
this.createDataStore();
|
||||
|
||||
var tls_path = this.wtvshared.getAbsolutePath(this.minisrv_config.config.ServiceDeps + '/wtv-news');
|
||||
var tls_options = {
|
||||
ca: this.fs.readFileSync(tls_path + this.path.sep + 'localserver_ca.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'),
|
||||
if (using_auth && (!username && !password)) {
|
||||
// using auth, but no auth info specified, so randomly generate it
|
||||
this.username = this.wtvshared.generateString(8);
|
||||
this.password = this.wtvshared.generatePassword(16);
|
||||
}
|
||||
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);
|
||||
|
||||
if (run_server) {
|
||||
// nntp-server module overrides
|
||||
var self = this;
|
||||
|
||||
nntp_server.prototype = {
|
||||
...nntp_server.prototype,
|
||||
_authenticate: function (session) {
|
||||
// authenticate
|
||||
if (session.authinfo_user == self.username && session.authinfo_pass == self.password) {
|
||||
session.posting_allowed = true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
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.error(e)
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
_getGroups: function (session, time = 0, wildmat = null) {
|
||||
if (time > 0) return false // unimplemented
|
||||
return self.getGroups(wildmat);
|
||||
},
|
||||
_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);
|
||||
if (!res.failed) {
|
||||
session.group = res;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
_buildHead: function (session, message) {
|
||||
var out = "";
|
||||
Object.keys(message.headers).forEach((k) => {
|
||||
if (k.length > 0) out += `${k}: ${message.headers[k]}\r\n`;
|
||||
});
|
||||
out = out.substr(0, out.length - 2);
|
||||
return out;
|
||||
},
|
||||
|
||||
_buildHeaderField: function (session, message, field) {
|
||||
if (field.indexOf(':') > 0) field = field.replace(/\:/g, '');
|
||||
var search = self.getHeader(message, field);
|
||||
if (search) return search;
|
||||
else return null;
|
||||
},
|
||||
|
||||
_getOverviewFmt: function (session) {
|
||||
var headers = [
|
||||
"Subject:",
|
||||
"From:",
|
||||
"Date:",
|
||||
"Message-ID:",
|
||||
"References:",
|
||||
":bytes",
|
||||
":lines"
|
||||
]
|
||||
return headers;
|
||||
},
|
||||
_getArticle: function (session, message_id) {
|
||||
// getArticle
|
||||
return new Promise((resolve, reject) => {
|
||||
var res = self.getArticle(session.group.name, message_id);
|
||||
if (!res.messageId) reject(res);
|
||||
else resolve(res)
|
||||
});
|
||||
},
|
||||
|
||||
_buildBody: function (session, message) {
|
||||
return message.body;
|
||||
},
|
||||
|
||||
_getRange: function (session, first, last) {
|
||||
var res = self.listGroup(session.group.name, first, last)
|
||||
if (res.failed) return false;
|
||||
session.group = res.group_data;
|
||||
return res.articles;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var tls_path = this.wtvshared.getAbsolutePath(this.minisrv_config.config.ServiceDeps + '/wtv-news');
|
||||
var tls_options = {
|
||||
ca: this.fs.readFileSync(tls_path + this.path.sep + 'localserver_ca.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'),
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
getMetaFilename(group) {
|
||||
var g = this.getGroupPath(group);
|
||||
if (g) return g + this.path.sep + "meta.json";
|
||||
else return null;
|
||||
}
|
||||
|
||||
getHeader(message, header) {
|
||||
@@ -160,27 +168,62 @@ class WTVNewsServer {
|
||||
return true;
|
||||
}
|
||||
|
||||
getArticleIdMeta(group) {
|
||||
const g = this.getGroupPath(group) + this.path.sep + "meta.json";
|
||||
if (this.fs.existsSync(g)) return JSON.parse(this.fs.readFileSync(g));
|
||||
return { group: group, last_article_id: (this.selectGroup(group).max_index + 1) }
|
||||
|
||||
createMetaFile(group, description = null) {
|
||||
const g = this.getMetaFilename(group);
|
||||
if (this.fs.existsSync(g)) return false;
|
||||
var metadata = {};
|
||||
metadata.group = group;
|
||||
metadata.last_article_id = this.selectGroup(group).max_index;
|
||||
if (description) metadata.description = description;
|
||||
this.saveMetadata(group, metadata, true);
|
||||
return metadata;
|
||||
}
|
||||
|
||||
saveMetadata(group, metadata, creating = false) {
|
||||
const g = this.getMetaFilename(group);
|
||||
if (g) {
|
||||
if (!this.fs.existsSync(g) && !creating) this.createMetaFile(group);
|
||||
else this.fs.writeFileSync(g, JSON.stringify(metadata));
|
||||
} else return false;
|
||||
}
|
||||
|
||||
getMetadata(group) {
|
||||
const g = this.getMetaFilename(group);
|
||||
if (g) {
|
||||
if (this.fs.existsSync(g)) return JSON.parse(this.fs.readFileSync(g));
|
||||
else return this.createMetaFile(group);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
incrementArticleIdMeta(group) {
|
||||
const g = this.getGroupPath(group) + this.path.sep + "meta.json";
|
||||
var meta = this.getArticleIdMeta(group);
|
||||
meta.last_article_id = meta.last_article_id + 1;
|
||||
this.fs.writeFileSync(g, JSON.stringify(meta))
|
||||
var metadata = this.getMetadata(group);
|
||||
metadata.last_article_id = metadata.last_article_id + 1;
|
||||
this.saveMetadata(group, metadata)
|
||||
}
|
||||
|
||||
findHeaderCaseInsensitive(headers, header) {
|
||||
// returns the key with the found case
|
||||
var response = null;
|
||||
if (headers) {
|
||||
Object.keys(headers).forEach((k) => {
|
||||
if (k.toLowerCase() == header.toLowerCase()) {
|
||||
response = k;
|
||||
return false;
|
||||
}
|
||||
})
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
postArticle(group, post_data) {
|
||||
var articleNumber = this.getArticleIdMeta(group).last_article_id;
|
||||
var articleNumber = this.getMetadata(group).last_article_id + 1;
|
||||
if (!articleNumber) return false;
|
||||
try {
|
||||
post_data.articleNumber = articleNumber;
|
||||
post_data.messageId = this.getHeader(post_data, "message-id");
|
||||
if (!post_data.messageId) {
|
||||
var messageId = "<" + this.wtvshared.generatePassword(16) + "@" + this.minisrv_config.config.domain_name + ">";
|
||||
var messageId = "<" + this.wtvshared.generateString(16) + "@" + this.minisrv_config.config.domain_name + ">";
|
||||
post_data.messageId = post_data.headers['Message-ID'] = messageId;
|
||||
}
|
||||
|
||||
@@ -188,7 +231,11 @@ class WTVNewsServer {
|
||||
if (!post_data.headers.Subject) post_data.headers.Subject = "(No subject)";
|
||||
|
||||
post_data.headers.Date = this.strftime("%a, %-d %b %Y %H:%M:%S %z", Date.parse(post_data.headers.date))
|
||||
|
||||
// server added Injection-Date
|
||||
post_data.headers['Injection-Date'] = this.strftime("%a, %-d %b %Y %H:%M:%S %z", Date.parse(Date.now()))
|
||||
|
||||
// Reorder headers per examples in RFC3977 sect 6.2.1.3, not sure if needed
|
||||
post_data.headers = this.wtvshared.moveObjectElement('Path', null, post_data.headers, true);
|
||||
post_data.headers = this.wtvshared.moveObjectElement('From', 'Path', post_data.headers, true);
|
||||
post_data.headers = this.wtvshared.moveObjectElement('Newsgroups', 'From', post_data.headers, true);
|
||||
@@ -196,8 +243,10 @@ class WTVNewsServer {
|
||||
post_data.headers = this.wtvshared.moveObjectElement('Date', 'Subject', post_data.headers, true);
|
||||
post_data.headers = this.wtvshared.moveObjectElement('Organization', 'Date', post_data.headers, true);
|
||||
post_data.headers = this.wtvshared.moveObjectElement('Message-ID', 'Organization', post_data.headers, true);
|
||||
if (this.articleExists(group, articleNumber)) return false // should not occur, but just in case
|
||||
return this.createArticle(group, articleNumber, post_data);
|
||||
// end reordering of headers
|
||||
|
||||
if (this.articleExists(group, post_data.articleNumber)) return false // should not occur, but just in case
|
||||
return this.createArticle(group, post_data.articleNumber, post_data);
|
||||
} catch (e) {
|
||||
console.error(" * WTVNewsServer Error: postArticle: ", e);
|
||||
}
|
||||
@@ -231,10 +280,14 @@ class WTVNewsServer {
|
||||
return false;
|
||||
}
|
||||
|
||||
createGroup(group) {
|
||||
createGroup(group, description = null) {
|
||||
var g = this.getGroupPath(group);
|
||||
if (!this.fs.existsSync(g)) return this.fs.mkdirSync(g);
|
||||
return true;
|
||||
if (!this.fs.existsSync(g)) {
|
||||
this.fs.mkdirSync(g);
|
||||
this.createMetaFile(group, description)
|
||||
return this.fs.existsSync(g);
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
getArticle(group, article) {
|
||||
@@ -242,9 +295,10 @@ class WTVNewsServer {
|
||||
if (!this.fs.existsSync(g)) return false;
|
||||
try {
|
||||
var data = JSON.parse(this.fs.readFileSync(g));
|
||||
if (data.article) data = data.article;
|
||||
data.index = data.articleNumber;
|
||||
if (!data.body) data.body = [''];
|
||||
if (!data.headers.Subject) data.headers.Subject = "(No subject)";
|
||||
if (!this.findHeaderCaseInsensitive(data.headers,'subject')) data.headers.Subject = "(No subject)";
|
||||
return data
|
||||
} catch (e) {
|
||||
console.error(" * WTVNewsServer Error: getArticle: ", e);
|
||||
@@ -286,10 +340,14 @@ class WTVNewsServer {
|
||||
return out;
|
||||
}
|
||||
|
||||
getGroups() {
|
||||
getGroups(wildmat = null) {
|
||||
var groups = [];
|
||||
this.fs.readdirSync(this.data_path).forEach(file => {
|
||||
if (this.fs.lstatSync(this.data_path + this.path.sep + file).isDirectory()) groups.push(this.selectGroup(file));
|
||||
if (this.fs.lstatSync(this.data_path + this.path.sep + file).isDirectory()) {
|
||||
if (wildmat) {
|
||||
if (file.match(wildmat)) groups.push(this.selectGroup(file));
|
||||
} else groups.push(this.selectGroup(file));
|
||||
}
|
||||
});
|
||||
return groups;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ class WTVShared {
|
||||
if (typeof val === 'string')
|
||||
val = val.toLowerCase();
|
||||
|
||||
return val === true || val === "true" || val === 1;
|
||||
return (val === true || val === "true" || val === 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ class WTVShared {
|
||||
|
||||
|
||||
isASCII(str) {
|
||||
if (typeof str !== 'string') return false;
|
||||
for (var i = 0, strLen = str.length; i < strLen; ++i) {
|
||||
if (str.charCodeAt(i) > 127) return false;
|
||||
}
|
||||
@@ -147,7 +148,37 @@ class WTVShared {
|
||||
}
|
||||
|
||||
isHTML(str) {
|
||||
return /<[a-z][\s\S]*>/i.test(str);
|
||||
return /<\/?[a-z][\s\S]*>/i.test()
|
||||
}
|
||||
|
||||
isBase64(str, opts) {
|
||||
// from https://github.com/miguelmota/is-base64/blob/master/is-base64.js
|
||||
if (str instanceof Boolean || typeof str === 'boolean') {
|
||||
return false
|
||||
}
|
||||
|
||||
if (!(opts instanceof Object)) {
|
||||
opts = {}
|
||||
}
|
||||
|
||||
if (opts.allowEmpty === false && str === '') {
|
||||
return false
|
||||
}
|
||||
|
||||
var regex = '(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\/]{3}=)?'
|
||||
var mimeRegex = '(data:\\w+\\/[a-zA-Z\\+\\-\\.]+;base64,)'
|
||||
|
||||
if (opts.mimeRequired === true) {
|
||||
regex = mimeRegex + regex
|
||||
} else if (opts.allowMime === true) {
|
||||
regex = mimeRegex + '?' + regex
|
||||
}
|
||||
|
||||
if (opts.paddingRequired === false) {
|
||||
regex = '(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}(==)?|[A-Za-z0-9+\\/]{3}=?)?'
|
||||
}
|
||||
|
||||
return (new RegExp('^' + regex + '$', 'gi')).test(str)
|
||||
}
|
||||
|
||||
utf8Decode(utf8String) {
|
||||
@@ -357,14 +388,45 @@ class WTVShared {
|
||||
}
|
||||
}
|
||||
|
||||
generatePassword(len) {
|
||||
return CryptoJS.lib.WordArray.random(Math.round(len / 2)).toString(CryptoJS.enc.Hex);
|
||||
generateString(len, extra_chars = null) {
|
||||
var result = '';
|
||||
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
if (extra_chars) characters += extra_chars;
|
||||
var charactersLength = characters.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() *
|
||||
charactersLength));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
generatePassword(len, simple = false) {
|
||||
return this.generateString(len, (simple) ? null : '!@#$%&()[]-_+=?.');
|
||||
}
|
||||
|
||||
getMiniSrvConfig() {
|
||||
return this.minisrv_config;
|
||||
}
|
||||
|
||||
lineWrap(string, len = 72, join = "\n") {
|
||||
if (string.length <= len) return string;
|
||||
var split;
|
||||
|
||||
if (string.match(" ")) {
|
||||
// split if text with space, respecting words
|
||||
split = string.match(new RegExp('([\\s\\S]){1,' + len + '}?!\\S', "g"));
|
||||
}
|
||||
if (!split) {
|
||||
// fallback if above failed, or if its just a really long word (eg base64)
|
||||
split = string.match(new RegExp('.{1,' + len + '}', "g"));
|
||||
} else Object.keys(split).forEach((k) => {
|
||||
if (split[k].substr(0, 1) == ' ') split[k] = split[k].trim(' ');
|
||||
});
|
||||
|
||||
if (split) return split.join(join);
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Last-Modified date in Unix Timestamp format
|
||||
|
||||
Reference in New Issue
Block a user