From da37682a032b2a2dd2d108968c92aeb86237d4c2 Mon Sep 17 00:00:00 2001 From: zefie Date: Sun, 8 Aug 2021 18:11:33 -0400 Subject: [PATCH] v0.9.13 - wtv-cookie support - further development will be in dev branch (may rebase alot) - compression not yet ready, leave it disabled --- README.md | 3 +- .../ServiceVault/wtv-cookie/add.js | 2 +- .../ServiceVault/wtv-cookie/get.js | 1 - zefie_wtvp_minisrv/WTVClientSessionData.js | 29 +++++++++++++++---- zefie_wtvp_minisrv/package.json | 2 +- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9efbec10..9d146267 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This open source server is in alpha status. Use at your own risk. - Suports `.js` service files with synchronous or asynchronous requests - Supports multiple simultaneous users - WebTV-compatible HTTP(S) Proxy (via minisrv, or using an external proxy for enhanced features (such as [WebOne](https://github.com/atauenis/webone)) +- WebTV Cookie (wtv-cookie) support for HTTP(s) - Flashrom flashing support for all known units (including bf0app 'Old Classic') - Can flash anything on [Ultra Willies](https://wtv.zefie.com/willie.php) with optional `use_zefie_server` flag set on `wtv-flashrom` service. - `wtv-update:/sync` for Download-o-Rama style file downloading @@ -29,8 +30,8 @@ This open source server is in alpha status. Use at your own risk. ### Feature Todo: - wtv-lzpf support *(Milestone v1.0)* -- wtv-cookie full support *(Milestone v1.1)* - TellyScript generation and/or manipulation without external dependancies +- wtv-cookie full support ***Done [v0.9.13](https://github.com/zefie/zefie_wtvp_minisrv/releases/tag/v0.9.13)*** - ~~Flashrom flashing for bf0app old classic~~ ***Done [v0.9.9](https://github.com/zefie/zefie_wtvp_minisrv/releases/tag/v0.9.9)*** - ~~SSID/IP black/whitelisting (including tying SSID to an IP or multiple IPs)~~ ***Done [v0.9.4](https://github.com/zefie/zefie_wtvp_minisrv/releases/tag/v0.9.4)*** - ~~Flashrom flashing functionality (at least for LC2 and higher)~~ ***Done [v0.8.0](https://github.com/zefie/zefie_wtvp_minisrv/releases/tag/v0.8.0)*** diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/add.js b/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/add.js index 36a46124..80975afb 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/add.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/add.js @@ -1,7 +1,7 @@ if (socket.ssid) { if (request_headers.post_data) { if (ssid_sessions[socket.ssid]) { - ssid_sessions[socket.ssid].addCookie(cookie_data); + ssid_sessions[socket.ssid].addCookie(request_headers.query.domain,request_headers.query.path,request_headers.query.expires,request_headers.query.cookie); headers = "200 OK\n"; headers += "Content-Type: text/html"; } diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/get.js b/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/get.js index 13f6dff5..90f5ad98 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/get.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/get.js @@ -2,7 +2,6 @@ if (request_headers.post_data) { if (request_headers.query.domain && request_headers.query.path) { if (socket.ssid) { if (ssid_sessions[socket.ssid]) { - data = ssid_sessions[socket.ssid].getCookieString(request_headers.query.domain, request_headers.query.path); headers = "200 OK\n"; headers += "Content-Type: text/plain"; diff --git a/zefie_wtvp_minisrv/WTVClientSessionData.js b/zefie_wtvp_minisrv/WTVClientSessionData.js index 55c2c5be..bf1099dd 100644 --- a/zefie_wtvp_minisrv/WTVClientSessionData.js +++ b/zefie_wtvp_minisrv/WTVClientSessionData.js @@ -77,9 +77,23 @@ class WTVClientSessionData { } else { return false; } - } - this.session_store.cookies[this.countCookies()] = Object.assign({}, cookie_data); - this.storeSessionData(); + } + + var self = this; + var cookie_index = -1; + // see if we have a cookie for this domain/path + Object.keys(this.session_store.cookies).forEach(function (k) { + if (cookie_index >= 0) return; + if (domain == self.session_store.cookies[k].domain && path == self.session_store.cookies[k].path) cookie_index = k; + }); + // otherwise add a new one + if (cookie_index == -1) cookie_index = this.countCookies(); + + this.session_store.cookies[cookie_index] = Object.assign({}, cookie_data); + + // do not write file if user is not registered + if (getSessionData('registered')) this.storeSessionData(); + return true; } @@ -92,8 +106,8 @@ class WTVClientSessionData { if (self.session_store['cookies'][k].domain == domain && self.session_store['cookies'][k].path == path) { - var current_epoch_utc = Math.floor(Date.toUTCString().getTime() / 1000); - var cookie_expires_epoch_utc = Math.floor(Date.Parse(self.session_store['cookies'][k].expires).toUTCString().getTime()); + var current_epoch_utc = Date.parse((new Date()).toUTCString()); + var cookie_expires_epoch_utc = Date.parse(new Date(Date.parse(self.session_store['cookies'][k].expires)).toUTCString()); if (cookie_expires_epoch_utc <= current_epoch_utc) self.deleteCookie(self.session_store['cookies'][k]); else result = self.session_store['cookies'][k]; } @@ -103,11 +117,14 @@ class WTVClientSessionData { getCookieString(domain, path) { var cookie_data = this.getCookie(domain, path); - var outstring = ""; + /* + var outstring = ""; Object.keys(cookie_data).forEach(function (k) { outstring += k + "=" + escape(cookie_data[k]) + "&"; }); return outstring.substring(0, outstring.length - 1); + */ + return cookie_data.cookie; } deleteCookie(domain, path = null) { diff --git a/zefie_wtvp_minisrv/package.json b/zefie_wtvp_minisrv/package.json index 295d08ad..6ae035e2 100644 --- a/zefie_wtvp_minisrv/package.json +++ b/zefie_wtvp_minisrv/package.json @@ -1,6 +1,6 @@ { "name": "zefie_wtvp_minisrv", - "version": "0.9.13-dev", + "version": "0.9.13", "description": "WebTV Service (WTVP) Emulation Server", "main": "app.js", "homepage": "https://github.com/zefie/zefie_wtvp_minisrv",