implement internal shared ROMCache

- make most ROMCache URLS relative
- create wtvshared.htmlEntitize function
- update wtv-mail:/readmail to use wtvshared.htmlEntitize
This commit is contained in:
zefie
2022-02-12 21:45:06 -05:00
parent b124cfa33c
commit 445e28c91a
85 changed files with 319 additions and 221 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 B

View File

@@ -41,15 +41,14 @@ Choose your name
<td absheight=8> <td absheight=8>
</table> </table>
</sidebar> </sidebar>
<body background="wtv-content:/ROMCache/NameStrip.gif" <body background="ROMCache/NameStrip.gif"
novtilebg novtilebg
nohtilebg nohtilebg
bgcolor=191919 bgcolor=191919
text="AA9B4A" link=189cd6 vlink=189cd6 hspace=0 fontsize="large"> text="AA9B4A" link=189cd6 vlink=189cd6 hspace=0 fontsize="large">
<LINK href="wtv-content:/ROMCache/TopBackground_Classic.jpg" rel=next> <LINK href="ROMCache/TopBackground_Classic.jpg" rel=next>
<LINK href="wtv-content:/ROMCache/Community.gif" rel=next> <LINK href="ROMCache/Community.gif" rel=next>
<LINK href="wtv-content:/ROMCache/UtilityBullet.gif" rel=next> <LINK href="ROMCache/UtilityBullet.gif" rel=next>
<LINK href="wtv-content:/ROMCache/BackgroundWebTVToday_a.swf" rel=next>
<form action=/ValidateLogin enctype="x-www-form-encoded" method=post> <form action=/ValidateLogin enctype="x-www-form-encoded" method=post>
<input type="hidden" NAME="target-url" VALUE=""> <input type="hidden" NAME="target-url" VALUE="">
<table cellspacing=0 cellpadding=0> <table cellspacing=0 cellpadding=0>

View File

@@ -17,7 +17,7 @@ ${minisrv_config.config.service_name} Service Privacy Statement
<tr> <tr>
<td colspan=3 abswidth=104 absheight=4> <td colspan=3 abswidth=104 absheight=4>
<td rowspan=99 width=6 absheight=420 valign=top align=left> <td rowspan=99 width=6 absheight=420 valign=top align=left>
<img src="wtv-home:/ROMCache/Shadow.gif" width=6 height=420> <img src="ROMCache/Shadow.gif" width=6 height=420>
<tr> <tr>
<td abswidth=6> <td abswidth=6>
<td abswidth=92 absheight=76> <td abswidth=92 absheight=76>
@@ -30,10 +30,10 @@ ${minisrv_config.config.service_name} Service Privacy Statement
<tr><td absheight=5 colspan=3> <tr><td absheight=5 colspan=3>
<table cellspacing=0 cellpadding=0> <table cellspacing=0 cellpadding=0>
<tr><td abswidth=104 absheight=2 valign=middle align=center bgcolor="5a4521"> <tr><td abswidth=104 absheight=2 valign=middle align=center bgcolor="5a4521">
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1> <img src="ROMCache/Spacer.gif" width=1 height=1>
<tr><td abswidth=104 absheight=1 valign=top align=left> <tr><td abswidth=104 absheight=1 valign=top align=left>
<tr><td abswidth=104 absheight=2 valign=top align=left bgcolor="c0954a"> <tr><td abswidth=104 absheight=2 valign=top align=left bgcolor="c0954a">
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1> <img src="ROMCache/Spacer.gif" width=1 height=1>
</table> </table>
<tr><td absheight=100> <tr><td absheight=100>
<tr><td absheight=244 align=right colspan=3> <tr><td absheight=244 align=right colspan=3>

View File

@@ -53,7 +53,7 @@ xnocancel>
<HTML> <HTML>
<head> <head>
<title> <title>
${html_entities.encode((message.subject) ? message.subject : '(No subject)')} ${(message.subject) ? wtvshared.htmlEntitize(message.subject) : '(No subject)'}
</title> </title>
</head> </head>
<body <body
@@ -236,9 +236,9 @@ From:
<td width=10> <td width=10>
<td>`; <td>`;
if (message.from_name != message.from_addr) { if (message.from_name != message.from_addr) {
data += `${html_entities.encode(message.from_addr)} <a href="client:showalert?sound=none&message=To%20add%20%3Cblackface%3E${escape(escape(message.from_name))}%3C%2Fblackface%3E%20to%20your%20Address%20book,%20choose%20%3Cb%3EAdd%3C%2Fb%3E.&buttonlabel2=Cancel&buttonaction2=client:donothing&buttonlabel1=Add&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">(${html_entities.encode(message.from_name)})</a>`; data += `${wtvshared.htmlEntitize(message.from_addr)} <a href="client:showalert?sound=none&message=To%20add%20%3Cblackface%3E${escape(escape(message.from_name))}%3C%2Fblackface%3E%20to%20your%20Address%20book,%20choose%20%3Cb%3EAdd%3C%2Fb%3E.&buttonlabel2=Cancel&buttonaction2=client:donothing&buttonlabel1=Add&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_name)})</a>`;
} else { } else {
data += `${html_entities.encode(message.from_addr)}`; data += `${wtvshared.htmlEntitize(message.from_addr)}`;
} }
data += `<tr> data += `<tr>
@@ -252,7 +252,7 @@ ${strftime("%a, %b %e, %Y, %I:%M %P", new Date(message.date * 1000))} (UTC)
To: To:
<td> <td>
<td> <td>
${html_entities.encode(message.to_addr)} ${(html_entities.encode(message.to_name)) ? '(' + html_entities.encode(message.to_name) + ')' : ''} ${wtvshared.htmlEntitize(message.to_addr)} ${(message.to_name) ? '(' + wtvshared.htmlEntitize(message.to_name) + ')' : ''}
<tr> <tr>
<td nowrap valign=top> <td nowrap valign=top>
Subject: <td> Subject: <td>
@@ -260,7 +260,7 @@ Subject: <td>
if (typeof message.subject == "object") message.subject = new Buffer.from(message.subject).toString('latin1'); if (typeof message.subject == "object") message.subject = new Buffer.from(message.subject).toString('latin1');
data += ` data += `
${html_entities.encode((message.subject) ? message.subject : '(No subject)')} ${(message.subject) ? wtvshared.htmlEntitize(message.subject) : '(No subject)'}
<tr> <tr>
<td height=10> <td height=10>
<spacer type=vertical size=10> <spacer type=vertical size=10>
@@ -270,22 +270,22 @@ ${html_entities.encode((message.subject) ? message.subject : '(No subject)')}
<tr> <tr>
<td width=425> <td width=425>
<p>`; <p>`;
if (typeof message.body == "object") { if (typeof message.body === "object" && message.body) {
message.body = wtvshared.decodeBufferText(message.body); message.body = wtvshared.decodeBufferText(message.body);
} }
data += ` data += `
${html_entities.encode(message.body).replace(/\n/gi, "<br>").replace(/\r/gi, "").replace(/&apos;/gi, "'")} ${wtvshared.htmlEntitize(message.body, true)}
<br> <br>
<br>`; <br>`;
if (message.signature) { if (message.signature) {
data += ssid_sessions[socket.ssid].mailstore.sanitizeSignature(message.signature); data += ssid_sessions[socket.ssid].mailstore.sanitizeSignature(message.signature);
} }
data += `<p> data += `<p>
`; `;
if (message.attachments) { if (message.attachments) {
message.attachments.forEach((v, k) => { message.attachments.forEach((v, k) => {
if (v) { if (v) {
console.log("*****************",v['Content-Type']); console.log("*****************", v['Content-Type']);
switch (v['Content-Type']) { switch (v['Content-Type']) {
case "image/jpeg": case "image/jpeg":
data += `<img border=2 src="wtv-mail:/get-attachment?message_id=${messageid}&attachment_id=${k}&wtv-title=Video%20Snapshot" width="380" height="290"><br><br>`; data += `<img border=2 src="wtv-mail:/get-attachment?message_id=${messageid}&attachment_id=${k}&wtv-title=Video%20Snapshot" width="380" height="290"><br><br>`;
@@ -293,7 +293,7 @@ data += `<p>
case "audio/wav": case "audio/wav":
data += `<table href="wtv-mail:/get-attachment?message_id=${messageid}&attachment_id=${k}&wtv-title=Voice%20Mail" width=386 cellspacing=0 cellpadding=0> data += `<table href="wtv-mail:/get-attachment?message_id=${messageid}&attachment_id=${k}&wtv-title=Voice%20Mail" width=386 cellspacing=0 cellpadding=0>
<td align=left valign=middle> <td align=left valign=middle>
<img src="wtv-mail:/ROMCache/FileSound.gif" align=absmiddle>&nbsp;&nbsp;Recording <img src="ROMCache/FileSound.gif" align=absmiddle>&nbsp;&nbsp;Recording
<td align=right valign=middle> <td align=right valign=middle>
</table><br><br> </table><br><br>
`; `;
@@ -302,7 +302,7 @@ data += `<p>
} }
}); });
} }
data += `<p> data += `<p>
<p> <p>
</table> </table>
</table> </table>

View File

@@ -71,10 +71,10 @@ Content-Type: audio/wav`;
'noback': true, 'noback': true,
}).getURL(); }).getURL();
if (request_headers.query.sendoff == "Send" || request_headers.query.saveoff || request_headers.query.get_snap || request_headers.query.get_gab) { if ((typeof request_headers.query.sendoff !== 'undefined' && request_headers.query.sendoff != false) || request_headers.query.saveoff || request_headers.query.get_snap || request_headers.query.get_gab) {
var from_addr = address; var from_addr = address;
var signature = ssid_sessions[socket.ssid].getSessionData("subscriber_signature") || null; var signature = ssid_sessions[socket.ssid].getSessionData("subscriber_signature") || null;
if (request_headers.query.sendoff == "Send") { if (typeof request_headers.query.sendoff !== 'undefined' && request_headers.query.sendoff != false) {
var attachments = []; var attachments = [];
@@ -459,30 +459,30 @@ USESTYLE NOARGS>
if ((request_headers.query.snapping && request_headers.query.snapping !== 'false') || mail_draft_attachments.message_snapshot_data) { if ((request_headers.query.snapping && request_headers.query.snapping !== 'false') || mail_draft_attachments.message_snapshot_data) {
data += `<tr> data += `<tr>
<td absheight="10"> <td absheight="10">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="10"> <img src="ROMCache/Spacer.gif" width="1" height="10">
</td></tr></tbody></table> </td></tr></tbody></table>
<table cellspacing="0" cellpadding="0" bgcolor="#1F2033" background=""> <table cellspacing="0" cellpadding="0" bgcolor="#1F2033" background="">
<tbody><tr> <tbody><tr>
<td rowspan="100" abswidth="10" bgcolor="191919"> <td rowspan="100" abswidth="10" bgcolor="191919">
<img src="wtv-star:/ROMCache/Spacer.gif" width="10" height="1"> <img src="ROMCache/Spacer.gif" width="10" height="1">
</td><td colspan="9" abswidth="422" valign="bottom"> </td><td colspan="9" abswidth="422" valign="bottom">
<img src="wtv-mail:/ROMCache/PaperTopFlat.gif" noprint="" width="422" height="6"> <img src="ROMCache/PaperTopFlat.gif" noprint="" width="422" height="6">
</td></tr><tr> </td></tr><tr>
<td rowspan="100" abswidth="2" absheight="0" bgcolor="313131"> <td rowspan="100" abswidth="2" absheight="0" bgcolor="313131">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td rowspan="100" abswidth="14" absheight="0"> </td><td rowspan="100" abswidth="14" absheight="0">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td colspan="2" abswidth="386"> </td><td colspan="2" abswidth="386">
</td><td rowspan="100" abswidth="14" absheight="0"> </td><td rowspan="100" abswidth="14" absheight="0">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td rowspan="100" abswidth="3" absheight="0" bgcolor="0b0b0b"> </td><td rowspan="100" abswidth="3" absheight="0" bgcolor="0b0b0b">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td rowspan="100" abswidth="1" absheight="0" bgcolor="0f0f0f"> </td><td rowspan="100" abswidth="1" absheight="0" bgcolor="0f0f0f">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td rowspan="100" abswidth="1" absheight="0" bgcolor="131313"> </td><td rowspan="100" abswidth="1" absheight="0" bgcolor="131313">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td rowspan="100" abswidth="1" absheight="0" bgcolor="171717"> </td><td rowspan="100" abswidth="1" absheight="0" bgcolor="171717">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td></tr><tr> </td></tr><tr>
<td colspan="2" absheight="15">`; <td colspan="2" absheight="15">`;
if (!mail_draft_attachments.message_snapshot_data) { if (!mail_draft_attachments.message_snapshot_data) {
@@ -502,51 +502,51 @@ USESTYLE NOARGS>
<tbody><tr><td valign="middle"> <tbody><tr><td valign="middle">
</td><td valign="middle" align="right"> </td><td valign="middle" align="right">
<a href="javascript:ErasingMedia('snapping')"> <a href="javascript:ErasingMedia('snapping')">
&nbsp;Detach&nbsp;<img src="wtv-mail:/ROMCache/RemoveButton.gif" width="25" height="25" align="absmiddle"></a> &nbsp;Detach&nbsp;<img src="ROMCache/RemoveButton.gif" width="25" height="25" align="absmiddle"></a>
</td></tr></tbody></table> </td></tr></tbody></table>
</td></tr><tr> </td></tr><tr>
<td colspan="2" absheight="8"> <td colspan="2" absheight="8">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="8"> <img src="ROMCache/Spacer.gif" width="1" height="8">
</td></tr></tbody></table> </td></tr></tbody></table>
<table cellspacing="0" cellpadding="0"> <table cellspacing="0" cellpadding="0">
<tbody><tr> <tbody><tr>
<td rowspan="100" abswidth="10"> <td rowspan="100" abswidth="10">
<img src="wtv-star:/ROMCache/Spacer.gif" width="10" height="2"> <img src="ROMCache/Spacer.gif" width="10" height="2">
</td><td abswidth="422"> </td><td abswidth="422">
<img src="wtv-mail:/ROMCache/PaperBase.gif" noprint="" width="422" height="6"> <img src="ROMCache/PaperBase.gif" noprint="" width="422" height="6">
</td></tr><tr> </td></tr><tr>
<td absheight="6"> <td absheight="6">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="6"> <img src="ROMCache/Spacer.gif" width="1" height="6">
</td></tr>`; </td></tr>`;
} }
if ((request_headers.query.gabbing && request_headers.query.gabbing !== 'false') || mail_draft_attachments.message_voicemail_data) { if ((request_headers.query.gabbing && request_headers.query.gabbing !== 'false') || mail_draft_attachments.message_voicemail_data) {
data += `<tr> data += `<tr>
<td absheight="10"> <td absheight="10">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="10"> <img src="ROMCache/Spacer.gif" width="1" height="10">
</td></tr></tbody></table> </td></tr></tbody></table>
<table cellspacing="0" cellpadding="0" bgcolor="#1F2033" background=""> <table cellspacing="0" cellpadding="0" bgcolor="#1F2033" background="">
<tbody><tr> <tbody><tr>
<td rowspan="100" abswidth="10" bgcolor="191919"> <td rowspan="100" abswidth="10" bgcolor="191919">
<img src="wtv-star:/ROMCache/Spacer.gif" width="10" height="1"> <img src="ROMCache/Spacer.gif" width="10" height="1">
</td><td colspan="9" abswidth="422" valign="bottom"> </td><td colspan="9" abswidth="422" valign="bottom">
<img src="wtv-mail:/ROMCache/PaperTopFlat.gif" noprint="" width="422" height="6"> <img src="ROMCache/PaperTopFlat.gif" noprint="" width="422" height="6">
</td></tr><tr> </td></tr><tr>
<td rowspan="100" abswidth="2" absheight="0" bgcolor="313131"> <td rowspan="100" abswidth="2" absheight="0" bgcolor="313131">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td rowspan="100" abswidth="14" absheight="0"> </td><td rowspan="100" abswidth="14" absheight="0">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td colspan="2" abswidth="386"> </td><td colspan="2" abswidth="386">
</td><td rowspan="100" abswidth="14" absheight="0"> </td><td rowspan="100" abswidth="14" absheight="0">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td rowspan="100" abswidth="3" absheight="0" bgcolor="0b0b0b"> </td><td rowspan="100" abswidth="3" absheight="0" bgcolor="0b0b0b">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td rowspan="100" abswidth="1" absheight="0" bgcolor="0f0f0f"> </td><td rowspan="100" abswidth="1" absheight="0" bgcolor="0f0f0f">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td rowspan="100" abswidth="1" absheight="0" bgcolor="131313"> </td><td rowspan="100" abswidth="1" absheight="0" bgcolor="131313">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td><td rowspan="100" abswidth="1" absheight="0" bgcolor="171717"> </td><td rowspan="100" abswidth="1" absheight="0" bgcolor="171717">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="1"> <img src="ROMCache/Spacer.gif" width="1" height="1">
</td></tr><tr> </td></tr><tr>
<td colspan="2" absheight="15"> <td colspan="2" absheight="15">
<input type=file device=audio name=message_voicemail_data <input type=file device=audio name=message_voicemail_data
@@ -556,23 +556,23 @@ ${(!mail_draft_attachments.message_voicemail_data) ? '' : '<input type=hidden na
<td colspan="2" align="center"> <td colspan="2" align="center">
<table width=386 cellspacing=0 cellpadding=0> <table width=386 cellspacing=0 cellpadding=0>
<td align=left valign=middle> <td align=left valign=middle>
<a href="${(mail_draft_attachments.message_voicemail_data) ? 'wtv-mail:/sendmail?get_gab=true&wtv-title=Voice%20Mail' : 'cache:voicemail.wav'}" id=focus><img src="wtv-mail:/ROMCache/FileSound.gif" align=absmiddle></a>&nbsp;&nbsp;Recording <a href="${(mail_draft_attachments.message_voicemail_data) ? 'wtv-mail:/sendmail?get_gab=true&wtv-title=Voice%20Mail' : 'cache:voicemail.wav'}" id=focus><img src="ROMCache/FileSound.gif" align=absmiddle></a>&nbsp;&nbsp;Recording
<td align=right valign=middle> <td align=right valign=middle>
<a href="javascript:ErasingMedia('gabbing')"> <a href="javascript:ErasingMedia('gabbing')">
&nbsp;Detach&nbsp;<img src="wtv-mail:/ROMCache/RemoveButton.gif" align=absmiddle height=25 width=25></a> &nbsp;Detach&nbsp;<img src="ROMCache/RemoveButton.gif" align=absmiddle height=25 width=25></a>
</table><tr> </table><tr>
<td colspan="2" absheight="8"> <td colspan="2" absheight="8">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="8"> <img src="ROMCache/Spacer.gif" width="1" height="8">
</td></tr></tbody></table> </td></tr></tbody></table>
<table cellspacing="0" cellpadding="0"> <table cellspacing="0" cellpadding="0">
<tbody><tr> <tbody><tr>
<td rowspan="100" abswidth="10"> <td rowspan="100" abswidth="10">
<img src="wtv-star:/ROMCache/Spacer.gif" width="10" height="2"> <img src="ROMCache/Spacer.gif" width="10" height="2">
</td><td abswidth="422"> </td><td abswidth="422">
<img src="wtv-mail:/ROMCache/PaperBase.gif" noprint="" width="422" height="6"> <img src="ROMCache/PaperBase.gif" noprint="" width="422" height="6">
</td></tr><tr> </td></tr><tr>
<td absheight="6"> <td absheight="6">
<img src="wtv-star:/ROMCache/Spacer.gif" width="1" height="6"> <img src="ROMCache/Spacer.gif" width="1" height="6">
</td></tr>`; </td></tr>`;
} }

View File

@@ -22,7 +22,7 @@ Users setup
<tr> <tr>
<td colspan=3 abswidth=104 absheight=4> <td colspan=3 abswidth=104 absheight=4>
<td rowspan=99 width=6 absheight=420 valign=top align=left> <td rowspan=99 width=6 absheight=420 valign=top align=left>
<img src="wtv-home:/ROMCache/Shadow.gif" width=6 height=420> <img src="ROMCache/Shadow.gif" width=6 height=420>
<tr> <tr>
<td abswidth=6> <td abswidth=6>
<td abswidth=92 absheight=76> <td abswidth=92 absheight=76>
@@ -35,10 +35,10 @@ Users setup
<tr><td absheight=5 colspan=3> <tr><td absheight=5 colspan=3>
<table cellspacing=0 cellpadding=0> <table cellspacing=0 cellpadding=0>
<tr><td abswidth=104 absheight=2 valign=middle align=center bgcolor="1C1E28"> <tr><td abswidth=104 absheight=2 valign=middle align=center bgcolor="1C1E28">
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1> <img src="ROMCache/Spacer.gif" width=1 height=1>
<tr><td abswidth=104 absheight=1 valign=top align=left> <tr><td abswidth=104 absheight=1 valign=top align=left>
<tr><td abswidth=104 absheight=2 valign=top align=left bgcolor="4D5573"> <tr><td abswidth=104 absheight=2 valign=top align=left bgcolor="4D5573">
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1> <img src="ROMCache/Spacer.gif" width=1 height=1>
</table> </table>
<tr><td absheight=37> <tr><td absheight=37>
<tr><td absheight=263 align=right colspan=3> <tr><td absheight=263 align=right colspan=3>
@@ -96,14 +96,14 @@ Subscriber:
<tr> <tr>
<TD> <TD>
<td colspan=4 height=2 valign=middle align=center bgcolor="2B2B2B"> <td colspan=4 height=2 valign=middle align=center bgcolor="2B2B2B">
<img src="wtv-home:/ROMCache/Spacer.gif" width=436 height=1> <img src="ROMCache/Spacer.gif" width=436 height=1>
<tr> <tr>
<TD> <TD>
<td colspan=4 height=1 valign=top align=left> <td colspan=4 height=1 valign=top align=left>
<tr> <tr>
<TD> <TD>
<td colspan=4 height=2 valign=top align=left bgcolor="0D0D0D"> <td colspan=4 height=2 valign=top align=left bgcolor="0D0D0D">
<img src="wtv-home:/ROMCache/Spacer.gif" width=436 height=1> <img src="ROMCache/Spacer.gif" width=436 height=1>
<TR> <TR>
<TD> <TD>
<TD COLSPAN=4 HEIGHT=4 VALIGN=top ALIGN=left> <TD COLSPAN=4 HEIGHT=4 VALIGN=top ALIGN=left>
@@ -114,11 +114,11 @@ Subscriber:
<INPUT action="/remove-users?user-count=x" <INPUT action="/remove-users?user-count=x"
name="RemoveUser" value="Remove User" WIDTH=140 ${(num_accounts >= 1) ? 'USESTYLE' : 'disabled="disabled" text=gray' } name="RemoveUser" value="Remove User" WIDTH=140 ${(num_accounts >= 1) ? 'USESTYLE' : 'disabled="disabled" text=gray' }
TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button1" WIDTH=103> TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button1" WIDTH=103>
<IMG SRC="wtv-home:/ROMCache/Spacer.gif" WIDTH=4 HEIGHT=1> <IMG SRC="ROMCache/Spacer.gif" WIDTH=4 HEIGHT=1>
<INPUT action="/add-user?user_count=${num_accounts}" <INPUT action="/add-user?user_count=${num_accounts}"
name="AddUser" value="Add User" WIDTH=120 ${(num_accounts >= minisrv_config.config.user_accounts.max_users_per_account) ? 'disabled="disabled" text=gray' : 'USESTYLE'} name="AddUser" value="Add User" WIDTH=120 ${(num_accounts >= minisrv_config.config.user_accounts.max_users_per_account) ? 'disabled="disabled" text=gray' : 'USESTYLE'}
TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button2" WIDTH=103> TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button2" WIDTH=103>
<IMG SRC="wtv-home:/ROMCache/Spacer.gif" WIDTH=4 HEIGHT=1> <IMG SRC="ROMCache/Spacer.gif" WIDTH=4 HEIGHT=1>
<INPUT action="client:goback" <INPUT action="client:goback"
name="Done" name="Done"
value="Done" value="Done"

View File

@@ -36,7 +36,7 @@ noscroll>
<tr> <tr>
<td colspan=3 abswidth=104 absheight=4> <td colspan=3 abswidth=104 absheight=4>
<td rowspan=99 width=6 absheight=420 valign=top align=left> <td rowspan=99 width=6 absheight=420 valign=top align=left>
<img src="wtv-home:/ROMCache/Shadow.gif" width=6 height=420> <img src="ROMCache/Shadow.gif" width=6 height=420>
<tr> <tr>
<td abswidth=6> <td abswidth=6>
<td abswidth=92 absheight=76> <td abswidth=92 absheight=76>
@@ -49,10 +49,10 @@ noscroll>
<tr><td absheight=5 colspan=3> <tr><td absheight=5 colspan=3>
<table cellspacing=0 cellpadding=0> <table cellspacing=0 cellpadding=0>
<tr><td abswidth=104 absheight=2 valign=middle align=center bgcolor="1C1E28"> <tr><td abswidth=104 absheight=2 valign=middle align=center bgcolor="1C1E28">
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1> <img src="ROMCache/Spacer.gif" width=1 height=1>
<tr><td abswidth=104 absheight=1 valign=top align=left> <tr><td abswidth=104 absheight=1 valign=top align=left>
<tr><td abswidth=104 absheight=2 valign=top align=left bgcolor="4D5573"> <tr><td abswidth=104 absheight=2 valign=top align=left bgcolor="4D5573">
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1> <img src="ROMCache/Spacer.gif" width=1 height=1>
</table> </table>
<tr><td absheight=37> <tr><td absheight=37>
<tr><td absheight=263 align=right colspan=3> <tr><td absheight=263 align=right colspan=3>
@@ -123,13 +123,13 @@ MAXLENGTH="${minisrv_config.config.passwords.max_length}">
<tr> <tr>
<td> <td>
<td colspan=2 absheight=2 bgcolor="2B2B2B"> <td colspan=2 absheight=2 bgcolor="2B2B2B">
<img src="wtv-home:/ROMCache/Spacer.gif" width=426 height=1> <img src="ROMCache/Spacer.gif" width=426 height=1>
<tr> <tr>
<td absheight=1> <td absheight=1>
<tr> <tr>
<td> <td>
<td colspan=2 absheight=2 bgcolor="0D0D0D"> <td colspan=2 absheight=2 bgcolor="0D0D0D">
<img src="wtv-home:/ROMCache/Spacer.gif" width=426 height=1> <img src="ROMCache/Spacer.gif" width=426 height=1>
<tr> <tr>
<td absheight=4> <td absheight=4>
</table> </table>

View File

@@ -40,7 +40,7 @@ noscroll>
<tr> <tr>
<td colspan=3 abswidth=104 absheight=4> <td colspan=3 abswidth=104 absheight=4>
<td rowspan=99 width=6 absheight=420 valign=top align=left> <td rowspan=99 width=6 absheight=420 valign=top align=left>
<img src="wtv-home:/ROMCache/Shadow.gif" width=6 height=420> <img src="ROMCache/Shadow.gif" width=6 height=420>
<tr> <tr>
<td abswidth=6> <td abswidth=6>
<td abswidth=92 absheight=76> <td abswidth=92 absheight=76>
@@ -53,10 +53,10 @@ noscroll>
<tr><td absheight=5 colspan=3> <tr><td absheight=5 colspan=3>
<table cellspacing=0 cellpadding=0> <table cellspacing=0 cellpadding=0>
<tr><td abswidth=104 absheight=2 valign=middle align=center bgcolor="1C1E28"> <tr><td abswidth=104 absheight=2 valign=middle align=center bgcolor="1C1E28">
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1> <img src="ROMCache/Spacer.gif" width=1 height=1>
<tr><td abswidth=104 absheight=1 valign=top align=left> <tr><td abswidth=104 absheight=1 valign=top align=left>
<tr><td abswidth=104 absheight=2 valign=top align=left bgcolor="4D5573"> <tr><td abswidth=104 absheight=2 valign=top align=left bgcolor="4D5573">
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1> <img src="ROMCache/Spacer.gif" width=1 height=1>
</table> </table>
<tr><td absheight=37> <tr><td absheight=37>
<tr><td absheight=263 align=right colspan=3> <tr><td absheight=263 align=right colspan=3>
@@ -154,13 +154,13 @@ user_password2=${request_headers.query.user_password2}">`;
<tr> <tr>
<td> <td>
<td colspan=2 absheight=2 bgcolor="2B2B2B"> <td colspan=2 absheight=2 bgcolor="2B2B2B">
<img src="wtv-home:/ROMCache/Spacer.gif" width=426 height=1> <img src="ROMCache/Spacer.gif" width=426 height=1>
<tr> <tr>
<td absheight=1> <td absheight=1>
<tr> <tr>
<td> <td>
<td colspan=2 absheight=2 bgcolor="0D0D0D"> <td colspan=2 absheight=2 bgcolor="0D0D0D">
<img src="wtv-home:/ROMCache/Spacer.gif" width=426 height=1> <img src="ROMCache/Spacer.gif" width=426 height=1>
<tr> <tr>
<td absheight=4> <td absheight=4>
</table> </table>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 84 B

After

Width:  |  Height:  |  Size: 84 B

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 98 B

After

Width:  |  Height:  |  Size: 98 B

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 843 B

After

Width:  |  Height:  |  Size: 843 B

View File

Before

Width:  |  Height:  |  Size: 967 B

After

Width:  |  Height:  |  Size: 967 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 763 B

After

Width:  |  Height:  |  Size: 763 B

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 66 B

After

Width:  |  Height:  |  Size: 66 B

View File

Before

Width:  |  Height:  |  Size: 186 B

After

Width:  |  Height:  |  Size: 186 B

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 185 B

After

Width:  |  Height:  |  Size: 185 B

View File

Before

Width:  |  Height:  |  Size: 484 B

After

Width:  |  Height:  |  Size: 484 B

View File

Before

Width:  |  Height:  |  Size: 111 B

After

Width:  |  Height:  |  Size: 111 B

View File

Before

Width:  |  Height:  |  Size: 111 B

After

Width:  |  Height:  |  Size: 111 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 44 B

After

Width:  |  Height:  |  Size: 44 B

View File

Before

Width:  |  Height:  |  Size: 43 B

After

Width:  |  Height:  |  Size: 43 B

View File

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@@ -7,8 +7,9 @@ class WTVShared {
path = require('path'); path = require('path');
fs = require('fs'); fs = require('fs');
html_entities = require('html-entities'); // used externally by service scripts
minisrv_config = []; minisrv_config = [];
constructor(minisrv_config) { constructor(minisrv_config) {
if (minisrv_config == null) this.minisrv_config = this.readMiniSrvConfig(); if (minisrv_config == null) this.minisrv_config = this.readMiniSrvConfig();
else this.minisrv_config = minisrv_config; else this.minisrv_config = minisrv_config;
@@ -23,6 +24,12 @@ class WTVShared {
} }
} }
htmlEntitize(string, process_newline = false) {
string = this.html_entities.encode(string).replace(/&apos;/g, "'");
if (process_newline) string = string.replace(/\n/gi, "<br>").replace(/\r/gi, "");
return string;
}
isASCII(str) { isASCII(str) {
for (var i = 0, strLen = str.length; i < strLen; ++i) { for (var i = 0, strLen = str.length; i < strLen; ++i) {
if (str.charCodeAt(i) > 127) return false; if (str.charCodeAt(i) > 127) return false;
@@ -327,10 +334,16 @@ class WTVShared {
* @param {string} base Base path * @param {string} base Base path
* @param {string} target Sub path * @param {string} target Sub path
*/ */
makeSafePath(base, target) { makeSafePath(base, target = null) {
target.replace(/[\|\&\;\$\%\@\"\<\>\+\,\\]/g, ""); if (target) {
var targetPath = this.path.posix.normalize(target) target.replace(/[\|\&\;\$\%\@\"\<\>\+\,\\]/g, "");
return this.fixPathSlashes(base + this.path.sep + targetPath); var targetPath = this.path.posix.normalize(target)
return this.fixPathSlashes(base + this.path.sep + targetPath);
} else {
base.replace(/[\|\&\;\$\%\@\"\<\>\+\,\\]/g, "");
var targetPath = this.path.posix.normalize(base)
return this.fixPathSlashes(base);
}
} }
makeSafeUsername(username) { makeSafeUsername(username) {

View File

@@ -6,7 +6,6 @@ const zlib = require('zlib');
const http = require('http'); const http = require('http');
const https = require('https'); const https = require('https');
const strftime = require('strftime'); // used externally by service scripts const strftime = require('strftime'); // used externally by service scripts
const html_entities = require('html-entities'); // used externally by service scripts
const net = require('net'); const net = require('net');
const CryptoJS = require('crypto-js'); const CryptoJS = require('crypto-js');
const { crc16 } = require('easy-crc'); const { crc16 } = require('easy-crc');
@@ -101,162 +100,183 @@ async function sendRawFile(socket, path) {
}); });
} }
async function processPath(socket, service_vault_file_path, request_headers = new Array(), service_name) { async function processPath(socket, service_vault_file_path, request_headers = new Array(), service_name, shared_romcache = null) {
var headers, data = null; var headers, data = null;
var request_is_async = false; var request_is_async = false;
var service_vault_found = false; var service_vault_found = false;
var service_path = unescape(service_vault_file_path); var service_path = unescape(service_vault_file_path);
var usingSharedROMCache = false;
try { try {
service_vaults.forEach(function (service_vault_dir) { service_vaults.forEach(function (service_vault_dir) {
if (service_vault_found) return; if (service_vault_found) return;
service_vault_file_path = wtvshared.makeSafePath(service_vault_dir, service_path); if (!usingSharedROMCache) {
// deny access to catchall file name directly if (minisrv_config.config.SharedROMCache && shared_romcache) {
var service_path_split = service_path.split("/"); if (shared_romcache.indexOf(minisrv_config.config.SharedROMCache) != -1) {
var service_path_request_file = service_path_split[service_path_split.length - 1]; var service_path_presplit = shared_romcache.split(path.sep);
if (minisrv_config.config.catchall_file_name) { service_path_presplit.splice(service_path_presplit.findIndex((element) => element === 'ROMCache'), 1);
var minisrv_catchall = null; var service_path_romcache = service_path_presplit.join(path.sep);
if (minisrv_config.services[service_name]) minisrv_catchall = minisrv_config.services[service_name].catchall_file_name || minisrv_config.config.catchall_file_name || null; var service_vault_file_path_romcache = wtvshared.returnAbsolutePath(wtvshared.makeSafePath(service_path_romcache));
else minisrv_catchall = minisrv_config.config.catchall_file_name || null; if (fs.existsSync(service_vault_file_path_romcache)) {
if (minisrv_catchall) { service_path = service_path.replace(wtvshared.fixPathSlashes(minisrv_config.config.SharedROMCache), 'ROMCache');
if (service_path_request_file == minisrv_catchall) { service_vault_file_path = service_vault_file_path_romcache;
request_is_async = true; usingSharedROMCache = true;
var errpage = wtvshared.doErrorPage(401, "Access Denied"); } else {
sendToClient(socket, errpage[0], errpage[1]); service_vault_file_path = wtvshared.makeSafePath(service_vault_dir, service_path);
return; }
} } else {
} service_vault_file_path = wtvshared.makeSafePath(service_vault_dir, service_path);
}
var is_dir = false;
var file_exists = false;
minisrv_catchall, service_path_split, service_path_request_file = null;
if (fs.existsSync(service_vault_file_path)) {
file_exists = true;
is_dir = fs.lstatSync(service_vault_file_path).isDirectory()
}
if (file_exists && !is_dir) {
// file exists, read it and return it
service_vault_found = true;
request_is_async = true;
request_headers.service_file_path = service_vault_file_path;
request_headers.raw_file = true;
// service parsed files, we might not want to expose our service source files so we can protect them with a flag on the first line
if (wtvshared.getFileExt(service_vault_file_path).toLowerCase() == "js" || wtvshared.getFileExt(service_vault_file_path).toLowerCase() == "txt") {
if (wtvshared.getFileExt(service_vault_file_path).toLowerCase() == "js") {
wtvshared.getLineFromFile(service_vault_file_path, 0, function (status, line) {
if (!status) {
if (line.match(/minisrv\_service\_file.*true/i)) {
var errpage = wtvshared.doErrorPage(403, "Access Denied");
sendToClient(socket, errpage[0], errpage[1]);
} else {
sendRawFile(socket, service_vault_file_path);
}
} else {
var errpage = wtvshared.doErrorPage(400);
sendToClient(socket, errpage[0], errpage[1]);
}
});
}
if (wtvshared.getFileExt(service_vault_file_path).toLowerCase() == "txt") {
wtvshared.getLineFromFile(service_vault_file_path, 0, function (status, line) {
if (!status) {
if (line.match(/^#!minisrv/i)) {
var errpage = wtvshared.doErrorPage(403, "Access Denied");
sendToClient(socket, errpage[0], errpage[1]);
} else {
sendRawFile(socket, service_vault_file_path);
}
} else {
var errpage = wtvshared.doErrorPage(400);
sendToClient(socket, errpage[0], errpage[1]);
}
});
} }
} else { } else {
// not a potential service file, so save to send service_vault_file_path = wtvshared.makeSafePath(service_vault_dir, service_path);
sendRawFile(socket, service_vault_file_path); }
// deny access to catchall file name directly
var service_path_split = service_path.split("/");
var service_path_request_file = service_path_split[service_path_split.length - 1];
if (minisrv_config.config.catchall_file_name) {
var minisrv_catchall = null;
if (minisrv_config.services[service_name]) minisrv_catchall = minisrv_config.services[service_name].catchall_file_name || minisrv_config.config.catchall_file_name || null;
else minisrv_catchall = minisrv_config.config.catchall_file_name || null;
if (minisrv_catchall) {
if (service_path_request_file == minisrv_catchall) {
request_is_async = true;
var errpage = wtvshared.doErrorPage(401, "Access Denied");
sendToClient(socket, errpage[0], errpage[1]);
return;
}
}
}
var is_dir = false;
var file_exists = false;
minisrv_catchall, service_path_split, service_path_request_file = null;
if (fs.existsSync(service_vault_file_path)) {
file_exists = true;
is_dir = fs.lstatSync(service_vault_file_path).isDirectory()
} }
} else if (fs.existsSync(service_vault_file_path + ".txt")) { if (file_exists && !is_dir) {
// raw text format, entire payload expected (headers and content) // file exists, read it and return it
service_vault_found = true; service_vault_found = true;
request_is_async = true; request_is_async = true;
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found " + service_vault_file_path + ".txt to handle request (Raw TXT Mode) [Socket " + socket.id + "]"); request_headers.service_file_path = service_vault_file_path;
request_headers.service_file_path = service_vault_file_path + ".txt"; request_headers.raw_file = true;
fs.readFile(service_vault_file_path + ".txt", 'Utf-8', function (err, file_raw) {
if (file_raw.indexOf("\n\n") > 0) {
// split headers and data by newline (unix format)
var file_raw_split = file_raw.split("\n\n");
headers = file_raw_split[0];
file_raw_split.shift();
data = file_raw_split.join("\n");
} else if (file_raw.indexOf("\r\n\r\n") > 0) {
// split headers and data by carrage return + newline (windows format)
var file_raw_split = file_raw.split("\r\n\r\n");
headers = file_raw_split[0].replace(/\r/g, "");
file_raw_split.shift();
data = file_raw_split.join("\r\n");
} else {
// couldn't find two line breaks, assume entire file is just headers
headers = file_raw;
data = '';
}
sendToClient(socket, headers, data);
});
} else if (fs.existsSync(service_vault_file_path + ".js")) {
// synchronous js scripting, process with vars, must set 'headers' and 'data' appropriately.
// loaded script will have r/w access to any JavaScript vars this function does.
// request headers are in an array named `request_headers`.
// Query arguments in `request_headers.query`
// Can upgrade to asynchronous by setting `request_is_async` to `true`
// In Asynchronous mode, you are expected to call sendToClient(socket,headers,data) by the end of your script
// `socket` is already defined and should be passed-through.
service_vault_found = true;
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found " + service_vault_file_path + ".js to handle request (JS Interpreter mode) [Socket " + socket.id + "]");
request_headers.service_file_path = service_vault_file_path + ".js";
// expose var service_dir for script path to the root of the wtv-service
var service_dir = service_vault_dir + path.sep + service_name;
socket_sessions[socket.id].starttime = Math.floor(new Date().getTime() / 1000);
var jscript_eval = fs.readFileSync(service_vault_file_path + ".js").toString();
eval(jscript_eval);
if (request_is_async && !minisrv_config.config.debug_flags.quiet) console.log(" * Script requested Asynchronous mode");
}
else if (fs.existsSync(service_vault_file_path + ".html")) {
// Standard HTML with no headers, WTV Style
service_vault_found = true;
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found " + service_vault_file_path + ".html to handle request (HTML Mode) [Socket " + socket.id + "]");
request_headers.service_file_path = service_vault_file_path + ".html";
request_is_async = true;
headers = "200 OK\n"
headers += "Content-Type: text/html"
fs.readFile(service_vault_file_path + ".html", null, function (err, data) {
sendToClient(socket, headers, data);
});
} else {
// look for a catchallin the current path and all parent paths up until the service root
if (minisrv_config.config.catchall_file_name) {
var minisrv_catchall_file_name = null;
if (minisrv_config.services[service_name]) minisrv_catchall_file_name = minisrv_config.services[service_name].catchall_file_name || minisrv_config.config.catchall_file_name || null;
else minisrv_catchall_file_name = minisrv_config.config.catchall_file_name || null;
if (minisrv_catchall_file_name) {
var service_check_dir = service_vault_file_path.split(path.sep);
service_check_dir.pop(); // pop filename
while (service_check_dir.join(path.sep) != service_vault_dir) { // service parsed files, we might not want to expose our service source files so we can protect them with a flag on the first line
var catchall_file = service_check_dir.join(path.sep) + path.sep + minisrv_catchall_file_name; if (wtvshared.getFileExt(service_vault_file_path).toLowerCase() == "js" || wtvshared.getFileExt(service_vault_file_path).toLowerCase() == "txt") {
if (fs.existsSync(catchall_file)) { if (wtvshared.getFileExt(service_vault_file_path).toLowerCase() == "js") {
service_vault_found = true; wtvshared.getLineFromFile(service_vault_file_path, 0, function (status, line) {
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found catchall at " + catchall_file + " to handle request (JS Interpreter Mode) [Socket " + socket.id + "]"); if (!status) {
request_headers.service_file_path = catchall_file; if (line.match(/minisrv\_service\_file.*true/i)) {
var jscript_eval = fs.readFileSync(catchall_file).toString(); var errpage = wtvshared.doErrorPage(403, "Access Denied");
// don't pass these vars to the script sendToClient(socket, errpage[0], errpage[1]);
var service_check_dir, minisrv_catchall_file_name = null; } else {
eval(jscript_eval); sendRawFile(socket, service_vault_file_path);
if (request_is_async && !minisrv_config.config.debug_flags.quiet) console.log(" * Script requested Asynchronous mode"); }
} else { } else {
service_check_dir.pop(); var errpage = wtvshared.doErrorPage(400);
sendToClient(socket, errpage[0], errpage[1]);
}
});
}
if (wtvshared.getFileExt(service_vault_file_path).toLowerCase() == "txt") {
wtvshared.getLineFromFile(service_vault_file_path, 0, function (status, line) {
if (!status) {
if (line.match(/^#!minisrv/i)) {
var errpage = wtvshared.doErrorPage(403, "Access Denied");
sendToClient(socket, errpage[0], errpage[1]);
} else {
sendRawFile(socket, service_vault_file_path);
}
} else {
var errpage = wtvshared.doErrorPage(400);
sendToClient(socket, errpage[0], errpage[1]);
}
});
}
} else {
// not a potential service file, so save to send
sendRawFile(socket, service_vault_file_path);
}
} else if (fs.existsSync(service_vault_file_path + ".txt")) {
// raw text format, entire payload expected (headers and content)
service_vault_found = true;
request_is_async = true;
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found " + service_vault_file_path + ".txt to handle request (Raw TXT Mode) [Socket " + socket.id + "]");
request_headers.service_file_path = service_vault_file_path + ".txt";
fs.readFile(service_vault_file_path + ".txt", 'Utf-8', function (err, file_raw) {
if (file_raw.indexOf("\n\n") > 0) {
// split headers and data by newline (unix format)
var file_raw_split = file_raw.split("\n\n");
headers = file_raw_split[0];
file_raw_split.shift();
data = file_raw_split.join("\n");
} else if (file_raw.indexOf("\r\n\r\n") > 0) {
// split headers and data by carrage return + newline (windows format)
var file_raw_split = file_raw.split("\r\n\r\n");
headers = file_raw_split[0].replace(/\r/g, "");
file_raw_split.shift();
data = file_raw_split.join("\r\n");
} else {
// couldn't find two line breaks, assume entire file is just headers
headers = file_raw;
data = '';
}
sendToClient(socket, headers, data);
});
} else if (fs.existsSync(service_vault_file_path + ".js")) {
// synchronous js scripting, process with vars, must set 'headers' and 'data' appropriately.
// loaded script will have r/w access to any JavaScript vars this function does.
// request headers are in an array named `request_headers`.
// Query arguments in `request_headers.query`
// Can upgrade to asynchronous by setting `request_is_async` to `true`
// In Asynchronous mode, you are expected to call sendToClient(socket,headers,data) by the end of your script
// `socket` is already defined and should be passed-through.
service_vault_found = true;
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found " + service_vault_file_path + ".js to handle request (JS Interpreter mode) [Socket " + socket.id + "]");
request_headers.service_file_path = service_vault_file_path + ".js";
// expose var service_dir for script path to the root of the wtv-service
var service_dir = service_vault_dir + path.sep + service_name;
socket_sessions[socket.id].starttime = Math.floor(new Date().getTime() / 1000);
var jscript_eval = fs.readFileSync(service_vault_file_path + ".js").toString();
eval(jscript_eval);
if (request_is_async && !minisrv_config.config.debug_flags.quiet) console.log(" * Script requested Asynchronous mode");
}
else if (fs.existsSync(service_vault_file_path + ".html")) {
// Standard HTML with no headers, WTV Style
service_vault_found = true;
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found " + service_vault_file_path + ".html to handle request (HTML Mode) [Socket " + socket.id + "]");
request_headers.service_file_path = service_vault_file_path + ".html";
request_is_async = true;
headers = "200 OK\n"
headers += "Content-Type: text/html"
fs.readFile(service_vault_file_path + ".html", null, function (err, data) {
sendToClient(socket, headers, data);
});
} else {
// look for a catchallin the current path and all parent paths up until the service root
if (minisrv_config.config.catchall_file_name) {
var minisrv_catchall_file_name = null;
if (minisrv_config.services[service_name]) minisrv_catchall_file_name = minisrv_config.services[service_name].catchall_file_name || minisrv_config.config.catchall_file_name || null;
else minisrv_catchall_file_name = minisrv_config.config.catchall_file_name || null;
if (minisrv_catchall_file_name) {
var service_check_dir = service_vault_file_path.split(path.sep);
service_check_dir.pop(); // pop filename
while (service_check_dir.join(path.sep) != service_vault_dir && service_check_dir.length > 0) {
var catchall_file = service_check_dir.join(path.sep) + path.sep + minisrv_catchall_file_name;
if (fs.existsSync(catchall_file)) {
service_vault_found = true;
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found catchall at " + catchall_file + " to handle request (JS Interpreter Mode) [Socket " + socket.id + "]");
request_headers.service_file_path = catchall_file;
var jscript_eval = fs.readFileSync(catchall_file).toString();
// don't pass these vars to the script
var service_check_dir, minisrv_catchall_file_name = null;
eval(jscript_eval);
if (request_is_async && !minisrv_config.config.debug_flags.quiet) console.log(" * Script requested Asynchronous mode");
} else {
service_check_dir.pop();
}
} }
} }
} }
@@ -272,7 +292,7 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
} }
if (!request_is_async) { if (!request_is_async) {
if (!service_vault_found) { if (!service_vault_found) {
console.error(" * Could not find a Service Vault for " + service_name + ":/" + service_path.replace(service_name + path.sep, "")); console.error(" * Could not find a Service Vault for " + service_name + ":/" + service_path.replace(service_name + path.sep, "").replace(path.sep, '/'));
var errpage = wtvshared.doErrorPage(404, null, socket.minisrv_pc_mode); var errpage = wtvshared.doErrorPage(404, null, socket.minisrv_pc_mode);
headers = errpage[0]; headers = errpage[0];
data = errpage[1]; data = errpage[1];
@@ -428,9 +448,13 @@ Location: " + minisrv_config.config.unauthorized_url`;
// assume webtv since there is a :/ in the GET // assume webtv since there is a :/ in the GET
var service_name = shortURL.split(':/')[0]; var service_name = shortURL.split(':/')[0];
var urlToPath = wtvshared.fixPathSlashes(service_name + path.sep + shortURL.split(':/')[1]); var urlToPath = wtvshared.fixPathSlashes(service_name + path.sep + shortURL.split(':/')[1]);
var shared_romcache = null;
if (shortURL.indexOf("/ROMCache/") != -1 && minisrv_config.config.enable_shared_romcache) {
shared_romcache = wtvshared.fixPathSlashes(minisrv_config.config.SharedROMCache + path.sep + shortURL.split(':/')[1]);
}
if (minisrv_config.config.debug_flags.show_headers) console.log(" * Incoming headers on socket ID", socket.id, (await wtvshared.decodePostData(wtvshared.filterSSID(Object.assign({}, request_headers))))); if (minisrv_config.config.debug_flags.show_headers) console.log(" * Incoming headers on socket ID", socket.id, (await wtvshared.decodePostData(wtvshared.filterSSID(Object.assign({}, request_headers)))));
socket_sessions[socket.id].request_headers = request_headers; socket_sessions[socket.id].request_headers = request_headers;
processPath(socket, urlToPath, request_headers, service_name); processPath(socket, urlToPath, request_headers, service_name, shared_romcache);
} else if (shortURL.indexOf('http://') >= 0 || shortURL.indexOf('https://') >= 0) { } else if (shortURL.indexOf('http://') >= 0 || shortURL.indexOf('https://') >= 0) {
doHTTPProxy(socket, request_headers); doHTTPProxy(socket, request_headers);
} else { } else {

View File

@@ -6,6 +6,8 @@
"ServiceVault" "ServiceVault"
], ],
"SessionStore": "SessionStore", "SessionStore": "SessionStore",
"SharedROMCache": "SharedROMCache",
"enable_shared_romcache": true,
"service_owner": "a minisrv user", "service_owner": "a minisrv user",
"service_owner_account": "minisrvuser", "service_owner_account": "minisrvuser",
"service_owner_contact": "someone", "service_owner_contact": "someone",

View File

@@ -338,6 +338,63 @@
<Content Include="ServiceVault\wtv-head-waiter\login.js" /> <Content Include="ServiceVault\wtv-head-waiter\login.js" />
<Content Include="ServiceVault\wtv-home\splash.js" /> <Content Include="ServiceVault\wtv-home\splash.js" />
<Content Include="ServiceVault\wtv-log\log.js" /> <Content Include="ServiceVault\wtv-log\log.js" />
<Content Include="SharedROMCache\AccountBanner.gif" />
<Content Include="SharedROMCache\AroundTownIcon2.gif" />
<Content Include="SharedROMCache\AT_BannerGradient.gif" />
<Content Include="SharedROMCache\AT_BannerIcon.gif" />
<Content Include="SharedROMCache\AT_BottomShadow.gif" />
<Content Include="SharedROMCache\AT_Shadow.gif" />
<Content Include="SharedROMCache\BulletArrow.gif" />
<Content Include="SharedROMCache\Chat.gif" />
<Content Include="SharedROMCache\CommunityBanner.gif" />
<Content Include="SharedROMCache\DottedLine.gif" />
<Content Include="SharedROMCache\ExploreTitle.gif" />
<Content Include="SharedROMCache\FileImage.gif" />
<Content Include="SharedROMCache\FileMovie.gif" />
<Content Include="SharedROMCache\FilePackage.gif" />
<Content Include="SharedROMCache\FileSound.gif" />
<Content Include="SharedROMCache\FileText.gif" />
<Content Include="SharedROMCache\HackTVLogoJewel.gif" />
<Content Include="SharedROMCache\help\common\helpMastheadBlank.swf" />
<Content Include="SharedROMCache\HomeBanner.gif" />
<Content Include="SharedROMCache\kb.gif" />
<Content Include="SharedROMCache\kb_alpha.gif" />
<Content Include="SharedROMCache\MSNLogo.gif" />
<Content Include="SharedROMCache\news_icon.gif" />
<Content Include="SharedROMCache\PanelEdge.gif" />
<Content Include="SharedROMCache\PaperBase.gif" />
<Content Include="SharedROMCache\PaperTop.gif" />
<Content Include="SharedROMCache\PaperTopFlat.gif" />
<Content Include="SharedROMCache\PromotionLeftEdge.gif" />
<Content Include="SharedROMCache\RemoveButton.gif" />
<Content Include="SharedROMCache\S20BV1.gif" />
<Content Include="SharedROMCache\S20BV2.gif" />
<Content Include="SharedROMCache\S20TH1.gif" />
<Content Include="SharedROMCache\S20TV1.gif" />
<Content Include="SharedROMCache\S20TV2.gif" />
<Content Include="SharedROMCache\S40H1.gif" />
<Content Include="SharedROMCache\S40V1.gif" />
<Content Include="SharedROMCache\S40V2.gif" />
<Content Include="SharedROMCache\S60HS1.gif" />
<Content Include="SharedROMCache\S60HS2.gif" />
<Content Include="SharedROMCache\S60HS3.gif" />
<Content Include="SharedROMCache\S60HS4.gif" />
<Content Include="SharedROMCache\S60HS5.gif" />
<Content Include="SharedROMCache\SAdH1.gif" />
<Content Include="SharedROMCache\SAdH2.gif" />
<Content Include="SharedROMCache\SAdH3.gif" />
<Content Include="SharedROMCache\SettingsBanner.gif" />
<Content Include="SharedROMCache\Shadow.gif" />
<Content Include="SharedROMCache\ShadowCorner.gif" />
<Content Include="SharedROMCache\ShadowH.gif" />
<Content Include="SharedROMCache\ShadowHCap.gif" />
<Content Include="SharedROMCache\ShadowHStart.gif" />
<Content Include="SharedROMCache\SiteShowcase.gif" />
<Content Include="SharedROMCache\Spacer.gif" />
<Content Include="SharedROMCache\splash_logo_hacktv.gif" />
<Content Include="SharedROMCache\up-arrows.swf" />
<Content Include="SharedROMCache\UsingWebTVBanner.gif" />
<Content Include="SharedROMCache\WebTVLogoJewel.gif" />
<Content Include="test.js" /> <Content Include="test.js" />
<Content Include="WTVBGMusic.js"> <Content Include="WTVBGMusic.js">
<SubType>Code</SubType> <SubType>Code</SubType>
@@ -405,6 +462,9 @@
<Folder Include="ServiceVault\wtv-log\" /> <Folder Include="ServiceVault\wtv-log\" />
<Folder Include="ServiceVault\wtv-disk\content\" /> <Folder Include="ServiceVault\wtv-disk\content\" />
<Folder Include="ServiceVault\wtv-disk\content\diskmaps\" /> <Folder Include="ServiceVault\wtv-disk\content\diskmaps\" />
<Folder Include="SharedROMCache\" />
<Folder Include="SharedROMCache\help\" />
<Folder Include="SharedROMCache\help\common\" />
</ItemGroup> </ItemGroup>
<Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsToolsV2.targets" /> <Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsToolsV2.targets" />
</Project> </Project>