wtv-news goodies
@@ -36,6 +36,7 @@ Location: wtv-mail:/sendmail`;
|
|||||||
if (newsgroup !== null) {
|
if (newsgroup !== null) {
|
||||||
var to_addr = newsgroup;
|
var to_addr = newsgroup;
|
||||||
var pageTitle = "Post to " + newsgroup;
|
var pageTitle = "Post to " + newsgroup;
|
||||||
|
var article = request_headers.query.article || null;
|
||||||
} else {
|
} else {
|
||||||
var to_addr = request_headers.query.message_to || null;
|
var to_addr = request_headers.query.message_to || null;
|
||||||
var pageTitle = "Write an e-mail message"
|
var pageTitle = "Write an e-mail message"
|
||||||
@@ -48,17 +49,31 @@ Location: wtv-mail:/sendmail`;
|
|||||||
var msg_url_title = request_headers.query.message_title || null;
|
var msg_url_title = request_headers.query.message_title || null;
|
||||||
var no_signature = false;
|
var no_signature = false;
|
||||||
|
|
||||||
var mail_draft_data = session_data.getSessionData("mail_draft");
|
|
||||||
var mail_draft_attachments = session_data.getSessionData("mail_draft_attachments") || {};
|
mail_draft_data = {};
|
||||||
if (mail_draft_data) {
|
mail_draft_attachments = {};
|
||||||
|
if (!wtvshared.parseBool(request_headers.query.discuss)) {
|
||||||
|
mail_draft_data = session_data.getSessionData("mail_draft");
|
||||||
|
mail_draft_attachments = session_data.getSessionData("mail_draft_attachments") || {};
|
||||||
|
if (mail_draft_data && !wtvshared.parseBool(request_headers.query.discuss)) {
|
||||||
session_data.deleteSessionData("mail_draft");
|
session_data.deleteSessionData("mail_draft");
|
||||||
if (mail_draft_data.to_addr) to_addr = mail_draft_data.to_addr;
|
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 = mail_draft_data.msg_subject;
|
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 = mail_draft_data.msg_body;
|
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.no_signature) no_signature = mail_draft_data.no_signature;
|
||||||
if (mail_draft_data.msg_url) msg_url = mail_draft_data.msg_url;
|
if (mail_draft_data.msg_url) msg_url = request_headers.query.message_url || mail_draft_data.msg_url;
|
||||||
if (mail_draft_data.msg_url_title) msg_url_title = mail_draft_data.msg_url_title;
|
if (mail_draft_data.msg_url_title) msg_url_title = request_headers.query.message_title || mail_draft_data.msg_url_title;
|
||||||
if (mail_draft.data.newsgroup) newsgroup = mail_draft_data.newsgroup;
|
}
|
||||||
|
} else {
|
||||||
|
mail_draft_data = session_data.getSessionData("usenet_draft");
|
||||||
|
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.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 (request_headers.query.togglesign == "true") no_signature = false;
|
if (request_headers.query.togglesign == "true") no_signature = false;
|
||||||
@@ -120,59 +135,21 @@ Content-Type: audio/wav`;
|
|||||||
headers = doClientError("Please type a message to send to the group.");
|
headers = doClientError("Please type a message to send to the group.");
|
||||||
sendToClient(socket, headers, '');
|
sendToClient(socket, headers, '');
|
||||||
} else {
|
} else {
|
||||||
const Client = require('newsie').default
|
const wtvnews = new WTVNews(minisrv_config, request_headers.query['discuss-prefix'] || "wtv-news");
|
||||||
const client = new Client({
|
from_addr = userdisplayname + " <" + from_addr + ">";
|
||||||
host: minisrv_config.services[request_headers.query['discuss-prefix'] || "wtv-news"].upstream_address,
|
wtvnews.postToGroup(newsgroup, from_addr, msg_subject, msg_body, article).then(() => {
|
||||||
port: minisrv_config.services[request_headers.query['discuss-prefix'] || "wtv-news"].upstream_port
|
session_data.deleteSessionData("usenet_draft");
|
||||||
})
|
session_data.deleteSessionData("usenet_draft_attachments");
|
||||||
|
|
||||||
client.connect()
|
|
||||||
.then(response => {
|
|
||||||
return client.post()
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.code == 340) {
|
|
||||||
var articleData = {};
|
|
||||||
articleData.headers = {
|
|
||||||
'Relay-Version': "version zefie_wtvp_minisrv " + minisrv_config.version + "; site " + minisrv_config.config.domain_name,
|
|
||||||
'Posting-Version': "version zefie_wtvp_minisrv " + minisrv_config.version + "; site " + minisrv_config.config.domain_name,
|
|
||||||
'Path': "@" + minisrv_config.config.domain_name,
|
|
||||||
'From': from_addr,
|
|
||||||
'Newsgroups': newsgroup,
|
|
||||||
'Subject': msg_subject || "(No subject)",
|
|
||||||
'Message-ID': "<"+session_data.generatePassword(16) + "@" + minisrv_config.config.domain_name+">",
|
|
||||||
'Date': strftime('%A, %d-%b-%y %k:%M:%S %z', new Date())
|
|
||||||
}
|
|
||||||
if (msg_body) {
|
|
||||||
articleData.body = msg_body.split("\n");
|
|
||||||
} else {
|
|
||||||
articleData.body = [];
|
|
||||||
}
|
|
||||||
return response.send(articleData);
|
|
||||||
} else {
|
|
||||||
headers = doClientError("Could not send post. Server returned error " + response.code);
|
|
||||||
sendToClient(socket, headers, '');
|
|
||||||
return client.quit();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.code !== 240) {
|
|
||||||
headers = doClientError("Could not send post. Server returned error " + response.code);
|
|
||||||
sendToClient(socket, headers, '');
|
|
||||||
} else {
|
|
||||||
headers = `300 OK
|
headers = `300 OK
|
||||||
wtv-expire: wtv-news:/news?group=${newsgroup}
|
wtv-expire: wtv-news:/news?group=${newsgroup}
|
||||||
wtv-expire: wtv-mail:/sendmail
|
wtv-expire: wtv-mail:/sendmail
|
||||||
Location: wtv-news:/news?group=${newsgroup}`;
|
Location: wtv-news:/news?group=${newsgroup}`;
|
||||||
sendToClient(socket, headers, '');
|
sendToClient(socket, headers, '');
|
||||||
return client.quit()
|
}).catch((e) => {
|
||||||
}
|
var err = this.wtvshared.doErrorPage(500,null,e.toString())
|
||||||
}).catch(e => {
|
sendToClient(socket, err[0], err[1]);
|
||||||
console.log('usenet upstream uncaught error', e);
|
|
||||||
headers = doClientError("Could not send post. Server returned unknown error");
|
|
||||||
|
|
||||||
sendToClient(socket, headers, '');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
var messagereturn = session_data.mailstore.sendMessageToAddr(from_addr, to_addr, msg_body, msg_subject, userdisplayname, to_name, signature, attachments, msg_url, msg_url_title);
|
||||||
@@ -198,7 +175,8 @@ Location: wtv-mail:/listmail`;
|
|||||||
no_signature: no_signature,
|
no_signature: no_signature,
|
||||||
msg_url: msg_url,
|
msg_url: msg_url,
|
||||||
msg_url_title: msg_url_title,
|
msg_url_title: msg_url_title,
|
||||||
newsgroup: newsgroup
|
newsgroup: newsgroup,
|
||||||
|
article: article
|
||||||
}
|
}
|
||||||
session_data.setSessionData("mail_draft", mail_draft_data);
|
session_data.setSessionData("mail_draft", mail_draft_data);
|
||||||
headers = `200 OK
|
headers = `200 OK
|
||||||
@@ -276,6 +254,7 @@ ${pageTitle}
|
|||||||
<form action="wtv-mail:/sendmail#focus" method="post" name=sendform >
|
<form action="wtv-mail:/sendmail#focus" method="post" name=sendform >
|
||||||
<input type=hidden name="wtv-saved-message-id" value="writemessage-outbox">
|
<input type=hidden name="wtv-saved-message-id" value="writemessage-outbox">
|
||||||
<input type=hidden name="message_reply_all_cc" value="">
|
<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="saveoff" value="true" autosubmit="onleave">
|
||||||
<input type=hidden name="discuss" value="${request_headers.query.discuss ? true : false}">
|
<input type=hidden name="discuss" value="${request_headers.query.discuss ? true : false}">
|
||||||
<sidebar width=109>
|
<sidebar width=109>
|
||||||
@@ -300,12 +279,22 @@ ${pageTitle}
|
|||||||
<tr>
|
<tr>
|
||||||
<td width=10 height=26>
|
<td width=10 height=26>
|
||||||
<td width=89 valgn=middle>
|
<td width=89 valgn=middle>
|
||||||
<table cellspacing=0 cellpadding=0 href="wtv-mail:/listmail" >
|
<table cellspacing=0 cellpadding=0 href="`
|
||||||
<tr>
|
if (newsgroup) {
|
||||||
|
data += "wtv-news:/news?group=" + newsgroup;
|
||||||
|
} else {
|
||||||
|
data += "wtv-mail:/listmail";
|
||||||
|
}
|
||||||
|
data += `"><tr>
|
||||||
<td height=1>
|
<td height=1>
|
||||||
<tr>
|
<tr>`;
|
||||||
<td><shadow><font sizerange=medium color=#E6CD4A>Mail list</font></shadow>
|
if (newsgroup) {
|
||||||
</table>`;
|
data += `<td><shadow><font sizerange=medium color=#E6CD4A>Group list</font></shadow>`;
|
||||||
|
} else {
|
||||||
|
data += `<td><shadow><font sizerange=medium color=#E6CD4A>Mail list</font></shadow>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
data += `</table>`;
|
||||||
if (!newsgroup) {
|
if (!newsgroup) {
|
||||||
data += `
|
data += `
|
||||||
<td width=5>
|
<td width=5>
|
||||||
|
|||||||
BIN
zefie_wtvp_minisrv/ServiceVault/wtv-news/images/ListLeftEdge.gif
Normal file
|
After Width: | Height: | Size: 90 B |
BIN
zefie_wtvp_minisrv/ServiceVault/wtv-news/images/ListNext.gif
Normal file
|
After Width: | Height: | Size: 300 B |
BIN
zefie_wtvp_minisrv/ServiceVault/wtv-news/images/ListNext_D.gif
Normal file
|
After Width: | Height: | Size: 300 B |
BIN
zefie_wtvp_minisrv/ServiceVault/wtv-news/images/ListPrevious.gif
Normal file
|
After Width: | Height: | Size: 292 B |
|
After Width: | Height: | Size: 292 B |
|
After Width: | Height: | Size: 91 B |
BIN
zefie_wtvp_minisrv/ServiceVault/wtv-news/images/news_logo.gif
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
@@ -1,5 +1,15 @@
|
|||||||
var minisrv_service_file = true;
|
var minisrv_service_file = true;
|
||||||
|
|
||||||
|
// max of 6, any more will be ignored
|
||||||
|
var featuredGroups = [
|
||||||
|
{ "name": "WebTV", "group": "webtv.users", "description": "A moderated discussion with WebTV customers" },
|
||||||
|
{ "name": "Hacking", "group": "alt.discuss.webtv.hacking", "description": "Not grandma friendly" },
|
||||||
|
{ "name": "4x4s", "group": "rec.autos.4x4", "description": "The on and off-road four wheel drive vehicle" },
|
||||||
|
{ "name": "WebTV Plus", "group": "webtv.plus", "description": "bf0 is for bitches and BPS is boring" },
|
||||||
|
{ "name": "MIDIs", "group": "alt.discuss.midis", "description": "The best music format" },
|
||||||
|
{ "name": "HTML", "group": "alt.discuss.html", "description": "Every timeline starts with HTML" }
|
||||||
|
];
|
||||||
|
|
||||||
headers = `200 OK
|
headers = `200 OK
|
||||||
Connection: Keep-Alive
|
Connection: Keep-Alive
|
||||||
Content-Type: text/html`
|
Content-Type: text/html`
|
||||||
@@ -82,7 +92,8 @@ cellspacing=0 cellpadding=0>
|
|||||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan=3 height=237 valign=bottom align=right >
|
<td colspan=3 height=237 valign=bottom align=right >
|
||||||
<img src="wtv-forum:/images/BannerDiscuss.gif" width=50 height=165> <tr><td colspan=3 absheight=36>
|
<img src="wtv-news:/images/BannerDiscuss.gif" width=50 height=165>
|
||||||
|
<tr><td colspan=3 absheight=36>
|
||||||
</table>
|
</table>
|
||||||
</sidebar>
|
</sidebar>
|
||||||
<body
|
<body
|
||||||
@@ -103,27 +114,25 @@ Featured discussions
|
|||||||
<td abswidth=20>
|
<td abswidth=20>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<td WIDTH=198 HEIGHT=200 VALIGN=top ALIGN=left>
|
<td WIDTH=198 HEIGHT=200 VALIGN=top ALIGN=left>`;
|
||||||
<a href="wtv-news:/news?group=webtv.users"><b>WebTV</b></a><br>
|
|
||||||
A moderated discussion with WebTV customers<br>
|
var limit = 6;
|
||||||
<IMG SRC="wtv-home:/ROMCache/Spacer.gif" WIDTH=1 HEIGHT=18><BR>
|
while (featuredGroups.length > limit) featuredGroups.pop(); // remove anything passing our limit
|
||||||
<a href="wtv-news:/news?group=alt.discuss.webtv.hacking"><b>Hacking</b></a><br>
|
|
||||||
Not grandma friendly<br>
|
function printGroup(group) {
|
||||||
<IMG SRC="wtv-home:/ROMCache/Spacer.gif" WIDTH=1 HEIGHT=18><BR>
|
return `<a href="wtv-news:/news?group=${group.group}"><b>${group.name}</b></a><br>${group.description}<br><IMG SRC="wtv-home:/ROMCache/Spacer.gif" WIDTH=1 HEIGHT=18><BR>`;
|
||||||
<a href="wtv-news:/news?group=rec.autos.4x4"><b>4x4s</b></a><br>
|
}
|
||||||
The on and off-road four wheel drive vehicle<br>
|
|
||||||
<IMG SRC="wtv-home:/ROMCache/Spacer.gif" WIDTH=1 HEIGHT=18><BR>
|
// evens
|
||||||
<td WIDTH=20>
|
Object.keys(featuredGroups).forEach((k) => { if (k % 2 == 0) { data += printGroup(featuredGroups[k]); } });
|
||||||
<td WIDTH=198 HEIGHT=220 VALIGN=top ALIGN=left>
|
|
||||||
<a href="wtv-news:/news?group=webtv.plus"><b>WebTV Plus</b></a><br>
|
if (featuredGroups.length > 1) data += `<td WIDTH=20><td WIDTH=198 HEIGHT=220 VALIGN=top ALIGN=left>`;
|
||||||
bf0 is for bitches and BPS is boring<br>
|
|
||||||
<IMG SRC="wtv-home:/ROMCache/Spacer.gif" WIDTH=1 HEIGHT=18><BR>
|
// odds
|
||||||
<a href="wtv-news:/news?group=alt.discuss.midis"><b>MIDIs</b></a><br>
|
Object.keys(featuredGroups).forEach((k) => { if (k % 2 != 0) data += printGroup(featuredGroups[k]); });
|
||||||
The best music format<br>
|
|
||||||
<IMG SRC="wtv-home:/ROMCache/Spacer.gif" WIDTH=1 HEIGHT=18><BR>
|
|
||||||
<a href="wtv-news:/news?group=alt.discuss.html"><b>HTML</b></a><br>
|
data += `
|
||||||
Every timeline starts with HTML<br>
|
|
||||||
<IMG SRC="wtv-home:/ROMCache/Spacer.gif" WIDTH=1 HEIGHT=18><BR>
|
|
||||||
</table>
|
</table>
|
||||||
<TABLE width=446 cellspacing=0 cellpadding=0>
|
<TABLE width=446 cellspacing=0 cellpadding=0>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
var minisrv_service_file = true;
|
var minisrv_service_file = true;
|
||||||
|
const wtvnews = new WTVNews(minisrv_config, service_name);
|
||||||
console.log('f')
|
|
||||||
|
|
||||||
async function throwError(e) {
|
async function throwError(e) {
|
||||||
var errpage = wtvshared.doErrorPage(400, null, e.toString());
|
var errpage = wtvshared.doErrorPage(400, null, e.toString());
|
||||||
@@ -8,15 +7,30 @@ async function throwError(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function isToday (chkdate) {
|
||||||
|
const today = new Date()
|
||||||
|
return chkdate.getDate() == today.getDate() &&
|
||||||
|
chkdate.getMonth() == today.getMonth() &&
|
||||||
|
chkdate.getFullYear() == today.getFullYear()
|
||||||
|
}
|
||||||
|
|
||||||
async function WebTVListGroup(group) {
|
async function WebTVListGroup(group) {
|
||||||
|
var page_limit_default = 100;
|
||||||
wtvnews.connectUsenet().then(() => {
|
wtvnews.connectUsenet().then(() => {
|
||||||
wtvnews.selectGroup(group).then(() => {
|
wtvnews.selectGroup(group).then(() => {
|
||||||
wtvnews.listGroup(group).then((response) => {
|
var limit_per_page = (request_headers.query.limit) ? parseInt(request_headers.query.limit) : page_limit_default;
|
||||||
|
var page = (request_headers.query.chunk) ? parseInt(request_headers.query.chunk) : 0;
|
||||||
|
|
||||||
|
wtvnews.listGroup(group, page, limit_per_page).then((response) => {
|
||||||
if (response.code == 211) {
|
if (response.code == 211) {
|
||||||
NGCount = response.group.number;
|
NGCount = response.group.number;
|
||||||
NGArticles = response.group.articleNumbers;
|
NGArticles = response.group.articleNumbers;
|
||||||
|
page_start = (limit_per_page * page) + 1;
|
||||||
|
page_end = (page + 1) * limit_per_page;
|
||||||
|
if (page_end > NGCount) page_end = NGCount;
|
||||||
|
|
||||||
wtvnews.getHeaderObj(NGArticles).then((messages) => {
|
wtvnews.getHeaderObj(NGArticles).then((messages) => {
|
||||||
|
messages = wtvnews.sortByResponse(messages);
|
||||||
wtvnews.quitUsenet();
|
wtvnews.quitUsenet();
|
||||||
headers = `200 OK
|
headers = `200 OK
|
||||||
Connection: Keep-Alive
|
Connection: Keep-Alive
|
||||||
@@ -30,6 +44,7 @@ top.location="news:${request_headers.query.group}";
|
|||||||
</script>
|
</script>
|
||||||
<TITLE>${request_headers.query.group}</TITLE>
|
<TITLE>${request_headers.query.group}</TITLE>
|
||||||
</HEAD>
|
</HEAD>
|
||||||
|
<body bgcolor="191919" text="42BD52" link="1bb0f1" vlink="826f7e" hspace=0 vspace=0 logo="wtv-news:/images/news_logo.gif">
|
||||||
<sidebar width=114 height=420 align=left>
|
<sidebar width=114 height=420 align=left>
|
||||||
<table cellspacing=0 cellpadding=0 bgcolor=3d2f3a>
|
<table cellspacing=0 cellpadding=0 bgcolor=3d2f3a>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -56,7 +71,7 @@ top.location="news:${request_headers.query.group}";
|
|||||||
<tr>
|
<tr>
|
||||||
<td abswidth=6 >
|
<td abswidth=6 >
|
||||||
<td abswidth=93 absheight=26 >
|
<td abswidth=93 absheight=26 >
|
||||||
<table href="wtv-mail:/sendmail?discuss=true&group=${request_headers.query.group}&discuss-prefix=wtv-news"
|
<table href="wtv-mail:/sendmail?discuss=true&group=${request_headers.query.group}&discuss-prefix=${service_name}"
|
||||||
cellspacing=0 cellpadding=0>
|
cellspacing=0 cellpadding=0>
|
||||||
<tr>
|
<tr>
|
||||||
<td abswidth=5>
|
<td abswidth=5>
|
||||||
@@ -103,15 +118,9 @@ cellspacing=0 cellpadding=0>
|
|||||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan=3 height=237 valign=bottom align=right >
|
<td colspan=3 height=237 valign=bottom align=right >
|
||||||
<img src="wtv-forum:/images/BannerDiscuss.gif" width=50 height=165> <tr><td colspan=3 absheight=36>
|
<img src="wtv-news:/images/BannerDiscuss.gif" width=50 height=165> <tr><td colspan=3 absheight=36>
|
||||||
</table>
|
</table>
|
||||||
</sidebar>
|
</sidebar>
|
||||||
<body
|
|
||||||
bgcolor="191919" text="42BD52" link="1bb0f1"
|
|
||||||
vlink="826f7e"
|
|
||||||
hspace=0
|
|
||||||
vspace=0
|
|
||||||
logo="wtv-forum:/images/news_logo.gif">
|
|
||||||
|
|
||||||
<table cellspacing=0 cellpadding=0>
|
<table cellspacing=0 cellpadding=0>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -148,9 +157,37 @@ Group: ${request_headers.query.group}
|
|||||||
</font>
|
</font>
|
||||||
<br>
|
<br>
|
||||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=0 height=8>
|
<img src="wtv-home:/ROMCache/Spacer.gif" width=0 height=8>
|
||||||
|
|
||||||
|
<td width=180 valign=bottom align=right>
|
||||||
|
<table cellspacing=0 cellpadding=0>
|
||||||
|
<td rowspan=4 height=26 width=30>
|
||||||
|
${(page > 0) ? `<a href="wtv-news:/news?group=${group}&chunk=${page - 1}${(limit_per_page != page_limit_default) ? `&limit=${limit_per_page}` : ''}"><img src="wtv-news:/images/ListPrevious.gif"></a>` : `<img src="wtv-news:/images/ListPrevious_D.gif">`}
|
||||||
|
<td rowspan=4 height=26 width=11>
|
||||||
|
<img src="wtv-news:/images/ListLeftEdge.gif">
|
||||||
|
<td height=2 valign=top align=left bgcolor="2b2b2b">
|
||||||
|
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||||
|
<td rowspan=4 height=26 width=11>
|
||||||
|
<img src="wtv-news:/images/ListRightEdge.gif">
|
||||||
|
<td rowspan=4 height=26 width=30>
|
||||||
|
${(page_end < NGCount) ? `<a href="wtv-news:/news?group=${group}&chunk=${page + 1}${(limit_per_page != page_limit_default) ? `&limit=${limit_per_page}` : ''}"><img src="wtv-news:/images/ListNext.gif"></a>` : `<img src="wtv-news:/images/ListNext_D.gif">`}
|
||||||
|
<td rowspan=4 width=5>
|
||||||
|
<tr>
|
||||||
|
<td height=2 valign=top align=left>
|
||||||
|
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||||
|
<tr>
|
||||||
|
<td height=20 valign=middle align=center>
|
||||||
|
${page_start}-${page_end}
|
||||||
|
<tr>
|
||||||
|
<td height=2 valign=top align=left bgcolor="000000">
|
||||||
|
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||||
|
<tr>
|
||||||
|
<td colspan=5 height=3>
|
||||||
|
</table> </table>
|
||||||
|
|
||||||
<TABLE width=446 cellspacing=0 cellpadding=0>
|
<TABLE width=446 cellspacing=0 cellpadding=0>
|
||||||
<tr>
|
<tr>
|
||||||
<td rowspan=4 width=10 height=1>
|
<td rowspan=4>
|
||||||
|
<tr>
|
||||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=10 height=1>
|
<img src="wtv-home:/ROMCache/Spacer.gif" width=10 height=1>
|
||||||
<td height=2 width=436 bgcolor="2B2B2B">
|
<td height=2 width=436 bgcolor="2B2B2B">
|
||||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=436 height=1>
|
<img src="wtv-home:/ROMCache/Spacer.gif" width=436 height=1>
|
||||||
@@ -165,8 +202,10 @@ Group: ${request_headers.query.group}
|
|||||||
if (NGCount > 0) {
|
if (NGCount > 0) {
|
||||||
|
|
||||||
Object.keys(messages).forEach(function (k) {
|
Object.keys(messages).forEach(function (k) {
|
||||||
var message = messages[k]
|
var message = messages[k].article;
|
||||||
var message_date = message.headers.DATE;
|
var has_relation = (messages[k].relation !== null) ? true : false;
|
||||||
|
var date_obj = new Date(Date.parse(message.headers.DATE));
|
||||||
|
var date = (isToday(date_obj)) ? strftime("%I:%M %p", date_obj) : strftime("%b %d", date_obj)
|
||||||
data += `
|
data += `
|
||||||
<table cellspacing=0 cellpadding=0>
|
<table cellspacing=0 cellpadding=0>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -174,13 +213,13 @@ Group: ${request_headers.query.group}
|
|||||||
<td abswidth=426 height=42 valign=bottom>
|
<td abswidth=426 height=42 valign=bottom>
|
||||||
<table cellspacing=0 cellpadding=0 href="wtv-news:/news?group=${request_headers.query.group}&article=${message.articleNumber}" id="${message.messageId}" nocolor selected>
|
<table cellspacing=0 cellpadding=0 href="wtv-news:/news?group=${request_headers.query.group}&article=${message.articleNumber}" id="${message.messageId}" nocolor selected>
|
||||||
<tr>
|
<tr>
|
||||||
|
${(has_relation) ? `<td abswidth=20 rowspan=2 valign=top><font size="+2">•` : ''}
|
||||||
<td abswidth=426 maxlines=1>
|
<td abswidth=426 maxlines=1>
|
||||||
<font color=1bb0f1>${(message.headers.SUBJECT) ? message.headers.SUBJECT : "(No Subject)"}
|
<font color=1bb0f1>${(message.headers.SUBJECT) ? message.headers.SUBJECT : "(No Subject)"}
|
||||||
<tr>
|
<tr>
|
||||||
<td maxlines=1>
|
<td maxlines=1>
|
||||||
<font size="-1" color=544f53><b>
|
<font size="-1" color=544f53><b>
|
||||||
${message.headers.FROM}, ${message.headers.DATE}
|
${(message.headers.FROM.indexOf(' ') > 0) ? message.headers.FROM.split(' ')[0] : message.headers.FROM}, ${date}
|
||||||
</b>
|
|
||||||
</table>
|
</table>
|
||||||
<td abswidth=10>
|
<td abswidth=10>
|
||||||
</table>`;
|
</table>`;
|
||||||
@@ -218,17 +257,17 @@ ${message.headers.FROM}, ${message.headers.DATE}
|
|||||||
}).catch((e) => { throwError(e) });
|
}).catch((e) => { throwError(e) });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function WebTVShowMessage(client, group, article) {
|
async function WebTVShowMessage(group, article) {
|
||||||
var connected = await clientConnect(client)
|
var article = parseInt(article);
|
||||||
if (connected) {
|
wtvnews.connectUsenet().then(() => {
|
||||||
response = await selectGroup(client, group);
|
wtvnews.selectGroup(group).then((response) => {
|
||||||
if (response) {
|
wtvnews.getArticle(article).then((response) => {
|
||||||
response = await getArticle(client, article);
|
wtvnews.quitUsenet();
|
||||||
console.log(response);
|
|
||||||
if (response.code == 220) {
|
if (response.code == 220) {
|
||||||
|
console.log(response);
|
||||||
headers = `200 OK
|
headers = `200 OK
|
||||||
Content-type: text/html`;
|
Content-type: text/html
|
||||||
|
wtv-expire-all: wtv-news:/news?group=${group}&article=`;
|
||||||
var message_colors = session_data.mailstore.defaultColors;
|
var message_colors = session_data.mailstore.defaultColors;
|
||||||
|
|
||||||
data = `<head>
|
data = `<head>
|
||||||
@@ -295,11 +334,11 @@ cellspacing=0 cellpadding=0>
|
|||||||
<tr>
|
<tr>
|
||||||
<td abswidth=6 >
|
<td abswidth=6 >
|
||||||
<td abswidth=93 absheight=26 >
|
<td abswidth=93 absheight=26 >
|
||||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0${(response.prev_article) ? ` href="wtv-news:/news?group=${request_headers.query.group}&article=${response.prev_article}"` : ''}>
|
||||||
<tr>
|
<tr>
|
||||||
<td abswidth=5>
|
<td abswidth=5>
|
||||||
<td abswidth=88 valign=middle align=left >
|
<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 cellspacing=0 cellpadding=0><tr><td><shadow><font color="${(response.prev_article) ? "#E7CE4A" : "#5b4b58"}" sizerange=medium>Previous</font></shadow></table>
|
||||||
</table>
|
</table>
|
||||||
<td abswidth=5>
|
<td abswidth=5>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -314,11 +353,11 @@ cellspacing=0 cellpadding=0>
|
|||||||
<tr>
|
<tr>
|
||||||
<td abswidth=6 >
|
<td abswidth=6 >
|
||||||
<td abswidth=93 absheight=26 >
|
<td abswidth=93 absheight=26 >
|
||||||
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0>
|
<table bgcolor=3d2f3a cellspacing=0 cellpadding=0${(response.next_article) ? ` href="wtv-news:/news?group=${request_headers.query.group}&article=${response.next_article}"` : ''}>
|
||||||
<tr>
|
<tr>
|
||||||
<td abswidth=5>
|
<td abswidth=5>
|
||||||
<td abswidth=88 valign=middle align=left >
|
<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 cellspacing=0 cellpadding=0><tr><td><shadow><font color="${(response.next_article) ? "#E7CE4A" : "#5b4b58"}" sizerange=medium>Next</font></shadow></table>
|
||||||
</table>
|
</table>
|
||||||
<td abswidth=5>
|
<td abswidth=5>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -384,7 +423,7 @@ cellspacing=0 cellpadding=0>
|
|||||||
<tr>
|
<tr>
|
||||||
<td abswidth=6>
|
<td abswidth=6>
|
||||||
<td abswidth=93 absheight=26>
|
<td abswidth=93 absheight=26>
|
||||||
<table href="wtv-mail:/sendmail?discuss=true&message_subject=${("Re: " + response.article.headers.SUBJECT)}&group=${response.article.headers.NEWSGROUPS}"
|
<table href="wtv-mail:/sendmail?discuss=true&message_subject=${encodeURIComponent("Re: " + response.article.headers.SUBJECT)}&group=${response.article.headers.NEWSGROUPS}&discuss-prefix=${service_name}&article=${request_headers.query.article}"
|
||||||
cellspacing=0 cellpadding=0>
|
cellspacing=0 cellpadding=0>
|
||||||
<tr>
|
<tr>
|
||||||
<td abswidth=5>
|
<td abswidth=5>
|
||||||
@@ -461,8 +500,7 @@ ${wtvshared.htmlEntitize(response.article.headers.NEWSGROUPS)}
|
|||||||
<tr>
|
<tr>
|
||||||
<td valign=top>
|
<td valign=top>
|
||||||
Date: <td>
|
Date: <td>
|
||||||
${console.log(Date.parse(response.article.headers.DATE))}
|
${strftime("%a, %b %e, %Y, %I:%M%P", new Date(Date.parse(response.article.headers.DATE)))}
|
||||||
${strftime("%a, %b %e, %Y, %I:%M%P", new Date(Date.parse(response.article.headers.DATE) / 1000))}
|
|
||||||
<font size=-1> </font>
|
<font size=-1> </font>
|
||||||
<tr>
|
<tr>
|
||||||
<td valign=top>
|
<td valign=top>
|
||||||
@@ -493,8 +531,7 @@ ${(response.article.headers.SUBJECT) ? wtvshared.htmlEntitize(response.article.h
|
|||||||
${wtvshared.htmlEntitize(message_body, true)}
|
${wtvshared.htmlEntitize(message_body, true)}
|
||||||
<br>
|
<br>
|
||||||
<br>`;
|
<br>`;
|
||||||
data += `<p>
|
data += "<p>";
|
||||||
`;
|
|
||||||
/*
|
/*
|
||||||
if (message.attachments) {
|
if (message.attachments) {
|
||||||
message.attachments.forEach((v, k) => {
|
message.attachments.forEach((v, k) => {
|
||||||
@@ -519,21 +556,21 @@ ${wtvshared.htmlEntitize(message_body, true)}
|
|||||||
data += `Included Page: <a href="${(message.url)}">${wtvshared.htmlEntitize(message.url_title).replace(/'/gi, "'")}`;
|
data += `Included Page: <a href="${(message.url)}">${wtvshared.htmlEntitize(message.url_title).replace(/'/gi, "'")}`;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
data += `
|
data += "</table></body></html>";
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`;
|
|
||||||
sendToClient(socket, headers, data);
|
sendToClient(socket, headers, data);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var errpage = wtvshared.doErrorPage(400, null, "No such article in group <b>"+group+"</b>");
|
throwError("invalid response code. expected: 220, received:", response.code);
|
||||||
sendToClient(socket, errpage[0], errpage[1]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var errpage = wtvshared.doErrorPage(400, null, "No such group: <b>"+group+"</b>");
|
|
||||||
sendToClient(socket, errpage[0], errpage[1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}).catch((e) => {
|
||||||
|
throwError(e);
|
||||||
|
});
|
||||||
|
}).catch((e) => {
|
||||||
|
throwError(e);
|
||||||
|
});
|
||||||
|
}).catch((e) => {
|
||||||
|
throwError(e);
|
||||||
|
});;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!minisrv_config.services[service_name].upstream_address || !minisrv_config.services[service_name].upstream_port) {
|
if (!minisrv_config.services[service_name].upstream_address || !minisrv_config.services[service_name].upstream_port) {
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ var runScriptInVM = function (script_data, user_contextObj = {}, privileged = fa
|
|||||||
contextObj[vm_modules[k]] = require(module_file);
|
contextObj[vm_modules[k]] = require(module_file);
|
||||||
modules_loaded.push(module_file)
|
modules_loaded.push(module_file)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(" *!* Could not load module", module_file, "requested by service", contextObj.service_name)
|
console.error(" *!* Could not load module", module_file, "requested by service", contextObj.service_name, e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ class WTVClientSessionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generatePassword(len) {
|
generatePassword(len) {
|
||||||
return CryptoJS.lib.WordArray.random(Math.round(len / 2)).toString(CryptoJS.enc.Hex);
|
return this.wtvshared.generatePassword(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
setUserPassword(passwd) {
|
setUserPassword(passwd) {
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ class WTVNews {
|
|||||||
|
|
||||||
minisrv_config = null;
|
minisrv_config = null;
|
||||||
newsie = require('newsie').default;
|
newsie = require('newsie').default;
|
||||||
|
strftime = require('strftime');
|
||||||
|
wtvshared = null;
|
||||||
service_name = null;
|
service_name = null;
|
||||||
client = null;
|
client = null;
|
||||||
|
|
||||||
constructor(minisrv_config, service_name) {
|
constructor(minisrv_config, service_name) {
|
||||||
this.minisrv_config = minisrv_config;
|
this.minisrv_config = minisrv_config;
|
||||||
this.service_name = service_name;
|
this.service_name = service_name;
|
||||||
|
const { WTVShared } = require("./WTVShared.js");
|
||||||
|
this.wtvshared = new WTVShared(minisrv_config);
|
||||||
this.client = new this.newsie({
|
this.client = new this.newsie({
|
||||||
host: this.minisrv_config.services[service_name].upstream_address,
|
host: this.minisrv_config.services[service_name].upstream_address,
|
||||||
port: this.minisrv_config.services[service_name].upstream_port
|
port: this.minisrv_config.services[service_name].upstream_port
|
||||||
@@ -27,21 +31,32 @@ class WTVNews {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
listGroup(group) {
|
listGroup(group, page = 0, limit = 100) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.client.listGroup(group).then((data) => {
|
this.selectGroup(group).then((res) => {
|
||||||
|
var range = {
|
||||||
|
start: (limit * page) + res.group.low,
|
||||||
|
}
|
||||||
|
range.end = range.start + limit;
|
||||||
|
if (page) range.start++;
|
||||||
|
if (range.end > res.high) delete range.group.end;
|
||||||
|
console.log(res, range);
|
||||||
|
this.client.listGroup(group, range).then((data) => {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.error(" * WTVNews Error:", "Command: listGroup", e);
|
console.error(" * WTVNews Error:", "Command: listGroup", e);
|
||||||
reject(`No such group <b>${group}</b>`);
|
reject(`No such group <b>${group}</b>`);
|
||||||
});
|
});
|
||||||
|
}).catch((e) => {
|
||||||
|
console.error(" * WTVNews Error:", "Command: selectGroup", e);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
selectGroup(group) {
|
selectGroup(group) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.client.group(group).then((response) => {
|
this.client.group(group).then((response) => {
|
||||||
if (response.code == 211) resolve(true);
|
if (response.code == 211) resolve(response);
|
||||||
else reject(`No such group <b>${group}</b>`);
|
else reject(`No such group <b>${group}</b>`);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.error(" * WTVNews Error:", "Command: selectGroup", e);
|
console.error(" * WTVNews Error:", "Command: selectGroup", e);
|
||||||
@@ -51,12 +66,50 @@ class WTVNews {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getArticle(articleID) {
|
getArticle(articleID) {
|
||||||
|
var articleID = parseInt(articleID);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
var promises = [];
|
||||||
this.client.article(articleID).then((data) => {
|
this.client.article(articleID).then((data) => {
|
||||||
resolve(data)
|
// ask server for next article
|
||||||
|
promises.push(new Promise((resolve, reject) => {
|
||||||
|
this.client.next().then((res) => {
|
||||||
|
data.next_article = res.article.articleNumber;
|
||||||
|
resolve(data.next_article);
|
||||||
|
}).catch(() => {
|
||||||
|
data.next_article = null;
|
||||||
|
resolve(data.next_article);
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
|
||||||
|
// ask server for previous article
|
||||||
|
promises.push(new Promise((resolve, reject) => {
|
||||||
|
this.client.last().then((res) => {
|
||||||
|
data.prev_article = res.article.articleNumber;
|
||||||
|
// do it again
|
||||||
|
this.client.article(data.prev_article).then(() => {
|
||||||
|
this.client.last().then((res) => {
|
||||||
|
data.prev_article = res.article.articleNumber;
|
||||||
|
resolve(data.prev_article);
|
||||||
|
}).catch(() => {
|
||||||
|
data.prev_article = null;
|
||||||
|
resolve(data.prev_article);
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
data.prev_article = null;
|
||||||
|
resolve(data.prev_article);
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
data.prev_article = null;
|
||||||
|
resolve(data.prev_article);
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
|
||||||
|
Promise.all(promises).then(() => {
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
reject(`Error reading article ID ${articleID}`);
|
reject(`Error reading article ID ${articleID}`);
|
||||||
console.error(" * WTVNews Error:", "Command: article", e);
|
console.error(" * WTVNews Error:", "Command: article", "args:", articleID, "Error:", e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -87,24 +140,193 @@ class WTVNews {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postToGroup(group, from_addr, msg_subject, msg_body, article = null) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var promises = [];
|
||||||
|
var messageid = null;
|
||||||
|
this.connectUsenet()
|
||||||
|
.then(() => {
|
||||||
|
if (article) {
|
||||||
|
promises.push(new Promise((resolve, reject) => {
|
||||||
|
this.selectGroup(group).then((res) => {
|
||||||
|
this.getArticleMessageID(article).then((data) => {
|
||||||
|
console.log(data);
|
||||||
|
messageid = data;
|
||||||
|
resolve(data);
|
||||||
|
}).catch((e) => {
|
||||||
|
console.log(e);
|
||||||
|
reject(e)
|
||||||
|
});
|
||||||
|
}).catch((e) => {
|
||||||
|
console.log(e);
|
||||||
|
reject(e)
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
Promise.all(promises).then(() => {
|
||||||
|
this.client.post()
|
||||||
|
.then((response) => {
|
||||||
|
if (response.code == 340) {
|
||||||
|
var articleData = {};
|
||||||
|
articleData.headers = {
|
||||||
|
'Relay-Version': "version zefie_wtvp_minisrv " + this.minisrv_config.version + "; site " + this.minisrv_config.config.domain_name,
|
||||||
|
'Posting-Version': "version zefie_wtvp_minisrv " + this.minisrv_config.version + "; site " + this.minisrv_config.config.domain_name,
|
||||||
|
'Path': "@" + this.minisrv_config.config.domain_name,
|
||||||
|
'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())
|
||||||
|
}
|
||||||
|
if (messageid) articleData.headers.References = messageid;
|
||||||
|
|
||||||
|
if (msg_body) {
|
||||||
|
articleData.body = msg_body.split("\n");
|
||||||
|
} else {
|
||||||
|
articleData.body = [];
|
||||||
|
}
|
||||||
|
console.log(articleData);
|
||||||
|
response.send(articleData).then((response) => {
|
||||||
|
this.client.quit();
|
||||||
|
if (response.code !== 240) {
|
||||||
|
reject("Could not send post. Server returned error " + response.code);
|
||||||
|
} else {
|
||||||
|
resolve(true);
|
||||||
|
}
|
||||||
|
}).catch((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);
|
||||||
|
reject("Could not send post. Server returned unknown error");
|
||||||
|
};
|
||||||
|
}).catch((e) => {
|
||||||
|
console.log('could not connect to server', e);
|
||||||
|
reject("could not connect to server");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getArticleMessageID(articleID) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.client.article(articleID).then((data) => {
|
||||||
|
resolve(data.article.messageId);
|
||||||
|
}).catch((e) => {
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getHeaderObj(NGArticles) {
|
getHeaderObj(NGArticles) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var messages = [];
|
var messages = [];
|
||||||
var failed = false;
|
var promises = [];
|
||||||
for (var article in NGArticles) {
|
for (var article in NGArticles) {
|
||||||
if (failed) continue;
|
|
||||||
if (article == "getCaseInsensitiveKey") continue;
|
if (article == "getCaseInsensitiveKey") continue;
|
||||||
|
promises.push(new Promise((resolve, reject) => {
|
||||||
this.getHeader(NGArticles[article]).then((data) => {
|
this.getHeader(NGArticles[article]).then((data) => {
|
||||||
if (data.article) messages.push(data.article)
|
if (data.article) messages.push(data.article)
|
||||||
|
resolve();
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log(e, article);
|
console.log(e, article);
|
||||||
failed = e;
|
reject(e);
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if (promises.length > 0) {
|
||||||
|
Promise.all(promises).then(() => {
|
||||||
|
if (messages.length > 0) resolve(messages);
|
||||||
|
}).catch((e) => {
|
||||||
|
reject("Could not read message list", e);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve(messages);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!failed) resolve(messages);
|
|
||||||
else reject("Could not read message list", failed);
|
sortByResponse(messages) {
|
||||||
|
var sorted = [];
|
||||||
|
var message_id_roots = [];
|
||||||
|
var message_relations = [];
|
||||||
|
Object.keys(messages).forEach((k) => {
|
||||||
|
var messageId = messages[k].messageId;
|
||||||
|
var ref = messages[k].headers.REFERENCES;
|
||||||
|
if (ref) {
|
||||||
|
var res = message_id_roots.find(e => e.messageId == ref);
|
||||||
|
if (res) {
|
||||||
|
// see if its attached to a root post
|
||||||
|
if (message_relations[res.messageId]) message_relations[res.messageId].push({ "messageId": messageId, "index": k });
|
||||||
|
else message_relations[res.messageId] = [{ "messageId": messageId, "index": k }];
|
||||||
|
} else {
|
||||||
|
// see if its related to a relation
|
||||||
|
if (Object.keys(message_relations).length > 0) {
|
||||||
|
var found = false;
|
||||||
|
Object.keys(message_relations).forEach((j) => {
|
||||||
|
if (message_relations[j].length > 0) {
|
||||||
|
Object.keys(message_relations[j]).forEach((h) => {
|
||||||
|
if (found) return;
|
||||||
|
if (message_relations[j][h].messageId == ref) {
|
||||||
|
var searchref = messages[message_relations[j][h].index].headers.REFERENCES || null;
|
||||||
|
var mainref = null;
|
||||||
|
while (searchref !== null) {
|
||||||
|
var searchart = messages.find(e => e.messageId == searchref);
|
||||||
|
var searchref = searchart.headers.REFERENCES || null;
|
||||||
|
}
|
||||||
|
mainref = searchart.messageId;
|
||||||
|
message_relations[mainref].push({ "messageId": messageId, "index": k });
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
if (!found) {
|
||||||
|
message_id_roots.push({ "messageId": messageId, "index": j });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
message_id_roots.push({ "messageId": messageId, "index": k });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
message_id_roots.push({ "messageId": messageId, "index": k });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// sort the relations, putting root articles first, followed by their relations
|
||||||
|
var message_roots_sorted = [];
|
||||||
|
Object.keys(message_id_roots).forEach((k) => {
|
||||||
|
// sort relations by date
|
||||||
|
var article = messages[message_id_roots[k].index];
|
||||||
|
var article_date = Date.parse(article.headers.DATE);
|
||||||
|
message_roots_sorted.push({ "article": article, "relation": null, "date": article_date });
|
||||||
|
});
|
||||||
|
message_roots_sorted.sort((a, b) => { return (a.date > b.date) });
|
||||||
|
Object.keys(message_roots_sorted).forEach((k) => {
|
||||||
|
sorted.push(message_roots_sorted[k]);
|
||||||
|
|
||||||
|
if (message_relations[message_id_roots[k].messageId]) {
|
||||||
|
var relations = [];
|
||||||
|
Object.keys(message_relations[message_id_roots[k].messageId]).forEach((j) => {
|
||||||
|
// sort relations by date
|
||||||
|
var article = messages[message_relations[message_id_roots[k].messageId][j].index];
|
||||||
|
var article_date = Date.parse(article.headers.DATE);
|
||||||
|
relations.push({ "article": article, "relation": message_id_roots[k].messageId, "date": article_date })
|
||||||
|
});
|
||||||
|
relations.sort((a, b) => { return (a.date > b.date) });
|
||||||
|
Object.keys(relations).forEach((j) => {
|
||||||
|
sorted.push(relations[j]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return sorted;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = WTVNews;
|
module.exports = WTVNews;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Shared functions across all classes and apps
|
* Shared functions across all classes and apps
|
||||||
*/
|
*/
|
||||||
|
const CryptoJS = require('crypto-js');
|
||||||
|
|
||||||
class WTVShared {
|
class WTVShared {
|
||||||
|
|
||||||
@@ -9,7 +9,6 @@ class WTVShared {
|
|||||||
fs = require('fs');
|
fs = require('fs');
|
||||||
v8 = require('v8');
|
v8 = require('v8');
|
||||||
zlib = require('zlib');
|
zlib = require('zlib');
|
||||||
CryptoJS = require('crypto-js');
|
|
||||||
html_entities = require('html-entities'); // used externally by service scripts
|
html_entities = require('html-entities'); // used externally by service scripts
|
||||||
sanitizeHtml = require('sanitize-html');
|
sanitizeHtml = require('sanitize-html');
|
||||||
iconv = require('iconv-lite');
|
iconv = require('iconv-lite');
|
||||||
@@ -310,6 +309,10 @@ class WTVShared {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generatePassword(len) {
|
||||||
|
return CryptoJS.lib.WordArray.random(Math.round(len / 2)).toString(CryptoJS.enc.Hex);
|
||||||
|
}
|
||||||
|
|
||||||
getMiniSrvConfig() {
|
getMiniSrvConfig() {
|
||||||
return this.minisrv_config;
|
return this.minisrv_config;
|
||||||
}
|
}
|
||||||
@@ -435,7 +438,7 @@ class WTVShared {
|
|||||||
var post_obj = {};
|
var post_obj = {};
|
||||||
post_obj.query = [];
|
post_obj.query = [];
|
||||||
try {
|
try {
|
||||||
var post_text = obj.post_data.toString(this.CryptoJS.enc.Utf8);
|
var post_text = obj.post_data.toString(CryptoJS.enc.Utf8);
|
||||||
if (post_text.length > 0) {
|
if (post_text.length > 0) {
|
||||||
post_text = post_text.split("&");
|
post_text = post_text.split("&");
|
||||||
for (let i = 0; i < post_text.length; i++) {
|
for (let i = 0; i < post_text.length; i++) {
|
||||||
@@ -454,7 +457,7 @@ class WTVShared {
|
|||||||
post_text = post_text.substring(0, post_text.length - 1);
|
post_text = post_text.substring(0, post_text.length - 1);
|
||||||
obj.post_data = post_text.hexEncode();
|
obj.post_data = post_text.hexEncode();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
obj.post_data = obj.post_data.toString(this.CryptoJS.enc.Hex);
|
obj.post_data = obj.post_data.toString(CryptoJS.enc.Hex);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// simple, no filter
|
// simple, no filter
|
||||||
|
|||||||
@@ -126,7 +126,10 @@
|
|||||||
},
|
},
|
||||||
"wtv-mail": {
|
"wtv-mail": {
|
||||||
"port": 1608,
|
"port": 1608,
|
||||||
"connections": 3
|
"connections": 3,
|
||||||
|
"modules": [
|
||||||
|
"WTVNews"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"wtv-passport": {
|
"wtv-passport": {
|
||||||
"port": 1654
|
"port": 1654
|
||||||
|
|||||||