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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -369,3 +369,4 @@ FodyWeavers.xsd
|
||||
/zefie_wtvp_minisrv/SessionStore/*.json
|
||||
/zefie_wtvp_minisrv/SessionStore/*/
|
||||
/zefie_wtvp_minisrv/ServiceVault/http_pc/viewergen/viewers/HackTV.zip
|
||||
/zefie_wtvp_minisrv/postest.js
|
||||
|
||||
231
zefie_wtvp_minisrv/ServiceDeps/wtv-news/post-unavailable.html
Normal file
231
zefie_wtvp_minisrv/ServiceDeps/wtv-news/post-unavailable.html
Normal file
@@ -0,0 +1,231 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Posting unavailable</TITLE>
|
||||
</HEAD>
|
||||
<sidebar width=114 height=420 align=left>
|
||||
<table cellspacing=0 cellpadding=0 bgcolor=3d2f3a>
|
||||
<tr>
|
||||
<td colspan=3 width=104 absheight=4>
|
||||
<td rowspan=100 width=10 height=420 valign=top align=left bgcolor=${message_colors.bgcolor}>
|
||||
<img src="wtv-mail:/ROMCache/Shadow.gif" width=6 height=420>
|
||||
<tr>
|
||||
<td abswidth=6>
|
||||
<td abswidth=93 absheight=76>
|
||||
<table href="wtv-home:/home" absheight=76 cellspacing=0 cellpadding=0 width=100%>
|
||||
<tr>
|
||||
<td abswidth=6>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1>
|
||||
<td align=center>
|
||||
<img src="${minisrv_config.config.service_logo}" width=87 height=67>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=202434>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td abswidth=6>
|
||||
<td abswidth=93 absheight=26>
|
||||
<table selected href="wtv-news:/news?group=${group}"
|
||||
cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
<td abswidth=90 valign=middle align=left>
|
||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td absheight=1>
|
||||
<tr>
|
||||
<td maxlines=1><shadow><font sizerange=medium color="E7CE4A">Group</font></shadow>
|
||||
</table>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=202434>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td abswidth=6 >
|
||||
<td abswidth=93 absheight=26 >
|
||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
<td abswidth=88 valign=middle align=left >
|
||||
<table cellspacing=0 cellpadding=0><tr><td><shadow><font color="#5b4b58" sizerange=medium>Previous</font></shadow></table>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=202434>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left >
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td abswidth=6 >
|
||||
<td abswidth=93 absheight=26 >
|
||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
<td abswidth=88 valign=middle align=left >
|
||||
<table cellspacing=0 cellpadding=0><tr><td><shadow><font color="#5b4b58" sizerange=medium>Next</font></shadow></table>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=202434>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td abswidth=6>
|
||||
<td abswidth=93 absheight=26>
|
||||
<table
|
||||
xnocancel
|
||||
cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
<td abswidth=90 valign=middle align=left>
|
||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td absheight=1>
|
||||
<tr>
|
||||
<td maxlines=1><shadow><font color=5b4b58 sizerange=medium>Next New</font></shadow>
|
||||
</table>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=202434>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td abswidth=6>
|
||||
<td abswidth=93 absheight=26>
|
||||
<table
|
||||
cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
<td abswidth=90 valign=middle align=left>
|
||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td absheight=1>
|
||||
<tr>
|
||||
<td maxlines=1><shadow><font sizerange=medium color="5b4b58">Mail to</font></shadow>
|
||||
</table>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=202434>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td abswidth=6>
|
||||
<td abswidth=93 absheight=26>
|
||||
<table cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
<td abswidth=90 valign=middle align=left>
|
||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td absheight=1>
|
||||
<tr>
|
||||
<td maxlines=1><shadow><font sizerange=medium color="5b4b58">Respond</font></shadow>
|
||||
</table>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=202434>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td abswidth=6>
|
||||
<td abswidth=93 absheight=26>
|
||||
<table href="wtv-guide:/helpindex?title=Index_Mail&topic=2&subtopic=1"
|
||||
cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
<td abswidth=90 valign=middle align=left>
|
||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td absheight=1>
|
||||
<tr>
|
||||
<td maxlines=1><shadow><font sizerange=medium color="E7CE4A">Help</font></shadow>
|
||||
</table>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=202434>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 height=81 valign=bottom align=right>
|
||||
<tr><td colspan=3 absheight=36>
|
||||
</table>
|
||||
</sidebar>
|
||||
|
||||
<body
|
||||
bgcolor="191919"
|
||||
text="42BD52"
|
||||
link="189CD6"
|
||||
vlink="36d5ff"
|
||||
vspace=0>
|
||||
|
||||
<table cellspacing=0 cellpadding=0>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td colspan=3 height=16 valign=top align=left>
|
||||
|
||||
<td rowspan=100 width=20 height=384 valign=top align=left>
|
||||
|
||||
<tr>
|
||||
<td colspan=3 valign=top>
|
||||
<font color="E7CE4A">
|
||||
<blackface>
|
||||
<shadow>
|
||||
Posting
|
||||
</shadow>
|
||||
</blackface>
|
||||
</font>
|
||||
|
||||
</table>
|
||||
<br><br><br><br>
|
||||
|
||||
This posting is no longer available.
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -52,7 +52,7 @@ else {
|
||||
if (session_data.isRegistered()) {
|
||||
// check for SMTP Password
|
||||
if (session_data.getSessionData("subscriber_smtp_password") === null) {
|
||||
session_data.setUserSMTPPassword(session_data.generatePassword(16));
|
||||
session_data.setUserSMTPPassword(wtvshared.generatePassword(16));
|
||||
}
|
||||
if (session_data.user_id == 0) {
|
||||
var accounts = session_data.listPrimaryAccountUsers();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var minisrv_service_file = true;
|
||||
|
||||
var message_snapshot_data = null;
|
||||
var message_voicemail_data = null;
|
||||
|
||||
var intro_seen = session_data.mailstore.checkMailIntroSeen();
|
||||
if (!intro_seen && !request_headers.query.intro_seen) {
|
||||
// user is trying to bypass the intro screen
|
||||
@@ -19,29 +19,34 @@ if (!intro_seen && !request_headers.query.intro_seen) {
|
||||
return "200 OK\nwtv-visit: " + clientErrorMsg;
|
||||
}
|
||||
|
||||
if (request_headers.query.clear == "true") {
|
||||
session_data.deleteSessionData("mail_draft");
|
||||
session_data.deleteSessionData("mail_draft_attachments");
|
||||
headers = `300 OK
|
||||
wtv-expire: wtv-mail:/listmail
|
||||
wtv-expire: wtv-mail:/sendmail
|
||||
Location: wtv-mail:/sendmail`;
|
||||
}
|
||||
|
||||
var newsgroup = null;
|
||||
if (wtvshared.parseBool(request_headers.query.discuss)) {
|
||||
newsgroup = request_headers.query.group || request_headers.query.message_to || null;
|
||||
}
|
||||
|
||||
var gourl = "wtv-mail:/sendmail";
|
||||
|
||||
if (newsgroup !== null) {
|
||||
var to_addr = newsgroup;
|
||||
var pageTitle = "Post to " + newsgroup;
|
||||
var article = request_headers.query.article || null;
|
||||
var gourl = gourl + "?group=" + newsgroup;
|
||||
} else {
|
||||
var to_addr = request_headers.query.message_to || null;
|
||||
var pageTitle = "Write an e-mail message"
|
||||
}
|
||||
|
||||
if (request_headers.query.clear == "true") {
|
||||
session_data.deleteSessionData("usenet_draft");
|
||||
session_data.deleteSessionData("usenet_draft_attachments");
|
||||
session_data.deleteSessionData("mail_draft");
|
||||
session_data.deleteSessionData("mail_draft_attachments");
|
||||
headers = `300 OK
|
||||
wtv-expire: wtv-mail:/listmail
|
||||
wtv-expire: wtv-mail:/sendmail
|
||||
${gourl}`;
|
||||
}
|
||||
|
||||
var msg_subject = request_headers.query.message_subject || null;
|
||||
var msg_body = request_headers.query.message_body || null;
|
||||
var to_name = request_headers.query.whatever_webtv_sends_this_as || null;
|
||||
@@ -69,10 +74,11 @@ Location: wtv-mail:/sendmail`;
|
||||
mail_draft_attachments = session_data.getSessionData("usenet_draft_attachments") || {};
|
||||
if (mail_draft_data && !wtvshared.parseBool(request_headers.query.discuss)) {
|
||||
session_data.deleteSessionData("usenet_draft");
|
||||
if (mail_draft_data.to_addr) to_addr = request_headers.query.message_to || mail_draft_data.to_addr;
|
||||
if (mail_draft_data.msg_subject) msg_subject = request_headers.query.message_subject || mail_draft_data.msg_subject;
|
||||
if (mail_draft_data.msg_body) msg_body = request_headers.query.message_body || mail_draft_data.msg_body;
|
||||
if (mail_draft_data.no_signature) no_signature = mail_draft_data.no_signature;
|
||||
if (mail_draft_data.msg_url) newsgroup = newsgroup || mail_draft_data.msg_url;
|
||||
if (mail_draft_data.article) article = article || mail_draft_data.article;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,62 +121,114 @@ Content-Type: audio/wav`;
|
||||
|
||||
|
||||
if (message_snapshot_data) {
|
||||
if (typeof message_snapshot_data == "object") {
|
||||
attachments.push({ 'Content-Type': 'image/jpeg', data: new Buffer.from(message_snapshot_data).toString('base64') });
|
||||
} else {
|
||||
attachments.push({ 'Content-Type': 'image/jpeg', data: message_snapshot_data });
|
||||
var attachment = {
|
||||
'Content-Type': 'image/jpeg',
|
||||
'filename': 'snapshot.jpg'
|
||||
}
|
||||
if (typeof message_snapshot_data == "object") {
|
||||
attachment.data = new Buffer.from(message_snapshot_data).toString('base64');
|
||||
attachment.is_base64 = true;
|
||||
} else
|
||||
attachment.data = message_snapshot_data;
|
||||
|
||||
attachments.push(attachment);
|
||||
}
|
||||
|
||||
if (message_voicemail_data) {
|
||||
if (typeof message_voicemail_data == "object") {
|
||||
attachments.push({ 'Content-Type': 'audio/wav', data: new Buffer.from(message_voicemail_data).toString('base64') });
|
||||
} else {
|
||||
attachments.push({ 'Content-Type': 'audio/wav', data: new message_voicemail_data });
|
||||
var attachment = {
|
||||
'Content-Type': 'audio/wav',
|
||||
'filename': 'voicemail.wav'
|
||||
}
|
||||
|
||||
if (typeof message_voicemail_data == "object") {
|
||||
attachment.data = new Buffer.from(message_voicemail_data).toString('base64');
|
||||
attachment.is_base64 = true;
|
||||
} else
|
||||
attachment.data = message_voicemail_data;
|
||||
|
||||
attachments.push(attachment);
|
||||
}
|
||||
if (newsgroup !== null) {
|
||||
|
||||
if (newsgroup !== null) {
|
||||
var request_is_async = true;
|
||||
if (msg_body === null) {
|
||||
headers = doClientError("Please type a message to send to the group.");
|
||||
sendToClient(socket, headers, '');
|
||||
} else {
|
||||
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);
|
||||
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; }
|
||||
}
|
||||
from_addr = userdisplayname + " <" + from_addr + ">";
|
||||
wtvnews.postToGroup(newsgroup, from_addr, msg_subject, msg_body, article).then(() => {
|
||||
session_data.deleteSessionData("usenet_draft");
|
||||
session_data.deleteSessionData("usenet_draft_attachments");
|
||||
headers = `300 OK
|
||||
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 + ">";
|
||||
news_headers = null;
|
||||
if (signature && signature != "" && !no_signature) {
|
||||
var signature_tuple = null;
|
||||
if (signature.indexOf('<html>') >= 0) {
|
||||
attachments.push({
|
||||
"Content-Type": 'text/html',
|
||||
"data": signature,
|
||||
"use_base64": false,
|
||||
"filename": "wtv_signature.html"
|
||||
});
|
||||
} else {
|
||||
if (msg_body) msg_body += "\n" + signature;
|
||||
else msg_body = signature;
|
||||
}
|
||||
}
|
||||
|
||||
if (attachments.length > 0) {
|
||||
// usenet attachments
|
||||
var tuples = [{
|
||||
"mime": 'text/plain',
|
||||
"content": msg_body || '',
|
||||
"use_base64": false
|
||||
}];
|
||||
if (signature_tuple) tuples.push(signature_tuple);
|
||||
attachments.forEach((attachment) => {
|
||||
var tuple = {};
|
||||
tuple.mime = attachment['Content-Type'];
|
||||
tuple.content = attachment.data;
|
||||
tuple.use_base64 = (typeof attachment.use_base64 === 'boolean') ? attachment.use_base64 : true;
|
||||
tuple.is_base64 = (typeof attachment.is_base64 === 'boolean') ? attachment.is_base64 : false;
|
||||
tuple.filename = attachment.filename || null;
|
||||
tuples.push(tuple);
|
||||
});
|
||||
var multipart_data = wtvmime.generateMultipartMIME(tuples);
|
||||
news_headers = {
|
||||
"Content-Type": multipart_data.content_type,
|
||||
"MIME-Version": multipart_data.mime_version,
|
||||
"User-Agent": minisrv_version_string + " for WebTV",
|
||||
"Content-Language": "en-US"
|
||||
}
|
||||
msg_body = multipart_data.content.toString();
|
||||
}
|
||||
wtvnews.postToGroup(newsgroup, from_addr, msg_subject, msg_body, article, news_headers).then(() => {
|
||||
session_data.deleteSessionData("usenet_draft");
|
||||
session_data.deleteSessionData("usenet_draft_attachments");
|
||||
headers = `300 OK
|
||||
wtv-expire: wtv-news:/news?group=${newsgroup}
|
||||
wtv-expire: wtv-mail:/sendmail
|
||||
Location: wtv-news:/news?group=${newsgroup}`;
|
||||
sendToClient(socket, headers, '');
|
||||
}).catch((e) => {
|
||||
var err = this.wtvshared.doErrorPage(500,null,e.toString())
|
||||
sendToClient(socket, err[0], err[1]);
|
||||
});
|
||||
sendToClient(socket, headers, '');
|
||||
}).catch((e) => {
|
||||
var err = this.wtvshared.doErrorPage(500, null, e.toString())
|
||||
sendToClient(socket, err[0], err[1]);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
var messagereturn = session_data.mailstore.sendMessageToAddr(from_addr, to_addr, msg_body, msg_subject, userdisplayname, to_name, signature, attachments, msg_url, msg_url_title);
|
||||
if (messagereturn !== true) {
|
||||
@@ -195,10 +253,9 @@ Location: wtv-mail:/listmail`;
|
||||
no_signature: no_signature,
|
||||
msg_url: msg_url,
|
||||
msg_url_title: msg_url_title,
|
||||
newsgroup: newsgroup,
|
||||
article: article
|
||||
}
|
||||
session_data.setSessionData("mail_draft", mail_draft_data);
|
||||
if (newsgroup) mail_draft_data.article = article;
|
||||
session_data.setSessionData((newsgroup) ? "usenet_draft" : "mail_draft", mail_draft_data);
|
||||
headers = `200 OK
|
||||
Content-type: text/html
|
||||
wtv-expire: wtv-mail:/sendmail`;
|
||||
@@ -207,27 +264,27 @@ wtv-expire: wtv-mail:/sendmail`;
|
||||
|
||||
headers = `200 OK
|
||||
Content-type: text/html`;
|
||||
var mail_draft_data = session_data.getSessionData("mail_draft_attachments") || {};
|
||||
var mail_draft_data = session_data.getSessionData((newsgroup) ? "usenet_draft_attachments" : "mail_draft_attachments") || {};
|
||||
if (request_headers.query.snapping == "false") {
|
||||
headers += "\nwtv-expire: cache:snapshot.jpg";
|
||||
if (mail_draft_data.message_snapshot_data) mail_draft_data.message_snapshot_data = null;
|
||||
session_data.setSessionData("mail_draft_attachments", mail_draft_data);
|
||||
session_data.setSessionData((newsgroup) ? "usenet_draft_attachments" : "mail_draft_attachments", mail_draft_data);
|
||||
}
|
||||
|
||||
if (request_headers.query.gabbing == "false") {
|
||||
headers += "\nwtv-expire: cache:voicemail.wav";
|
||||
if (mail_draft_data.message_voicemail_data) mail_draft_data.message_voicemail_data = null;
|
||||
session_data.setSessionData("mail_draft_attachments", mail_draft_data);
|
||||
session_data.setSessionData((newsgroup) ? "usenet_draft_attachments" : "mail_draft_attachments", mail_draft_data);
|
||||
}
|
||||
|
||||
if (request_headers.query.message_snapshot_data) {
|
||||
mail_draft_data.message_snapshot_data = request_headers.query.message_snapshot_data
|
||||
session_data.setSessionData("mail_draft_attachments", mail_draft_data);
|
||||
session_data.setSessionData((newsgroup) ? "usenet_draft_attachments" : "mail_draft_attachments", mail_draft_data);
|
||||
}
|
||||
|
||||
if (request_headers.query.message_voicemail_data) {
|
||||
mail_draft_data.message_voicemail_data = request_headers.query.message_voicemail_data
|
||||
session_data.setSessionData("mail_draft_attachments", mail_draft_data);
|
||||
session_data.setSessionData((newsgroup) ? "usenet_draft_attachments" : "mail_draft_attachments", mail_draft_data);
|
||||
}
|
||||
var message_colors = null;
|
||||
if (no_signature) message_colors = session_data.mailstore.getSignatureColors(null, true);
|
||||
@@ -276,7 +333,7 @@ ${pageTitle}
|
||||
<input type=hidden name="message_reply_all_cc" value="">
|
||||
${(request_headers.query.article) ? `<input type="hidden" name="article" value="${request_headers.query.article}">` : ''}
|
||||
<input type=hidden name="saveoff" value="true" autosubmit="onleave">
|
||||
<input type=hidden name="discuss" value="${request_headers.query.discuss ? true : false}">
|
||||
<input type=hidden name="discuss" value="${wtvshared.parseBool(request_headers.query.discuss)}">
|
||||
<sidebar width=109>
|
||||
<table cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
@@ -609,7 +666,7 @@ USESTYLE NOARGS>
|
||||
data += `
|
||||
</td></tr><tr>
|
||||
<td colspan="2" align="center">
|
||||
<img src="${(mail_draft_attachments.message_snapshot_data) ? 'wtv-mail:/sendmail?get_snap=true' : 'cache:snapshot.jpg'}" width="380" height="290">
|
||||
<img src="${(mail_draft_attachments.message_snapshot_data) ? 'wtv-mail:/sendmail?get_snap=true' : (request_headers.query.message_snapshot_url) ? request_headers.query.message_snapshot_url : 'cache:snapshot.jpg'}" width="380" height="290">
|
||||
</td></tr><tr>
|
||||
<td colspan="2" abswidth="386" absheight="10">
|
||||
</td></tr><tr>
|
||||
|
||||
@@ -37,7 +37,7 @@ data = `<HTML>
|
||||
<tr>
|
||||
<td abswidth=6 >
|
||||
<td abswidth=93 absheight=26 >
|
||||
<table href="wtv-news:news?category=1"
|
||||
<table href="wtv-news:/news?category=1"
|
||||
cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
@@ -147,7 +147,7 @@ data += `
|
||||
<td abswidth=416 valign=top align=left>
|
||||
Type a discussion topic<br>
|
||||
<img src="/ROMCache/Spacer.gif" width=1 height=4>
|
||||
<form action="wtv-news:search">
|
||||
<form action="wtv-news:/news" method="GET">
|
||||
<input name="search" bgcolor=#202020 cursor=#cc9933 text="E7CE4A" font=proportional value="" SIZE=28 MAXLENGTH=100>
|
||||
|
||||
<font color=E7CE4A><shadow>
|
||||
|
||||
@@ -90,6 +90,30 @@ top.location="news:${request_headers.query.group}";
|
||||
<tr>
|
||||
<td abswidth=6 >
|
||||
<td abswidth=93 absheight=26 >
|
||||
<table href="wtv-news:/lobby"
|
||||
cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
<td abswidth=90 valign=middle align=left>
|
||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td absheight=1>
|
||||
<tr>
|
||||
<td maxlines=1>
|
||||
<shadow><font sizerange=medium color="E7CE4A">Lobby</font></shadow></table>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=231d22>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left <img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td abswidth=6 >
|
||||
<td abswidth=93 absheight=26 >
|
||||
<table href="wtv-mail:/sendmail?discuss=true&group=${request_headers.query.group}&discuss-prefix=${service_name}"
|
||||
cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
@@ -136,7 +160,7 @@ cellspacing=0 cellpadding=0>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 height=237 valign=bottom align=right >
|
||||
<td colspan=3 height=207 valign=bottom align=right >
|
||||
<img src="wtv-news:/images/BannerDiscuss.gif" width=50 height=165> <tr><td colspan=3 absheight=36>
|
||||
</table>
|
||||
</sidebar>
|
||||
@@ -270,11 +294,23 @@ ${(message.headers.FROM.indexOf(' ') > 0) ? message.headers.FROM.split(' ')[0] :
|
||||
</HTML>`;
|
||||
|
||||
sendToClient(socket, headers, data);
|
||||
}).catch((e) => { throwError(e) });;
|
||||
}).catch((e) => {
|
||||
// getHeaderObj err
|
||||
throwError(e)
|
||||
});;
|
||||
}
|
||||
}).catch((e) => { throwError(e) });;
|
||||
}).catch((e) => { throwError(e) });;
|
||||
}).catch((e) => { throwError(e) });
|
||||
}).catch((e) => {
|
||||
// listGroup error
|
||||
throwError(e)
|
||||
});;
|
||||
}).catch((e) => {
|
||||
// selectGroup error
|
||||
throwError(e)
|
||||
});
|
||||
}).catch((e) => {
|
||||
// connect error
|
||||
throwError(e)
|
||||
});
|
||||
}
|
||||
|
||||
async function WebTVShowMessage(group, article) {
|
||||
@@ -283,13 +319,30 @@ async function WebTVShowMessage(group, article) {
|
||||
wtvnews.selectGroup(group).then((response) => {
|
||||
wtvnews.getArticle(article).then((response) => {
|
||||
wtvnews.quitUsenet();
|
||||
if (response.code == 220) {
|
||||
headers = `200 OK
|
||||
headers = `200 OK
|
||||
Content-type: text/html
|
||||
wtv-expire-all: wtv-news:/news?group=${group}&article=`;
|
||||
var message_colors = session_data.mailstore.defaultColors;
|
||||
var signature = null;
|
||||
var message_colors = session_data.mailstore.defaultColors;
|
||||
var display_signature = true; // todo make a toggle
|
||||
var message = wtvnews.parseAttachments(response);
|
||||
var message_body = message.text;
|
||||
var attachments = null;
|
||||
var signature_index = null;
|
||||
if (message.attachments) attachments = message.attachments;
|
||||
Object.keys(attachments).forEach((k) => {
|
||||
if (attachments[k].filename == "wtv_signature.html" && attachments[k].content_type.match(/text\/html/)) {
|
||||
signature = attachments[k].data;
|
||||
signature_index = k;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
attachments.splice(signature_index, 1);
|
||||
console.log(signature)
|
||||
|
||||
data = `<head>
|
||||
if (signature) message_colors = session_data.mailstore.getSignatureColors(signature);
|
||||
|
||||
data = `<head>
|
||||
<sendpanel
|
||||
action="wtv-mail:/sendmail?message_forward_id=1&mailbox_name=inbox"
|
||||
message="Forward this post to someone else."
|
||||
@@ -525,13 +578,13 @@ ${strftime("%a, %b %e, %Y, %I:%M%P", new Date(Date.parse(response.article.header
|
||||
<td valign=top>
|
||||
From:
|
||||
<td>`;
|
||||
// if (message.from_name != message.from_addr) {
|
||||
// data += `<a href="client:showalert?sound=none&message=Would%20you%20like%20to%20add%20%3Cblackface%3E${wtvshared.htmlEntitize(message.from_name)}%3C%2Fblackface%3E%20to%20your%20address%20list%3F&buttonlabel2=No&buttonaction2=client:donothing&buttonlabel1=Yes&buttonaction1=wtv-mail:/addressbook%3Faction%3Deditfromheader%26noresponse%3Dtrue%26nickname%3D${escape(escape(message.from_name))}%26address%3D${escape(escape(message.from_addr))}%26new_address%3Dtrue">${wtvshared.htmlEntitize(message.from_addr)} </a>`;
|
||||
// } else {
|
||||
data += `${wtvshared.htmlEntitize(response.article.headers.FROM)}`;
|
||||
// }
|
||||
// if (message.from_name != message.from_addr) {
|
||||
// data += `<a href="client:showalert?sound=none&message=Would%20you%20like%20to%20add%20%3Cblackface%3E${wtvshared.htmlEntitize(message.from_name)}%3C%2Fblackface%3E%20to%20your%20address%20list%3F&buttonlabel2=No&buttonaction2=client:donothing&buttonlabel1=Yes&buttonaction1=wtv-mail:/addressbook%3Faction%3Deditfromheader%26noresponse%3Dtrue%26nickname%3D${escape(escape(message.from_name))}%26address%3D${escape(escape(message.from_addr))}%26new_address%3Dtrue">${wtvshared.htmlEntitize(message.from_addr)} </a>`;
|
||||
// } else {
|
||||
data += `${wtvshared.htmlEntitize(response.article.headers.FROM)}`;
|
||||
// }
|
||||
|
||||
data += `<tr>
|
||||
data += `<tr>
|
||||
<td nowrap valign=top>
|
||||
<td>
|
||||
</table>
|
||||
@@ -544,68 +597,259 @@ ${(response.article.headers.SUBJECT) ? wtvshared.htmlEntitize(response.article.h
|
||||
<td abswidth=20 rowspan=99>
|
||||
<tr>
|
||||
<td>
|
||||
`;
|
||||
var message = wtvnews.parseAttachments(response);
|
||||
var message_body = message.text;
|
||||
var attachments = null;
|
||||
if (message.attachments) attachments = message.attachments;
|
||||
data += `
|
||||
`
|
||||
data += `
|
||||
${wtvshared.htmlEntitize(message_body, true)}
|
||||
<br>
|
||||
<br>`;
|
||||
data += "<p>";
|
||||
|
||||
if (attachments) {
|
||||
var supported_images = /image\/(jpe?g|png|gif|x-wtv-bitmap)/;
|
||||
var supported_audio = /audio\/(mp[eg|2|3]|midi?|wav|x-wav|mod|x-mod)/;
|
||||
attachments.forEach((v, k) => {
|
||||
if (v.content_type) {
|
||||
if (v.content_type.match(supported_images))
|
||||
data += `<img border=2 src="wtv-news:/get-attachment?group=${group}&article=${article}&attachment_id=${k}&wtv-title=Video%20Snapshot"><br><br>`;
|
||||
else if (v.content_type.match(supported_audio))
|
||||
data += `<table href="wtv-news:/get-attachment?group=${group}&article=${article}&attachment_id=${k}&wtv-title=${(v.filename) ? encodeURIComponent(v.filename) : "Audio%20file"}" width=386 cellspacing=0 cellpadding=0>
|
||||
if (signature) data += wtvshared.sanitizeSignature(signature);
|
||||
data += "<p>";
|
||||
|
||||
if (attachments) {
|
||||
var supported_images = /image\/(jpe?g|png|gif|x-wtv-bitmap)/;
|
||||
var supported_audio = /audio\/(mp[eg|2|3]|midi?|wav|x-wav|mod|x-mod)/;
|
||||
attachments.forEach((v, k) => {
|
||||
if (v.content_type) {
|
||||
if (v.content_type.match(supported_images))
|
||||
data += `<img border=2 src="wtv-news:/get-attachment?group=${group}&article=${article}&attachment_id=${k}&wtv-title=Video%20Snapshot"><br><br>`;
|
||||
else if (v.content_type.match(supported_audio))
|
||||
data += `<table href="wtv-news:/get-attachment?group=${group}&article=${article}&attachment_id=${k}&wtv-title=${(v.filename) ? encodeURIComponent(v.filename) : "Audio%20file"}" width=386 cellspacing=0 cellpadding=0>
|
||||
<td align=left valign=middle><img src="wtv-news:/ROMCache/FileSound.gif" align=absmiddle><font color="#189CD6"> ${(v.filename) ? (v.filename) : "Audio file"} (${v.content_type.split('/')[1]} attachment)</font>
|
||||
<td align=right valign=middle>
|
||||
</table><br><br>`;
|
||||
else
|
||||
data += `<table width=386><td><td align=left valign=middle><font color="#565656"><i>A file ${(v.filename) ? `(${v.filename}) ` : ''}that WebTV cannot use, with type ${v.content_type} is attached to this message.</i></font>`
|
||||
}
|
||||
});
|
||||
}
|
||||
/*
|
||||
if (message.url) {
|
||||
data += `Included Page: <a href="${(message.url)}">${wtvshared.htmlEntitize(message.url_title).replace(/'/gi, "'")}`;
|
||||
}
|
||||
*/
|
||||
data += "</table></body></html>";
|
||||
sendToClient(socket, headers, data);
|
||||
|
||||
} else {
|
||||
throwError("invalid response code. expected: 220, received:", response.code);
|
||||
else
|
||||
data += `<table width=386><td><td align=left valign=middle><font color="#565656"><i>A file ${(v.filename) ? `(${v.filename}) ` : ''}that WebTV cannot use, with type ${v.content_type} is attached to this message.</i></font>`
|
||||
}
|
||||
});
|
||||
}
|
||||
/*
|
||||
if (message.url) {
|
||||
data += `Included Page: <a href="${(message.url)}">${wtvshared.htmlEntitize(message.url_title).replace(/'/gi, "'")}`;
|
||||
}
|
||||
*/
|
||||
data += "</table></body></html>";
|
||||
sendToClient(socket, headers, data);
|
||||
|
||||
}).catch((e) => {
|
||||
throwError(e);
|
||||
// no such article
|
||||
var post_unavailable_file = this.wtvshared.getAbsolutePath(this.minisrv_config.config.ServiceDeps + '/wtv-news/post-unavailable.html');
|
||||
if (fs.existsSync(post_unavailable_file)) {
|
||||
headers = "200 OK\nContent-type: text/html";
|
||||
data = fs.readFileSync(post_unavailable_file).toString('ascii').replace("${group}", group).replace("${minisrv_config.config.service_logo}", minisrv_config.config.service_logo).replace("${message_colors.bgcolor}",session_data.mailstore.defaultColors.bgcolor);
|
||||
sendToClient(socket, headers, data);
|
||||
} else {
|
||||
throwError(e);
|
||||
}
|
||||
});
|
||||
}).catch((e) => {
|
||||
// no such group
|
||||
throwError(e);
|
||||
});
|
||||
}).catch((e) => {
|
||||
//no connection
|
||||
throwError(e);
|
||||
});;
|
||||
});
|
||||
}
|
||||
|
||||
function WebTVSearchGroups(search) {
|
||||
console.log('WebTVSearchGroups init')
|
||||
wtvnews.connectUsenet().then(() => {
|
||||
console.log('WebTVSearchGroups connected')
|
||||
wtvnews.listGroups(search).then((response) => {
|
||||
console.log('WebTVSearchGroups listGroups response', response)
|
||||
wtvnews.quitUsenet();
|
||||
headers = `200 OK
|
||||
Content-type: text/html
|
||||
wtv-expire-all: wtv-news:/news?search=`;
|
||||
|
||||
data = `<HTML>
|
||||
<HEAD>
|
||||
<DISPLAY fontsize=medium>
|
||||
<TITLE>${(response.length == 0) ? "No " : ""}Discussion groups found</TITLE>
|
||||
</HEAD>
|
||||
<sidebar width=114 height=420 align=left>
|
||||
<table cellspacing=0 cellpadding=0 bgcolor=3d2f3a>
|
||||
<tr>
|
||||
<td colspan=3 width=104 absheight=4>
|
||||
<td rowspan=100 width=10 height=420 valign=top align=left bgcolor=191919>
|
||||
<img src="wtv-mail:/ROMCache/Shadow.gif" width=6 height=420>
|
||||
<tr>
|
||||
<td abswidth=6>
|
||||
<td abswidth=93 absheight=76>
|
||||
<table href="wtv-home:/home" absheight=76 cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td align=right>
|
||||
<img src="${minisrv_config.config.service_logo}" width=87 height=67>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=231d22>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left <img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td abswidth=6 >
|
||||
<td abswidth=93 absheight=26 >
|
||||
<table href="wtv-news:/news?category=1"
|
||||
cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
<td abswidth=90 valign=middle align=left>
|
||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td absheight=1>
|
||||
<tr>
|
||||
<td maxlines=1>
|
||||
<shadow><font sizerange=medium color="E7CE4A">All groups</font></shadow></table>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=231d22>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left <img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td abswidth=6 >
|
||||
<td abswidth=93 absheight=26 >
|
||||
<table href="wtv-guide:/help?topic=Discuss&subtopic=Index&appName=Discuss"
|
||||
cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=5>
|
||||
<td abswidth=90 valign=middle align=left>
|
||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td absheight=1>
|
||||
<tr>
|
||||
<td maxlines=1>
|
||||
<shadow><font sizerange=medium color="E7CE4A">Help</font></shadow></table>
|
||||
</table>
|
||||
<td abswidth=5>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=middle align=center bgcolor=231d22>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=1 valign=top align=left <img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 absheight=2 valign=top align=left bgcolor=5b4b58>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr>
|
||||
<td colspan=3 height=237 valign=bottom align=right >
|
||||
<img src="wtv-news:/images/BannerDiscuss.gif" width=50 height=165>
|
||||
<tr><td colspan=3 absheight=36>
|
||||
</table>
|
||||
</sidebar>
|
||||
<body
|
||||
bgcolor="191919" text="42BD52" link="189CD6"
|
||||
vlink="189CD6"
|
||||
hspace=0
|
||||
vspace=0>
|
||||
<table cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=10>
|
||||
<td colspan=3>
|
||||
<table cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td valign=center absheight=80>
|
||||
<font size="+2" color="E7CE4A"><blackface><shadow>
|
||||
${(response.length == 0) ? "No " : ""}Discussion groups found
|
||||
</table>
|
||||
<td abswidth=20>
|
||||
<tr>
|
||||
<td>
|
||||
<td WIDTH=198 HEIGHT=200 VALIGN=top ALIGN=left>`;
|
||||
|
||||
if (response.length == 0) {
|
||||
data += `There are no discussion groups that match your request. Do you want to look for something else?`;
|
||||
} else {
|
||||
response.forEach((group) => {
|
||||
data += `<hr width=436>
|
||||
<IMG src="wtv-home:/ROMCache/Spacer.gif" width=1 height=6><br>
|
||||
<table cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td width=10>
|
||||
<td width=426> <table href="wtv-news:/news?group=${group.name}" selected cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td abswidth=401 height=19 valign=top>
|
||||
<shadow><b>${group.name}</table>
|
||||
<td width=10>
|
||||
|
||||
`
|
||||
if (group.description) {
|
||||
data += `<tr><td colspan=3 width=10 height=6><tr><td width=10><td colspan=99><i><font color=828282>${group.description}</font></i>`
|
||||
}
|
||||
data += "</table>";
|
||||
});
|
||||
}
|
||||
|
||||
data += `
|
||||
</table>
|
||||
<TABLE width=446 cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td rowspan=3 width=10 height=1>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=10 height=1>
|
||||
<td height=2 width=436 bgcolor="2B2B2B">
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=436 height=1>
|
||||
<tr>
|
||||
<td height=1>
|
||||
<tr>
|
||||
<td height=2 bgcolor="0D0D0D">
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
</TABLE>
|
||||
<table cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td rowspan=2 abswidth=10>
|
||||
<td absheight=10>
|
||||
<tr>
|
||||
<td abswidth=416 valign=top align=left>
|
||||
Do you want to look for something else?<br>
|
||||
<img src="/ROMCache/Spacer.gif" width=1 height=4>
|
||||
<form action="wtv-news:search">
|
||||
<input name="search" bgcolor=#202020 cursor=#cc9933 text="E7CE4A" font=proportional value="" SIZE=28 MAXLENGTH=100>
|
||||
|
||||
<font color=E7CE4A><shadow>
|
||||
<input type=submit borderimage="file://ROM/Borders/ButtonBorder2.bif" value="Look for" usestyle>
|
||||
</shadow></font>
|
||||
</form>
|
||||
</table>
|
||||
</BODY>
|
||||
</HTML>`;
|
||||
sendToClient(socket, headers, data);
|
||||
}).catch((e) => {
|
||||
// listGroups error
|
||||
throwError(e);
|
||||
});
|
||||
|
||||
}).catch((e) => {
|
||||
// no connection
|
||||
throwError(e);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (!wtvnews.client) {
|
||||
var errpage = doErrorPage();
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
} else {
|
||||
var request_is_async = true;
|
||||
if (request_headers.query.group) {
|
||||
if (request_headers.query.search) {
|
||||
WebTVSearchGroups(request_headers.query.search)
|
||||
} else if (request_headers.query.group) {
|
||||
if (request_headers.query.article) {
|
||||
WebTVShowMessage(request_headers.query.group, request_headers.query.article);
|
||||
} else {
|
||||
WebTVListGroup(request_headers.query.group);
|
||||
}
|
||||
} else {
|
||||
// redirect to lobby if no understandable queries passed
|
||||
headers = "300 OK\nLocation: wtv-news:/lobby";
|
||||
sendToClient(socket, headers, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1009,7 +1009,7 @@ function headerStringToObj(headers, response = false) {
|
||||
async function sendToClient(socket, headers_obj, data) {
|
||||
var headers = "";
|
||||
var content_length = 0;
|
||||
if (typeof (data) === 'undefined') data = '';
|
||||
if (typeof (data) === 'undefined' || data === null) data = '';
|
||||
if (typeof (headers_obj) === 'string') {
|
||||
// string to header object
|
||||
headers_obj = headerStringToObj(headers_obj, true);
|
||||
|
||||
29140
zefie_wtvp_minisrv/fuck.txt
Normal file
29140
zefie_wtvp_minisrv/fuck.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
|
||||
@@ -14,6 +14,7 @@ const wtvshared = new WTVShared(); // creates minisrv_config
|
||||
classPath = wtvshared.getAbsolutePath(classPath, __dirname);
|
||||
const minisrv_config = wtvshared.getMiniSrvConfig();
|
||||
const WTVNews = require(classPath + "/WTVNews.js");
|
||||
const WTVNewsServer = require(classPath + "/WTVNewsServer.js");
|
||||
var data_path = wtvshared.getAbsolutePath(minisrv_config.config.SessionStore + '/minisrv_internal_nntp');
|
||||
const service_name = "wtv-news";
|
||||
|
||||
@@ -31,6 +32,8 @@ if (!minisrv_config.config.debug_flags.quiet) console.log(" *** Successfully rea
|
||||
|
||||
|
||||
const service_config = minisrv_config.services[service_name];
|
||||
const wtvnewsserver = new WTVNewsServer(minisrv_config, minisrv_config.services['wtv-news'].local_server_port, false, null, null, false);
|
||||
|
||||
const wtvnews = new WTVNews(minisrv_config, service_name);
|
||||
|
||||
if (service_config.upstream_auth) {
|
||||
@@ -41,37 +44,8 @@ if (service_config.upstream_auth) {
|
||||
|
||||
|
||||
|
||||
function createDataStore() {
|
||||
if (!fs.existsSync(data_path)) return fs.mkdirSync(data_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
function getGroupPath(group) {
|
||||
return data_path + path.sep + group;
|
||||
}
|
||||
|
||||
function createGroup(group) {
|
||||
createDataStore();
|
||||
if (!fs.existsSync(getGroupPath(group))) return fs.mkdirSync(getGroupPath(group));
|
||||
return true;
|
||||
}
|
||||
|
||||
function createArticle(group, articleNumber, article) {
|
||||
var g = getGroupPath(group);
|
||||
var file = g + path.sep + articleNumber + ".newz";
|
||||
if (verifyMessage(group, articleNumber, article)) return "exists";
|
||||
else {
|
||||
try {
|
||||
fs.writeFileSync(file, JSON.stringify(article.article));
|
||||
return file;
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function verifyMessage(group, articleNumber, article) {
|
||||
var g = getGroupPath(group);
|
||||
var g = wtvnewsserver.getGroupPath(group);
|
||||
var file = g + path.sep + articleNumber + ".newz";
|
||||
if (!fs.existsSync(file)) return false;
|
||||
var old_data = fs.readFileSync(file);
|
||||
@@ -83,7 +57,7 @@ function verifyMessage(group, articleNumber, article) {
|
||||
}
|
||||
|
||||
function deleteMissing(group, articles) {
|
||||
var g = getGroupPath(group);
|
||||
var g = wtvnewsserver.getGroupPath(group);
|
||||
try {
|
||||
fs.readdirSync(g).forEach(file => {
|
||||
var articleNumber = parseInt(file.split('.')[0]);
|
||||
@@ -112,12 +86,15 @@ wtvnews.connectUsenet().then((res) => {
|
||||
wtvnews.listGroup(group, null, null, range).then((res) => {
|
||||
if (res.group.articleNumbers) {
|
||||
var promises = [];
|
||||
createGroup(group);
|
||||
deleteMissing(group, res.group.articleNumbers)
|
||||
wtvnewsserver.createGroup(group);
|
||||
var meta = wtvnewsserver.getMetadata(group);
|
||||
meta.last_article_id = res.group.high;
|
||||
wtvnewsserver.saveMetadata(group, meta);
|
||||
//deleteMissing(group, res.group.articleNumbers)
|
||||
res.group.articleNumbers.forEach((article) => {
|
||||
promises.push(new Promise((resolve, reject) => {
|
||||
wtvnews.getArticle(article, false).then((message) => {
|
||||
res = createArticle(group, article, message);
|
||||
res = wtvnewsserver.createArticle(group, article, message);
|
||||
if (res) {
|
||||
if (res == "exists") {
|
||||
console.log(" * ", group, "article", article, "already exists")
|
||||
|
||||
@@ -1193,6 +1193,7 @@
|
||||
<Folder Include="ServiceDeps\wtv-guide\prerendered\Users\AddUser\" />
|
||||
<Folder Include="ServiceDeps\wtv-guide\prerendered\WhatIs\" />
|
||||
<Folder Include="ServiceDeps\wtv-guide\templates\" />
|
||||
<Folder Include="ServiceDeps\wtv-news\" />
|
||||
<Folder Include="ServiceVault\" />
|
||||
<Folder Include="ServiceVault\http_pc\" />
|
||||
<Folder Include="ServiceVault\http_pc\viewergen\" />
|
||||
|
||||
Reference in New Issue
Block a user