Skip to content

Commit

Permalink
v0.8.0
Browse files Browse the repository at this point in the history
 - FlashROM Support for LC2 and newer.
 - FlashROM system can handle local files, or proxy from server (default). No need to have a local FlashROM collection!
 - Added 'verbosity' configuration option
 - Update HTML Mode to async fileRead
 - Config option for sending tellyscripts or not
 - Config option to mask SSIDs in console log
 - Update wtv-home:/home and wtv-home:/zefie
 - Update .gitignore
 - Add wtv-music:/demo/index courtesy of MattMan69
 - Update HTML Mode to async fileRead
 - Update Raw TXT Mode to async fileRead
 - Replaced .async.js feature with defining `request_is_async` in standard .js script
 - Cleaned up code a bit
 - Moved global var 'query' to 'request_headers.query'
 - Tidied ServiceDeps
 - Upgraded wtv-log:/log to async, now also logs query arguments, saves to .txt for easier reading.
  • Loading branch information
zefie committed Nov 29, 2022
1 parent ccc7951 commit 23d014a
Show file tree
Hide file tree
Showing 160 changed files with 1,413 additions and 378 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ This open source server is in alpha status. Use at your own risk.
- Suports `.async.js` service files with asynchronous requests
- Supports multiple simultaneous users
- WebTV-compatible HTTP Proxy (via minisrv, or using an external proxy for enhanced features (such as [WebOne](https://github.com/atauenis/webone))
- wtv-flashrom for LC2 and newer boxes (bf0app unsupported, need test unit)
- Can flash anything on [Ultra Willies](https://wtv.zefie.com/willie.php) with optional `use_zefie_server` flag set on `wtv-flashrom` service.

### Current issues:
- May not run on non-development Windows machines (VS2019 with nodejs and python)
- Power cycling box and re-connecting via ConnectSetup may invalidate encryption until server is restarted
- wtv-update:/update does not yet function as intended
- wtv-flashrom features do not yet function as intended
- HTTPS Proxying untested, likely needs SSL spoofing with self-signed solution

### Won't fix:
Expand All @@ -26,7 +27,8 @@ This open source server is in alpha status. Use at your own risk.
### Feature Todo:
- ~~(maybe) implement HTTP proxy (needs to be able to defluff most of the web, think retro WAP converter)~~ ***Done***
- ~~(maybe) enable "internet mode" (let user outside of minisrv)~~ ***Done***
- Flashrom flashing functionality (at least for LC2 and higher)
- ~~Flashrom flashing functionality (at least for LC2 and higher)~~ ***Done***
- Flashrom flashing for bf0app old classic (need donor unit)
- SSID/IP black/whitelisting (including tying SSID to an IP or multiple IPs)
- (maybe) Proper wtv-star (generic service outage page) support (maybe useful for allowing a unit to multiple sub-minisrvs).
- (maybe) wtvchat stuff
Expand Down
33 changes: 33 additions & 0 deletions ServiceVault.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Brief ServiceVault Explanation

The server will look for a subdirectory under the running directory, called `ServiceVault` (might be user-configurable in the future).

Within that directory, it looks for a subdirectory named after the wtv-service URL requested.

The server will then look for files in sequential order when requesting a URL, stopping at the first match.

Let us use the URL `wtv-1800:/preregister` as an example. This is what the server would look for (in order):

- `./ServiceVault/wtv-1800/preregister` \[ [Example](zefie_wtvp_minisrv/ServiceVault/wtv-star/images/HackTVLogo.gif) \]
- Exact file name match (*Direct File Mode*)
- Server sends the raw file, with its content-type. No parsing is done on the file.
- You do not need to do anything special with this format.
- `./ServiceVault/wtv-1800/preregister.txt` \[ [Example](zefie_wtvp_minisrv/ServiceVault/wtv-home/splash.txt) \]
- TXT file match (*Raw TXT Mode*)
- Service parses and sends AS-IS.
- You are expected to define headers
- `./ServiceVault/wtv-1800/preregister.js` \[ [Example](zefie_wtvp_minisrv/ServiceVault/wtv-home/home.js) \]
- Synchronous JS match (*JS Interpreter mode*)
- Executes the JavaScript in synchronous mode.
- You are expected to define `headers` and `data` before the end of your script.
- Access Asynchronous mode by setting `request_is_async = true;`
- Client request headers are available as an Array in variable `request_headers`, query arguments are also an Array, in `request_headers.query`
- In Asynchronous mode, you are expected to call `sendToClient(socket,headers,data)` yourself, `socket` is already defined by the time your script runs, so you can just pass it through.
- `./ServiceVault/wtv-1800/preregister.html` \[ [Example](zefie_wtvp_minisrv/ServiceVault/wtv-home/zefie.html) \]
- HTML match (*HTML mode*)
- Like Direct File Mode, but you don't need to append `.html`.
- You do not need to do anything special with this format.

The server will stop at the first result it finds using the order above.

So if you have `preregister.txt` and `preregister.js`, it will use `preregister.txt`, but not `preregister.js`.
1 change: 1 addition & 0 deletions zefie_wtvp_minisrv/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ServiceLogPost/*_*
# Large files not pertaining to the service code
ServiceVault/wtv-flashrom/content/*
ServiceVault/wtv-music/content/*
ServiceVault/wtv-music/midi/*

# User-specific files
*.rsuser
Expand Down
54 changes: 32 additions & 22 deletions zefie_wtvp_minisrv/ServiceVault/wtv-1800/finish-prereg.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
if (socket_session_data[socket.id].ssid != null && !getSessionData(socket_session_data[socket.id].ssid, 'wtvsec_login')) {
var wtvsec_login = new WTVSec();
wtvsec_login.IssueChallenge();
wtvsec_login.set_incarnation(request_headers['wtv-incarnation']);
wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]);
setSessionData(socket_session_data[socket.id].ssid, 'wtvsec_login', wtvsec_login)
} else {
var wtvsec_login = getSessionData(socket_session_data[socket.id].ssid, 'wtvsec_login')
}

var contype = "text/tellyscript";

var skip_tellyscript = false;
var prereg_contype = "text/html";

// if relogin, skip tellyscript
if (query['relogin']) {
contype = "text/html"; // skip tellyscript
if (request_headers.query.relogin) { // skip tellyscript
wtvsec_login.ticket_b64 = null; // clear old ticket
}

// if relogin, skip tellyscript
var romtype, file_path = null;
if (!request_headers.query.relogin && services_configured.config.send_tellyscripts) {
var romtype = getSessionData(socket_session_data[socket.id].ssid, 'wtv-client-rom-type');
}

switch (romtype) {
case "US-LC2-disk-0MB-8MB":
prereg_contype = "text/tellyscript";
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/LC2/LC2_OISP_5555732_56k.tok";
break;

default:
data = '';
break;
}

headers = `200 OK
Connection: Keep-Alive
wtv-initial-key: ` + wtvsec_login.challenge_key.toString(CryptoJS.enc.Base64) + `
Content-Type: `+ contype + `
Content-Type: `+ prereg_contype + `
wtv-service: reset
` + getServiceString('wtv-1800') + `
` + getServiceString('wtv-star') + `
Expand All @@ -30,20 +44,16 @@ 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 relogin, skip tellyscript
var romtype = null;
if (!query['relogin'] && skip_tellyscript == false) {
var romtype = getSessionData(socket_session_data[socket.id].ssid, 'wtv-client-rom-type');
}

switch (romtype) {
case "US-LC2-disk-0MB-8MB":
data = getFile("LC2/LC2_OISP_5555732_56k.tok", true);
break;
wtv-client-date: `+ strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + ` GMT`;

default:
data = '';
break;
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);
});
}
4 changes: 2 additions & 2 deletions zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var gourl = "wtv-1800:/finish-prereg?";
if (query['relogin']) gourl += "relogin=true";
if (request_headers.query.relogin) gourl += "relogin=true";


if (request_headers['wtv-ticket']) {
if (request_headers["wtv-ticket"]) {
gourl = "wtv-head-waiter:/login-stage-two?";
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/get-by-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
request_is_async = true;

var request_path = unescape(request_headers.query.path);
headers = "200 OK\n"

if (request_headers.query.raw) {
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
else headers += "Content-Type: binary/x-wtv-flashblock";
if (services_configured.services[service_name].use_zefie_server) {
// get flashrom files from archive.midnightchannel.net
var options = {
host: "archive.midnightchannel.net",
path: "/zefie/files/wtv-flashrom/" + request_path,
timeout: 5000,
method: 'GET'
}
const req = https.request(options, function (res) {
var data_hex = '';
res.setEncoding('hex');

res.on('data', d => {
data_hex += d;
})

res.on('end', function () {
if (!zquiet) console.log(` * Zefie's FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
if (res.statusCode == 200) {
data = Buffer.from(data_hex, 'hex');
} else if (res.statusCode == 404) {
var errpage = doErrorPage(404, "The service could not find the requested ROM on zefie's server.")
headers = errpage[0];
data = errpage[1];
} else {
var errpage = doErrorPage(400)
headers = errpage[0];
data = errpage[1];
}
sendToClient(socket, headers, data);
});
});
req.end();
} else {
// use local flashrom files);
var flashrom_file_path = service_dir + '/' + request_path;
try {
fs.readFile(flashrom_file_path, null, function (err, data) {
if (err) {
errpage = doErrorPage(400)
headers = errpage[0];
data = err.toString();
}
sendToClient(socket, headers, data);
});
} catch (e) {
var errpage = doErrorPage(404, "The service could not find the requested ROM.")
headers = errpage[0];
data = errpage[1];
sendToClient(socket, headers, data);
}
}
} else {
// no support for bf0app yet, but here we send the client to initiate-lc2-download
// to get the rom image
if (request_headers.query.path) {
headers += "Content-type: text/html\n"
headers += "wtv-visit: wtv-flashrom:/initiate-lc2-download?path=" + request_headers.query.path;
data = '';
} else {
var errpage = doErrorPage(404)
headers = errpage[0];
data = errpage[1];
}
sendToClient(socket, headers, data);
}
Loading

0 comments on commit 23d014a

Please sign in to comment.