add catchall system & http pc server

- define a catchall name to run globally or per service
- catchall must be javascript, but not necessarily a .js file
- catchall can request async mode
- catchall will catch any non-existing requests under its directory
- see wtv-flashrom:/content/content-serve.js as an example, which will catch wtv-flashrom:/content/ URLs.

- http pc: sends HTTP/1.0 to PC clients
- can be disabled with `pc_server_hidden_service_enabled`: false
- can change servicevault path by changing string of pc_server_hidden_service
- get.js in default PC service vault to get any WTV Url on the service
This commit is contained in:
zefie
2021-08-09 17:31:31 -04:00
parent 895397abee
commit 4a2dc1680d
8 changed files with 213 additions and 22 deletions

View File

@@ -0,0 +1,37 @@
if (request_headers.query.url) {
if (request_headers.query.url.indexOf(":/") > 0) {
var service_request = request_headers.query.url.split(":/")[0];
var service_port = 0;
Object.keys(minisrv_config.services).forEach(function (k) {
if (minisrv_config.services[k].disabled) return;
if (k == service_request) service_port = minisrv_config.services[k].port;
});
if (service_port > 0) {
request_is_async = true;
var request_headers_out = new Array()
request_headers_out.request = "GET " + request_headers.query.url;
request_headers_out.request_url = request_headers.query.url;
request_headers_out['wtv-client-serial-number'] = socket.id + "HTTPPCReq";
processURL(socket, request_headers_out);
/*
var s = require('net').Socket();
var outdata = "";
s.connect(service_port);
s.setTimeout(1, function () {
outdata = outdata.split()
sendToClient(socket,outdata);
});
s.on('data', function (data) {
outdata += data;
});
s.write()
*/
}
}
}
if (!headers) {
var errpage = doErrorPage(500)
headers = errpage[0];
data = errpage[1];
}

View File

@@ -0,0 +1,31 @@
headers = `200 OK
Content-Type: text/html`
var splash_logo = minisrv_config.config.service_splash_logo;
if (splash_logo.substring(0, 4) == "file") splash_logo = "wtv-star:/ROMCache/splash_logo_hacktv.gif";
data = `<html>
<head>
<display hideoptions nostatus showwhencomplete skipback clearback fontsize=medium>
<title>zefie minisrv ${minisrv_config.version}</title>
<meta http-equiv=Refresh content="4; url=wtv-home:/home?">
</head>
<body bgcolor="#000000" text="#449944">
<center>
<spacer type=block height=88 width=21>
<img src="/get?url=${escape('wtv-star:/ROMCache/spacer.gif')}" height=4><br>
<img src="/get?url=${escape(splash_logo)}">
<br><br><br>
<p><br>
<p><br>
<table border>
<tr><td width=150>
Mini service
<tr><td>
zefie minisrv v${minisrv_config.version}`;
if (minisrv_config.config.git_commit) data += " (git " + minisrv_config.config.git_commit + ")";
data += `
</table>
</center>
</body>
</html>`;

View File

@@ -0,0 +1,23 @@
const WTVFlashrom = require("./WTVFlashrom.js");
request_is_async = true;
console.log(request_headers);
var bf0app_update = false;
var request_path = request_headers.request_url.replace(service_name + ":/", "");
var romtype = ssid_sessions[socket.ssid].get("wtv-client-rom-type");
var bootver = ssid_sessions[socket.ssid].get("wtv-client-bootrom-version")
if ((romtype == "bf0app" || !romtype) && (bootver == "105" || !bootver)) {
// assume old classic in flash mode, override user setting and send tellyscript
// because it is required to proceed in flash mode
bf0app_update = true;
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
}
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) {
ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server, bf0app_update, minisrv_config.services[service_name].debug);
}
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {
sendToClient(socket, headers, data);
});