fix: app.js: Use \r\n, fix connections= service setting
update: config.json: fix some service flags that were misset
Add ServiceFlags.txt: brief description of wtv-service flags
update: Moved tellyscripts to wtv-1800:/preregister
update: fixed bug where "send_tellyscript was undefined"
update: initial work on bf0app flashrom support (incomplete)
This commit is contained in:
zefie
2021-07-29 09:06:42 -04:00
parent fd8d7e2d2e
commit 150f0253b8
11 changed files with 210 additions and 111 deletions

16
ServiceFlags.txt Normal file
View File

@@ -0,0 +1,16 @@
wtv service flags:
DontEncryptRequests (Do not encrypt requests from client -> server)
UseHTTP (Instead of WTVP)
WideOpen (Allow untrusted links to this service)
UseServiceCookies (Pass service cookie to this service)
NoMeter (Dont meter this service)
0x00000001 = DontEncryptRequests
0x00000002 = UseHTTP (untested)
0x00000004 = WideOpen
0x00000007 = DontEncryptRequests + WideOpen + UseHTTP
0x00000010 = UseServiceCookies
0x00000040 = NoMeter
Note:
Service Cookies and Metering are not implemented in minisrv.

View File

@@ -1,78 +0,0 @@
if (socket.ssid != null) {
if (!ssid_sessions[socket.ssid].data_store.wtvsec_login) {
ssid_sessions[socket.ssid].data_store.wtvsec_login = new WTVSec();
ssid_sessions[socket.ssid].data_store.wtvsec_login.IssueChallenge();
ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]);
}
} else {
console.log(" * Something bad happened (we don't know the client ssid???)");
var errpage = doErrorCode(400)
headers = errpage[0];
data = errpage[1];
}
if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
var prereg_contype = "text/html";
if (request_headers.query.relogin) { // relogin
ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64 = null; // clear old ticket
}
// if relogin and wtv-script-id != 0, skip tellyscript
var romtype, file_path = null;
var send_tellyscript = true;
var wtv_script_id = parseInt(ssid_sessions[socket.ssid].get("wtv-script-id"));
if (request_headers.query.relogin && wtv_script_id != 0) send_tellyscript = false;
if (send_tellyscript && minisrv_config.services[service_name].send_tellyscripts) {
if (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist) {
var send_telly_to_ssid = (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist.findIndex(element => element == socket.ssid) != -1)
if (send_telly_to_ssid) romtype = ssid_sessions[socket.ssid].get("wtv-client-rom-type");
} else {
romtype = ssid_sessions[socket.ssid].get("wtv-client-rom-type");
}
}
switch (romtype) {
case "US-LC2-disk-0MB-8MB":
prereg_contype = "text/tellyscript";
// if wtv-open-access: true then client expects OpenISP
if (ssid_sessions[socket.ssid].get("wtv-open-access") == "true") var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/LC2/LC2_OISP_5555732_56k.tok";
else var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/LC2/LC2_WTV_18006138199_56k.tok";
break;
default:
data = '';
break;
}
headers = `200 OK
Connection: Keep-Alive
wtv-initial-key: ` + ssid_sessions[socket.ssid].data_store.wtvsec_login.challenge_key.toString(CryptoJS.enc.Base64) + `
Content-Type: `+ prereg_contype + `
wtv-service: reset
` + getServiceString('wtv-1800') + `
` + getServiceString('wtv-star') + `
` + getServiceString('wtv-head-waiter') + `
` + getServiceString('wtv-flashrom') + `
wtv-boot-url: wtv-1800:/preregister?relogin=true
wtv-visit: wtv-head-waiter:/login?
wtv-client-time-zone: GMT -0000
wtv-client-time-dst-rule: GMT
wtv-client-date: `+ strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + ` GMT`;
if (file_path) {
request_is_async = true;
fs.readFile(file_path, null, function (err, file_read_data) {
if (err) {
var errmsg = doErrorCode(400);
headers = errmsg[0];
file_read_data = errmsg[1] + "\n" + err.toString();
}
sendToClient(socket, headers, file_read_data);
});
}
} else {
var errpage = doErrorCode(400);
headers = errpage[0];
data = errpage[1];
}

View File

@@ -0,0 +1,49 @@
if (socket.ssid != null && !ssid_sessions[socket.ssid].get("wtvsec_login")) {
var wtvsec_login = new WTVSec();
wtvsec_login.IssueChallenge();
wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]);
ssid_sessions[socket.ssid].set("wtvsec_login", wtvsec_login);
} else if (socket.ssid != null) {
var wtvsec_login = ssid_sessions[socket.ssid].get("wtvsec_login");
}
if (wtvsec_login) {
headers = `200 OK
Connection: Keep-Alive
wtv-initial-key: ` + wtvsec_login.challenge_key.toString(CryptoJS.enc.Base64) + `
Content-Type: text/tellyscript
wtv-service: reset
` + getServiceString('wtv-head-waiter') + `
` + getServiceString('wtv-star') + `
` + getServiceString('wtv-flashrom') + `
wtv-boot-url: wtv-head-waiter:/login?
wtv-visit: wtv-head-waiter:/login?
wtv-client-time-zone: GMT -0000
wtv-client-time-dst-rule: GMT
wtv-client-date: `+ strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + ` GMT`;
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/bf0app/bf0app_production_braindead";
//var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/LC2/LC2_OISP_5555732_56k.tok";
if (file_path) {
request_is_async = true;
fs.readFile(file_path, null, function (err, file_read_data) {
if (err) {
headers=`500 Some error occurred...`
}
sendToClient(socket, headers, file_read_data);
});
}
} else {
console.log(" * Something bad happened (we don't know the client ssid???)");
headers=`500 missing ssid`
}

View File

@@ -1,10 +1,6 @@
var gourl = "wtv-1800:/finish-prereg?";
var gourl = "wtv-head-waiter:/login?";
if (request_headers.query.relogin) gourl += "relogin=true";
if (request_headers["wtv-ticket"]) {
gourl = "wtv-head-waiter:/login-stage-two?";
}
var send_initial_key = true;
if (socket.ssid) {
if (ssid_sessions[socket.ssid].data_store) {
@@ -19,17 +15,132 @@ if (socket.ssid) {
}
}
});
if (i > 0 && zdebug) console.log(" # Closed", i, "previous sockets for", socket.ssid);
if (i > 0 && zdebug) console.log(" # Closed", i, "previous sockets for", filterSSID(socket.ssid));
}
}
if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
delete ssid_sessions[socket.ssid].data_store.wtvsec_login;
}
ssid_sessions[socket.ssid].data_store.wtvsec_login = new WTVSec();
ssid_sessions[socket.ssid].data_store.wtvsec_login.IssueChallenge();
ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]);
} else {
console.log(" * Something bad happened (we don't know the client ssid???)");
var errpage = doErrorCode(400)
headers = errpage[0];
data = errpage[1];
}
headers = `200 OK
Connection: Keep-Alive
wtv-expire-all: wtv-
wtv-open-isp-disabled: false
wtv-visit: `+ gourl + `
Content-type: text/html`;
if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
var prereg_contype = "text/html";
if (request_headers.query.relogin) { // relogin
ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64 = null; // clear old ticket
}
// if relogin and wtv-script-id != 0, skip tellyscript
var file_path = null;
var bf0app_update = false;
var romtype = ssid_sessions[socket.ssid].get("wtv-client-rom-type");
var send_tellyscripts = (minisrv_config.services[service_name].send_tellyscripts && !request_headers.query.relogin);
var wtv_script_id = parseInt(ssid_sessions[socket.ssid].get("wtv-script-id"));
var bootrom = ssid_sessions[socket.ssid].get("wtv-client-bootrom-version");
if (request_headers.query.relogin && wtv_script_id != 0) send_tellyscript = false;
if (send_tellyscripts) {
if (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist) {
var send_telly_to_ssid = (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist.findIndex(element => element == socket.ssid) != -1)
if (send_telly_to_ssid) {
romtype = ssid_sessions[socket.ssid].get("wtv-client-rom-type");
}
} else {
romtype = ssid_sessions[socket.ssid].get("wtv-client-rom-type");
}
switch (romtype) {
case "US-LC2-disk-0MB-8MB":
prereg_contype = "text/tellyscript";
// if wtv-open-access: true then client expects OpenISP
if (ssid_sessions[socket.ssid].get("wtv-open-access") == "true") var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/LC2/LC2_OISP_5555732_56k.tok";
else var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/LC2/lc2_production_normal.tok";
break;
case "US-LC2-disk-0MB-8MB-softmodem-CPU5230":
prereg_contype = "text/tellyscript";
// if wtv-open-access: true then client expects OpenISP
if (ssid_sessions[socket.ssid].get("wtv-open-access") == "true") var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/DERBY/derby_production_normal.tok";
else var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/DERBY/derby_production_normal.tok";
break;
case "US-WEBSTAR-disk-0MB-16MB-softmodem-CPU5230":
prereg_contype = "text/tellyscript";
// if wtv-open-access: true then client expects OpenISP
if (ssid_sessions[socket.ssid].get("wtv-open-access") == "true") var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/WEBSTAR/dishplayer_production_normal.tok";
else var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/WEBSTAR/dishplayer_production_normal.tok";
break;
case "JP-Fiji":
prereg_contype = "text/tellyscript";
// if wtv-open-access: true then client expects OpenISP
if (ssid_sessions[socket.ssid].get("wtv-open-access") == "true") var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/DC/dc_production_normal.tok";
else var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/DC/dc_production_normal.tok";
break;
case "bf0app":
prereg_contype = "text/tellyscript";
// if wtv-open-access: true then client expects OpenISP
if (ssid_sessions[socket.ssid].get("wtv-open-access") == "true") var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/BF0APP/bf0app_production_braindead.tok";
else var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/BF0APP/bf0app_production_braindead.tok";
break;
default:
data = '';
break;
}
}
if (!request_headers['wtv-client-rom-type'] && bootrom == "105") {
// assume old classic in flash mode, override user setting and send tellyscript
// because it is required to proceed in flash mode
prereg_contype = "text/tellyscript";
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/bf0app/bf0app_production_braindead.tok";
bf0app_update = true;
}
if (request_headers["wtv-ticket"]) {
gourl = "wtv-head-waiter:/login-stage-two?relogin=true";
send_initial_key = false;
}
headers = "200 OK\n"
headers += "Connection: Keep-Alive\n";
if (send_initial_key) headers += "wtv-initial-key: " + ssid_sessions[socket.ssid].data_store.wtvsec_login.challenge_key.toString(CryptoJS.enc.Base64) + "\n";
headers += "Content-Type: " + prereg_contype + "\n";
headers += "wtv-service: reset\n";
headers += getServiceString('wtv-1800') + "\n";
headers += getServiceString('wtv-star') + "\n";
if (!bf0app_update) headers += getServiceString('wtv-head-waiter') + "\n";
headers += getServiceString('wtv-flashrom') + "\n";
if (!bf0app_update) headers += "wtv-boot-url: wtv-1800:/preregister?relogin=true\n"
if (!bf0app_update) headers += "wtv-open-isp-disabled: false\n";
if (!bf0app_update) headers += "wtv-visit: "+gourl+"\n";
if (!bf0app_update) headers += "wtv-client-time-zone: GMT -0000\n";
if (!bf0app_update) headers += "wtv-client-time-dst-rule: GMT\n"
if (!bf0app_update) headers += "wtv-client-date: " + strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + " GMT";
if (file_path) {
request_is_async = true;
fs.readFile(file_path, null, function (err, file_read_data) {
if (err) {
var errmsg = doErrorCode(400);
headers = errmsg[0];
file_read_data = errmsg[1] + "\n" + err.toString();
}
sendToClient(socket, headers, file_read_data);
});
}
} else {
var errpage = doErrorCode(400);
headers = errpage[0];
data = errpage[1];
}

View File

@@ -22,8 +22,9 @@ function doLocalFlashROM(flashrom_file_path) {
}
}
var romtype = ssid_sessions[socket.ssid].get("wtv-client-rom-type");
if (request_headers.query.raw) {
if (request_headers.query.raw || romtype == "bf0app") {
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
else headers += "Content-Type: binary/x-wtv-flashblock";
var flashrom_file_path = null;

View File

@@ -1,7 +1,12 @@
if (request_headers.query.path) {
var url = "wtv-flashrom:/get-lc2-page?path=" + request_headers.query.path;
var romtype = ssid_sessions[socket.ssid].get("wtv-client-rom-type");
if (romtype == "bf0app") {
url = "client:updateflash?ipaddr="+minisrv_config.services[service_name].host+"&port="+minisrv_config.services[service_name].port+"&path=" + request_headers.query.path;
}
headers = "300 OK\n";
headers += "wtv-visit: wtv-flashrom:/get-lc2-page?path=" + request_headers.query.path + "\n";
headers += "Location: wtv-flashrom:/get-lc2-page?path=" + request_headers.query.path + "\n";
headers += "wtv-visit: " + url + "\n";
headers += "Location: " + url + "\n";
headers += "Content-type: text/html";
data = '';
} else {

View File

@@ -494,9 +494,9 @@ async function sendToClient(socket, headers_obj, data) {
} else {
if (k.indexOf('_') >= 0) {
var j = k.split('_')[0];
headers += j + ": " + headers_obj[k] + "\n";
headers += j + ": " + headers_obj[k] + "\r\n";
} else {
headers += k + ": " + headers_obj[k] + "\n";
headers += k + ": " + headers_obj[k] + "\r\n";
}
}
});
@@ -505,17 +505,17 @@ async function sendToClient(socket, headers_obj, data) {
// send to client
var toClient = null;
if (typeof data == 'string') {
toClient = headers + "\n" + data;
toClient = headers + "\r\n" + data;
socket.write(toClient);
} else if (typeof data == 'object') {
if (zquiet) var verbosity_mod = (headers_obj["wtv-encrypted"] == 'true') ? " encrypted response" : "";
if (socket_sessions[socket.id].secure_headers == true) {
// encrypt headers
if (zquiet)verbosity_mod += " with encrypted headers";
var enc_headers = socket_sessions[socket.id].wtvsec.Encrypt(1, headers + "\n");
var enc_headers = socket_sessions[socket.id].wtvsec.Encrypt(1, headers + "\r\n");
socket.write(new Uint8Array(concatArrayBuffer(enc_headers, data)));
} else {
socket.write(new Uint8Array(concatArrayBuffer(Buffer.from(headers + "\n"), data)));
socket.write(new Uint8Array(concatArrayBuffer(Buffer.from(headers + "\r\n"), data)));
}
if (zquiet) console.log(" * Sent" + verbosity_mod + " " + headers_obj.http_response + " to client (Content-Type:", headers_obj['Content-Type'], "~", headers_obj['Content-Length'], "bytes)");
}
@@ -1221,11 +1221,11 @@ Object.keys(minisrv_config.services).forEach(function (k) {
minisrv_config.services[k].toString = function () {
var outstr = "wtv-service: name=" + this.name + " host=" + this.host + " port=" + this.port;
if (this.flags) outstr += " flags=" + this.flags;
if (this.connections) outstr += " flags=" + this.connections;
if (this.connections) outstr += " connections=" + this.connections;
if (k == "wtv-star") {
outstr += "\nwtv-service: name=wtv-* host=" + this.host + " port=" + this.port;
if (this.flags) outstr += " flags=" + this.flags;
if (this.connections) outstr += " flags=" + this.connections;
if (this.connections) outstr += " connections=" + this.connections;
}
return outstr;
}

View File

@@ -17,6 +17,7 @@
"wtv-1800": {
"port": 1615,
"connections": 1,
"flags": "0x00000004",
"send_tellyscripts": false
},
"wtv-star": {
@@ -25,12 +26,10 @@
},
"wtv-head-waiter": {
"port": 1601,
"flags": "0x00000001",
"connections": 1
},
"wtv-update": {
"port": 1619,
"flags": "0x04",
"port": 1635,
"connections": 3
},
"wtv-log": {
@@ -39,8 +38,7 @@
"write_logs_to_disk": false
},
"wtv-home": {
"port": 1612,
"flags": "0x00000010"
"port": 1612
},
"wtv-tricks": {
"port": 1602,
@@ -53,7 +51,6 @@
},
"wtv-music": {
"port": 1656,
"flags": "0x04",
"connections": 3
},
"wtv-setup": {
@@ -63,8 +60,7 @@
},
"wtv-chat": {
"port": 1630,
"connections": 3,
"flags": "0x00000010"
"connections": 3
},
"http": {
"port": 1650,

View File

@@ -1,6 +1,6 @@
{
"name": "zefie_wtvp_minisrv",
"version": "0.9.7",
"version": "0.9.8",
"description": "WebTV Service (WTVP) Emulation Server",
"main": "app.js",
"homepage": "https://github.com/zefie/zefie_wtvp_minisrv",

View File

@@ -200,7 +200,6 @@
<Content Include="ServiceVault\wtv-update\DealerDemo.js" />
<Content Include="ServiceVault\wtv-home\home.js" />
<Content Include="ServiceVault\wtv-update\updatesuccess.txt" />
<Content Include="ServiceVault\wtv-1800\finish-prereg.js" />
<Content Include="ServiceVault\wtv-1800\preregister.js" />
<Content Include="ServiceVault\wtv-head-waiter\finalize-security.js" />
<Content Include="ServiceVault\wtv-head-waiter\login-stage-two.js" />