var minisrv_service_file = true; const wtvnews = new WTVNews(minisrv_config, service_name); var service_config = minisrv_config.services[service_name]; if (service_config.local_nntp_port && 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_config.upstream_port, service_config.upstream_tls || null); } async function throwError(e) { console.log(e); var errpage = wtvshared.doErrorPage(400, null, e.toString()); sendToClient(socket, errpage[0], errpage[1]); } function isToday (chkdate) { const today = new Date() return chkdate.getDate() == today.getDate() && chkdate.getMonth() == today.getMonth() && chkdate.getFullYear() == today.getFullYear() } async function WebTVListGroup(group) { var page_limit_default = 100; wtvnews.connectUsenet().then(() => { wtvnews.selectGroup(group).then(() => { 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) { NGCount = response.group.number; 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) => { messages = wtvnews.sortByResponse(messages); wtvnews.quitUsenet(); headers = `200 OK Connection: Keep-Alive Content-Type: text/html wtv-expire: wtv-news:/news?group=${request_headers.query.group}` data = ` ${request_headers.query.group}
Post
Help
Group: ${request_headers.query.group}
` if (NGCount == 0) { data += `This group has no postings`; } else { data += NGCount + " posting"; if (NGCount != 1) data += "s" } data += `
`; if (NGCount > 0) { data += `
${(page > 0) ? `` : ``} ${(page_end < NGCount) ? `` : ``}
${page_start}-${page_end}
`; } data += `
` if (NGCount > 0) { Object.keys(messages).forEach(function (k) { var message = messages[k].article; 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 += `
${(has_relation) ? `
•` : ''} ${(message.headers.SUBJECT) ? message.headers.SUBJECT : "(No Subject)"}
${(message.headers.FROM.indexOf(' ') > 0) ? message.headers.FROM.split(' ')[0] : message.headers.FROM}, ${date}
`; }); } data += `
`; sendToClient(socket, headers, data); }).catch((e) => { throwError(e) });; } }).catch((e) => { throwError(e) });; }).catch((e) => { throwError(e) });; }).catch((e) => { throwError(e) }); } async function WebTVShowMessage(group, article) { var article = parseInt(article); wtvnews.connectUsenet().then(() => { wtvnews.selectGroup(group).then((response) => { wtvnews.getArticle(article).then((response) => { wtvnews.quitUsenet(); if (response.code == 220) { headers = `200 OK Content-type: text/html wtv-expire-all: wtv-news:/news?group=${group}&article=`; var message_colors = session_data.mailstore.defaultColors; data = ` ${(response.article.headers.SUBJECT) ? wtvshared.htmlEntitize(response.article.headers.SUBJECT) : '(No subject)'}
Group
Previous
Next
Next New
Mail to
Respond
Help
  
Post
Group: ${wtvshared.htmlEntitize(response.article.headers.NEWSGROUPS)}
Date: ${strftime("%a, %b %e, %Y, %I:%M%P", new Date(Date.parse(response.article.headers.DATE)))}
From: `; // if (message.from_name != message.from_addr) { // data += `${wtvshared.htmlEntitize(message.from_addr)} `; // } else { data += `${wtvshared.htmlEntitize(response.article.headers.FROM)}`; // } data += `



${(response.article.headers.SUBJECT) ? wtvshared.htmlEntitize(response.article.headers.SUBJECT) : '(No subject)'}

`; var message = wtvnews.parseAttachments(response); var message_body = message.text; var attachments = null; if (message.attachments) attachments = message.attachments; data += ` ${wtvshared.htmlEntitize(message_body, true)}

`; data += "

"; 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 += `

`; else if (v.content_type.match(supported_audio)) data += `
  ${(v.filename) ? (v.filename) : "Audio file"} (${v.content_type.split('/')[1]} attachment)


`; else data += `
A file ${(v.filename) ? `(${v.filename}) ` : ''}that WebTV cannot use, with type ${v.content_type} is attached to this message.` } }); } /* if (message.url) { data += `Included Page: ${wtvshared.htmlEntitize(message.url_title).replace(/'/gi, "'")}`; } */ data += "
"; sendToClient(socket, headers, data); } else { throwError("invalid response code. expected: 220, received:", response.code); } }).catch((e) => { throwError(e); }); }).catch((e) => { throwError(e); }); }).catch((e) => { 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.article) { WebTVShowMessage(request_headers.query.group, request_headers.query.article); } else { WebTVListGroup(request_headers.query.group); } } }